/** * 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); }
/** * Returns <code>true</code> if this is an exclusive, temporary exclusive, or * directly inherited lock, and the given user is the owner of this lock, * checking also the project of the lock.<p> * * @param user the user to compare to the owner of this lock * @param project the project to compare to the project of this lock * * @return <code>true</code> if this is an exclusive, temporary exclusive, or * directly inherited lock, and the given user is the owner of this lock */ public boolean isDirectlyOwnedInProjectBy(CmsUser user, CmsProject project) { return (isExclusive() || isDirectlyInherited()) && isOwnedInProjectBy(user, project); }
/** * 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(); }
/** * Returns <code>true</code> if this is an exclusive (or temporary exclusive) lock, * and the given user is the owner of this lock.<p> * * @param user the user to compare to the owner of this lock * * @return <code>true</code> if this is an exclusive (or temporary exclusive) lock, * and the given user is the owner of this lock */ public boolean isExclusiveOwnedBy(CmsUser user) { return isExclusive() && isOwnedBy(user); }
/** * Returns <code>true</code> if this is an exclusive, temporary exclusive, or * directly inherited lock, and the given user is the owner of this lock.<p> * * @param user the user to compare to the owner of this lock * * @return <code>true</code> if this is an exclusive, temporary exclusive, or * directly inherited lock, and the given user is the owner of this lock */ public boolean isDirectlyOwnedBy(CmsUser user) { return (isExclusive() || isDirectlyInherited()) && isOwnedBy(user); }
/** * Returns <code>true</code> if the given user is the owner of this lock, * and this lock belongs to the given project.<p> * * @param user the user to compare to the owner of this lock * @param project the project to compare to the project of this lock * * @return <code>true</code> if the given user is the owner of this lock, * and this lock belongs to the given project */ public boolean isOwnedInProjectBy(CmsUser user, CmsProject project) { return isOwnedBy(user) && isInProject(project); }
CmsLock currentLock) throws CmsLockException { if (!currentLock.isLockableBy(user)) { if (currentLock.getSystemLock().isUnlocked() || (currentLock.getType() != type) || !currentLock.isOwnedInProjectBy(user, project)) { if (currentLock.getSystemLock().isPublish()) { message = Messages.get().container( Messages.ERR_RESOURCE_LOCKED_FORPUBLISH_1, dbc.getRequestContext().getSitePath(resource)); } else if (currentLock.getEditionLock().isInherited()) { message = Messages.get().container( Messages.ERR_RESOURCE_LOCKED_INHERITED_1,
if (!exclusiveLock.getSystemLock().isUnlocked()) { lock = new CmsLock( siblingName, exclusiveLock.getUserId(), exclusiveLock.getProject(), exclusiveLock.getSystemLock().getType()); if ((lock == null) || !exclusiveLock.getEditionLock().isNullLock()) { CmsLockType type = CmsLockType.SHARED_EXCLUSIVE; if (!getParentLock(siblingName).isNullLock()) { type = CmsLockType.SHARED_INHERITED; lock = new CmsLock(siblingName, exclusiveLock.getUserId(), exclusiveLock.getProject(), type); } else { CmsLock editionLock = new CmsLock( siblingName, exclusiveLock.getUserId(), exclusiveLock.getProject(), type); lock.setRelatedLock(editionLock);
/** * Moves a lock during the move resource operation.<p> * * @param source the source root path * @param destination the destination root path */ public void moveResource(String source, String destination) { CmsLock lock = OpenCms.getMemoryMonitor().getCachedLock(source); if (lock != null) { OpenCms.getMemoryMonitor().uncacheLock(lock.getResourceName()); CmsLock newLock = new CmsLock(destination, lock.getUserId(), lock.getProject(), lock.getType()); lock = lock.getRelatedLock(); if ((lock != null) && !lock.isNullLock()) { CmsLock relatedLock = new CmsLock(destination, lock.getUserId(), lock.getProject(), lock.getType()); newLock.setRelatedLock(relatedLock); } OpenCms.getMemoryMonitor().cacheLock(newLock); } }
if (m_includeChildren) { match = lock.getResourceName().startsWith(rootPath); if (lock.getResourceName().endsWith("/")) { match = rootPath.startsWith(lock.getResourceName()); if (match && (m_projectId != null) && !m_projectId.isNullUUID() && (lock.getProjectId() != null)) { match = lock.getProjectId().equals(m_projectId); match = lock.getUserId().equals(m_ownedByUserId); match = !lock.getUserId().equals(m_notOwnedByUserId); match = lock.isLockableBy(m_lockableByUser); match = !lock.isLockableBy(m_notLockableByUser); match = m_types.contains(lock.getType()); match = match || (m_includeParents && lock.isInherited()); if (!match && !lock.getRelatedLock().isNullLock()) { match = match(rootPath, lock.getRelatedLock());
/** * @see org.opencms.workplace.explorer.menu.I_CmsMenuItemRule#matches(org.opencms.file.CmsObject, CmsResourceUtil[]) */ public boolean matches(CmsObject cms, CmsResourceUtil[] resourceUtil) { if (resourceUtil[0].isInsideProject()) { CmsLock lock = resourceUtil[0].getLock(); boolean lockedForPublish = resourceUtil[0].getProjectState().isLockedForPublishing(); return (!lockedForPublish && !lock.isShared() && lock.isOwnedInProjectBy( cms.getRequestContext().currentUser(), cms.getRequestContext().currentProject())) || (!lockedForPublish && lock.isNullLock() && OpenCms.getWorkplaceManager().autoLockResources()); } // resource is not locked by the user in current project or not locked with enabled autolock, rule does not match return false; }
/** * Returns the related Lock.<p> * * @return the related Lock */ protected CmsLock getRelatedLock() { if (m_relatedLock == null) { CmsLockType type; if (isSystemLock()) { type = CmsLockType.UNLOCKED; } else { type = CmsLockType.SYSTEM_UNLOCKED; } CmsLock lock = new CmsLock(getResourceName(), getUserId(), getProject(), type); lock.setRelatedLock(this); if (isUnlocked()) { // prevent the null lock gets modified return lock; } m_relatedLock = lock; } return m_relatedLock; }
if ((type.isExclusive()) && !(type.isTemporary() && currentLock.isInherited())) { if (!currentLock.getEditionLock().isUnlocked()) { needNewLock = false; CmsLock newLock = CmsLock.getNullLock(); if (needNewLock) { newLock = new CmsLock(resource.getRootPath(), user.getId(), project, type); lockResource(newLock); if (resource.isFolder() && newLock.getSystemLock().isUnlocked()) { String resourceName = resource.getRootPath(); Iterator<CmsLock> itLocks = OpenCms.getMemoryMonitor().getAllCachedLocks().iterator(); while (itLocks.hasNext()) { CmsLock lock = itLocks.next(); String lockedPath = lock.getResourceName(); if (lockedPath.startsWith(resourceName) && !lockedPath.equals(resourceName)) { unlockResource(lockedPath, false);
return CmsLock.getNullLock(); if (!lock.getSystemLock().isUnlocked()) { } else { return CmsLock.getNullLock(); if (lock.getSystemLock().isUnlocked()) { } else { if (!lock.getEditionLock().isUnlocked()) { CmsLock tmp = lock.getEditionLock(); CmsLock sysLock = lock.getSystemLock(); sysLock.setRelatedLock(null); if (!sysLock.equals(lock)) { } else { return CmsLock.getNullLock();
/** * Returns the inherited lock of a resource.<p> * * @param resourcename the name of the resource * @return the inherited lock or the null lock */ private CmsLock getParentLock(String resourcename) { CmsLock parentFolderLock = getParentFolderLock(resourcename); if (!parentFolderLock.isNullLock()) { return new CmsLock( resourcename, parentFolderLock.getUserId(), parentFolderLock.getProject(), CmsLockType.INHERITED); } return CmsLock.getNullLock(); }
return CmsLock.getNullLock(); if (!lock.getSystemLock().isUnlocked()) { lock = lock.getSystemLock(); } else { lock = lock.getEditionLock();
/** * Builds a string representation of the current state.<p> * * @see java.lang.Object#toString() */ @Override public String toString() { StringBuffer buf = new StringBuffer(); buf.append("[CmsLock: resource: "); buf.append(getResourceName()); buf.append(", type: "); buf.append(getType()); buf.append(", project: "); buf.append(getProjectId()); buf.append(", user: "); buf.append(getUserId()); if (getRelatedLock() != null) { buf.append(", related lock: "); buf.append(getRelatedLock().getType()); } buf.append("]"); return buf.toString(); }
/** * 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 } }
/** * 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)); } }
/** * 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); } }