org.opencms.file
Class CmsResource

java.lang.Object
  extended byorg.opencms.file.CmsResource
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable, java.io.Serializable
Direct Known Subclasses:
CmsFile, CmsFolder

public class CmsResource
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable, java.lang.Comparable

Base class for all OpenCms VFS resources like CmsFile or CmsFolder.

Since:
6.0.0
Version:
$Revision: 1.45 $
Author:
Alexander Kandzior, Michael Emmerich, Thomas Weckert
See Also:
Serialized Form

Field Summary
static java.util.Comparator COMPARE_DATE_RELEASED
          A comparator for the release date of 2 resources.
static java.util.Comparator COMPARE_ROOT_PATH
          A comparator for the root path of 2 resources.
static java.util.Comparator COMPARE_ROOT_PATH_IGNORE_CASE
          A comparator for the root path of 2 resources ignoring case differences.
static java.util.Comparator COMPARE_ROOT_PATH_IGNORE_CASE_FOLDERS_FIRST
          A comparator for the root path of 2 resources ignoring case differences, putting folders before files.
static int COPY_AS_NEW
          Copy mode for copy resources as new resource.
static int COPY_AS_SIBLING
          Copy mode for copy resources as sibling.
static int COPY_PRESERVE_SIBLING
          Copy mode to preserve siblings during copy.
static long DATE_EXPIRED_DEFAULT
          The default expiration date of a resource (which is: never expires).
static long DATE_RELEASED_DEFAULT
          The default release date of a resource (which is: always released).
static int DELETE_PRESERVE_SIBLINGS
          Signals that siblings of this resource should not be deleted.
static int DELETE_REMOVE_SIBLINGS
          Signals that siblings of this resource should be deleted.
static int FLAG_INTERNAL
          Flag to indicate that this is an internal resource, that can't be accessed directly.
static int FLAG_LABELED
          The resource is linked inside a site folder specified in the OpenCms configuration.
static int FLAG_TEMPFILE
          Flag to indicate that this is a temporary resource.
protected  int m_length
          The size of the content.
static java.lang.String NAME_CONSTRAINTS
          The name constraints when generating new resources.
static int STATE_CHANGED
          Indicates if a resource has been changed in the offline version when compared to the online version.
static int STATE_DELETED
          Indicates if a resource has been deleted in the offline version when compared to the online version.
static int 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.
static int STATE_NEW
          Indicates if a resource is new in the offline version when compared to the online version.
static int STATE_UNCHANGED
          Indicates if a resource is unchanged in the offline version when compared to the online version.
static long TOUCH_DATE_UNCHANGED
          Flag for leaving a date unchanged during a touch operation.
static java.lang.String VFS_FOLDER_CHANNELS
          The vfs path of the channel folder.
static java.lang.String VFS_FOLDER_SITES
          The vfs path of the sites master folder.
static java.lang.String VFS_FOLDER_SYSTEM
          The vfs path of the system folder.
 
Constructor Summary
CmsResource(CmsUUID structureId, CmsUUID resourceId, java.lang.String rootPath, int type, boolean isFolder, int flags, int projectId, int state, long dateCreated, CmsUUID userCreated, long dateLastModified, CmsUUID userLastModified, long dateReleased, long dateExpired, int linkCount, int size)
          Constructor, creates a new CmsRecource object.
 
Method Summary
static void checkResourceName(java.lang.String name)
          Checks if the provided resource name is a valid resource name, that is contains only valid characters.
 java.lang.Object clone()
          Returns a clone of this Objects instance.
 int compareTo(java.lang.Object obj)
           
 boolean equals(java.lang.Object obj)
           
 long getDateCreated()
          Returns the date of the creation of this resource.
 long getDateExpired()
          Returns the expiration date this resource.
 long getDateLastModified()
          Returns the date of the last modification of this resource.
 long getDateReleased()
          Returns the release date this resource.
 int getFlags()
          Returns the flags of this resource.
static java.lang.String getFolderPath(java.lang.String resource)
          Returns the folder path of the resource with the given name, if the resource is a folder (i.e. ends with a "/"), the complete path of the folder is returned (not the parent folder path).
 int getLength()
          Returns the length of the resource.
 java.lang.String getName()
          Returns the name of this resource, e.g.
static java.lang.String getName(java.lang.String resource)
          Returns the name of a resource without the path information.
static java.lang.String getParentFolder(java.lang.String resource)
          Returns the absolute parent folder name of a resource.
static int getPathLevel(java.lang.String resource)
          Returns the directory level of a resource.
static java.lang.String getPathPart(java.lang.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.
 int getProjectLastModified()
          Returns the id of the project where the resource has been last modified.
 CmsUUID getResourceId()
          Returns the id of the resource database entry of this resource.
 java.lang.String getRootPath()
          Returns the name of a resource with it's full path from the root folder including the current site root, for example /sites/default/myfolder/index.html.
 int getSiblingCount()
          Returns the number of siblings of the resource, also counting this resource.
 int getState()
          Returns the state of this resource.
 CmsUUID getStructureId()
          Returns the id of the structure record of this resource.
 int getTypeId()
          Returns the resource type id for this resource.
 CmsUUID getUserCreated()
          Returns the user id of the user who created this resource.
 CmsUUID getUserLastModified()
          Returns the user id of the user who made the last change on this resource.
 int hashCode()
           
 boolean isFile()
          Returns true if the resource is a file, i.e. can have no sub-resources.
 boolean isFolder()
          Returns true if the resource is a folder, i.e. can have sub-resources.
static boolean isFolder(java.lang.String resource)
          Returns true if the resource name is a folder name, i.e. ends with a "/".
 boolean isInternal()
          Checks if the resource is internal.
 boolean isLabeled()
          Checks if the link has to be labeled with a special icon in the explorer view.
 boolean isTouched()
          Returns true if this resource was touched.
 void setDateExpired(long time)
          Sets the expiration date this resource.
 void setDateLastModified(long time)
          Sets the date of the last modification of this resource.
 void setDateReleased(long time)
          Sets the release date this resource.
 void setFlags(int flags)
          Sets the flags of this resource.
 void setState(int state)
          Sets the state of this resource.
 void setType(int type)
          Sets the type of this resource.
 void setUserLastModified(CmsUUID resourceLastModifiedByUserId)
          Sets the user id of the user who changed this resource.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

COMPARE_DATE_RELEASED

public static final java.util.Comparator COMPARE_DATE_RELEASED
A comparator for the release date of 2 resources.

If the release date of a resource is not set, the creation date is used instead.


COMPARE_ROOT_PATH

public static final java.util.Comparator COMPARE_ROOT_PATH
A comparator for the root path of 2 resources.


COMPARE_ROOT_PATH_IGNORE_CASE

public static final java.util.Comparator COMPARE_ROOT_PATH_IGNORE_CASE
A comparator for the root path of 2 resources ignoring case differences.


COMPARE_ROOT_PATH_IGNORE_CASE_FOLDERS_FIRST

public static final java.util.Comparator COMPARE_ROOT_PATH_IGNORE_CASE_FOLDERS_FIRST
A comparator for the root path of 2 resources ignoring case differences, putting folders before files.


COPY_AS_NEW

public static final int COPY_AS_NEW
Copy mode for copy resources as new resource.

See Also:
Constant Field Values

COPY_AS_SIBLING

public static final int COPY_AS_SIBLING
Copy mode for copy resources as sibling.

See Also:
Constant Field Values

COPY_PRESERVE_SIBLING

public static final int COPY_PRESERVE_SIBLING
Copy mode to preserve siblings during copy.

See Also:
Constant Field Values

DATE_EXPIRED_DEFAULT

public static final long DATE_EXPIRED_DEFAULT
The default expiration date of a resource (which is: never expires).

See Also:
Constant Field Values

DATE_RELEASED_DEFAULT

public static final long DATE_RELEASED_DEFAULT
The default release date of a resource (which is: always released).

See Also:
Constant Field Values

DELETE_PRESERVE_SIBLINGS

public static final int DELETE_PRESERVE_SIBLINGS
Signals that siblings of this resource should not be deleted.

See Also:
Constant Field Values

DELETE_REMOVE_SIBLINGS

public static final int DELETE_REMOVE_SIBLINGS
Signals that siblings of this resource should be deleted.

See Also:
Constant Field Values

FLAG_INTERNAL

public static final int FLAG_INTERNAL
Flag to indicate that this is an internal resource, that can't be accessed directly.

See Also:
Constant Field Values

FLAG_LABELED

public static final int FLAG_LABELED
The resource is linked inside a site folder specified in the OpenCms configuration.

See Also:
Constant Field Values

FLAG_TEMPFILE

public static final int FLAG_TEMPFILE
Flag to indicate that this is a temporary resource.

See Also:
Constant Field Values

NAME_CONSTRAINTS

public static final java.lang.String NAME_CONSTRAINTS
The name constraints when generating new resources.

See Also:
Constant Field Values

STATE_CHANGED

public static final int STATE_CHANGED
Indicates if a resource has been changed in the offline version when compared to the online version.

See Also:
Constant Field Values

STATE_DELETED

public static final int STATE_DELETED
Indicates if a resource has been deleted in the offline version when compared to the online version.

See Also:
Constant Field Values

STATE_KEEP

public static final int 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.

See Also:
Constant Field Values

STATE_NEW

public static final int STATE_NEW
Indicates if a resource is new in the offline version when compared to the online version.

See Also:
Constant Field Values

STATE_UNCHANGED

public static final int STATE_UNCHANGED
Indicates if a resource is unchanged in the offline version when compared to the online version.

See Also:
Constant Field Values

TOUCH_DATE_UNCHANGED

public static final long TOUCH_DATE_UNCHANGED
Flag for leaving a date unchanged during a touch operation.

See Also:
Constant Field Values

VFS_FOLDER_CHANNELS

public static final java.lang.String VFS_FOLDER_CHANNELS
The vfs path of the channel folder.

See Also:
Constant Field Values

VFS_FOLDER_SITES

public static final java.lang.String VFS_FOLDER_SITES
The vfs path of the sites master folder.

See Also:
Constant Field Values

VFS_FOLDER_SYSTEM

public static final java.lang.String VFS_FOLDER_SYSTEM
The vfs path of the system folder.

See Also:
Constant Field Values

m_length

protected int m_length
The size of the content.

Constructor Detail

CmsResource

public CmsResource(CmsUUID structureId,
                   CmsUUID resourceId,
                   java.lang.String rootPath,
                   int type,
                   boolean isFolder,
                   int flags,
                   int projectId,
                   int state,
                   long dateCreated,
                   CmsUUID userCreated,
                   long dateLastModified,
                   CmsUUID userLastModified,
                   long dateReleased,
                   long dateExpired,
                   int linkCount,
                   int size)
Constructor, creates a new CmsRecource object.

Parameters:
structureId - the id of this resources structure record
resourceId - the id of this resources resource record
rootPath - the root path to the resource
type - the type of this resource
isFolder - must be true if thr resource is a folder, or false if it is a file
flags - the flags of this resource
projectId - the project id this resource was last modified in
state - the state of this resource
dateCreated - the creation date of this resource
userCreated - the id of the user who created this resource
dateLastModified - the date of the last modification of this resource
userLastModified - the id of the user who did the last modification of this resource
dateReleased - the release date of this resource
dateExpired - the expiration date of this resource
linkCount - the count of all siblings of this resource
size - the size of the file content of this resource
Method Detail

checkResourceName

public static void checkResourceName(java.lang.String name)
                              throws CmsIllegalArgumentException
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

getFolderPath

public static java.lang.String getFolderPath(java.lang.String resource)
Returns the folder path of the resource with the given name, if the resource is a folder (i.e. ends with a "/"), the complete path of the folder is returned (not the parent folder path).

This is achived by just cutting of everthing behind the last occurence 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.html and /system/def/ for the (folder) resource /system/def/.

Parameters:
resource - the name of a resource
Returns:
the folder of the given resource

getName

public static java.lang.String getName(java.lang.String resource)
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 name workplace/.

Parameters:
resource - the resource to get the name for
Returns:
the name of a resource without the path information

getParentFolder

public static java.lang.String getParentFolder(java.lang.String resource)
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 null for the root folder

getPathLevel

public static int getPathLevel(java.lang.String resource)
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 determin the directory level for
Returns:
the directory level of a resource

getPathPart

public static java.lang.String getPathPart(java.lang.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.

Parameters:
resource - the name of a resource
level - of levels to walk up or down
Returns:
the name of a parent folder of the given resource

isFolder

public static boolean isFolder(java.lang.String resource)
Returns true if the resource name is a folder name, i.e. ends with a "/".

Parameters:
resource - the resource to check
Returns:
true if the resource name is a folder name, i.e. ends with a "/"

clone

public java.lang.Object clone()
Returns a clone of this Objects instance.

Returns:
a clone of this instance

compareTo

public int compareTo(java.lang.Object obj)
Specified by:
compareTo in interface java.lang.Comparable
See Also:
Comparable.compareTo(java.lang.Object)

equals

public boolean equals(java.lang.Object obj)
See Also:
Object.equals(java.lang.Object)

getDateCreated

public long getDateCreated()
Returns the date of the creation of this resource.

Returns:
the date of the creation of this resource

getDateExpired

public long getDateExpired()
Returns the expiration date this resource.

Returns:
the expiration date of this resource

getDateLastModified

public long getDateLastModified()
Returns the date of the last modification of this resource.

Returns:
the date of the last modification of this resource

getDateReleased

public long getDateReleased()
Returns the release date this resource.

Returns:
the release date of this resource

getFlags

public int getFlags()
Returns the flags of this resource.

Returns:
the flags of this resource

getLength

public int getLength()
Returns the length of the 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.

Returns:
the length of the content

getName

public java.lang.String getName()
Returns the name of this resource, e.g. index.html.

Returns:
the name of this resource

getProjectLastModified

public int getProjectLastModified()
Returns the id of the project where the resource has been last modified.

Returns:
the id of the project where the resource has been last modified

getResourceId

public CmsUUID getResourceId()
Returns the id of the resource database entry of this resource.

Returns:
the id of the resource database entry

getRootPath

public java.lang.String getRootPath()
Returns the name of a resource with it's full path from the root folder including the current site root, 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.

Returns:
the name of a resource with it's full path from the root folder including the current site root
See Also:
CmsObject.getSitePath(CmsResource), CmsRequestContext.getSitePath(CmsResource), CmsRequestContext.removeSiteRoot(String)

getSiblingCount

public int getSiblingCount()
Returns the number of siblings of the resource, also counting this resource.

If a resource has no sibling, the total sibling count for this resource is 1, if a resource has n siblings, the sibling count is n + 1.

Returns:
the number of siblings

getState

public int getState()
Returns the state of this resource.

This may be STATE_UNCHANGED, STATE_CHANGED, STATE_NEW or STATE_DELETED.

Returns:
the state of this resource

getStructureId

public CmsUUID getStructureId()
Returns the id of the structure record of this resource.

Returns:
the id of the structure record of this resource

getTypeId

public int getTypeId()
Returns the resource type id for this resource.

Returns:
the resource type id of this resource

getUserCreated

public CmsUUID getUserCreated()
Returns the user id of the user who created this resource.

Returns:
the user id

getUserLastModified

public CmsUUID getUserLastModified()
Returns the user id of the user who made the last change on this resource.

Returns:
the user id of the user who made the last change


hashCode

public int hashCode()
See Also:
Object.hashCode()

isFile

public boolean isFile()
Returns true if the resource is a file, i.e. can have no sub-resources.

Returns:
true if this resource is a file, false otherwise

isFolder

public boolean isFolder()
Returns true if the resource is a folder, i.e. can have sub-resources.

Returns:
true if this resource is a folder, false otherwise

isInternal

public boolean isInternal()
Checks if the resource is internal.

This state is stored as bit 1 in the resource flags.

Returns:
true if the resource is internal, otherwise false

isLabeled

public boolean isLabeled()
Checks if the link has to be labeled with a special icon in the explorer view.

This state is stored as bit 2 in the resource flags.

Returns:
true if a link to the resource has to be labeled, otherwise false

isTouched

public boolean isTouched()
Returns true if this resource was touched.

Returns:
boolean true if this resource was touched

setDateExpired

public void setDateExpired(long time)
Sets the expiration date this resource.

Parameters:
time - the date to set

setDateLastModified

public void setDateLastModified(long time)
Sets the date of the last modification of this resource.

Parameters:
time - the date to set

setDateReleased

public void setDateReleased(long time)
Sets the release date this resource.

Parameters:
time - the date to set

setFlags

public void setFlags(int flags)
Sets the flags of this resource.

Parameters:
flags - int value with flag values to set

setState

public void setState(int state)
Sets the state of this resource.

Parameters:
state - the state to set

setType

public void setType(int type)
Sets the type of this resource.

Parameters:
type - the type to set

setUserLastModified

public void setUserLastModified(CmsUUID resourceLastModifiedByUserId)
Sets the user id of the user who changed this resource.

Parameters:
resourceLastModifiedByUserId - the user id of the user who changed the resource

toString

public java.lang.String toString()
See Also:
Object.toString()