/** * Returns <code>true</code> if this lock is the <code>NULL</code> lock which can * be obtained by {@link #getNullLock()}.<p> * * Only for the <code>NULL</code> lock, {@link #isUnlocked()} is <code>true</code>.<p> * * @return <code>true</code> if this lock is the <code>NULL</code> lock */ public boolean isNullLock() { return isUnlocked(); }
/** * Returns <code>true</code> if this lock is the <code>NULL</code> lock which can * be obtained by {@link #getNullLock()}.<p> * * Only for the <code>NULL</code> lock, {@link #isUnlocked()} is <code>true</code>.<p> * * @return <code>true</code> if this lock is the <code>NULL</code> lock */ public boolean isNullLock() { return isUnlocked(); }
/** * Sets the related Lock.<p> * * @param relatedLock the related Lock to set */ protected void setRelatedLock(CmsLock relatedLock) { if (this == NULL_LOCK) { throw new RuntimeException("null lock"); } if ((relatedLock == null) || relatedLock.isUnlocked()) { m_relatedLock = null; } else { m_relatedLock = relatedLock; m_relatedLock.m_relatedLock = this; } } }
/** * Sets the related Lock.<p> * * @param relatedLock the related Lock to set */ protected void setRelatedLock(CmsLock relatedLock) { if (this == NULL_LOCK) { throw new RuntimeException("null lock"); } if ((relatedLock == null) || relatedLock.isUnlocked()) { m_relatedLock = null; } else { m_relatedLock = relatedLock; m_relatedLock.m_relatedLock = this; } } }
/** * Returns the start HTML for a disabled direct edit button.<p> * * @param params the direct edit parameters * @param resourceInfo contains information about the resource to edit * * @return the start HTML for a disabled direct edit button */ public String startDirectEditDisabled(CmsDirectEditParams params, CmsDirectEditResourceInfo resourceInfo) { StringBuffer result = new StringBuffer(256); result.append("<!-- EDIT BLOCK START (DISABLED): "); result.append(params.m_resourceName); result.append(" ["); result.append(resourceInfo.getResource().getState()); result.append("] "); if (!resourceInfo.getLock().isUnlocked()) { result.append(" locked "); result.append(resourceInfo.getLock().getProject().getName()); } result.append(" -->\n"); return result.toString(); }
/** * Returns the lock of a possible locked parent folder of a resource, system locks are ignored.<p> * * @param resourceName the name of the resource * * @return the lock of a parent folder, or {@link CmsLock#getNullLock()} if no parent folders are locked by a non system lock */ private CmsLock getParentFolderLock(String resourceName) { Iterator itLocks = OpenCms.getMemoryMonitor().getAllCachedLocks().iterator(); while (itLocks.hasNext()) { CmsLock lock = (CmsLock)itLocks.next(); if (lock.getResourceName().endsWith("/") && resourceName.startsWith(lock.getResourceName()) && !resourceName.equals(lock.getResourceName())) { // system locks does not get inherited lock = lock.getEditionLock(); // check the lock if (!lock.isUnlocked()) { return lock; } } } return CmsLock.getNullLock(); }
/** * Checks if a resource can be locked by a user.<p> * * The resource is not lockable if it already has a lock of type {@link CmsLockType#PUBLISH}.<p> * * The resource is lockable either * - if it is currently unlocked * - if it has a lock of another type set and the user is the lock owner * * @param user the user to test lockeability for * * @return <code>true</code> if this lock blocks any operation on the locked resource until it is unlocked */ public boolean isLockableBy(CmsUser user) { if (getSystemLock().isPublish()) { return false; } if (getEditionLock().isUnlocked() && getSystemLock().isUnlocked()) { return true; } return getEditionLock().isOwnedBy(user); }
/** * Checks if a resource can be locked by a user.<p> * * The resource is not lockable if it already has a lock of type {@link CmsLockType#PUBLISH}.<p> * * The resource is lockable either * - if it is currently unlocked * - if it has a lock of another type set and the user is the lock owner * * @param user the user to test lockeability for * * @return <code>true</code> if this lock blocks any operation on the locked resource until it is unlocked */ public boolean isLockableBy(CmsUser user) { if (getSystemLock().isPublish()) { return false; } if (getEditionLock().isUnlocked() && getSystemLock().isUnlocked()) { return true; } return getEditionLock().isOwnedBy(user); }
/** * Tries to to touch a resource by setting its last modification date, but only if its state is 'unchanged'.<p> * * @param cms the current CMS context * @param resource the resource which should be 'touched'. */ private void touch(CmsObject cms, CmsResource resource) { if (resource.getState().isUnchanged()) { try { CmsLock lock = cms.getLock(resource); if (lock.isUnlocked() || !lock.isOwnedBy(cms.getRequestContext().getCurrentUser())) { cms.lockResourceTemporary(resource); long now = System.currentTimeMillis(); resource.setDateLastModified(now); cms.writeResource(resource); if (lock.isUnlocked()) { cms.unlockResource(resource); } } } catch (CmsException e) { LOG.warn("Could not touch resource after alias modification: " + resource.getRootPath(), e); } } }
/** * Checks that the resource is not locked by another user.<p> * * @param resource the resource * @return true if the resource is not locked by another user * * @throws CmsException if something goes wrong */ private boolean checkLock(CmsResource resource) throws CmsException { CmsLock lock = m_cms.getLock(resource); return lock.isUnlocked() || lock.getUserId().equals(m_cms.getRequestContext().getCurrentUser().getId()); }
/** * Make sure that this resource is locked.<p> * * @throws CmsException if something goes wrong */ protected void ensureLock() throws CmsException { CmsLock lock = m_cms.getLock(m_resource); if (lock.isUnlocked() || !lock.isLockableBy(m_cms.getRequestContext().getCurrentUser())) { m_cms.lockResourceTemporary(m_cms.getSitePath(m_resource)); } }
/** * Returns the id of the project which the resource belongs to.<p> * * @return the id of the project which the resource belongs to */ public CmsUUID getProjectId() { CmsUUID projectId = m_resource.getProjectLastModified(); if (!getLock().isUnlocked() && !getLock().isInherited()) { // use lock project ID only if lock is not inherited projectId = getLock().getProjectId(); } return projectId; }
/** * Returns the id of the project which the resource belongs to.<p> * * @return the id of the project which the resource belongs to */ public CmsUUID getProjectId() { CmsUUID projectId = m_resource.getProjectLastModified(); if (!getLock().isUnlocked() && !getLock().isInherited()) { // use lock project ID only if lock is not inherited projectId = getLock().getProjectId(); } return projectId; }
/** * @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); } }
/** * 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); }
/** * Enumeration class for the mode parameter in the * {@link CmsDriverManager#readChangedResourcesInsideProject(CmsDbContext, CmsUUID, CmsReadChangedProjectResourceMode)} * method.<p> */ private static class CmsReadChangedProjectResourceMode { /** * Default constructor.<p> */ protected CmsReadChangedProjectResourceMode() { // noop } }
/** * Writes a sitemap configuration back to the VFS.<p> * * @param content the content to write * @param sitemapConfigFile the file to which the sitemap config should be written * * @throws CmsXmlException if an XML processing error occurs * @throws CmsException if something goes wrong */ private void writeSitemapConfig(CmsXmlContent content, CmsFile sitemapConfigFile) throws CmsXmlException, CmsException { content.correctXmlStructure(m_cms); byte[] contentBytes = content.marshal(); sitemapConfigFile.setContents(contentBytes); try { CmsLock lock = m_cms.getLock(sitemapConfigFile); if (lock.isUnlocked() || !lock.isOwnedBy(m_cms.getRequestContext().getCurrentUser())) { m_cms.lockResourceTemporary(sitemapConfigFile); } m_cms.writeFile(sitemapConfigFile); } finally { m_cms.unlockResource(sitemapConfigFile); } }
/** * @see org.opencms.workplace.tools.I_CmsHtmlIconButton#getName() */ @Override public CmsMessageContainer getName() { if (super.getName() == null) { if (! getResourceUtil().getLock().isUnlocked()) { return Messages.get().container( Messages.GUI_EXPLORER_LIST_ACTION_LOCK_NAME_2, getResourceUtil().getLockedByName(), getResourceUtil().getLockedInProjectName()); } else { return Messages.get().container(Messages.GUI_EXPLORER_LIST_ACTION_UNLOCK_NAME_0); } } return super.getName(); } }
/** * @see org.opencms.workplace.tools.I_CmsHtmlIconButton#getName() */ @Override public CmsMessageContainer getName() { if (super.getName() == null) { if (!getResourceUtil().getLock().isUnlocked()) { return Messages.get().container( Messages.GUI_EXPLORER_LIST_ACTION_LOCK_NAME_2, getResourceUtil().getLockedByName(), getResourceUtil().getLockedInProjectName()); } else { return Messages.get().container(Messages.GUI_EXPLORER_LIST_ACTION_UNLOCK_NAME_0); } } return super.getName(); } }
/** * Generates a client side lock info object representing the current lock state of the given resource.<p> * * @param resource the resource * * @return the client lock * * @throws CmsException if something goes wrong */ private CmsClientLock generateClientLock(CmsResource resource) throws CmsException { CmsObject cms = getCmsObject(); CmsLock lock = cms.getLock(resource); CmsClientLock clientLock = new CmsClientLock(); clientLock.setLockType(CmsClientLock.LockType.valueOf(lock.getType().getMode())); CmsUUID ownerId = lock.getUserId(); if (!lock.isUnlocked() && (ownerId != null)) { clientLock.setLockOwner(cms.readUser(ownerId).getDisplayName(cms, cms.getRequestContext().getLocale())); clientLock.setOwnedByUser(cms.getRequestContext().getCurrentUser().getId().equals(ownerId)); } return clientLock; }