Class CmsResource

    • Constructor Detail

      • CmsResource

        public CmsResource​(CmsUUID structureId,
                           CmsUUID resourceId,
                           java.lang.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 record
        resourceId - the id of this resources resource record
        rootPath - the root path to the resource
        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
        size - the size of the file content of this resource
        dateContent - the date of the last modification of the content of this resource
        version - the version number of this resource
      • CmsResource

        public CmsResource​(CmsUUID structureId,
                           CmsUUID resourceId,
                           java.lang.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 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 the 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
        dateContent - the date of the last modification of the content of this resource
        version - the version number 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
      • getExtension

        public static java.lang.String getExtension​(java.lang.String resourceName)
        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 null if not available
      • 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 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/.

        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 determine 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 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

        public static boolean isTemporaryFileName​(java.lang.String path)
        Returns 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.

        Parameters:
        path - the resource path to check
        Returns:
        true if the given resource name is a temporary file name
        See Also:
        isTemporaryFile()
      • clone

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

        Overrides:
        clone in class java.lang.Object
        Returns:
        a clone of this instance
      • equals

        public boolean equals​(java.lang.Object obj)
        Two resources are considered equal in case their structure id is equal.

        Overrides:
        equals in class java.lang.Object
        See Also:
        Object.equals(java.lang.Object)
      • getCopy

        public CmsResource 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 CmsFile or CmsFolder, which may happen if you just call clone().

        Returns:
        a copy of this resource
      • getDateContent

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

        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.

        Specified by:
        getDateContent in interface I_CmsResource
        Returns:
        the date of the last modification of the content of this resource
        Since:
        7.0.0
      • getDateCreated

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

        Specified by:
        getDateCreated in interface I_CmsResource
        Returns:
        the date of the creation of this resource
      • getDateExpired

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

        If the expiration date has not been set, DATE_EXPIRED_DEFAULT is returned. This means: The resource does never expire.

        Specified by:
        getDateExpired in interface I_CmsResource
        Returns:
        the expiration date of this resource
      • getLength

        public int 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:
        getLength in interface I_CmsResource
        Returns:
        the content length of the content
      • getName

        public java.lang.String getName()
        Returns the file name of this resource without parent folders, for example index.html.

        Specified by:
        getName in interface I_CmsResource
        Returns:
        the file name of this resource without parent folders
      • getResourceId

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

        Specified by:
        getResourceId in interface I_CmsResource
        Returns:
        the id of the database content record of this resource
      • getSiblingCount

        public int 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 has n siblings, the sibling count is n + 1.

        Specified by:
        getSiblingCount in interface I_CmsResource
        Returns:
        the number of siblings of this resource, also counting this resource
      • getStructureId

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

        Specified by:
        getStructureId in interface I_CmsResource
        Returns:
        the id of the database structure record of this resource
      • getTypeId

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

        Specified by:
        getTypeId in interface I_CmsResource
        Returns:
        the resource type id of this resource
      • getVersion

        public int getVersion()
        Returns the current version number of this resource.

        Specified by:
        getVersion in interface I_CmsResource
        Returns:
        the current version number of this resource
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
        See Also:
        Object.hashCode()
      • isFile

        public boolean isFile()
        Returns true if the resource is a CmsFile, that is not a CmsFolder.

        Specified by:
        isFile in interface I_CmsResource
        Returns:
        true if this resource is a file, false otherwise
      • isInternal

        public boolean isInternal()
        Returns 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.

        Specified by:
        isInternal in interface I_CmsResource
        Returns:
        true if the resource is internal
      • isInternalOrInInternalFolder

        public boolean 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

        public boolean isLabeled()
        Returns 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.

        Specified by:
        isLabeled in interface I_CmsResource
        Returns:
        true if the resource has to be labeled in the explorer view
      • isTemporaryFile

        public boolean isTemporaryFile()
        Returns 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).

        Returns:
        true if the given resource name is a temporary file
        See Also:
        isTemporaryFileName(String)
      • isTouched

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

        Specified by:
        isTouched in interface I_CmsResource
        Returns:
        true if this resource was touched
      • setDateExpired

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

        Parameters:
        time - the expiration date to set
      • setDateLastModified

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

        Parameters:
        time - the last modification date to set
      • setDateReleased

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

        Parameters:
        time - the release date to set
      • setFlags

        public void setFlags​(int flags)
        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

        public void setInternal​(boolean internal)
        Sets or clears the internal flag.

        Parameters:
        internal - true if the internal flag should be set, false if it should be cleared
      • setState

        public void setState​(CmsResourceState 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()
        Overrides:
        toString in class java.lang.Object
        See Also:
        Object.toString()