Class WebdavContext

  • Direct Known Subclasses:
    CatWebdavContext, FileWebdavContext

    public abstract class WebdavContext
    extends java.lang.Object
    This class is an Abstract Representation of a Webdav Context. It is used to:
    • Handle and wrap all Servlet elements: Request, Response, Config...
    • Manage response/error status code/message
    • Write XML response for PROPFIND or LOCK
    • Decode webdav header parameters
    • Partially handle Webdav Properties in mempory
    Since:
    jcms-5.5.0
    Version:
    $Revision: 118093 $
    Author:
    Jean-Philippe Encausse
    • Field Summary

      Fields 
      Modifier and Type Field Description
      javax.servlet.ServletConfig conf  
      static java.lang.String EMPTY_STRING
      EMPTY_STRING Convenient empty String
      protected boolean hasError  
      protected java.text.SimpleDateFormat httpDate  
      protected java.text.SimpleDateFormat httpDateUS  
      static int INFINITY
      INFINITY used for internal RFC2518
      protected byte[] inputStreamContent  
      protected java.text.SimpleDateFormat isoDate  
      java.lang.String lang  
      java.util.Locale locale  
      protected static java.util.Hashtable<java.lang.Integer,​java.lang.String> mapStatusCodes
      This Hashtable contains the mapping of HTTP and WebDAV status codes to descriptive text.
      static org.jdom.Namespace NAMESPACE
      WebDav RFC2518 NAMESPACE - DAV: used for RFC2518 Properties declaration - D shortcut
      static org.jdom.Namespace NAMESPACE_MS
      When PROPFINDing collections, the webfolder client tries to retrieve values for a set of properties in the "DAV:" namespace, although they aren't defined in any WebDAV related specification (DAV:contentclass, DAV:defaultdocument, DAV:href, DAV:iscollection, DAV:ishidden, DAV:isreadonly, DAV:isroot, DAV:isstructureddocument, DAV:lastaccessed, DAV:name and DAV:parentname).
      protected java.lang.String originalPathHeader  
      protected static java.util.Set<WebdavProperty> propAllSet  
      protected static java.util.Set<WebdavProperty> propFileSet  
      protected static java.util.Set<WebdavProperty> propMSWebFolderSet
      Microsoft Implementation can be found here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wss/wss/_cdo_schema_dav.asp http://www.greenbytes.de/tech/webdav/webdavfaq.html http://www.greenbytes.de/tech/webdav/draft-hopmann-collection-props-00.txt
      protected static java.util.Set<WebdavProperty> propRFC2518Set
      Sets of webdav properties used to filter webdav properties for folder, files, microsoft, rfc2518
      protected static java.util.Set<WebdavProperty> propSubSet  
      javax.servlet.http.HttpServletRequest req  
      javax.servlet.http.HttpServletResponse res  
      static java.lang.String REVISION  
      static int SC_ACCEPTED
      Status code (202) indicating that a request was accepted for processing, but was not completed.
      static int SC_BAD_GATEWAY
      Status code (502) indicating that the HTTP server received an invalid response from a server it consulted when acting as a proxy or gateway.
      static int SC_BAD_REQUEST
      Status code (400) indicating the request sent by the client was syntactically incorrect.
      static int SC_CONFLICT
      Status code (409) indicating that the request could not be completed due to a conflict with the current state of the resource.
      static int SC_CONTINUE
      Status code (100) indicating the client may continue with its request.
      static int SC_CREATED
      Status code (201) indicating the request succeeded and created a new resource on the server.
      static int SC_FORBIDDEN
      Status code (403) indicating the server understood the request but refused to fulfill it.
      static int SC_INSUFFICIENT_SPACE_ON_RESOURCE
      Status code (419) indicating that the resource does not have sufficient space to record the state of the resource after the execution of this method.
      static int SC_INTERNAL_SERVER_ERROR
      Status code (500) indicating an error inside the HTTP service which prevented it from fulfilling the request.
      static int SC_LOCKED
      Status code (423) indicating the destination resource of a method is locked, and either the request did not contain a valid Lock-Info header, or the Lock-Info header identifies a lock held by another principal.
      static int SC_METHOD_FAILURE
      Status code (420) indicating the method was not executed on a particular resource within its scope because some part of the method's execution failed causing the entire method to be aborted.
      static int SC_METHOD_NOT_ALLOWED
      Status code (405) indicating the method specified is not allowed for the resource.
      static int SC_MOVED_PERMANENTLY
      Status code (301) indicating that the resource has permanently moved to a new location, and that future references should use a new URI with their requests.
      static int SC_MOVED_TEMPORARILY
      Status code (302) indicating that the resource has temporarily moved to another location, but that future references should still use the original URI to access the resource.
      static int SC_MULTI_STATUS
      Status code (207) indicating that the response requires providing status for multiple independent operations.
      static int SC_NO_CONTENT
      Status code (204) indicating that the request succeeded but that there was no new information to return.
      static int SC_NOT_FOUND
      Status code (404) indicating that the requested resource is not available.
      static int SC_NOT_IMPLEMENTED
      Status code (501) indicating the HTTP service does not support the functionality needed to fulfill the request.
      static int SC_NOT_MODIFIED
      Status code (304) indicating that a conditional GET operation found that the resource was available and not modified.
      static int SC_OK
      Status code (200) indicating the request succeeded normally.
      static int SC_PRECONDITION_FAILED
      Status code (412) indicating the precondition given in one or more of the request-header fields evaluated to false when it was tested on the server.
      static int SC_REQUEST_TOO_LONG
      Status code (413) indicating the server is refusing to process a request because the request entity is larger than the server is willing or able to process.
      static int SC_SERVICE_UNAVAILABLE
      Status code (503) indicating that the HTTP service is temporarily overloaded, and unable to handle the request.
      static int SC_UNAUTHORIZED
      Status code (401) indicating that the request requires HTTP authentication.
      static int SC_UNPROCESSABLE_ENTITY
      Status code (418) indicating the entity body submitted with the PATCH method was not understood by the resource.
      static int SC_UNSUPPORTED_MEDIA_TYPE
      Status code (415) indicating the server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method.
      protected java.lang.String servletURI  
      protected static java.util.Set<java.lang.Integer> setOkStatusCodes
      This HashSet contains all StatusCodes that doesn't define an error.
      protected java.util.List<java.lang.Integer> statusCode  
      protected java.util.List<org.jdom.Element> statusElm  
      protected java.util.List<java.lang.String> statusMsg  
      protected java.util.List<java.lang.String> statusPath  
    • Constructor Summary

      Constructors 
      Constructor Description
      WebdavContext()  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void addHeader​(java.lang.String key, java.lang.String value)
      Encapsulate response.addHeader()
      protected static void addStatusCodeMap​(int nKey, java.lang.String strVal)
      Adds a new status code -> status text mapping.
      protected static void addStatusCodeSet​(int nKey)
      Adds a new status code.
      void appendStatus​(int code)
      Append a StatusCode to the Context.
      void appendStatus​(int code, java.lang.String message)
      Append a StatusCode to the Context.
      void appendStatus​(int code, java.lang.String message, java.lang.String path)
      Append a StatusCode to the Context.
      void appendStatus​(int code, java.lang.String message, java.lang.String path, org.jdom.Element elm)
      Append a StatusCode to the Context.
      abstract boolean authenticate()
      This method have to do all authentication stuff with any behavior
      static java.lang.String decodePath​(java.lang.String path)
      Call URLDecoder with try/catch
      static java.lang.String encodePath​(java.lang.String s)
      Convenient method to encode a WebDav path using webdav encoding.
      static java.lang.String escapeWebdavChars​(java.lang.String str)
      Replace characters not supported in WebDAV from the specfied string.
      int getDepthHeader()
      Decode the depth Header or INFINITY if none
      java.lang.String getDestinationHeader()
      Decode the Destination Path
      java.lang.String getHttpDate​(long date)
      Get the HTTP format of the specified date.
      java.lang.String getHttpDate​(long date, java.util.Locale locale)
      Get the HTTP format of the specified date.
      java.lang.String getIfHeader()
      Decode the if Header
      java.lang.String getIfRangeHeader()
      Decode the If-Range Header
      java.lang.String getInitParam​(java.lang.String name)
      This method wrap ServletConfig.getInitParameter()
      java.util.Iterator<java.lang.String> getInitParameterNames()
      This method wrap the ServletConfig.getInitParameterNames()
      byte[] getInputStreamContent()
      This method will cache the request InputStream to allow multiple parsing
      java.lang.String getISO8601Date​(long date)
      Format a Date using the format: yyyy-MM-dd'T'HH:mm:ss'Z' ISO 8601
      java.lang.String getLockTokenHeader()
      Decode the Lock-Token Header
      java.lang.String getLockTokenValue()
      Retrieve the value extracted from the Lock-Token header.
      java.lang.String getOriginalPathHeader()  
      boolean getOverwriteHeader()
      Decode the Overwrite Header or INFINITY if none
      java.lang.String getPathHeader()
      Decode the Path Header
      java.lang.String getRangeHeader()
      Decode the Range
      java.lang.String getRealPath​(java.lang.String uri)
      Returns the real file path for the given uri.
      java.lang.String getServletURI()
      Return the Servlet URI ie http://server:port/webapp/servlet/my/path/resource.ext -> /webapp/servlet
      ie http://server:port/webapp/servlet/my/path/ -> /webapp/servlet
      TODO: Should check behavior with all application Server
      static java.lang.String getStatusText​(int nHttpStatusCode)
      Returns the HTTP status text for the HTTP or WebDav status code specified by looking it up in the static mapping.
      int getTimeoutHeader()
      Decode the Timeout Header
      abstract WebdavFileSystem getWebdavFileSystem()  
      boolean hasErrors()
      Check if the Context contains errors
      void init​(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, javax.servlet.ServletConfig conf)
      This method will initialize the WebdavContext with given HttpServletRequest, HttpServletResponse, and ServletConfig.
      boolean initAfterAuthentication()
      This method will initialize the WebdavContext.
      boolean isError​(int code)
      Check the kind of a Status Code.
      void sendError()
      Lookig for first error append then send an error throught response.
      void sendError​(int code, java.lang.String message)
      Send an error throught response
      void sendFile​(int code, WebdavResource resource, boolean printContent)
      Send a File throught response
      void sendHtml​(int code, java.lang.String html, WebdavResource resource, boolean printContent)
      Send html representation of a Webdav Folder throught response
      void sendMultiStatus​(java.util.List<org.jdom.Element> responseElms)
      Send a multivalued response status
      void sendMultiStatus​(java.util.List<org.jdom.Element> responseElms, int status)
      Send a multivalued response status Set the response status code Set the Content Type Add XML Tag <multistatus> Embed in the tag the response
      void sendMultiStatus​(org.jdom.Element responseElm)
      Send a multivalued response status
      void sendSingleStatus​(int status, java.lang.String responseText)
      Send a response status Set the Content Type
      void sendSingleStatus​(int status, org.jdom.Element responseElm)
      Send a response status Set the Content Type
      void sendStatus()
      If there is no Status code then return If there is only one status code then sendError() or setStatus() If there is more than one Status code then sendMultiStatus()
      boolean service()
      Hook for service method to do Authentification and other filters
      void setHeader​(java.lang.String key, java.lang.String value)
      Encapsulate response.setHeader()
      java.lang.String writeHtmlFolder​(WebdavResource res)
      This method will generate an HTML Page representing a Web Folder TODO: Should Format Strings to be Web Compatible
      org.jdom.Element writeLock​(WebdavLock lock)
      <activelock>   <locktype></locktype>   <lockscope></lockscope>   <depth></depth>   <owner></owner>   <timeout></timeout>   <locktoken>     <href></href>   </locktoken> </activelock>
      org.jdom.Element writeLocks​(java.util.Collection<WebdavLock> locks)
      <lockdiscovery>The lock list</lockdiscovery>
      protected java.util.List<org.jdom.Element> writeProperties​(java.lang.String resourcePath, java.lang.String statusMsg, com.jalios.jcms.webdav.WebdavManager.PropFindType propType, java.util.Collection<WebdavProperty> properties, WebdavContext ctxt)
      This method will write all properties of a given resource in a given type
      java.util.List<org.jdom.Element> writeProperties_FindAllProp​(java.lang.String resourcePath)  
      java.util.List<org.jdom.Element> writeProperties_FindByProperty​(java.lang.String resourcePath, java.util.Collection<WebdavProperty> props, java.util.Collection<WebdavProperty> propertiesNotFound)  
      java.util.List<org.jdom.Element> writeProperties_FindPropertyNames()
      From RFC 2518 <creationdate/> <displayname/> <getcontentlanguage/> <getcontentlength/> <getcontenttype/> <getetag/> <getlastmodified/> <resourcetype/> <source/> <lockdiscovery/> <supportedlock/> From Microsoft Web Folders http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wss/wss/_cdo_schema_dav.asp http://www.greenbytes.de/tech/webdav/webdavfaq.html http://www.greenbytes.de/tech/webdav/draft-hopmann-collection-props-00.txt <name/> <href/> <isreadonly/> <parentname/> <ishidden/> <contentclass/> <lastaccessed/> <defaultdocument/> <isroot/> <iscollection/> <isstructureddocument/> <save-view-location/> <save-profile-form-location/>
      java.util.List<org.jdom.Element> writePropPatch​(WebdavResource resource, java.util.List<WebdavProperty> wdPropList)
      Write PropPatch XML answer for the given WebdavResource.
      org.jdom.Element writeResponse​(java.lang.String path, java.util.List<org.jdom.Element> contentList)
      <response> <href></href> content </response>
      org.jdom.Element writeResponseProperties​(java.lang.String resPath, com.jalios.jcms.webdav.WebdavManager.PropFindType propType, java.util.Collection<WebdavProperty> properties, WebdavContext ctxt)  
      org.jdom.Element writeStatus​(int code, java.lang.String message)
      <status>HTTP/1.1 code message</status>
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • SC_OK

        public static final int SC_OK
        Status code (200) indicating the request succeeded normally.
        See Also:
        Constant Field Values
      • SC_CREATED

        public static final int SC_CREATED
        Status code (201) indicating the request succeeded and created a new resource on the server.
        See Also:
        Constant Field Values
      • SC_ACCEPTED

        public static final int SC_ACCEPTED
        Status code (202) indicating that a request was accepted for processing, but was not completed.
        See Also:
        Constant Field Values
      • SC_NO_CONTENT

        public static final int SC_NO_CONTENT
        Status code (204) indicating that the request succeeded but that there was no new information to return.
        See Also:
        Constant Field Values
      • SC_MOVED_PERMANENTLY

        public static final int SC_MOVED_PERMANENTLY
        Status code (301) indicating that the resource has permanently moved to a new location, and that future references should use a new URI with their requests.
        See Also:
        Constant Field Values
      • SC_MOVED_TEMPORARILY

        public static final int SC_MOVED_TEMPORARILY
        Status code (302) indicating that the resource has temporarily moved to another location, but that future references should still use the original URI to access the resource.
        See Also:
        Constant Field Values
      • SC_NOT_MODIFIED

        public static final int SC_NOT_MODIFIED
        Status code (304) indicating that a conditional GET operation found that the resource was available and not modified.
        See Also:
        Constant Field Values
      • SC_BAD_REQUEST

        public static final int SC_BAD_REQUEST
        Status code (400) indicating the request sent by the client was syntactically incorrect.
        See Also:
        Constant Field Values
      • SC_UNAUTHORIZED

        public static final int SC_UNAUTHORIZED
        Status code (401) indicating that the request requires HTTP authentication.
        See Also:
        Constant Field Values
      • SC_FORBIDDEN

        public static final int SC_FORBIDDEN
        Status code (403) indicating the server understood the request but refused to fulfill it.
        See Also:
        Constant Field Values
      • SC_NOT_FOUND

        public static final int SC_NOT_FOUND
        Status code (404) indicating that the requested resource is not available.
        See Also:
        Constant Field Values
      • SC_INTERNAL_SERVER_ERROR

        public static final int SC_INTERNAL_SERVER_ERROR
        Status code (500) indicating an error inside the HTTP service which prevented it from fulfilling the request.
        See Also:
        Constant Field Values
      • SC_NOT_IMPLEMENTED

        public static final int SC_NOT_IMPLEMENTED
        Status code (501) indicating the HTTP service does not support the functionality needed to fulfill the request.
        See Also:
        Constant Field Values
      • SC_BAD_GATEWAY

        public static final int SC_BAD_GATEWAY
        Status code (502) indicating that the HTTP server received an invalid response from a server it consulted when acting as a proxy or gateway.
        See Also:
        Constant Field Values
      • SC_SERVICE_UNAVAILABLE

        public static final int SC_SERVICE_UNAVAILABLE
        Status code (503) indicating that the HTTP service is temporarily overloaded, and unable to handle the request.
        See Also:
        Constant Field Values
      • SC_CONTINUE

        public static final int SC_CONTINUE
        Status code (100) indicating the client may continue with its request. This interim response is used to inform the client that the initial part of the request has been received and has not yet been rejected by the server.
        See Also:
        Constant Field Values
      • SC_METHOD_NOT_ALLOWED

        public static final int SC_METHOD_NOT_ALLOWED
        Status code (405) indicating the method specified is not allowed for the resource.
        See Also:
        Constant Field Values
      • SC_CONFLICT

        public static final int SC_CONFLICT
        Status code (409) indicating that the request could not be completed due to a conflict with the current state of the resource.
        See Also:
        Constant Field Values
      • SC_PRECONDITION_FAILED

        public static final int SC_PRECONDITION_FAILED
        Status code (412) indicating the precondition given in one or more of the request-header fields evaluated to false when it was tested on the server.
        See Also:
        Constant Field Values
      • SC_REQUEST_TOO_LONG

        public static final int SC_REQUEST_TOO_LONG
        Status code (413) indicating the server is refusing to process a request because the request entity is larger than the server is willing or able to process.
        See Also:
        Constant Field Values
      • SC_UNSUPPORTED_MEDIA_TYPE

        public static final int SC_UNSUPPORTED_MEDIA_TYPE
        Status code (415) indicating the server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method.
        See Also:
        Constant Field Values
      • SC_MULTI_STATUS

        public static final int SC_MULTI_STATUS
        Status code (207) indicating that the response requires providing status for multiple independent operations.
        See Also:
        Constant Field Values
      • SC_UNPROCESSABLE_ENTITY

        public static final int SC_UNPROCESSABLE_ENTITY
        Status code (418) indicating the entity body submitted with the PATCH method was not understood by the resource.
        See Also:
        Constant Field Values
      • SC_INSUFFICIENT_SPACE_ON_RESOURCE

        public static final int SC_INSUFFICIENT_SPACE_ON_RESOURCE
        Status code (419) indicating that the resource does not have sufficient space to record the state of the resource after the execution of this method.
        See Also:
        Constant Field Values
      • SC_METHOD_FAILURE

        public static final int SC_METHOD_FAILURE
        Status code (420) indicating the method was not executed on a particular resource within its scope because some part of the method's execution failed causing the entire method to be aborted.
        See Also:
        Constant Field Values
      • SC_LOCKED

        public static final int SC_LOCKED
        Status code (423) indicating the destination resource of a method is locked, and either the request did not contain a valid Lock-Info header, or the Lock-Info header identifies a lock held by another principal.
        See Also:
        Constant Field Values
      • mapStatusCodes

        protected static final java.util.Hashtable<java.lang.Integer,​java.lang.String> mapStatusCodes
        This Hashtable contains the mapping of HTTP and WebDAV status codes to descriptive text. This is a static variable.
      • setOkStatusCodes

        protected static final java.util.Set<java.lang.Integer> setOkStatusCodes
        This HashSet contains all StatusCodes that doesn't define an error.
      • NAMESPACE

        public static final org.jdom.Namespace NAMESPACE
        WebDav RFC2518 NAMESPACE - DAV: used for RFC2518 Properties declaration - D shortcut
      • propRFC2518Set

        protected static final java.util.Set<WebdavProperty> propRFC2518Set
        Sets of webdav properties used to filter webdav properties for folder, files, microsoft, rfc2518
      • NAMESPACE_MS

        public static final org.jdom.Namespace NAMESPACE_MS
        When PROPFINDing collections, the webfolder client tries to retrieve values for a set of properties in the "DAV:" namespace, although they aren't defined in any WebDAV related specification (DAV:contentclass, DAV:defaultdocument, DAV:href, DAV:iscollection, DAV:ishidden, DAV:isreadonly, DAV:isroot, DAV:isstructureddocument, DAV:lastaccessed, DAV:name and DAV:parentname). Except one (DAV:hidden), none of these properties seems to be actually used by the client. Note that proprietary properties (vendor extensions) MUST NOT use the "DAV:" namespace.
      • propMSWebFolderSet

        protected static final java.util.Set<WebdavProperty> propMSWebFolderSet
        Microsoft Implementation can be found here:
        • http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wss/wss/_cdo_schema_dav.asp
        • http://www.greenbytes.de/tech/webdav/webdavfaq.html
        • http://www.greenbytes.de/tech/webdav/draft-hopmann-collection-props-00.txt
      • propAllSet

        protected static final java.util.Set<WebdavProperty> propAllSet
      • propFileSet

        protected static final java.util.Set<WebdavProperty> propFileSet
      • propSubSet

        protected static final java.util.Set<WebdavProperty> propSubSet
      • httpDateUS

        protected java.text.SimpleDateFormat httpDateUS
      • httpDate

        protected java.text.SimpleDateFormat httpDate
      • isoDate

        protected java.text.SimpleDateFormat isoDate
      • EMPTY_STRING

        public static final java.lang.String EMPTY_STRING
        EMPTY_STRING Convenient empty String
        See Also:
        Constant Field Values
      • INFINITY

        public static final int INFINITY
        INFINITY used for internal RFC2518
        See Also:
        Constant Field Values
      • statusPath

        protected java.util.List<java.lang.String> statusPath
      • statusCode

        protected java.util.List<java.lang.Integer> statusCode
      • statusMsg

        protected java.util.List<java.lang.String> statusMsg
      • statusElm

        protected java.util.List<org.jdom.Element> statusElm
      • hasError

        protected boolean hasError
      • inputStreamContent

        protected byte[] inputStreamContent
      • servletURI

        protected java.lang.String servletURI
      • req

        public javax.servlet.http.HttpServletRequest req
      • res

        public javax.servlet.http.HttpServletResponse res
      • conf

        public javax.servlet.ServletConfig conf
      • lang

        public java.lang.String lang
      • locale

        public java.util.Locale locale
      • originalPathHeader

        protected java.lang.String originalPathHeader
    • Constructor Detail

      • WebdavContext

        public WebdavContext()
    • Method Detail

      • getStatusText

        public static java.lang.String getStatusText​(int nHttpStatusCode)
        Returns the HTTP status text for the HTTP or WebDav status code specified by looking it up in the static mapping. This is a static function.
        Parameters:
        nHttpStatusCode - [IN] HTTP or WebDAV status code
        Returns:
        A string with a short descriptive phrase for the HTTP status code (e.g., "OK").
      • addStatusCodeMap

        protected static void addStatusCodeMap​(int nKey,
                                               java.lang.String strVal)
        Adds a new status code -> status text mapping. This is a static method because the mapping is a static variable.
        Parameters:
        nKey - [IN] HTTP or WebDAV status code
        strVal - [IN] HTTP status text
      • addStatusCodeSet

        protected static void addStatusCodeSet​(int nKey)
        Adds a new status code. This is a static method because the mapping is a static variable.
        Parameters:
        nKey - [IN] HTTP or WebDAV status code
      • init

        public void init​(javax.servlet.http.HttpServletRequest req,
                         javax.servlet.http.HttpServletResponse res,
                         javax.servlet.ServletConfig conf)
        This method will initialize the WebdavContext with given HttpServletRequest, HttpServletResponse, and ServletConfig.
        Parameters:
        req - the HttpServletRequest
        res - the HttpServletResponse
        conf - the ServletConfig
      • initAfterAuthentication

        public boolean initAfterAuthentication()
        This method will initialize the WebdavContext.
        Returns:
        true
      • service

        public boolean service()
        Hook for service method to do Authentification and other filters
        Returns:
        false to stop request processing
      • getWebdavFileSystem

        public abstract WebdavFileSystem getWebdavFileSystem()
        Returns:
        WebdavFileSystem the Webdav FileSystem from the context or any other ways.
      • authenticate

        public abstract boolean authenticate()
        This method have to do all authentication stuff with any behavior
        Returns:
        true if authentication has been done
      • getRealPath

        public java.lang.String getRealPath​(java.lang.String uri)
        Returns the real file path for the given uri. The file path will be in native path format (with native path separators). This method calls context.getRealPath() but it cleans the results to be cross-AppServer. It insures that if the uri contains, resp. does not contains, a trailing '/' the return path will, resp. will not, contains a trailing File.separator.
        Parameters:
        uri - the path of the resource
        Returns:
        path relative to the application root to be translated.
      • getInputStreamContent

        public byte[] getInputStreamContent()
        This method will cache the request InputStream to allow multiple parsing
        Returns:
        byte[] the cached response
      • getServletURI

        public java.lang.String getServletURI()
        Return the Servlet URI ie http://server:port/webapp/servlet/my/path/resource.ext -> /webapp/servlet
        ie http://server:port/webapp/servlet/my/path/ -> /webapp/servlet
        TODO: Should check behavior with all application Server
        Returns:
        String the Servlet URI with the Webapp name
      • getInitParam

        public java.lang.String getInitParam​(java.lang.String name)
        This method wrap ServletConfig.getInitParameter()
        Parameters:
        name - the prameter name
        Returns:
        String the parameter value for the given name
      • getInitParameterNames

        public java.util.Iterator<java.lang.String> getInitParameterNames()
        This method wrap the ServletConfig.getInitParameterNames()
        Returns:
        Iterator on the init parameter names
      • getDestinationHeader

        public java.lang.String getDestinationHeader()
        Decode the Destination Path
        Returns:
        String the Destination Path Header
      • getPathHeader

        public java.lang.String getPathHeader()
        Decode the Path Header
        Returns:
        String the Path Header
      • getOriginalPathHeader

        public java.lang.String getOriginalPathHeader()
      • getOverwriteHeader

        public boolean getOverwriteHeader()
        Decode the Overwrite Header or INFINITY if none
        Returns:
        boolean the Overwrite Header
      • getDepthHeader

        public int getDepthHeader()
        Decode the depth Header or INFINITY if none
        Returns:
        int the depth Header
      • getIfHeader

        public java.lang.String getIfHeader()
        Decode the if Header
        Returns:
        String the if Header
      • getIfRangeHeader

        public java.lang.String getIfRangeHeader()
        Decode the If-Range Header
        Returns:
        String the If-Range Header
      • getRangeHeader

        public java.lang.String getRangeHeader()
        Decode the Range
        Returns:
        String the Range Header
      • getLockTokenHeader

        public java.lang.String getLockTokenHeader()
        Decode the Lock-Token Header
        Returns:
        String the Lock-Token Header
      • getLockTokenValue

        public java.lang.String getLockTokenValue()
        Retrieve the value extracted from the Lock-Token header.
        Returns:
        null if no lock token was provided or if an invalid lock token was specified, otherwise return the value inside the <>
        Since:
        jcms-6.1
      • getTimeoutHeader

        public int getTimeoutHeader()
        Decode the Timeout Header
        Returns:
        int the Timeout Header
      • writeResponse

        public org.jdom.Element writeResponse​(java.lang.String path,
                                              java.util.List<org.jdom.Element> contentList)
        <response> <href></href> content </response>
        Parameters:
        path - the resource path
        contentList - the XML to put inside
        Returns:
        Element the response Element
      • writeResponseProperties

        public org.jdom.Element writeResponseProperties​(java.lang.String resPath,
                                                        com.jalios.jcms.webdav.WebdavManager.PropFindType propType,
                                                        java.util.Collection<WebdavProperty> properties,
                                                        WebdavContext ctxt)
      • writeProperties

        protected java.util.List<org.jdom.Element> writeProperties​(java.lang.String resourcePath,
                                                                   java.lang.String statusMsg,
                                                                   com.jalios.jcms.webdav.WebdavManager.PropFindType propType,
                                                                   java.util.Collection<WebdavProperty> properties,
                                                                   WebdavContext ctxt)
        This method will write all properties of a given resource in a given type
        Parameters:
        resourcePath - the resource to work with
        statusMsg - the status message (May be null or an Error if resource is locked)
        propType - the type of property to display
        properties - the list of property to display
        ctxt - the Webdav Context
      • writeStatus

        public org.jdom.Element writeStatus​(int code,
                                            java.lang.String message)
        <status>HTTP/1.1 code message</status>
        Parameters:
        code - the HTTP Status code
        message - the message to display or null
        Returns:
        String an XML String
      • writeLocks

        public org.jdom.Element writeLocks​(java.util.Collection<WebdavLock> locks)
        <lockdiscovery>The lock list</lockdiscovery>
        Parameters:
        locks - a Collection of WebdavLock locks
        Returns:
        String an XML String
      • writeLock

        public org.jdom.Element writeLock​(WebdavLock lock)
        <activelock>   <locktype></locktype>   <lockscope></lockscope>   <depth></depth>   <owner></owner>   <timeout></timeout>   <locktoken>     <href></href>   </locktoken> </activelock>
        Parameters:
        lock - a WebdavLock
        Returns:
        String an XML String
      • writePropPatch

        public java.util.List<org.jdom.Element> writePropPatch​(WebdavResource resource,
                                                               java.util.List<WebdavProperty> wdPropList)
        Write PropPatch XML answer for the given WebdavResource. This method has not been correctly tested because JCMS does handle correctly PROPATCH for the moment.
        Parameters:
        resource - the Webdav Resource
        wdPropList - the List of WebdavProperty to update (remove when value is null, add/update otherwise)
        Returns:
        String representing the XML response.
      • writeProperties_FindPropertyNames

        public java.util.List<org.jdom.Element> writeProperties_FindPropertyNames()
        From RFC 2518
        • <creationdate/>
        • <displayname/>
        • <getcontentlanguage/>
        • <getcontentlength/>
        • <getcontenttype/>
        • <getetag/>
        • <getlastmodified/>
        • <resourcetype/>
        • <source/>
        • <lockdiscovery/>
        • <supportedlock/>
        From Microsoft Web Folders http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wss/wss/_cdo_schema_dav.asp http://www.greenbytes.de/tech/webdav/webdavfaq.html http://www.greenbytes.de/tech/webdav/draft-hopmann-collection-props-00.txt
        • <name/>
        • <href/>
        • <isreadonly/>
        • <parentname/>
        • <ishidden/>
        • <contentclass/>
        • <lastaccessed/>
        • <defaultdocument/>
        • <isroot/>
        • <iscollection/>
        • <isstructureddocument/>
        • <save-view-location/>
        • <save-profile-form-location/>
        Returns:
        String an XML String
      • writeProperties_FindAllProp

        public java.util.List<org.jdom.Element> writeProperties_FindAllProp​(java.lang.String resourcePath)
        Parameters:
        resourcePath - the resource path to work with
        Returns:
        String an XML String
        See Also:
        writeProperties_FindPropertyNames()
      • writeProperties_FindByProperty

        public java.util.List<org.jdom.Element> writeProperties_FindByProperty​(java.lang.String resourcePath,
                                                                               java.util.Collection<WebdavProperty> props,
                                                                               java.util.Collection<WebdavProperty> propertiesNotFound)
        Parameters:
        resourcePath - the resource path to work with
        props - a Collection of properties to work with
        propertiesNotFound - a Collection filled by wrong properties
        Returns:
        String an XML String
        See Also:
        writeProperties_FindPropertyNames()
      • writeHtmlFolder

        public java.lang.String writeHtmlFolder​(WebdavResource res)
        This method will generate an HTML Page representing a Web Folder TODO: Should Format Strings to be Web Compatible
        Parameters:
        res - the WebdavResource to work with
        Returns:
        String an HTML Web Page representation
      • sendSingleStatus

        public void sendSingleStatus​(int status,
                                     java.lang.String responseText)
        Send a response status
        • Set the Content Type
        Parameters:
        status - the response status
        responseText - the response tag
      • sendSingleStatus

        public void sendSingleStatus​(int status,
                                     org.jdom.Element responseElm)
        Send a response status
        • Set the Content Type
        Parameters:
        status - the response status
        responseElm - the response tag
      • sendMultiStatus

        public void sendMultiStatus​(java.util.List<org.jdom.Element> responseElms,
                                    int status)
        Send a multivalued response status
        • Set the response status code
        • Set the Content Type
        • Add XML Tag <multistatus>
        • Embed in the tag the response
        Parameters:
        status - the response status
        responseElms - the response tag
      • sendMultiStatus

        public void sendMultiStatus​(org.jdom.Element responseElm)
        Send a multivalued response status
        Parameters:
        responseElm - the response tag
      • sendMultiStatus

        public void sendMultiStatus​(java.util.List<org.jdom.Element> responseElms)
        Send a multivalued response status
        Parameters:
        responseElms - the responses tag
      • sendStatus

        public void sendStatus()
        If there is no Status code then return If there is only one status code then sendError() or setStatus() If there is more than one Status code then sendMultiStatus()
      • sendError

        public void sendError​(int code,
                              java.lang.String message)
        Send an error throught response
        Parameters:
        code - the error code
        message - the error message
      • sendError

        public void sendError()
        Lookig for first error append then send an error throught response.
      • sendHtml

        public void sendHtml​(int code,
                             java.lang.String html,
                             WebdavResource resource,
                             boolean printContent)
        Send html representation of a Webdav Folder throught response
        Parameters:
        code - the status code
        html - the html to send
        resource - the WebdavResource
        printContent - HEAD or GET ?
      • sendFile

        public void sendFile​(int code,
                             WebdavResource resource,
                             boolean printContent)
        Send a File throught response
        Parameters:
        code - the error code
        resource - the WebdavResource
        printContent - HEAD or GET ?
      • addHeader

        public void addHeader​(java.lang.String key,
                              java.lang.String value)
        Encapsulate response.addHeader()
        Parameters:
        key - the header key
        value - the header value
      • setHeader

        public void setHeader​(java.lang.String key,
                              java.lang.String value)
        Encapsulate response.setHeader()
        Parameters:
        key - the header key
        value - the header value
      • isError

        public boolean isError​(int code)
        Check the kind of a Status Code.
        Parameters:
        code - the StatusCode
        Returns:
        true if the Status Code is an Error
      • hasErrors

        public boolean hasErrors()
        Check if the Context contains errors
        Returns:
        true if Context contains errors status codes
      • appendStatus

        public void appendStatus​(int code,
                                 java.lang.String message,
                                 java.lang.String path,
                                 org.jdom.Element elm)
        Append a StatusCode to the Context.
        Parameters:
        code - the status code
        message - the status message
        path - the status path. Must start with a /
        elm - an optional elm element to use for output instead of simple message
      • appendStatus

        public void appendStatus​(int code,
                                 java.lang.String message,
                                 java.lang.String path)
        Append a StatusCode to the Context.
        Parameters:
        code - the status code
        message - the status message
        path - the status path. Must start with a /
      • appendStatus

        public void appendStatus​(int code,
                                 java.lang.String message)
        Append a StatusCode to the Context.
        Parameters:
        code - the status code
        message - the status message
      • appendStatus

        public void appendStatus​(int code)
        Append a StatusCode to the Context.
        Parameters:
        code - the status code
      • escapeWebdavChars

        public static java.lang.String escapeWebdavChars​(java.lang.String str)
        Replace characters not supported in WebDAV from the specfied string.

        Invalid characters are all characters specified in property channel.webdav.invalid-chars.
        Those characters are replaced with the character specified by property channel.webdav.invalid-chars.replacement, or if property is empty, a dash (-).

        Parameters:
        str - the string to escape
        Returns:
        the escaped string if any invalid characters were found, otherwise return the same string.
      • getISO8601Date

        public java.lang.String getISO8601Date​(long date)
        Format a Date using the format: yyyy-MM-dd'T'HH:mm:ss'Z' ISO 8601
        Parameters:
        date - a long representing a date
        Returns:
        String a formated Date
      • getHttpDate

        public final java.lang.String getHttpDate​(long date)
        Get the HTTP format of the specified date. The used format is EEE, dd MMM yyyy HH:mm:ss zzz
        Parameters:
        date - a long representing a date
        Returns:
        String a formated Date
      • getHttpDate

        public final java.lang.String getHttpDate​(long date,
                                                  java.util.Locale locale)
        Get the HTTP format of the specified date. The used format is EEE, dd MMM yyyy HH:mm:ss zzz
        Parameters:
        date - a long representing a date
        locale - the locale to use
        Returns:
        String a formated Date
      • encodePath

        public static java.lang.String encodePath​(java.lang.String s)
        Convenient method to encode a WebDav path using webdav encoding.
        Same implementation as URLEncoder.encode(String, String), but space is encoded with %20 and '/' is not encoded.
        Parameters:
        s - String to be translated.
        Returns:
        the translated String.
        Since:
        jcms-6.1
        See Also:
        Util.encodeUrl(String, String)
      • decodePath

        public static java.lang.String decodePath​(java.lang.String path)
        Call URLDecoder with try/catch
        Parameters:
        path - the URL encoded path
        Returns:
        String the decoded path