/** * Caches the given lock.<p> * * The lock is cached by it resource's root path.<p> * * @param lock the lock to cache */ public void cacheLock(CmsLock lock) { if (m_disabled.get(CacheType.LOCK) != null) { return; } m_cacheLock.put(lock.getResourceName(), lock); }
/** * Caches the given lock.<p> * * The lock is cached by it resource's root path.<p> * * @param lock the lock to cache */ public void cacheLock(CmsLock lock) { if (m_disabled.get(CacheType.LOCK) != null) { return; } m_cacheLock.put(lock.getResourceName(), lock); }
/** * 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<CmsLock> itLocks = OpenCms.getMemoryMonitor().getAllCachedLocks().iterator(); while (itLocks.hasNext()) { CmsLock lock = 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 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 the lock of a possible locked parent folder of a resource, system locks are ignored.<p> * * @param absoluteResourceName 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(final String absoluteResourceName) { Iterator<CmsLock> itLocks = OpenCms.getMemoryMonitor().getAllCachedLocks().iterator(); while (itLocks.hasNext()) { CmsLock lock = itLocks.next(); if (lock.getResourceName().endsWith("/") && absoluteResourceName.startsWith(lock.getResourceName()) && !absoluteResourceName.equals(lock.getResourceName())) { // system locks does not get inherited lock = lock.getEditionLock(); // check the lock if (!lock.isUnlocked()) { return lock; } } } return CmsLock.getNullLock(); }
/** * Returns all locked resources in a given folder.<p> * * @param dbc the current database context * @param resource the folder to search in * @param filter the lock filter * * @return a list of locked resource paths (relative to current site) * * @throws CmsException if the current project is locked */ public List getLockedResources(CmsDbContext dbc, CmsResource resource, CmsLockFilter filter) throws CmsException { List lockedResources = new ArrayList(); // get locked resources Iterator it = m_lockManager.getLocks(dbc, resource.getRootPath(), filter).iterator(); while (it.hasNext()) { CmsLock lock = (CmsLock)it.next(); lockedResources.add(dbc.removeSiteRoot(lock.getResourceName())); } Collections.sort(lockedResources); return lockedResources; }
/** * Returns all locked resources in a given folder.<p> * * @param dbc the current database context * @param resource the folder to search in * @param filter the lock filter * * @return a list of locked resource paths (relative to current site) * * @throws CmsException if the current project is locked */ public List<String> getLockedResources(CmsDbContext dbc, CmsResource resource, CmsLockFilter filter) throws CmsException { List<String> lockedResources = new ArrayList<String>(); // get locked resources Iterator<CmsLock> it = m_lockManager.getLocks(dbc, resource.getRootPath(), filter).iterator(); while (it.hasNext()) { CmsLock lock = it.next(); lockedResources.add(dbc.removeSiteRoot(lock.getResourceName())); } Collections.sort(lockedResources); return lockedResources; }
/** * 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(); }
/** * 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(); }
/** * Removes all exclusive temporary locks of a user.<p> * * Only edition lock can be temporary, so no system locks are removed.<p> * * @param userId the id of the user whose locks has to be removed */ public void removeTempLocks(CmsUUID userId) { Iterator<CmsLock> itLocks = OpenCms.getMemoryMonitor().getAllCachedLocks().iterator(); while (itLocks.hasNext()) { CmsLock currentLock = itLocks.next(); if (currentLock.isTemporary() && currentLock.getUserId().equals(userId)) { unlockResource(currentLock.getResourceName(), false); } } }
/** * Removes all exclusive temporary locks of a user.<p> * * Only edition lock can be temporary, so no system locks are removed.<p> * * @param userId the id of the user whose locks has to be removed */ public void removeTempLocks(CmsUUID userId) { Iterator itLocks = OpenCms.getMemoryMonitor().getAllCachedLocks().iterator(); while (itLocks.hasNext()) { CmsLock currentLock = (CmsLock)itLocks.next(); if (currentLock.isTemporary() && currentLock.getUserId().equals(userId)) { unlockResource(currentLock.getResourceName(), false); } } }
/** * Removes all resources locked in a project.<p> * * @param projectId the ID of the project where the resources have been locked * @param removeSystemLocks if <code>true</code>, also system locks are removed */ public void removeResourcesInProject(CmsUUID projectId, boolean removeSystemLocks) { Iterator<CmsLock> itLocks = OpenCms.getMemoryMonitor().getAllCachedLocks().iterator(); while (itLocks.hasNext()) { CmsLock currentLock = itLocks.next(); if (removeSystemLocks && currentLock.getSystemLock().getProjectId().equals(projectId)) { unlockResource(currentLock.getResourceName(), true); } if (currentLock.getEditionLock().getProjectId().equals(projectId)) { unlockResource(currentLock.getResourceName(), false); } } }
/** * Removes all resources locked in a project.<p> * * @param projectId the ID of the project where the resources have been locked * @param removeSystemLocks if <code>true</code>, also system locks are removed */ public void removeResourcesInProject(CmsUUID projectId, boolean removeSystemLocks) { Iterator itLocks = OpenCms.getMemoryMonitor().getAllCachedLocks().iterator(); while (itLocks.hasNext()) { CmsLock currentLock = (CmsLock)itLocks.next(); if (removeSystemLocks && currentLock.getSystemLock().getProjectId().equals(projectId)) { unlockResource(currentLock.getResourceName(), true); } if (currentLock.getEditionLock().getProjectId().equals(projectId)) { unlockResource(currentLock.getResourceName(), false); } } }
/** * Removes all locks of a user.<p> * * Edition and system locks are removed.<p> * * @param userId the id of the user whose locks should be removed */ public void removeLocks(CmsUUID userId) { Iterator<CmsLock> itLocks = OpenCms.getMemoryMonitor().getAllCachedLocks().iterator(); while (itLocks.hasNext()) { CmsLock currentLock = itLocks.next(); boolean editLock = currentLock.getEditionLock().getUserId().equals(userId); boolean sysLock = currentLock.getSystemLock().getUserId().equals(userId); if (editLock) { unlockResource(currentLock.getResourceName(), false); } if (sysLock) { unlockResource(currentLock.getResourceName(), true); } } }
/** * Removes all locks of a user.<p> * * Edition and system locks are removed.<p> * * @param userId the id of the user whose locks should be removed */ public void removeLocks(CmsUUID userId) { Iterator itLocks = OpenCms.getMemoryMonitor().getAllCachedLocks().iterator(); while (itLocks.hasNext()) { CmsLock currentLock = (CmsLock)itLocks.next(); boolean editLock = currentLock.getEditionLock().getUserId().equals(userId); boolean sysLock = currentLock.getSystemLock().getUserId().equals(userId); if (editLock) { unlockResource(currentLock.getResourceName(), false); } if (sysLock) { unlockResource(currentLock.getResourceName(), true); } } }
/** * 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())); } } } }
/** * 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; }
/** * 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; }
/** * 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); } }
/** * 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); } }