/** * Changes the lock of a resource to the current user, * that is "steals" the lock from another user.<p> * * This is the "steal lock" operation.<p> * * @param resourcename the name of the resource to change the lock with complete path * * @throws CmsException if something goes wrong */ public void changeLock(String resourcename) throws CmsException { CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); changeLock(resource); }
/** * @see org.opencms.ui.actions.I_CmsWorkplaceAction#executeAction(org.opencms.ui.I_CmsDialogContext) */ public void executeAction(I_CmsDialogContext context) { CmsObject cms = A_CmsUI.getCmsObject(); List<CmsUUID> changedIds = Lists.newArrayList(); for (CmsResource res : context.getResources()) { try { cms.changeLock(res); changedIds.add(res.getStructureId()); } catch (CmsException e) { LOG.warn(e.getLocalizedMessage(), e); } } context.finish(changedIds); }
/** * Contains the visibility handler configuration for a content field path.<p> */ protected static class VisibilityConfiguration { /** The handler instance. */ private I_CmsXmlContentVisibilityHandler m_handler; /** The handler configuration parameters. */ private String m_params; /** * Constructor.<p> * * @param handler the handler instance * @param params the handler configuration parameteres */ protected VisibilityConfiguration(I_CmsXmlContentVisibilityHandler handler, String params) { m_handler = handler; m_params = params; } /** * Returns the visibility handler instance.<p> * * @return the handler instance */ public I_CmsXmlContentVisibilityHandler getHandler() {
/** * Locks the given resource.<p> * * @param cms the cms context * @param resource the resource to lock * * @throws CmsException in case locking fails */ private static void ensureLock(CmsObject cms, CmsResource resource) throws CmsException { CmsUser user = cms.getRequestContext().getCurrentUser(); CmsLock lock = cms.getLock(resource); if (!lock.isOwnedBy(user)) { cms.lockResourceTemporary(resource); } else if (!lock.isOwnedInProjectBy(user, cms.getRequestContext().getCurrentProject())) { cms.changeLock(resource); } }
/** * Deletes the given resource which is part of a form session project.<p> * * @param cms the CMS context to use * @param res the resource to delete * * @throws CmsException if something goes wrong */ private void deleteResourceFromProject(CmsObject cms, CmsResource res) throws CmsException { CmsLock lock = cms.getLock(res); if (lock.isUnlocked() || lock.isLockableBy(cms.getRequestContext().getCurrentUser())) { cms.lockResourceTemporary(res); } else { cms.changeLock(res); } cms.deleteResource(cms.getSitePath(res), CmsResource.DELETE_PRESERVE_SIBLINGS); }
/** * Locks the given resource temporarily.<p> * * @param resource the resource to lock * * @throws CmsException if locking fails */ private void lockTemporary(CmsResource resource) throws CmsException { CmsObject cms = getCms(); CmsUser user = cms.getRequestContext().getCurrentUser(); CmsLock lock = cms.getLock(resource); if (!lock.isOwnedBy(user)) { cms.lockResourceTemporary(resource); } else if (!lock.isOwnedInProjectBy(user, cms.getRequestContext().getCurrentProject())) { cms.changeLock(resource); } } }
/** * Deletes the category identified by the given path.<p> * * Only the most global category matching the given category path for the * given resource will be affected.<p> * * This method will try to lock the involved resource.<p> * * @param cms the current cms context * @param categoryPath the path of the category to delete * @param referencePath the reference path to find the category repositories * * @throws CmsException if something goes wrong */ public void deleteCategory(CmsObject cms, String categoryPath, String referencePath) throws CmsException { CmsCategory category = readCategory(cms, categoryPath, referencePath); String folderPath = cms.getRequestContext().removeSiteRoot(category.getRootPath()); CmsLock lock = cms.getLock(folderPath); if (lock.isNullLock()) { cms.lockResource(folderPath); } else if (lock.isLockableBy(cms.getRequestContext().getCurrentUser())) { cms.changeLock(folderPath); } cms.deleteResource(folderPath, CmsResource.DELETE_PRESERVE_SIBLINGS); }
/** * Deletes the category identified by the given path.<p> * * Only the most global category matching the given category path for the * given resource will be affected.<p> * * This method will try to lock the involved resource.<p> * * @param cms the current cms context * @param categoryPath the path of the category to delete * @param referencePath the reference path to find the category repositories * * @throws CmsException if something goes wrong */ public void deleteCategory(CmsObject cms, String categoryPath, String referencePath) throws CmsException { CmsCategory category = readCategory(cms, categoryPath, referencePath); String folderPath = cms.getRequestContext().removeSiteRoot(category.getRootPath()); CmsLock lock = cms.getLock(folderPath); if (lock.isNullLock()) { cms.lockResource(folderPath); } else if (lock.isLockableBy(cms.getRequestContext().currentUser())) { cms.changeLock(folderPath); } cms.deleteResource(folderPath, CmsResource.DELETE_PRESERVE_SIBLINGS); }
/** * Ensures that the resources to be released are unlocked.<p> * * @param project the project in which to operate * @param resources the resources for which the locks should be removed * * @throws CmsException if something goes wrong */ protected void clearLocks(CmsProject project, List<CmsResource> resources) throws CmsException { CmsObject rootCms = OpenCms.initCmsObject(m_adminCms); rootCms.getRequestContext().setCurrentProject(project); rootCms.getRequestContext().setSiteRoot(""); for (CmsResource resource : resources) { CmsLock lock = rootCms.getLock(resource); if (lock.isUnlocked()) { continue; } String currentPath = resource.getRootPath(); while (lock.isInherited()) { currentPath = CmsResource.getParentFolder(currentPath); lock = rootCms.getLock(currentPath); } rootCms.changeLock(currentPath); rootCms.unlockResource(currentPath); } }
/** * @see org.opencms.gwt.shared.rpc.I_CmsVfsService#forceUnlock(org.opencms.util.CmsUUID) */ public void forceUnlock(CmsUUID structureId) throws CmsRpcException { try { CmsResource resource = getCmsObject().readResource(structureId, CmsResourceFilter.ALL); // get the current lock CmsLock currentLock = getCmsObject().getLock(resource); // check if the resource is locked at all if (currentLock.getEditionLock().isUnlocked() && currentLock.getSystemLock().isUnlocked()) { getCmsObject().lockResourceTemporary(resource); } else { getCmsObject().changeLock(resource); } getCmsObject().unlockResource(resource); } catch (Throwable e) { error(e); } }
lock = cms.getLock(resource); } else if (!lock.isOwnedInProjectBy(user, cms.getRequestContext().getCurrentProject())) { cms.changeLock(resource); change = LockChange.changed; lock = cms.getLock(resource);
/** * Adds the given resource to the temporary project.<p> * * @param adminCms the admin cms context * @param userCms the user cms context * @param resource the resource * @param tmpProject the temporary project * @throws CmsException in case something goes wrong */ private void addToTempProject(CmsObject adminCms, CmsObject userCms, CmsResource resource, CmsProject tmpProject) throws CmsException { // copy the resource to the project adminCms.copyResourceToProject(resource); // lock the resource in the current project CmsLock lock = userCms.getLock(resource); // prove is current lock from current but not in current project if ((lock != null) && lock.isOwnedBy(userCms.getRequestContext().getCurrentUser()) && !lock.isOwnedInProjectBy( userCms.getRequestContext().getCurrentUser(), userCms.getRequestContext().getCurrentProject())) { // file is locked by current user but not in current project // change the lock from this file userCms.changeLock(resource); } // lock resource from current user in current project userCms.lockResource(resource); // get current lock lock = userCms.getLock(resource); }
justLocked = true; } else if (!lock.isOwnedInProjectBy(user, cms.getRequestContext().getCurrentProject())) { cms.changeLock(resource); lock = cms.getLock(resource); justLocked = true;
offlineAdminCms.lockResource(resource); } else if (!lock.isOwnedBy(admin)) { offlineAdminCms.changeLock(resource);
/** * Renames/Moves a category from the old path to the new one.<p> * * This method will keep all categories in their original repository.<p> * * @param cms the current cms context * @param oldCatPath the path of the category to move * @param newCatPath the new category path * @param referencePath the reference path to find the category * * @throws CmsException if something goes wrong */ public void moveCategory(CmsObject cms, String oldCatPath, String newCatPath, String referencePath) throws CmsException { CmsCategory category = readCategory(cms, oldCatPath, referencePath); String catPath = cms.getRequestContext().removeSiteRoot(category.getRootPath()); CmsLock lock = cms.getLock(catPath); if (lock.isNullLock()) { cms.lockResource(catPath); } else if (lock.isLockableBy(cms.getRequestContext().currentUser())) { cms.changeLock(catPath); } cms.moveResource(catPath, cms.getRequestContext().removeSiteRoot( internalCategoryRootPath(category.getBasePath(), newCatPath))); }
getCms().lockResource(originalResourceName); } else if (!lock.isDirectlyOwnedInProjectBy(getCms())) { getCms().changeLock(resourceName);
/** * Recursively steps up to the resource that is the originator of the given * resource which has an inherited lock.<p> * * @param absoluteResourcename the absolute resource with the inherited lock * * @throws CmsException if something goes wrong */ private void unlockInherited(final String absoluteResourcename) throws CmsException { CmsObject cms = getCms(); CmsLock parentLock = getParentLock(absoluteResourcename); if (!parentLock.isNullLock()) { if (parentLock.isInherited()) { unlockInherited(parentLock.getResourceName()); } else { if (!parentLock.isLockableBy(cms.getRequestContext().getCurrentUser())) { cms.changeLock(cms.getRequestContext().removeSiteRoot(parentLock.getResourceName())); } cms.unlockResource(cms.getRequestContext().removeSiteRoot(parentLock.getResourceName())); } } } }
/** * Renames/Moves a category from the old path to the new one.<p> * * This method will keep all categories in their original repository.<p> * * @param cms the current cms context * @param oldCatPath the path of the category to move * @param newCatPath the new category path * @param referencePath the reference path to find the category * * @throws CmsException if something goes wrong */ public void moveCategory(CmsObject cms, String oldCatPath, String newCatPath, String referencePath) throws CmsException { CmsCategory category = readCategory(cms, oldCatPath, referencePath); String catPath = cms.getRequestContext().removeSiteRoot(category.getRootPath()); CmsLock lock = cms.getLock(catPath); if (lock.isNullLock()) { cms.lockResource(catPath); } else if (lock.isLockableBy(cms.getRequestContext().getCurrentUser())) { cms.changeLock(catPath); } cms.moveResource( catPath, cms.getRequestContext().removeSiteRoot(internalCategoryRootPath(category.getBasePath(), newCatPath))); }
/** * Finishes the session and publishes the changed resources if necessary.<p> * * @throws CmsException if something goes wrong */ public void finish() throws CmsException { m_finished = true; m_requiresCleanup = false; CmsProject project = getProject(); CmsObject projectCms = OpenCms.initCmsObject(m_adminCms); projectCms.getRequestContext().setCurrentProject(project); if (m_configuration.isAutoPublish()) { // we don't necessarily publish with the user who has the locks on the resources, so we need to steal the locks List<CmsResource> projectResources = projectCms.readProjectView(project.getUuid(), CmsResource.STATE_KEEP); for (CmsResource projectResource : projectResources) { CmsLock lock = projectCms.getLock(projectResource); if (!lock.isUnlocked() && !lock.isLockableBy(projectCms.getRequestContext().getCurrentUser())) { projectCms.changeLock(projectResource); } } OpenCms.getPublishManager().publishProject( projectCms, new CmsLogReport(Locale.ENGLISH, CmsUgcSession.class)); } else { // try to unlock everything - we don't need this in case of auto-publish, since publishing already unlocks the resources projectCms.unlockProject(project.getUuid()); } }
} else if (!lock.isExclusiveOwnedBy(getCms().getRequestContext().currentUser()) || !lock.isInProject(getCms().getRequestContext().currentProject())) { getCms().changeLock(resourceName);