/** * 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(); }
/** * Returns the user, who had locked the resource.<p> * * A user can lock a resource, so he is the only one who can write this * resource. This methods checks, if a resource was locked. * * @param dbc the current database context * @param resource the resource * * @return the user, who had locked the resource * * @throws CmsException will be thrown, if the user has not the rights for this resource */ public CmsUser lockedBy(CmsDbContext dbc, CmsResource resource) throws CmsException { return readUser(dbc, m_lockManager.getLock(dbc, resource).getEditionLock().getUserId()); }
/** * 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); } } }
/** * Returns the user, who had locked the resource.<p> * * A user can lock a resource, so he is the only one who can write this * resource. This methods checks, if a resource was locked. * * @param dbc the current database context * @param resource the resource * * @return the user, who had locked the resource * * @throws CmsException will be thrown, if the user has not the rights for this resource */ public CmsUser lockedBy(CmsDbContext dbc, CmsResource resource) throws CmsException { return readUser(dbc, m_lockManager.getLock(dbc, resource).getEditionLock().getUserId()); }
/** * 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 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); } } }
/** * Returns the user name who owns the lock for the given resource.<p> * * @return the user name who owns the lock for the given resource */ public String getLockedByName() { String lockedBy = ""; if (!getLock().isNullLock()) { // user lockedBy = getLock().getUserId().toString(); try { lockedBy = getCurrentOuRelativeName( CmsPrincipal.readPrincipalIncludingHistory(getCms(), getLock().getUserId()).getName()); } catch (Throwable e) { lockedBy = e.getMessage(); } } return lockedBy; }
/** * Returns the user name who owns the lock for the given resource.<p> * * @return the user name who owns the lock for the given resource */ public String getLockedByName() { String lockedBy = ""; if (!getLock().isNullLock()) { // user lockedBy = getLock().getUserId().toString(); try { lockedBy = getCurrentOuRelativeName(CmsPrincipal.readPrincipalIncludingHistory( getCms(), getLock().getUserId()).getName()); } catch (Throwable e) { lockedBy = e.getMessage(); } } return lockedBy; }
/** * 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()); }
/** * 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(); }
/** * 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(); }
/** * Helper method for locking a resource which returns some information on whether the locking * failed, and why.<p> * * @param sitepath the site path of the resource to lock * @return the locking information * * @throws CmsException if something went wrong */ protected CmsLockInfo getLock(String sitepath) throws CmsException { CmsObject cms = getCmsObject(); CmsUser user = cms.getRequestContext().getCurrentUser(); CmsLock lock = cms.getLock(sitepath); if (lock.isOwnedBy(user)) { return CmsLockInfo.forSuccess(); } if (lock.getUserId().isNullUUID()) { cms.lockResourceTemporary(sitepath); return CmsLockInfo.forSuccess(); } CmsUser owner = cms.readUser(lock.getUserId()); return CmsLockInfo.forLockedResource(owner.getName()); }
/** * 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); } }
/** * @see org.opencms.workflow.CmsDefaultPublishResourceFormatter.I_PublishResourceValidator#getInfoForResource(org.opencms.file.CmsResource) */ public CmsPublishResourceInfo getInfoForResource(CmsResource resource) throws CmsException { String info; CmsPublishResourceInfo.Type infoType; CmsPublishResourceInfo infoObj; CmsLock lock = m_cms.getLock(resource); info = Messages.get().getBundle(getLocale()).key( Messages.GUI_RESOURCE_LOCKED_BY_2, getOuAwareName(m_cms, m_cms.readUser(lock.getUserId()).getName()), getOuAwareName(m_cms, lock.getProject().getName())); infoType = CmsPublishResourceInfo.Type.LOCKED; infoObj = new CmsPublishResourceInfo(info, infoType); return infoObj; } }
/** * @see org.opencms.repository.I_CmsRepositorySession#getLock(java.lang.String) */ public CmsRepositoryLockInfo getLock(String path) { try { CmsRepositoryLockInfo lockInfo = new CmsRepositoryLockInfo(); path = validatePath(path); CmsResource res = m_cms.readResource(path, CmsResourceFilter.DEFAULT); // check user locks CmsLock cmsLock = m_cms.getLock(res); if (!cmsLock.isUnlocked()) { lockInfo.setPath(path); CmsUser owner = m_cms.readUser(cmsLock.getUserId()); if (owner != null) { lockInfo.setUsername(owner.getName()); lockInfo.setOwner(owner.getName() + "||" + owner.getEmail()); } return lockInfo; } return null; } catch (CmsException ex) { // error occurred while finding locks // return null (no lock found) return null; } }
/** * @see org.opencms.repository.I_CmsRepositorySession#getLock(java.lang.String) */ public CmsRepositoryLockInfo getLock(String path) { try { CmsRepositoryLockInfo lockInfo = new CmsRepositoryLockInfo(); path = validatePath(path); CmsResource res = m_cms.readResource(path, CmsResourceFilter.DEFAULT); // check user locks CmsLock cmsLock = m_cms.getLock(res); if (!cmsLock.isUnlocked()) { lockInfo.setPath(path); CmsUser owner = m_cms.readUser(cmsLock.getUserId()); if (owner != null) { lockInfo.setUsername(owner.getName()); lockInfo.setOwner(owner.getName() + "||" + owner.getEmail()); } return lockInfo; } return null; } catch (CmsException ex) { // error occurred while finding locks // return null (no lock found) return null; } }
/** * 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; }