Class CmsResource
- All Implemented Interfaces:
Serializable,Cloneable,Comparable<I_CmsResource>,I_CmsResource
- Direct Known Subclasses:
CmsFile,CmsFolder,CmsJspResourceWrapper,CmsSearchResource
CmsFile or CmsFolder.The OpenCms VFS resource is an important object for using the OpenCms API. Basically, all entries in the OpenCms VFS are considered to be "resources". Currently, only two types of resources exists:
- Files, which are represented by the subclass
CmsFile. - Folders (also called Directories), which are represented by the subclass
CmsFolder.
isFile() or isFolder() to learn what kind of
subclass you have. Please note that this is usually not required, as the only real difference between a
CmsFile and a CmsResource is that the CmsFile also has the contents of the file,
which you can obtain using CmsFile.getContents(). As long as you don't need the content, you can
use the CmsResource for everything else. This is even more true for a CmsFolder, here you
will need the subclass only in special cases, since the signature is identical to CmsResource.
A OpenCms VFS resource can have any number of properties attached, which are represented by a CmsProperty.
To read the properties for a resource, use CmsObject.readPropertyObject(CmsResource, String, boolean)
or use CmsObject.readPropertyObjects(CmsResource, boolean) to read all properties of the resource.
- Since:
- 6.0.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classEnumeration class for resource copy modes.static final classEnumeration class for resource delete modes.static final classEnumeration class for resource undo changes modes.Nested classes/interfaces inherited from interface org.opencms.file.I_CmsResource
I_CmsResource.CmsResourceAttribute -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final CmsResource.CmsResourceCopyModeCopy mode for copy resources as new resource.static final CmsResource.CmsResourceCopyModeCopy mode for copy resources as sibling.static final CmsResource.CmsResourceCopyModeCopy mode to preserve siblings during copy.static final longThe default expiration date of a resource, which is: never expires.static final longThe default release date of a resource, which is: always released.static final longA special date that indicates release and expiration information are to be ignored.static final CmsResource.CmsResourceDeleteModeSignals that siblings of this resource should not be deleted.static final CmsResource.CmsResourceDeleteModeSignals that siblings of this resource should be deleted.static final intFlag to indicate that this is an internal resource, that can't be accessed directly.static final intThe resource is linked inside a site folder specified in the OpenCms configuration.static final intFlag to indicate that this is a temporary resource.protected longThe date of the last modification of the content of this resource.protected intThe size of the content.static final StringThe name constraints when generating new resources.static final CmsResourceStateIndicates if a resource has been changed in the offline version when compared to the online version.static final CmsResourceStateIndicates if a resource has been deleted in the offline version when compared to the online version.static final CmsResourceStateSpecial state value that indicates the current state must be kept on a resource, this value must never be written to the database.static final CmsResourceStateIndicates if a resource is new in the offline version when compared to the online version.static final CmsResourceStateIndicates if a resource is unchanged in the offline version when compared to the online version.static final StringPrefix for temporary files in the VFS.static final longFlag for leaving a date unchanged during a touch operation.static final CmsResource.CmsResourceUndoModeIndicates that the undo method will only undo content changes.static final CmsResource.CmsResourceUndoModeIndicates that the undo method will only recursive undo content changes.static final CmsResource.CmsResourceUndoModeIndicates that the undo method will undo move operations and content changes.static final CmsResource.CmsResourceUndoModeIndicates that the undo method will undo move operations and recursive content changes.static final StringThe vfs path of the sites master folder.static final StringThe vfs path of the system folder.Fields inherited from interface org.opencms.file.I_CmsResource
COMPARE_DATE_LAST_MODIFIED, COMPARE_DATE_RELEASED, COMPARE_ROOT_PATH, COMPARE_ROOT_PATH_IGNORE_CASE, COMPARE_ROOT_PATH_IGNORE_CASE_FOLDERS_FIRST -
Constructor Summary
ConstructorsConstructorDescriptionCmsResource(CmsUUID structureId, CmsUUID resourceId, String rootPath, int type, boolean isFolder, int flags, CmsUUID projectId, CmsResourceState state, long dateCreated, CmsUUID userCreated, long dateLastModified, CmsUUID userLastModified, long dateReleased, long dateExpired, int linkCount, int size, long dateContent, int version) Creates a new CmsRecource object.CmsResource(CmsUUID structureId, CmsUUID resourceId, String rootPath, I_CmsResourceType type, int flags, CmsUUID projectId, CmsResourceState state, long dateCreated, CmsUUID userCreated, long dateLastModified, CmsUUID userLastModified, long dateReleased, long dateExpired, int linkCount, int size, long dateContent, int version) Creates a new CmsRecource object. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckResourceName(String name) Checks if the provided resource name is a valid resource name, that is contains only valid characters.clone()Returns a clone of this Objects instance.intcompareTo(I_CmsResource obj) Uses the resource root path to compare two resources.booleanTwo resources are considered equal in case their structure id is equal.getCopy()Creates a copy of this resource.longReturns the date of the last modification of the content of this resource.longReturns the date of the creation of this resource.longReturns the expiration date this resource.longReturns the date of the last modification of this resource.longReturns the release date this resource.static StringgetExtension(String resourceName) Returns the resource name extension if present.intgetFlags()Returns the flags of this resource.static StringgetFolderPath(String resource) Returns the folder path of the resource with the given name.intReturns the content length of this resource.getName()Returns the file name of this resource without parent folders, for exampleindex.html.static StringReturns the name of a resource without the path information.static StringgetParentFolder(String resource) Returns the absolute parent folder name of a resource.static intgetPathLevel(String resource) Returns the directory level of a resource.static StringgetPathPart(String resource, int level) Returns the name of a parent folder of the given resource, that is either minus levels up from the current folder, or that is plus levels down from the root folder.Returns the id of theCmsProjectwhere this resource has been last modified.Returns the id of the database content record of this resource.Returns the name of this resource with it's full path from the top level root folder, for example/sites/default/myfolder/index.html.intReturns the number of siblings of this resource, also counting this resource.getState()Returns the state of this resource.Returns the id of the database structure record of this resource.intReturns the resource type id for this resource.Returns the user id of theCmsUserwho created this resource.Returns the id of theCmsUserwho made the last modification on this resource.intReturns the current version number of this resource.inthashCode()booleanisExpired(long time) Returnstrueif this resource is expired at the given time according to the information stored ingetDateExpired().booleanisFile()booleanisFolder()static booleanReturns true if the resource name certainly denotes a folder, that is ends with a "/".booleanReturnstrueif the resource is marked as internal.booleanChecks if either the resource's 'internal' flag is set, or if it's below a list of forbidden folders.booleanReturnstrueif the resource has to be labeled with a special icon in the explorer view.booleanisReleased(long time) Returnstrueif this resource is released at the given time according to the information stored ingetDateReleased().booleanisReleasedAndNotExpired(long time) Returnstrueif this resource is valid at the given time according to the information stored ingetDateReleased()andgetDateExpired().booleanReturnstrueif this resource is a temporary file.static booleanisTemporaryFileName(String path) Returnstrueif the given resource path points to a temporary file name.booleanReturnstrueif this resource was touched.voidsetDateExpired(long time) Sets the expiration date this resource.voidsetDateLastModified(long time) Sets the date of the last modification of this resource.voidsetDateReleased(long time) Sets the release date this resource.voidsetFlags(int flags) Sets the flags of this resource.voidsetInternal(boolean internal) Sets or clears the internal flag.voidsetState(CmsResourceState state) Sets the state of this resource.voidsetType(int type) Sets the type of this resource.voidsetUserLastModified(CmsUUID resourceLastModifiedByUserId) Sets the user id of the user who changed this resource.toString()
-
Field Details
-
COPY_AS_NEW
Copy mode for copy resources as new resource. -
COPY_AS_SIBLING
Copy mode for copy resources as sibling. -
COPY_PRESERVE_SIBLING
Copy mode to preserve siblings during copy. -
DATE_EXPIRED_DEFAULT
The default expiration date of a resource, which is: never expires.- See Also:
-
DATE_RELEASED_DEFAULT
The default release date of a resource, which is: always released.- See Also:
-
DATE_RELEASED_EXPIRED_IGNORE
A special date that indicates release and expiration information are to be ignored.- See Also:
-
DELETE_PRESERVE_SIBLINGS
Signals that siblings of this resource should not be deleted. -
DELETE_REMOVE_SIBLINGS
Signals that siblings of this resource should be deleted. -
FLAG_INTERNAL
Flag to indicate that this is an internal resource, that can't be accessed directly.- See Also:
-
FLAG_LABELED
The resource is linked inside a site folder specified in the OpenCms configuration.- See Also:
-
FLAG_TEMPFILE
Flag to indicate that this is a temporary resource.- See Also:
-
NAME_CONSTRAINTS
The name constraints when generating new resources.- See Also:
-
STATE_CHANGED
Indicates if a resource has been changed in the offline version when compared to the online version. -
STATE_DELETED
Indicates if a resource has been deleted in the offline version when compared to the online version. -
STATE_KEEP
Special state value that indicates the current state must be kept on a resource, this value must never be written to the database. -
STATE_NEW
Indicates if a resource is new in the offline version when compared to the online version. -
STATE_UNCHANGED
Indicates if a resource is unchanged in the offline version when compared to the online version. -
TEMP_FILE_PREFIX
Prefix for temporary files in the VFS.- See Also:
-
TOUCH_DATE_UNCHANGED
Flag for leaving a date unchanged during a touch operation.- See Also:
-
UNDO_CONTENT
Indicates that the undo method will only undo content changes. -
UNDO_CONTENT_RECURSIVE
Indicates that the undo method will only recursive undo content changes. -
UNDO_MOVE_CONTENT
Indicates that the undo method will undo move operations and content changes. -
UNDO_MOVE_CONTENT_RECURSIVE
Indicates that the undo method will undo move operations and recursive content changes. -
VFS_FOLDER_SITES
The vfs path of the sites master folder.- See Also:
-
VFS_FOLDER_SYSTEM
The vfs path of the system folder.- See Also:
-
m_dateContent
The date of the last modification of the content of this resource. -
m_length
The size of the content.
-
-
Constructor Details
-
CmsResource
public CmsResource(CmsUUID structureId, CmsUUID resourceId, String rootPath, I_CmsResourceType type, int flags, CmsUUID projectId, CmsResourceState state, long dateCreated, CmsUUID userCreated, long dateLastModified, CmsUUID userLastModified, long dateReleased, long dateExpired, int linkCount, int size, long dateContent, int version) Creates a new CmsRecource object.- Parameters:
structureId- the id of this resources structure recordresourceId- the id of this resources resource recordrootPath- the root path to the resourcetype- the type of this resourceflags- the flags of this resourceprojectId- the project id this resource was last modified instate- the state of this resourcedateCreated- the creation date of this resourceuserCreated- the id of the user who created this resourcedateLastModified- the date of the last modification of this resourceuserLastModified- the id of the user who did the last modification of this resourcedateReleased- the release date of this resourcedateExpired- the expiration date of this resourcelinkCount- the count of all siblings of this resourcesize- the size of the file content of this resourcedateContent- the date of the last modification of the content of this resourceversion- the version number of this resource
-
CmsResource
public CmsResource(CmsUUID structureId, CmsUUID resourceId, String rootPath, int type, boolean isFolder, int flags, CmsUUID projectId, CmsResourceState state, long dateCreated, CmsUUID userCreated, long dateLastModified, CmsUUID userLastModified, long dateReleased, long dateExpired, int linkCount, int size, long dateContent, int version) Creates a new CmsRecource object.- Parameters:
structureId- the id of this resources structure recordresourceId- the id of this resources resource recordrootPath- the root path to the resourcetype- the type of this resourceisFolder- must be true if the resource is a folder, or false if it is a fileflags- the flags of this resourceprojectId- the project id this resource was last modified instate- the state of this resourcedateCreated- the creation date of this resourceuserCreated- the id of the user who created this resourcedateLastModified- the date of the last modification of this resourceuserLastModified- the id of the user who did the last modification of this resourcedateReleased- the release date of this resourcedateExpired- the expiration date of this resourcelinkCount- the count of all siblings of this resourcesize- the size of the file content of this resourcedateContent- the date of the last modification of the content of this resourceversion- the version number of this resource
-
-
Method Details
-
checkResourceName
Checks if the provided resource name is a valid resource name, that is contains only valid characters.A resource name can only be composed of digits, standard ASCII letters and the symbols defined in
NAME_CONSTRAINTS. A resource name must also not contain only dots.- Parameters:
name- the resource name to check- Throws:
CmsIllegalArgumentException- if the given resource name is not valid
-
getExtension
Returns the resource name extension if present.The extension will be always lower case.
- Parameters:
resourceName- the resource name or path- Returns:
- the extension or
nullif not available
-
getFolderPath
Returns the folder path of the resource with the given name.If the resource name denotes a folder (that is ends with a "/"), the complete path of the folder is returned (not the parent folder path).
This is achieved by just cutting of everything behind the last occurrence of a "/" character in the String, no check if performed if the resource exists or not in the VFS, only resources that end with a "/" are considered to be folders. Example: Returns
/system/def/for the resource/system/def/file.htmland/system/def/for the (folder) resource/system/def/.- Parameters:
resource- the name of a resource- Returns:
- the folder of the given resource
-
getName
Returns the name of a resource without the path information.The resource name of a file is the name of the file. The resource name of a folder is the folder name with trailing "/". The resource name of the root folder is
/.Example:
/system/workplace/has the resource nameworkplace/.- Parameters:
resource- the resource to get the name for- Returns:
- the name of a resource without the path information
-
getParentFolder
Returns the absolute parent folder name of a resource.The parent resource of a file is the folder of the file. The parent resource of a folder is the parent folder. The parent resource of the root folder is
null.Example:
/system/workplace/has the parent/system/.- Parameters:
resource- the resource to find the parent folder for- Returns:
- the calculated parent absolute folder path, or
nullfor the root folder
-
getPathLevel
Returns the directory level of a resource.The root folder "/" has level 0, a folder "/foo/" would have level 1, a folfer "/foo/bar/" level 2 etc.
- Parameters:
resource- the resource to determine the directory level for- Returns:
- the directory level of a resource
-
getPathPart
Returns the name of a parent folder of the given resource, that is either minus levels up from the current folder, or that is plus levels down from the root folder.- Parameters:
resource- the name of a resourcelevel- of levels to walk up or down- Returns:
- the name of a parent folder of the given resource
-
isFolder
Returns true if the resource name certainly denotes a folder, that is ends with a "/".- Parameters:
resource- the resource to check- Returns:
- true if the resource name certainly denotes a folder, that is ends with a "/"
-
isTemporaryFileName
Returnstrueif the given resource path points to a temporary file name.A resource name is considered a temporary file name if the name of the file (without parent folders) starts with the prefix char
'~'(tilde). Existing parent folder elements are removed from the path before the file name is checked.- Parameters:
path- the resource path to check- Returns:
trueif the given resource name is a temporary file name- See Also:
-
clone
Returns a clone of this Objects instance. -
compareTo
Uses the resource root path to compare two resources.Please note a number of additional comparators for resources exists as members of this class.
- Specified by:
compareToin interfaceComparable<I_CmsResource>- See Also:
-
equals
Two resources are considered equal in case their structure id is equal. -
getCopy
Creates a copy of this resource.This is useful in case you want to create a copy of a resource and really make sure won't get a
CmsFileorCmsFolder, which may happen if you just callclone().- Returns:
- a copy of this resource
-
getDateContent
Returns the date of the last modification of the content of this resource.This applies only to resources of type
CmsFile, since aCmsFolderhas no content. In case of a folder,-1is always returned as content date.Any modification of a resource, including changes to the resource properties, will increase the "date of last modification" which is returned by
getDateLastModified(). The "date of the content" as returned by this method only changes when the file content as returned byCmsFile.getContents()is changed.- Specified by:
getDateContentin interfaceI_CmsResource- Returns:
- the date of the last modification of the content of this resource
- Since:
- 7.0.0
-
getDateCreated
Returns the date of the creation of this resource.- Specified by:
getDateCreatedin interfaceI_CmsResource- Returns:
- the date of the creation of this resource
-
getDateExpired
Returns the expiration date this resource.If the expiration date has not been set,
DATE_EXPIRED_DEFAULTis returned. This means: The resource does never expire.- Specified by:
getDateExpiredin interfaceI_CmsResource- Returns:
- the expiration date of this resource
-
getDateLastModified
Returns the date of the last modification of this resource.- Specified by:
getDateLastModifiedin interfaceI_CmsResource- Returns:
- the date of the last modification of this resource
-
getDateReleased
Returns the release date this resource.If the release date has not been set,
DATE_RELEASED_DEFAULTis returned. This means: The resource has always been released.- Specified by:
getDateReleasedin interfaceI_CmsResource- Returns:
- the release date of this resource
-
getFlags
Returns the flags of this resource.- Specified by:
getFlagsin interfaceI_CmsResource- Returns:
- the flags of this resource
- See Also:
-
getLength
Returns the content length of this resource.If the resource is a file, then this is the byte size of the file content. If the resource is a folder, then the size is always -1.
- Specified by:
getLengthin interfaceI_CmsResource- Returns:
- the content length of the content
-
getName
Returns the file name of this resource without parent folders, for exampleindex.html.- Specified by:
getNamein interfaceI_CmsResource- Returns:
- the file name of this resource without parent folders
-
getProjectLastModified
Returns the id of theCmsProjectwhere this resource has been last modified.- Specified by:
getProjectLastModifiedin interfaceI_CmsResource- Returns:
- the id of the
CmsProjectwhere this resource has been last modified, ornull
-
getResourceId
Returns the id of the database content record of this resource.- Specified by:
getResourceIdin interfaceI_CmsResource- Returns:
- the id of the database content record of this resource
-
getRootPath
Returns the name of this resource with it's full path from the top level root folder, for example/sites/default/myfolder/index.html.In a presentation level application usually the current site root must be cut of from the root path. Use
CmsObject.getSitePath(CmsResource)to get the "absolute" path of a resource in the current site.- Specified by:
getRootPathin interfaceI_CmsResource- Returns:
- the name of this resource with it's full path from the top level root folder
- See Also:
-
getSiblingCount
Returns the number of siblings of this resource, also counting this resource.If a resource has no sibling, the total sibling count for this resource is
1, if a resource hasnsiblings, the sibling count isn + 1.- Specified by:
getSiblingCountin interfaceI_CmsResource- Returns:
- the number of siblings of this resource, also counting this resource
-
getState
Returns the state of this resource.This may be
STATE_UNCHANGED,STATE_CHANGED,STATE_NEWorSTATE_DELETED.- Specified by:
getStatein interfaceI_CmsResource- Returns:
- the state of this resource
-
getStructureId
Returns the id of the database structure record of this resource.- Specified by:
getStructureIdin interfaceI_CmsResource- Returns:
- the id of the database structure record of this resource
-
getTypeId
Returns the resource type id for this resource.- Specified by:
getTypeIdin interfaceI_CmsResource- Returns:
- the resource type id of this resource
-
getUserCreated
Returns the user id of theCmsUserwho created this resource.- Specified by:
getUserCreatedin interfaceI_CmsResource- Returns:
- the user id of the
CmsUserwho created this resource
-
getUserLastModified
Returns the id of theCmsUserwho made the last modification on this resource.- Specified by:
getUserLastModifiedin interfaceI_CmsResource- Returns:
- the id of the
CmsUserwho made the last modification on this resource
-
getVersion
Returns the current version number of this resource.- Specified by:
getVersionin interfaceI_CmsResource- Returns:
- the current version number of this resource
-
hashCode
-
isExpired
Returnstrueif this resource is expired at the given time according to the information stored ingetDateExpired().- Specified by:
isExpiredin interfaceI_CmsResource- Parameters:
time- the time to check the expiration date against- Returns:
trueif this resource is expired at the given time- See Also:
-
isFile
- Specified by:
isFilein interfaceI_CmsResource- Returns:
- true if this resource is a file, false otherwise
-
isFolder
- Specified by:
isFolderin interfaceI_CmsResource- Returns:
- true if this resource is a folder, false otherwise
-
isInternal
Returnstrueif the resource is marked as internal.An internal resource can be read by the OpenCms API, but it can not be delivered by a direct request from an outside user.
For example if the resource
/internal.xmlhas been set as marked as internal, this resource can not be requested by an HTTP request, so when a user entershttp:/www.myserver.com/opencms/opencms/internal.xmlin the browser this will generate aCmsVfsResourceNotFoundException.This state is stored as bit 1 in the resource flags.
- Specified by:
isInternalin interfaceI_CmsResource- Returns:
trueif the resource is internal
-
isInternalOrInInternalFolder
Checks if either the resource's 'internal' flag is set, or if it's below a list of forbidden folders.- Returns:
- true if the resource should be treated as internal
-
isLabeled
Returnstrueif the resource has to be labeled with a special icon in the explorer view.This state is stored as bit 2 in the resource flags.
- Specified by:
isLabeledin interfaceI_CmsResource- Returns:
trueif the resource has to be labeled in the explorer view
-
isReleased
Returnstrueif this resource is released at the given time according to the information stored ingetDateReleased().- Specified by:
isReleasedin interfaceI_CmsResource- Parameters:
time- the time to check the release date against- Returns:
trueif this resource is released at the given time- See Also:
-
isReleasedAndNotExpired
Returnstrueif this resource is valid at the given time according to the information stored ingetDateReleased()andgetDateExpired().A resource is valid if it is released and not yet expired.
- Specified by:
isReleasedAndNotExpiredin interfaceI_CmsResource- Parameters:
time- the time to check the release and expiration date against- Returns:
trueif this resource is valid at the given time- See Also:
-
isTemporaryFile
Returnstrueif this resource is a temporary file.A resource is considered a temporary file it is a file where the
FLAG_TEMPFILEflag has been set, or if the file name (without parent folders) starts with the prefix char'~'(tilde).- Returns:
trueif the given resource name is a temporary file- See Also:
-
isTouched
Returnstrueif this resource was touched.- Specified by:
isTouchedin interfaceI_CmsResource- Returns:
trueif this resource was touched
-
setDateExpired
Sets the expiration date this resource.- Parameters:
time- the expiration date to set
-
setDateLastModified
Sets the date of the last modification of this resource.- Parameters:
time- the last modification date to set
-
setDateReleased
Sets the release date this resource.- Parameters:
time- the release date to set
-
setFlags
Sets the flags of this resource.The resource flags integer is used as bit set that contains special information about the resource. The following methods internally use the resource flags:
- Parameters:
flags- the flags value to set
-
setInternal
Sets or clears the internal flag.- Parameters:
internal- true if the internal flag should be set, false if it should be cleared
-
setState
Sets the state of this resource.- Parameters:
state- the state to set
-
setType
Sets the type of this resource.- Parameters:
type- the type to set
-
setUserLastModified
Sets the user id of the user who changed this resource.- Parameters:
resourceLastModifiedByUserId- the user id of the user who changed the resource
-
toString
-