Class WebdavFileSystem

  • Direct Known Subclasses:
    CatWebdavFileSystem, FileWebdavFileSystem

    public abstract class WebdavFileSystem
    extends java.lang.Object
    This class is an Abstract representation of a WebdavFileSystem. It's purpose is to handle all specific webdav concept and control before delegating to a a sub repository implementation doing more control and real commande.
    Since:
    jcms-5.5.0
    Version:
    $Revision: 107554 $
    Author:
    Jean-Philippe Encausse
    • Field Detail

      • resourceLocks

        protected java.util.Map<java.lang.String,​java.util.Set<WebdavLock>> resourceLocks
    • Constructor Detail

      • WebdavFileSystem

        protected WebdavFileSystem​(WebdavContext ctxt)
        Initialise the webdav FileSystem setting baseUri from ContextPath and ServletPath
        Parameters:
        ctxt - the Webdav Context
    • Method Detail

      • init

        public void init()
        Called after authentication for each request. Used to initialized cached data.
      • isReadOnly

        public boolean isReadOnly​(WebdavContext ctxt)
        Check if the FileSystem is ReadOnly. Default implementation always return false
        Parameters:
        ctxt - the Webdav Context
        Returns:
        true if the FileSystem is Read Only
      • isListing

        public boolean isListing​(WebdavContext ctxt)
        This method check if the FileSystem allow listing. Listing is used by PROPFIND Webdav Method. Default implementation return true.
        Parameters:
        ctxt - the Webdav Context
        Returns:
        true if the FileSystem folders can be listed
      • getRelativeUri

        public java.lang.String getRelativeUri​(java.lang.String uri,
                                               WebdavContext ctxt)
        This method will convert an absolute uri to a relative uri.

        Examples :

        • https://www.example.com:8443/jcms/webapp/my/folder/resource.ext -> /my/folder/resource.ext
        • http://www.example.com/jcms/webapp/my/folder/resource.ext -> /my/folder/resource.ext
        • /jcms/webdav/my/folder/resource.ext -> /my/folder/resource.ext
        Parameters:
        uri - the absolute uri
        ctxt - the Webdav Context
        Returns:
        the relative uri
      • getAbsoluteUri

        public java.lang.String getAbsoluteUri​(java.lang.String path,
                                               WebdavContext ctxt)
        This method will convert a relative path to an absolute uri ie /my/folder/resource.ext -> http://www.example.com/jcms/webapp/webdav/my/folder/resource.ext
        Parameters:
        path - the path to convert to absolute
        ctxt - the Webdav Context
        Returns:
        the relative uri
      • normalize

        public java.lang.String normalize​(java.lang.String path)
        Return a context-relative path, beginning with a "/", that represents the canonical version of the specified path after ".." and "." elements are resolved out. If the specified path attempts to go outside the boundaries of the current context (i.e. too many ".." path elements are present), return null instead. If path starts with http:// then clean behaviour to let http://
        Parameters:
        path - Path to be normalized
        Returns:
        String the normalized path
      • getResource

        public abstract WebdavResource getResource​(java.lang.String uri,
                                                   WebdavContext ctxt)
        Lookup the resource represented by the given URI. The resource must be a relative URI to the path folders starting and ending by '/'. ie /my/path/resource.ext -> /my/path/resource.ext
        ie /my/path/ -> /my/path/
        Parameters:
        uri - the resource URI
        ctxt - the Webdav Context
        Returns:
        WebdavResource the resource representing the given URI
      • doCopy

        public boolean doCopy​(WebdavResource source,
                              WebdavResource target,
                              boolean overwrite,
                              boolean recursive,
                              WebdavContext ctxt)
        This method perform copy from one Webdav Resource to an Other
        Parameters:
        source - a Webdav Resource
        target - a Webdav Resource
        overwrite - a boolean indicate to overite or not the resource
        recursive - is it a recursive copy
        ctxt - the Webdav Context
        Returns:
        boolean true if the copy has been done otherwise false
      • doMove

        public boolean doMove​(WebdavResource source,
                              WebdavResource target,
                              boolean overwrite,
                              boolean recursive,
                              WebdavContext ctxt)
        This method perform move from one Webdav Resource to an Other
        Parameters:
        source - a Webdav Resource
        target - a Webdav Resource
        overwrite - a boolean indicate to overite or not the resource
        recursive - is it a recursive copy
        ctxt - the Webdav Context
        Returns:
        boolean true if the move has been done otherwise false
      • afterDoMove

        public void afterDoMove​(WebdavResource source,
                                WebdavResource target,
                                boolean overwrite,
                                boolean recursive,
                                WebdavContext ctxt)
        Must be called by Sub Implementation to resolve properties and locks problem. Parameters are same than doMove().
        Parameters:
        source - the source WebdavResource
        target - the target WebdavResource
        overwrite - a boolean indicate to overite or not the resource
        recursive - is it a recursive copy
        ctxt - the Webdav Context
      • doCreate

        public abstract boolean doCreate​(WebdavResource resource,
                                         boolean overwrite,
                                         boolean isFolder,
                                         WebdavContext ctxt)
        This method perform create from one Webdav Resource
        Parameters:
        resource - the Webdav Resource
        overwrite - a boolean indicate to ovewrite the resource
        isFolder - create a File or a Folder
        ctxt -
        Returns:
        boolean true if the create has been done otherwise false
      • doDelete

        public boolean doDelete​(WebdavResource resource,
                                boolean recursive,
                                WebdavContext ctxt)
        This method perform delete from one Webdav Resource
        Parameters:
        resource - the Webdav Resource
        recursive - is it a recursive delete
        ctxt -
        Returns:
        boolean true if the delete has been done otherwise false
      • afterDoDelete

        public void afterDoDelete​(WebdavResource resource,
                                  WebdavContext ctxt)
        Must be called by Sub Implementation to resolve properties and locks problem. Parameters are same than doDelete().
        Parameters:
        resource - the Webdav Resource
        ctxt - the Webdav Context
      • doPut

        public boolean doPut​(WebdavResource resource,
                             boolean overwrite,
                             WebdavContext ctxt)
                      throws javax.servlet.ServletException,
                             java.io.IOException
        This method will do a create/overwrite a File or a Folder
        Parameters:
        resource - the WebdavResource
        overwrite - a boolean indicate to overite the resource
        ctxt - the Webdav Context
        Returns:
        boolean true if put has been done
        Throws:
        javax.servlet.ServletException
        java.io.IOException
      • matchesIfHeaderCondition

        public boolean matchesIfHeaderCondition​(WebdavContext ctxt)
        Check that the current resource matches the if header condition if any.
        Parameters:
        ctxt - the current WebdavContext
        Returns:
        true if resource matches condition, false otherwise
      • silentFilterResource

        protected boolean silentFilterResource​(WebdavResource resource,
                                               WebdavContext ctxt)
        Return true if the resource should be silently ignored.
        Parameters:
        resource - the WebdavResource
        ctxt - the WebdavContext
        Returns:
        boolean true to ignore resource
      • doLock

        public WebdavLock doLock​(WebdavResource resource,
                                 WebdavContext ctxt)
        This method will parse header to identify and create lock or locks on the given resource If Errors append or Lock only need a refresh then return false otherwise return true.
        Parameters:
        resource - the WebdavResource to lock
        ctxt - the WebdavContext
        Returns:
        WebdavLock if lock has been created
      • doUnlock

        public boolean doUnlock​(WebdavResource resource,
                                WebdavContext ctxt)
        This method will unlock the given resource lock defined in the if header.
        Parameters:
        resource - the WebdavResource to lock
        ctxt - the WebdavContext
        Returns:
        boolean if lock has been deleted
      • hasInternalLock

        public boolean hasInternalLock​(WebdavResource res,
                                       WebdavContext ctxt)
        This method is called for other mecanism outside of Webdav
        Parameters:
        res - the WebdavResource
        ctxt - the Webdav Context
        Returns:
        false
      • isInternallyLocked

        public boolean isInternallyLocked​(WebdavResource res,
                                          WebdavContext ctxt)
        This method is called for other mecanism outside of Webdav
        Parameters:
        res - the WebdavResource
        ctxt - the Webdav Context
        Returns:
        false
      • newLock

        public abstract WebdavLock newLock​(WebdavResource resource,
                                           WebdavContext ctxt)
        This method will return a new WebdavLock implementation
        Parameters:
        resource - the Webdav Resource
        ctxt - the Webdav Context
        Returns:
        a new WebdavLock
      • getLocks

        public java.util.Collection<WebdavLock> getLocks​(WebdavResource resource,
                                                         WebdavContext ctxt)
        This method will return all locks on the given resource and on all the parent collection.
        Parameters:
        resource - the Webdav Resource
        ctxt - the Webdav Context
        Returns:
        Collection a Collection of WebdavLock representing the given URI
      • getDescendantLocks

        public java.util.Collection<WebdavLock> getDescendantLocks​(WebdavResource resource,
                                                                   WebdavContext ctxt)
        This method will return locks of descendant on the given resource
        Parameters:
        resource - the Webdav Resource
        ctxt - the Webdav Context
        Returns:
        Collection a Collection of WebdavLock representing the given URI
      • putLock

        public WebdavLock putLock​(WebdavLock lock,
                                  WebdavResource resource,
                                  WebdavContext ctxt)
        This method will put a lock on single given resource
        Parameters:
        lock - the WebdavLock
        resource - the Webdav Resource
        ctxt - the Webdav Context
        Returns:
        true if Lock has been put
      • putLocks

        public WebdavLock putLocks​(WebdavLock lock,
                                   WebdavResource resource,
                                   WebdavContext ctxt)
        This method will put a lock on the given resource and its children
        Parameters:
        lock - the WebdavLock
        resource - the Webdav Resource
        ctxt - the Webdav Context
        Returns:
        WebdavLock the working lock
      • removeLock

        public boolean removeLock​(WebdavLock lock,
                                  WebdavResource resource,
                                  WebdavContext ctxt)
        This method will remove tokens on the given resource and its children If there is no more tokens then remove the lock.
        Parameters:
        lock - the WebdavLock
        resource - the Webdav Resource
        ctxt - the Webdav Context
        Returns:
        WebdavLock the working lock
      • removeLocks

        public boolean removeLocks​(WebdavResource resource,
                                   WebdavContext ctxt)
        This method will remove all lock for a given resource and its children (shared lock will also be removed)
        Parameters:
        resource - the Webdav Resource
        ctxt - the Webdav Context
        Returns:
        true if remove has been done
      • refreshLock

        public WebdavLock refreshLock​(WebdavResource resource,
                                      WebdavContext ctxt)
        This method will refresh a lock on the given resource and returned the refreshed lock if any or null otherwise.
        Parameters:
        resource - the Webdav Resource
        ctxt - the Webdav Context
        Returns:
        the Lock which has been refresh or null if none was refreshed