/** * 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); }
/** * Returns the system lock information tooltip for the explorer view.<p> * * @param forExplorer if the tool tip should be generated for the explorer view * * @return the system lock information tooltip */ public String getSystemLockInfo(boolean forExplorer) { if (getLock().getSystemLock().isPublish()) { if (!forExplorer) { return getMessages().key(Messages.GUI_PUBLISH_TOOLTIP_0); } else { // see explorer.js(sysLockInfo) and top_js.jsp(publishlock) return "p"; // should have length == 1 } } return ""; }
/** * Returns the system lock information tooltip for the explorer view.<p> * * @param forExplorer if the tool tip should be generated for the explorer view * * @return the system lock information tooltip */ public String getSystemLockInfo(boolean forExplorer) { if (getLock().getSystemLock().isPublish()) { if (!forExplorer) { return getMessages().key(Messages.GUI_PUBLISH_TOOLTIP_0); } else { // see explorer.js(sysLockInfo) and top_js.jsp(publishlock) return "p"; // should have length == 1 } } return ""; }
/** * 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); } } }
if (currentLock.getSystemLock().equals(lock) || currentLock.getEditionLock().equals(lock)) { return; if (!currentLock.getSystemLock().isUnlocked() && lock.getSystemLock().isUnlocked()) { lock.setRelatedLock(currentLock); if (locks == null) { locks.put(lock.getResourceName(), lock); } else if (currentLock.getSystemLock().isUnlocked() && !lock.getSystemLock().isUnlocked()) { currentLock.setRelatedLock(lock); } else {
/** * 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); } } }
if (currentLock.getSystemLock().equals(lock) || currentLock.getEditionLock().equals(lock)) { return; if (!currentLock.getSystemLock().isUnlocked() && lock.getSystemLock().isUnlocked()) { lock.setRelatedLock(currentLock); if (locks == null) { locks.put(lock.getResourceName(), lock); } else if (currentLock.getSystemLock().isUnlocked() && !lock.getSystemLock().isUnlocked()) { currentLock.setRelatedLock(lock); } else {
/** * 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); } } }
/** * 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); } } }
if (!lock.getSystemLock().isUnlocked()) { lock = lock.getSystemLock(); } else { lock = lock.getEditionLock();
if (!lock.getSystemLock().isUnlocked()) { lock = lock.getSystemLock(); } else { lock = lock.getEditionLock();
if (!lock.getSystemLock().isUnlocked()) { if (lock.getSystemLock().isUnlocked()) { CmsLock sysLock = lock.getSystemLock(); sysLock.setRelatedLock(null); if (!sysLock.equals(lock)) {
if (!exclusiveLock.getSystemLock().isUnlocked()) { lock = new CmsLock( siblingName, exclusiveLock.getUserId(), exclusiveLock.getProject(), exclusiveLock.getSystemLock().getType());
if (!exclusiveLock.getSystemLock().isUnlocked()) { lock = new CmsLock( siblingName, exclusiveLock.getUserId(), exclusiveLock.getProject(), exclusiveLock.getSystemLock().getType());
/** * Returns the project state of the given resource.<p> * * <ul> * <li>null: unchanged.</li> * <li>true: locked in current project.</li> * <li>false: not locked in current project.</li> * </ul> * * @return the project state of the given resource */ public CmsResourceProjectState getProjectState() { if (getResource().getState().isUnchanged()) { return STATE_CLEAN; // STATE_CLEAN } else if (getLock().getSystemLock().isPublish()) { return STATE_LOCKED_FOR_PUBLISHING; } else if (getResource().getProjectLastModified().equals(getReferenceProject().getUuid())) { return STATE_MODIFIED_IN_CURRENT_PROJECT; // STATE_MODIFIED_CURRENT_PROJECT } else { return STATE_MODIFIED_IN_OTHER_PROJECT; // STATE_MODIFIED_OTHER_PROJECT } }
/** * Returns the project state of the given resource.<p> * * <ul> * <li>null: unchanged.</li> * <li>true: locked in current project.</li> * <li>false: not locked in current project.</li> * </ul> * * @return the project state of the given resource */ public CmsResourceProjectState getProjectState() { if (getResource().getState().isUnchanged()) { return STATE_CLEAN; // STATE_CLEAN } else if (getLock().getSystemLock().isPublish()) { return STATE_LOCKED_FOR_PUBLISHING; } else if (getResource().getProjectLastModified().equals(getReferenceProject().getUuid())) { return STATE_MODIFIED_IN_CURRENT_PROJECT; // STATE_MODIFIED_CURRENT_PROJECT } else { return STATE_MODIFIED_IN_OTHER_PROJECT; // STATE_MODIFIED_OTHER_PROJECT } }
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,
/** * @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); } }
/** * Checks is the current resource can be edited by the current user.<p> * * @param locale the locale to use for the messages * @param ignoreExpiration <code>true</code> to ignore resource release and expiration date * * @return an empty string if editable, or a localized string with the reason * * @throws CmsException if something goes wrong */ public String getNoEditReason(Locale locale, boolean ignoreExpiration) throws CmsException { String reason = ""; if (m_resource instanceof I_CmsHistoryResource) { reason = Messages.get().getBundle(locale).key(Messages.GUI_NO_EDIT_REASON_HISTORY_0); } else if (!m_cms.hasPermissions( m_resource, CmsPermissionSet.ACCESS_WRITE, false, ignoreExpiration ? CmsResourceFilter.IGNORE_EXPIRATION : CmsResourceFilter.DEFAULT) || !isEditable()) { reason = Messages.get().getBundle(locale).key(Messages.GUI_NO_EDIT_REASON_PERMISSION_0); } else if (!getLock().isLockableBy(m_cms.getRequestContext().getCurrentUser())) { if (getLock().getSystemLock().isPublish()) { reason = Messages.get().getBundle(locale).key(Messages.GUI_PUBLISH_TOOLTIP_0); } else { reason = Messages.get().getBundle(locale).key(Messages.GUI_NO_EDIT_REASON_LOCK_1, getLockedByName()); } } return reason; }