Package org.opencms.lock
Class CmsLockUtil.LockedFile
- java.lang.Object
-
- org.opencms.lock.CmsLockUtil.LockedFile
-
- All Implemented Interfaces:
java.lang.AutoCloseable
- Enclosing class:
- CmsLockUtil
public static final class CmsLockUtil.LockedFile extends java.lang.Object implements java.lang.AutoCloseable
Helper to handle the lock reports together with the files.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
java.lang.String
getEncoding()
Returns the encoding used for the file.CmsFile
getFile()
Returns the file, or null if reading fails.CmsLockActionRecord
getLockActionRecord()
Returns the lock action record.boolean
isCreated()
Returns a flag, indicating if the file is newly created.static CmsLockUtil.LockedFile
lockResource(CmsObject cms, CmsResource resource)
Lock and read a file.void
setCreated(boolean isNew)
Set the flag, indicating if the file was newly created.boolean
tryUnlock()
Unlocks the resource if it was not formerly locked.
-
-
-
Method Detail
-
lockResource
public static CmsLockUtil.LockedFile lockResource(CmsObject cms, CmsResource resource) throws CmsException
Lock and read a file.- Parameters:
cms
- the cms user context.resource
- the resource to lock and read.- Returns:
- the read file with the lock action record.
- Throws:
CmsException
- thrown if locking fails
-
close
public void close() throws java.lang.Exception
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Throws:
java.lang.Exception
- See Also:
AutoCloseable.close()
-
getEncoding
public java.lang.String getEncoding()
Returns the encoding used for the file.- Returns:
- the encoding used for the file.
- See Also:
CmsFileUtil.getEncoding(CmsObject, CmsResource)
-
getFile
public CmsFile getFile()
Returns the file, or null if reading fails.- Returns:
- the file, or null if reading fails.
-
getLockActionRecord
public CmsLockActionRecord getLockActionRecord()
Returns the lock action record.- Returns:
- the lock action record.
-
isCreated
public boolean isCreated()
Returns a flag, indicating if the file is newly created.- Returns:
- flag, indicating if the file is newly created.
-
setCreated
public void setCreated(boolean isNew)
Set the flag, indicating if the file was newly created.- Parameters:
isNew
- flag, indicating if the file was newly created.
-
tryUnlock
public boolean tryUnlock()
Unlocks the resource if it was not formerly locked.- Returns:
true
in case the resource was unlocked
-
-