Class WebdavNsIntf

  • All Implemented Interfaces:
    Serializable, org.bedework.util.logging.Logged

    public abstract class WebdavNsIntf
    extends Object
    implements org.bedework.util.logging.Logged, Serializable
    This acts as an interface to the underlying namespace for which this servlet is acting as a gateway. This could be a file system, a set of dynamically created objects or some sort of CMS for example. A namespace consists of a number of nodes which may be containers for other nodes or leaf nodes. All nodes are considered identical in their capabilities, that is, a non-terminal node might contain content. Some nodes are aliases of other nodes (e.g. symlinks in a unix file system). By default these aliases will be followed.
    Author:
    Mike Douglass
    See Also:
    Serialized Form
    • Constructor Detail

      • WebdavNsIntf

        public WebdavNsIntf()
    • Method Detail

      • init

        public void init​(WebdavServlet servlet,
                         javax.servlet.http.HttpServletRequest req,
                         HashMap<String,​MethodBase.MethodInfo> methods,
                         boolean dumpContent)
                  throws WebdavException
        Called before any other method is called to allow initialisation to take place at the first or subsequent requests
        Parameters:
        servlet - the WebDAV servlet
        req - http request
        methods - HashMap table of method info
        dumpContent - true to provide a debug trace of content
        Throws:
        WebdavException - on error
      • getAccount

        public String getAccount()
        Returns:
        String
      • getXmlEmit

        public org.bedework.util.xml.XmlEmit getXmlEmit()
        Returns:
        XmlEmit xmlemitter
      • getRequest

        public javax.servlet.http.HttpServletRequest getRequest()
        Returns:
        HttpServletRequest
      • getServerInfo

        public ServerInfo getServerInfo()
        Returns:
        server info populated for basic webdav
      • emitError

        public void emitError​(QName errorTag,
                              String extra,
                              org.bedework.util.xml.XmlEmit xml)
        Emit some failed precondition tag
        Parameters:
        errorTag -
        extra -
        xml -
      • getSysIntf

        public abstract WdSysIntf getSysIntf()
        Returns:
        system interface
      • getAccessUtil

        public abstract AccessUtil getAccessUtil()
                                          throws WebdavException
        Get an object suitable for use in parsing acls and generating access.
        Returns:
        AccessUtil implementation.
        Throws:
        WebdavException - on error
      • getMethodNames

        public Collection<String> getMethodNames()
        Returns:
        Collection of method names.
      • getMethod

        public MethodBase getMethod​(String name)
                             throws WebdavException
        Return the named initialised method or null if no such method or the method requires authentication and we are anonymous
        Parameters:
        name - name
        Returns:
        MethodBase object or null
        Throws:
        WebdavException - on error
      • getAnonymous

        public boolean getAnonymous()
        Returns:
        boolean true for anon access
      • getUri

        public String getUri​(String href)
                      throws WebdavException
        Return the part of the href referring to the actual entity, e.g.
        for http://localhost/ucaldav/user/caluser/calendar/2656-uwcal-demouwcalendar@mysite.edu.ics
        user/caluser/calendar/2656-uwcal-demouwcalendar@mysite.edu.ics
        Parameters:
        href -
        Returns:
        String
        Throws:
        WebdavException - on error
      • makeName

        public String makeName​(String val)
        Turn val into something which can be used as a name for an entity. This involves removing path delimiters such as "/".
        Parameters:
        val -
        Returns:
        modified name
      • getServlet

        public WebdavServlet getServlet()
        Returns:
        WebdavServlet
      • getReturnMultistatusOk

        public boolean getReturnMultistatusOk()
        Returns:
        boolean
      • addNamespace

        public void addNamespace​(org.bedework.util.xml.XmlEmit xml)
        Add any namespaces for xml tag names in requests and responses. An abbreviation will be supplied by the servlet. The name should be globally unique in a global sense so don't return something like "RPI:"

        Something more like "http://ahost.rpi.edu/webdav/"

        Parameters:
        xml -
      • getDirectoryBrowsingDisallowed

        public abstract boolean getDirectoryBrowsingDisallowed()
                                                        throws WebdavException
        Return true if the system disallows directory browsing.
        Returns:
        boolean
        Throws:
        WebdavException - on error
      • rollback

        public abstract void rollback()
        Called on the way out before close if there was an error.
      • close

        public abstract void close()
                            throws WebdavException
        Called on the way out to allow resources to be freed.
        Throws:
        WebdavException - on error
      • getSupportedLocks

        public abstract String getSupportedLocks()
        Returns the supported locks for the supportedlock property.

        To ensure these will work always provide the full namespace "DAV:" for example, the result for supported exclusive and shared write locks would be the string "<DAV:lockentry>" + " <DAV:lockscope><DAV:exclusive/><DAV:/lockscope>" + " <DAV:locktype><DAV:write/><DAV:/locktype>" + "<DAV:/lockentry>" + "<DAV:lockentry>" + " <DAV:lockscope><DAV:shared/><DAV:/lockscope>" + "<DAV:/lockentry>"

        Returns:
        String response
      • getAccessControl

        public abstract boolean getAccessControl()
        Returns true if the namespace supports access control
        Returns:
        boolean
      • getNode

        public abstract WebdavNsNode getNode​(String uri,
                                             int existence,
                                             int nodeType,
                                             boolean addMember)
                                      throws WebdavException
        Retrieves a node by uri, following any links.
        Parameters:
        uri - String decoded uri of the node to retrieve
        existence - Say's something about the state of existence
        nodeType - Say's something about the type of node
        addMember - Called from POST with addMember
        Returns:
        WebdavNsNode node specified by the URI or the node aliased by the node at the URI.
        Throws:
        WebdavException - on error
      • getParent

        public abstract WebdavNsNode getParent​(WebdavNsNode node)
                                        throws WebdavException
        Returns the parent of a node.
        Parameters:
        node - node in question
        Returns:
        WebdavNsNode node's parent, or null if the specified node is the root
        Throws:
        WebdavException - on error
      • prefetch

        public boolean prefetch​(javax.servlet.http.HttpServletRequest req,
                                javax.servlet.http.HttpServletResponse resp,
                                WebdavNsNode node)
                         throws WebdavException
        Called before fetching in GET processing. ALlows implementations to add some pre-processing, for instance the schedule-tag processing in CalDAV.

        This method handles etag processing.

        Parameters:
        req - http request
        resp - http response
        node - - the node
        Returns:
        true - just proceed otherwise status is set
        Throws:
        WebdavException - on error
      • getContent

        public abstract WebdavNsIntf.Content getContent​(javax.servlet.http.HttpServletRequest req,
                                                        javax.servlet.http.HttpServletResponse resp,
                                                        String contentType,
                                                        WebdavNsNode node)
                                                 throws WebdavException
        Returns a Content object for the content.
        Parameters:
        req - http request
        resp - http response
        contentType - if non-null specifies the content we want
        node - node in question
        Returns:
        content.
        Throws:
        WebdavException - on error
      • getAcceptContentType

        public abstract String getAcceptContentType​(javax.servlet.http.HttpServletRequest req)
                                             throws WebdavException
        Returns:
        a valid content type string
        Throws:
        WebdavException
      • putContent

        public WebdavNsIntf.PutContentResult putContent​(javax.servlet.http.HttpServletRequest req,
                                                        String resourceUri,
                                                        javax.servlet.http.HttpServletResponse resp,
                                                        boolean fromPost,
                                                        Headers.IfHeaders ifHeaders)
                                                 throws WebdavException
        Put content for the PUT or POST methods
        Parameters:
        req - the request
        resourceUri - if not null use this otherwise obtain from request
        resp - the response
        fromPost - POST style - create
        ifHeaders - info from headers
        Returns:
        PutContentResult result of creating
        Throws:
        WebdavException - on error
      • putContent

        public abstract WebdavNsIntf.PutContentResult putContent​(javax.servlet.http.HttpServletRequest req,
                                                                 javax.servlet.http.HttpServletResponse resp,
                                                                 WebdavNsNode node,
                                                                 String[] contentTypePars,
                                                                 Reader contentRdr,
                                                                 Headers.IfHeaders ifHeaders)
                                                          throws WebdavException
        Set the content from a Reader
        Parameters:
        req -
        resp - For any additional headers
        node - node in question.
        contentTypePars - null or values from content-type header
        contentRdr - Reader for content
        ifHeaders - info from headers
        Returns:
        PutContentResult result of creating
        Throws:
        WebdavException - on error
      • putBinaryContent

        public abstract WebdavNsIntf.PutContentResult putBinaryContent​(javax.servlet.http.HttpServletRequest req,
                                                                       WebdavNsNode node,
                                                                       String[] contentTypePars,
                                                                       InputStream contentStream,
                                                                       Headers.IfHeaders ifHeaders)
                                                                throws WebdavException
        Set the content from a Stream
        Parameters:
        req -
        node - node in question.
        contentTypePars - null or values from content-type header
        contentStream - Stream for content
        ifHeaders - info from headers
        Returns:
        PutContentResult result of creating
        Throws:
        WebdavException - on error
      • createAlias

        public abstract void createAlias​(WebdavNsNode alias)
                                  throws WebdavException
        Creates an alias to another node.
        Parameters:
        alias - alias node that should be created with uri and targetUri set
        Throws:
        WebdavException - on error
      • acceptMkcolContent

        public abstract void acceptMkcolContent​(javax.servlet.http.HttpServletRequest req)
                                         throws WebdavException
        Throw an exception if we don't want the content for mkcol.
        Parameters:
        req - HttpServletRequest
        Throws:
        WebdavException - on error
      • makeCollection

        public abstract void makeCollection​(javax.servlet.http.HttpServletRequest req,
                                            javax.servlet.http.HttpServletResponse resp,
                                            WebdavNsNode node)
                                     throws WebdavException
        Create an empty collection at the given location. Status is set on return
        Parameters:
        req - HttpServletRequest
        resp - HttpServletResponse
        node - node to create
        Throws:
        WebdavException - on error
      • copyMove

        public abstract void copyMove​(javax.servlet.http.HttpServletRequest req,
                                      javax.servlet.http.HttpServletResponse resp,
                                      WebdavNsNode from,
                                      WebdavNsNode to,
                                      boolean copy,
                                      boolean overwrite,
                                      int depth)
                               throws WebdavException
        Copy or move a resource at the given location to another location. Status is set on return
        Parameters:
        req - HttpServletRequest
        resp - HttpServletResponse
        from - Source
        to - Destination
        copy - true for copying
        overwrite - true to overwrite destination
        depth - 0 for entity, infinity for collection.
        Throws:
        WebdavException - on error
      • specialUri

        public abstract boolean specialUri​(javax.servlet.http.HttpServletRequest req,
                                           javax.servlet.http.HttpServletResponse resp,
                                           String resourceUri)
                                    throws WebdavException
        Handle a special resource uri for GET. Status is set on return
        Parameters:
        req - HttpServletRequest
        resp - HttpServletResponse
        resourceUri -
        Returns:
        boolean true if it was a special uri and is processed
        Throws:
        WebdavException - on error
      • getSynchReport

        public abstract WdSynchReport getSynchReport​(String path,
                                                     String token,
                                                     int limit,
                                                     boolean recurse)
                                              throws WebdavException
        Parameters:
        path - to collection
        token - sync-token or null
        limit - - negative for no limit on result set size
        recurse - - true for infinite depth
        Returns:
        report
        Throws:
        WebdavException - on error
      • getSyncToken

        public abstract String getSyncToken​(String path)
                                     throws WebdavException
        Used to match tokens in If header
        Parameters:
        path - for collection
        Returns:
        sync token or null
        Throws:
        WebdavException - on error
      • getGroups

        public abstract Collection<WebdavNsNode> getGroups​(String resourceUri,
                                                           String principalUrl)
                                                    throws WebdavException
        Given a PrincipalMatchReport returns a Collection of matching nodes.
        Parameters:
        resourceUri - - url to base search on.
        principalUrl - - url of principal or null for current user
        Returns:
        Collection of WebdavNsNode
        Throws:
        WebdavException - on error
      • getPrincipalCollectionSet

        public abstract Collection<String> getPrincipalCollectionSet​(String resourceUri)
                                                              throws WebdavException
        Given a uri returns a Collection of uris that allow search operations on principals for that resource.
        Parameters:
        resourceUri -
        Returns:
        Collection of String
        Throws:
        WebdavException - on error
      • makeServerInfoUrl

        public String makeServerInfoUrl​(javax.servlet.http.HttpServletRequest req)
                                 throws WebdavException
        TODO - make the url value configurable
        Parameters:
        req - http request
        Returns:
        Throws:
        WebdavException - on error
      • openPropstat

        public void openPropstat()
        Open a propstat response.
      • closePropstat

        public void closePropstat​(int status)
        Close a propstat response with given result.
        Parameters:
        status - int value
      • makeProp

        public WebdavProperty makeProp​(Element propnode)
                                throws WebdavException
        Override this to create namespace specific property objects.
        Parameters:
        propnode - node specifying proeprty
        Returns:
        WebdavProperty
        Throws:
        WebdavException - on error
      • knownProperty

        public boolean knownProperty​(WebdavNsNode node,
                                     WebdavProperty pr)
        Return true if a call to generatePropValue will return a value.
        Parameters:
        node -
        pr -
        Returns:
        boolean
      • generatePropValue

        public boolean generatePropValue​(WebdavNsNode node,
                                         WebdavProperty pr,
                                         boolean allProp)
                                  throws WebdavException
        Generate a response for a single webdav property. This should be overrriden to handle other namespaces.
        Parameters:
        node -
        pr -
        allProp - true if we're doing allprop
        Returns:
        boolean false for unknown (or unset)
        Throws:
        WebdavException - on error
      • getLocation

        public String getLocation​(WebdavNsNode node)
                           throws WebdavException
        Return the complete URL describing the location of the object represented by the node
        Parameters:
        node - node in question
        Returns:
        String url
        Throws:
        WebdavException - on error
      • addStatus

        public void addStatus​(int status)
        Parameters:
        status - int value
      • getResourceUri

        public String getResourceUri​(javax.servlet.http.HttpServletRequest req)
                              throws WebdavException
        Get the decoded and fixed resource URI. This calls getServletPath() to obtain the path information. The description of that method is a little obscure in it's meaning. In a request of this form:

        "GET /ucaldav/user/douglm/calendar/1302064354993-g.ics HTTP/1.1[\r][\n]"

        getServletPath() will return

        /user/douglm/calendar/1302064354993-g.ics

        that is the context has been removed. In addition this method will URL decode the path. getRequestUrl() does neither.
        Parameters:
        req - Servlet request object
        Returns:
        String fixed up uri
        Throws:
        WebdavException - on error
      • fixPath

        public static String fixPath​(String path)
                              throws WebdavException
        Return a path, beginning with a "/", after "." and ".." are removed. If the parameter path attempts to go above the root we return null. Other than the backslash thing why not use URI?
        Parameters:
        path - String path to be fixed
        Returns:
        String fixed path
        Throws:
        WebdavException - on error
      • getReader

        public Reader getReader​(javax.servlet.http.HttpServletRequest req)
                         throws WebdavException
        Parameters:
        req - http request
        Returns:
        possibly wrapped reader
        Throws:
        WebdavException - on fatal error
      • generateHtml

        protected String generateHtml​(javax.servlet.http.HttpServletRequest req,
                                      WebdavNsNode node)
                               throws WebdavException
        Return a String giving an HTML representation of the directory. TODO

        Use some form of template to generate an internationalized form of the listing. We don't need a great deal to start with. It will also allow us to provide stylesheets, images etc. Probably place it in the resources directory.

        Parameters:
        req - http request
        node - WebdavNsNode
        Returns:
        Reader
        Throws:
        WebdavException - on error
      • getLogger

        public org.bedework.util.logging.BwLogger getLogger()
        Specified by:
        getLogger in interface org.bedework.util.logging.Logged