org.opencms.file
Class CmsFile

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

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

A file resource in the OpenCms VFS.

A file resource is a CmsResource that contains an additional byte[] array of binary data, which is the file content. A file object is not allowed to have sub-resources.

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

Field Summary
 
Fields inherited from class org.opencms.file.CmsResource
COMPARE_DATE_RELEASED, COMPARE_ROOT_PATH, COMPARE_ROOT_PATH_IGNORE_CASE, COMPARE_ROOT_PATH_IGNORE_CASE_FOLDERS_FIRST, COPY_AS_NEW, COPY_AS_SIBLING, COPY_PRESERVE_SIBLING, DATE_EXPIRED_DEFAULT, DATE_RELEASED_DEFAULT, DELETE_PRESERVE_SIBLINGS, DELETE_REMOVE_SIBLINGS, FLAG_INTERNAL, FLAG_LABELED, FLAG_TEMPFILE, m_length, NAME_CONSTRAINTS, STATE_CHANGED, STATE_DELETED, STATE_KEEP, STATE_NEW, STATE_UNCHANGED, TOUCH_DATE_UNCHANGED, VFS_FOLDER_CHANNELS, VFS_FOLDER_SITES, VFS_FOLDER_SYSTEM
 
Constructor Summary
CmsFile(CmsResource resource)
          Constructor, creates a new CmsFile Object from the given CmsResource with an empty byte array as file content.
CmsFile(CmsUUID structureId, CmsUUID resourceId, CmsUUID contentId, java.lang.String path, int type, int flags, int projectId, int state, long dateCreated, CmsUUID userCreated, long dateLastModified, CmsUUID userLastModified, long dateReleased, long dateExpired, int linkCount, int length, byte[] content)
          Constructor, creates a new CmsFile object.
 
Method Summary
 java.lang.Object clone()
          Returns a clone of this Objects instance.
 CmsUUID getContentId()
          Returns the id of the content database entry.
 byte[] getContents()
          Returns the content of this file.
 int getLength()
          Returns the length of the resource.
 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.
 void setContents(byte[] value)
          Sets the contents of this file.
static CmsFile upgrade(CmsResource resource, CmsObject cms)
          Utility method to upgrade a CmsResource to a CmsFile.
 
Methods inherited from class org.opencms.file.CmsResource
checkResourceName, compareTo, equals, getDateCreated, getDateExpired, getDateLastModified, getDateReleased, getFlags, getFolderPath, getName, getName, getParentFolder, getPathLevel, getPathPart, getProjectLastModified, getResourceId, getRootPath, getSiblingCount, getState, getStructureId, getTypeId, getUserCreated, getUserLastModified, hashCode, isFolder, isInternal, isLabeled, isTouched, setDateExpired, setDateLastModified, setDateReleased, setFlags, setState, setType, setUserLastModified, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.lang.Comparable
compareTo
 

Constructor Detail

CmsFile

public CmsFile(CmsResource resource)
Constructor, creates a new CmsFile Object from the given CmsResource with an empty byte array as file content.

Parameters:
resource - the base resource object to create a file from

CmsFile

public CmsFile(CmsUUID structureId,
               CmsUUID resourceId,
               CmsUUID contentId,
               java.lang.String path,
               int type,
               int flags,
               int projectId,
               int state,
               long dateCreated,
               CmsUUID userCreated,
               long dateLastModified,
               CmsUUID userLastModified,
               long dateReleased,
               long dateExpired,
               int linkCount,
               int length,
               byte[] content)
Constructor, creates a new CmsFile object.

Parameters:
structureId - the id of this resources structure record
resourceId - the id of this resources resource record
contentId - the id of this resources content record
path - the filename of this resouce
type - the type of this resource
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
length - the size of the file content of this resource
content - the binary content data of this file
Method Detail

upgrade

public static CmsFile upgrade(CmsResource resource,
                              CmsObject cms)
                       throws CmsException
Utility method to upgrade a CmsResource to a CmsFile.

Sometimes a CmsResource might already be a (casted) CmsFile that also has the contents read. This methods tries to optimize read access to the VFS by "upgrading" the CmsResource to a CmsFile first. If this fails, the CmsFile is read from the VFS.

Parameters:
resource - the resource to upgrade
cms - permission context for accessing the VFS
Returns:
the upgraded (or read) file
Throws:
CmsException - if something goes wrong

clone

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

Overrides:
clone in class CmsResource
Returns:
a clone of this instance

getContentId

public CmsUUID getContentId()
Returns the id of the content database entry.

Returns:
the id of the content database entry

getContents

public byte[] getContents()
Returns the content of this file.

Returns:
the content of this file

getLength

public int getLength()
Description copied from class: CmsResource
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.

Overrides:
getLength in class CmsResource
Returns:
the length of the content
See Also:
CmsResource.getLength()

isFile

public boolean isFile()
Description copied from class: CmsResource
Returns true if the resource is a file, i.e. can have no sub-resources.

Overrides:
isFile in class CmsResource
Returns:
true if this resource is a file, false otherwise
See Also:
CmsResource.isFile()

isFolder

public boolean isFolder()
Description copied from class: CmsResource
Returns true if the resource is a folder, i.e. can have sub-resources.

Overrides:
isFolder in class CmsResource
Returns:
true if this resource is a folder, false otherwise
See Also:
CmsResource.isFolder()

setContents

public void setContents(byte[] value)
Sets the contents of this file.

Parameters:
value - the content of this file