|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.opencms.file.CmsResource
public class CmsResource
Base class for all OpenCms VFS resources like
or CmsFile
.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:
CmsFile
.
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.
Nested Class Summary | |
---|---|
static class |
CmsResource.CmsResourceCopyMode
Enumeration class for resource copy modes. |
static class |
CmsResource.CmsResourceDeleteMode
Enumeration class for resource delete modes. |
static class |
CmsResource.CmsResourceUndoMode
Enumeration class for resource undo changes modes. |
Nested classes/interfaces inherited from interface org.opencms.file.I_CmsResource |
---|
I_CmsResource.CmsResourceAttribute |
Field Summary | |
---|---|
static CmsResource.CmsResourceCopyMode |
COPY_AS_NEW
Copy mode for copy resources as new resource. |
static CmsResource.CmsResourceCopyMode |
COPY_AS_SIBLING
Copy mode for copy resources as sibling. |
static CmsResource.CmsResourceCopyMode |
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 long |
DATE_RELEASED_EXPIRED_IGNORE
A special date that indicates release and expiration information are to be ignored. |
static CmsResource.CmsResourceDeleteMode |
DELETE_PRESERVE_SIBLINGS
Signals that siblings of this resource should not be deleted. |
static CmsResource.CmsResourceDeleteMode |
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 long |
m_dateContent
The date of the last modification of the content of this resource. |
protected int |
m_length
The size of the content. |
static String |
NAME_CONSTRAINTS
The name constraints when generating new resources. |
static CmsResourceState |
STATE_CHANGED
Indicates if a resource has been changed in the offline version when compared to the online version. |
static CmsResourceState |
STATE_DELETED
Indicates if a resource has been deleted in the offline version when compared to the online version. |
static CmsResourceState |
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 CmsResourceState |
STATE_NEW
Indicates if a resource is new in the offline version when compared to the online version. |
static CmsResourceState |
STATE_UNCHANGED
Indicates if a resource is unchanged in the offline version when compared to the online version. |
static String |
TEMP_FILE_PREFIX
Prefix for temporary files in the VFS. |
static long |
TOUCH_DATE_UNCHANGED
Flag for leaving a date unchanged during a touch operation. |
static CmsResource.CmsResourceUndoMode |
UNDO_CONTENT
Indicates that the undo method will only undo content changes. |
static CmsResource.CmsResourceUndoMode |
UNDO_CONTENT_RECURSIVE
Indicates that the undo method will only recursive undo content changes. |
static CmsResource.CmsResourceUndoMode |
UNDO_MOVE_CONTENT
Indicates that the undo method will undo move operations and content changes. |
static CmsResource.CmsResourceUndoMode |
UNDO_MOVE_CONTENT_RECURSIVE
Indicates that the undo method will undo move operations and recursive content changes. |
static String |
VFS_FOLDER_SITES
The vfs path of the sites master folder. |
static String |
VFS_FOLDER_SYSTEM
The 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 | |
---|---|
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. |
Method Summary | |
---|---|
static void |
checkResourceName(String name)
Checks if the provided resource name is a valid resource name, that is contains only valid characters. |
Object |
clone()
Returns a clone of this Objects instance. |
int |
compareTo(I_CmsResource obj)
Uses the resource root path to compare two resources. |
boolean |
equals(Object obj)
Two resources are considered equal in case their structure id is equal. |
CmsResource |
getCopy()
Creates a copy of this resource. |
long |
getDateContent()
Returns the date of the last modification of the content of this resource. |
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 String |
getFolderPath(String resource)
Returns the folder path of the resource with the given name. |
int |
getLength()
Returns the content length of this resource. |
String |
getName()
Returns the file name of this resource without parent folders, for example index.html . |
static String |
getName(String resource)
Returns the name of a resource without the path information. |
static String |
getParentFolder(String resource)
Returns the absolute parent folder name of a resource. |
static int |
getPathLevel(String resource)
Returns the directory level of a resource. |
static String |
getPathPart(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. |
CmsUUID |
getProjectLastModified()
Returns the id of the CmsProject where this resource has been last modified. |
CmsUUID |
getResourceId()
Returns the id of the database content record of this resource. |
String |
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 . |
int |
getSiblingCount()
Returns the number of siblings of this resource, also counting this resource. |
CmsResourceState |
getState()
Returns the state of this resource. |
CmsUUID |
getStructureId()
Returns the id of the database structure record of this resource. |
int |
getTypeId()
Returns the resource type id for this resource. |
CmsUUID |
getUserCreated()
Returns the user id of the CmsUser who created this resource. |
CmsUUID |
getUserLastModified()
Returns the id of the CmsUser who made the last modification on this resource. |
int |
getVersion()
Returns the current version number of this resource. |
int |
hashCode()
|
boolean |
isExpired(long time)
Returns true if this resource is expired at the given time according to the
information stored in getDateExpired() . |
boolean |
isFile()
Returns true if the resource is a CmsFile , that is not a CmsFolder . |
boolean |
isFolder()
Returns true if the resource is a CmsFolder , that is not a CmsFile . |
static boolean |
isFolder(String resource)
Returns true if the resource name certainly denotes a folder, that is ends with a "/". |
boolean |
isInternal()
Returns true if the resource is marked as internal. |
boolean |
isLabeled()
Returns true if the resource has to be labeled with a special icon in the explorer view. |
boolean |
isReleased(long time)
Returns true if this resource is released at the given time according to the
information stored in getDateReleased() . |
boolean |
isReleasedAndNotExpired(long time)
Returns true if this resource is valid at the given time according to the
information stored in getDateReleased() and getDateExpired() . |
boolean |
isTemporaryFile()
Returns true if this resource is a temporary file. |
static boolean |
isTemporaryFileName(String path)
Returns true if the given resource path points to a temporary file name. |
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(CmsResourceState 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. |
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final CmsResource.CmsResourceCopyMode COPY_AS_NEW
public static final CmsResource.CmsResourceCopyMode COPY_AS_SIBLING
public static final CmsResource.CmsResourceCopyMode COPY_PRESERVE_SIBLING
public static final long DATE_EXPIRED_DEFAULT
public static final long DATE_RELEASED_DEFAULT
public static final long DATE_RELEASED_EXPIRED_IGNORE
public static final CmsResource.CmsResourceDeleteMode DELETE_PRESERVE_SIBLINGS
public static final CmsResource.CmsResourceDeleteMode DELETE_REMOVE_SIBLINGS
public static final int FLAG_INTERNAL
public static final int FLAG_LABELED
public static final int FLAG_TEMPFILE
public static final String NAME_CONSTRAINTS
public static final CmsResourceState STATE_CHANGED
public static final CmsResourceState STATE_DELETED
public static final CmsResourceState STATE_KEEP
public static final CmsResourceState STATE_NEW
public static final CmsResourceState STATE_UNCHANGED
public static final String TEMP_FILE_PREFIX
isTemporaryFile()
,
isTemporaryFileName(String)
,
Constant Field Valuespublic static final long TOUCH_DATE_UNCHANGED
public static final CmsResource.CmsResourceUndoMode UNDO_CONTENT
public static final CmsResource.CmsResourceUndoMode UNDO_CONTENT_RECURSIVE
public static final CmsResource.CmsResourceUndoMode UNDO_MOVE_CONTENT
public static final CmsResource.CmsResourceUndoMode UNDO_MOVE_CONTENT_RECURSIVE
public static final String VFS_FOLDER_SITES
public static final String VFS_FOLDER_SYSTEM
protected long m_dateContent
protected int m_length
Constructor Detail |
---|
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)
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 resourceMethod Detail |
---|
public static void checkResourceName(String name) throws CmsIllegalArgumentException
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.
name
- the resource name to check
CmsIllegalArgumentException
- if the given resource name is not validpublic static String getFolderPath(String resource)
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.html
and
/system/def/
for the (folder) resource /system/def/
.
resource
- the name of a resource
public static String getName(String resource)
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/
.
resource
- the resource to get the name for
public static String getParentFolder(String 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/
.
resource
- the resource to find the parent folder for
null
for the root folderpublic static int getPathLevel(String resource)
The root folder "/" has level 0, a folder "/foo/" would have level 1, a folfer "/foo/bar/" level 2 etc.
resource
- the resource to determine the directory level for
public static String getPathPart(String resource, int level)
resource
- the name of a resourcelevel
- of levels to walk up or down
public static boolean isFolder(String resource)
resource
- the resource to check
public static boolean isTemporaryFileName(String path)
true
if 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.
path
- the resource path to check
true
if the given resource name is a temporary file nameisTemporaryFile()
public Object clone()
clone
in class Object
public int compareTo(I_CmsResource obj)
Please note a number of additional comparators for resources exists as members of this class.
compareTo
in interface Comparable<I_CmsResource>
Comparable.compareTo(java.lang.Object)
,
I_CmsResource.COMPARE_DATE_RELEASED
,
I_CmsResource.COMPARE_ROOT_PATH
,
I_CmsResource.COMPARE_ROOT_PATH_IGNORE_CASE
,
I_CmsResource.COMPARE_ROOT_PATH_IGNORE_CASE_FOLDERS_FIRST
public boolean equals(Object obj)
equals
in class Object
Object.equals(java.lang.Object)
public CmsResource getCopy()
This is useful in case you want to create a copy of a resource and
really make sure won't get a CmsFile
or CmsFolder
, which may happen
if you just call clone()
.
public long getDateContent()
This applies only to resources of type CmsFile
, since a CmsFolder
has no content.
In case of a folder, -1
is 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 by CmsFile.getContents()
is changed.
getDateContent
in interface I_CmsResource
public long getDateCreated()
getDateCreated
in interface I_CmsResource
public long getDateExpired()
If the expiration date has not been set, DATE_EXPIRED_DEFAULT
is returned.
This means: The resource does never expire.
getDateExpired
in interface I_CmsResource
public long getDateLastModified()
getDateLastModified
in interface I_CmsResource
public long getDateReleased()
If the release date has not been set, DATE_RELEASED_DEFAULT
is returned.
This means: The resource has always been released.
getDateReleased
in interface I_CmsResource
public int getFlags()
getFlags
in interface I_CmsResource
for an explanation of the resource flags
public int getLength()
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.
getLength
in interface I_CmsResource
public String getName()
index.html
.
getName
in interface I_CmsResource
public CmsUUID getProjectLastModified()
CmsProject
where this resource has been last modified.
getProjectLastModified
in interface I_CmsResource
CmsProject
where this resource has been last modified, or null
public CmsUUID getResourceId()
getResourceId
in interface I_CmsResource
public String getRootPath()
/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.
getRootPath
in interface I_CmsResource
CmsObject.getSitePath(CmsResource)
,
CmsRequestContext.getSitePath(CmsResource)
,
CmsRequestContext.removeSiteRoot(String)
public int getSiblingCount()
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
.
getSiblingCount
in interface I_CmsResource
public CmsResourceState getState()
This may be STATE_UNCHANGED
,
STATE_CHANGED
, STATE_NEW
or STATE_DELETED
.
getState
in interface I_CmsResource
public CmsUUID getStructureId()
getStructureId
in interface I_CmsResource
public int getTypeId()
getTypeId
in interface I_CmsResource
public CmsUUID getUserCreated()
CmsUser
who created this resource.
getUserCreated
in interface I_CmsResource
CmsUser
who created this resourcepublic CmsUUID getUserLastModified()
CmsUser
who made the last modification on this resource.
getUserLastModified
in interface I_CmsResource
CmsUser
who made the last modification on this resourcepublic int getVersion()
getVersion
in interface I_CmsResource
public int hashCode()
hashCode
in class Object
Object.hashCode()
public boolean isExpired(long time)
true
if this resource is expired at the given time according to the
information stored in getDateExpired()
.
isExpired
in interface I_CmsResource
time
- the time to check the expiration date against
true
if this resource is expired at the given timeisReleased(long)
,
isReleasedAndNotExpired(long)
,
DATE_RELEASED_EXPIRED_IGNORE
,
getDateReleased()
,
CmsRequestContext.getRequestTime()
public boolean isFile()
true
if the resource is a CmsFile
, that is not a CmsFolder
.
isFile
in interface I_CmsResource
public boolean isFolder()
true
if the resource is a CmsFolder
, that is not a CmsFile
.
isFolder
in interface I_CmsResource
public boolean isInternal()
true
if 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.xml
has been set as marked as internal, this resource can not be requested by an HTTP request,
so when a user enters http:/www.myserver.com/opencms/opencms/internal.xml
in the browser
this will generate a CmsVfsResourceNotFoundException
.
This state is stored as bit 1 in the resource flags.
isInternal
in interface I_CmsResource
true
if the resource is internalpublic boolean isLabeled()
true
if 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.
isLabeled
in interface I_CmsResource
true
if the resource has to be labeled in the explorer viewpublic boolean isReleased(long time)
true
if this resource is released at the given time according to the
information stored in getDateReleased()
.
isReleased
in interface I_CmsResource
time
- the time to check the release date against
true
if this resource is released at the given timeisExpired(long)
,
isReleasedAndNotExpired(long)
,
DATE_RELEASED_EXPIRED_IGNORE
,
getDateReleased()
,
CmsRequestContext.getRequestTime()
public boolean isReleasedAndNotExpired(long time)
true
if this resource is valid at the given time according to the
information stored in getDateReleased()
and getDateExpired()
.A resource is valid if it is released and not yet expired.
isReleasedAndNotExpired
in interface I_CmsResource
time
- the time to check the release and expiration date against
true
if this resource is valid at the given timeisExpired(long)
,
isReleased(long)
,
DATE_RELEASED_EXPIRED_IGNORE
,
getDateReleased()
,
CmsRequestContext.getRequestTime()
public boolean isTemporaryFile()
true
if this resource is a temporary file.
A resource is considered a temporary file it is a file where the
FLAG_TEMPFILE
flag has been set, or if the file name (without parent folders)
starts with the prefix char '~'
(tilde).
true
if the given resource name is a temporary fileisTemporaryFileName(String)
public boolean isTouched()
true
if this resource was touched.
isTouched
in interface I_CmsResource
true
if this resource was touchedpublic void setDateExpired(long time)
time
- the expiration date to setpublic void setDateLastModified(long time)
time
- the last modification date to setpublic void setDateReleased(long time)
time
- the release date to setpublic void setFlags(int flags)
The resource flags integer is used as bit set that contains special information about the resource. The following methods internally use the resource flags:
flags
- the flags value to setpublic void setState(CmsResourceState state)
state
- the state to setpublic void setType(int type)
type
- the type to setpublic void setUserLastModified(CmsUUID resourceLastModifiedByUserId)
resourceLastModifiedByUserId
- the user id of the user who changed the resourcepublic String toString()
toString
in class Object
Object.toString()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |