Class CmsLock

java.lang.Object
org.opencms.lock.CmsLock
All Implemented Interfaces:
Comparable<CmsLock>

public class CmsLock extends Object implements Comparable<CmsLock>
Represents the lock state of a VFS resource.

The lock state is combination of how, by whom and in which project a resource is currently locked.

Since:
6.0.0
See Also:
  • Constructor Details

    • CmsLock

      public CmsLock(String resourceName, CmsUUID userId, CmsProject project, CmsLockType type)
      Constructor for a new Cms lock.

      Parameters:
      resourceName - the full resource name including the site root
      userId - the ID of the user who locked the resource
      project - the project where the resource is locked
      type - flag indicating how the resource is locked
  • Method Details

    • getNullLock

      public static CmsLock getNullLock()
      Returns the shared Null CmsLock.

      Returns:
      the shared Null CmsLock
    • compareTo

      public int compareTo(CmsLock other)
      Specified by:
      compareTo in interface Comparable<CmsLock>
      See Also:
    • equals

      public boolean equals(Object obj)
      Compares this lock to the specified object.

      Overrides:
      equals in class Object
      Parameters:
      obj - the object to compare to
      Returns:
      true if and only if member values of this CmsLock are the same with the compared CmsLock
    • getEditionLock

      Returns the edition lock.

      Returns:
      the edition lock
    • getProject

      Returns the project where the resource is currently locked.

      Returns:
      the project where the resource is currently locked
    • getProjectId

      Returns the ID of the project where the resource is currently locked.

      Returns:
      the ID of the project
    • getResourceName

      Returns the name of the locked resource.

      Returns:
      the name of the locked resource
    • getSystemLock

      Returns the system lock.

      Returns:
      the system lock
    • getType

      public CmsLockType getType()
      Returns the type about how the resource is locked.

      Returns:
      the type of the lock
    • getUserId

      public CmsUUID getUserId()
      Returns the ID of the user who currently locked the resource.

      Returns:
      the ID of the user
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
      See Also:
    • isDirectlyInherited

      public boolean isDirectlyInherited()
      Returns true if this is an directly inherited lock.

      Returns:
      true if this is an directly inherited lock
    • isDirectlyOwnedBy

      public boolean isDirectlyOwnedBy(CmsUser user)
      Returns true if this is an exclusive, temporary exclusive, or directly inherited lock, and the given user is the owner of this lock.

      Parameters:
      user - the user to compare to the owner of this lock
      Returns:
      true if this is an exclusive, temporary exclusive, or directly inherited lock, and the given user is the owner of this lock
    • isDirectlyOwnedInProjectBy

      public boolean isDirectlyOwnedInProjectBy(CmsObject cms)
      Returns true if this is an exclusive, temporary exclusive, or directly inherited lock, and the current user is the owner of this lock, checking also the project of the lock.

      Parameters:
      cms - the CMS context to check
      Returns:
      true if this is an exclusive, temporary exclusive, or directly inherited lock, and the current user is the owner of this lock
    • isDirectlyOwnedInProjectBy

      public boolean isDirectlyOwnedInProjectBy(CmsUser user, CmsProject project)
      Returns true 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.

      Parameters:
      user - the user to compare to the owner of this lock
      project - the project to compare to the project of this lock
      Returns:
      true if this is an exclusive, temporary exclusive, or directly inherited lock, and the given user is the owner of this lock
    • isExclusive

      public boolean isExclusive()
      Returns true if this is an exclusive (or temporary exclusive) lock.

      Returns:
      true if this is an exclusive (or temporary exclusive) lock
    • isExclusiveOwnedBy

      public boolean isExclusiveOwnedBy(CmsUser user)
      Returns true if this is an exclusive (or temporary exclusive) lock, and the given user is the owner of this lock.

      Parameters:
      user - the user to compare to the owner of this lock
      Returns:
      true if this is an exclusive (or temporary exclusive) lock, and the given user is the owner of this lock
    • isExclusiveOwnedInProjectBy

      public boolean isExclusiveOwnedInProjectBy(CmsUser user, CmsProject project)
      Returns true if this is an exclusive (or temporary exclusive) lock, and the given user is the owner and the given project is the project of this lock.

      Parameters:
      user - the user to compare to the owner of this lock
      project - the project to compare to the project of this lock
      Returns:
      true if this is an exclusive (or temporary exclusive) lock, and the given user is the owner and the given project is the project of this lock
    • isInherited

      public boolean isInherited()
      Returns true if this is an inherited lock, which may either be directly or shared inherited.

      Returns:
      true if this is an inherited lock, which may either be directly or shared inherited
    • isInProject

      public boolean isInProject(CmsProject project)
      Returns true if the given project is the project of this lock.

      Parameters:
      project - the project to compare to the project of this lock
      Returns:
      true if the given project is the project of this lock
    • isLockableBy

      public boolean isLockableBy(CmsUser user)
      Checks if a resource can be locked by a user.

      The resource is not lockable if it already has a lock of type CmsLockType.PUBLISH.

      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

      Parameters:
      user - the user to test lockeability for
      Returns:
      true if this lock blocks any operation on the locked resource until it is unlocked
    • isNullLock

      public boolean isNullLock()
      Returns true if this lock is the NULL lock which can be obtained by getNullLock().

      Only for the NULL lock, isUnlocked() is true.

      Returns:
      true if this lock is the NULL lock
    • isOwnedBy

      public boolean isOwnedBy(CmsUser user)
      Returns true if the given user is the owner of this lock.

      Parameters:
      user - the user to compare to the owner of this lock
      Returns:
      true if the given user is the owner of this lock
    • isOwnedInProjectBy

      public boolean isOwnedInProjectBy(CmsUser user, CmsProject project)
      Returns true if the given user is the owner of this lock, and this lock belongs to the given project.

      Parameters:
      user - the user to compare to the owner of this lock
      project - the project to compare to the project of this lock
      Returns:
      true if the given user is the owner of this lock, and this lock belongs to the given project
    • isPersistent

      public boolean isPersistent()
      Returns true if this is a persistent lock that should be saved when the systems shuts down.

      Returns:
      true if this is a persistent lock that should be saved when the systems shuts down
    • isPublish

      public boolean isPublish()
      Returns true if this is a publish lock.

      Returns:
      true if this is a publish lock
    • isShared

      public boolean isShared()
      Returns true if this is a shared lock.

      Returns:
      true if this is a shared lock
    • isSystemLock

      public boolean isSystemLock()
      Returns true if this is a system (2nd level) lock.

      Returns:
      true if this is a system (2nd level) lock
    • isTemporary

      public boolean isTemporary()
      Returns true if this is a temporary lock.

      Returns:
      true if this is a temporary lock
    • isUnlocked

      public boolean isUnlocked()
      Returns true if this lock is in fact unlocked.

      Only if this is true, the result lock is equal to the NULL lock, which can be obtained by getNullLock().

      Returns:
      true if this lock is in fact unlocked
    • toString

      public String toString()
      Builds a string representation of the current state.

      Overrides:
      toString in class Object
      See Also:
    • clone

      protected Object clone()
      Overrides:
      clone in class Object
      See Also:
    • getRelatedLock

      protected CmsLock getRelatedLock()
      Returns the related Lock.

      Returns:
      the related Lock
    • setRelatedLock

      protected void setRelatedLock(CmsLock relatedLock)
      Sets the related Lock.

      Parameters:
      relatedLock - the related Lock to set