Class WebdavNsIntf

java.lang.Object
org.bedework.webdav.servlet.shared.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:
  • Field Details

    • session

      protected static final WebdavNsIntf.SessCt session
      Mostly to distinguish trace entries
    • sessNum

      protected int sessNum
    • servlet

      protected WebdavServlet servlet
    • account

      protected String account
    • anonymous

      protected boolean anonymous
    • dumpContent

      protected boolean dumpContent
    • xml

      protected org.bedework.util.xml.XmlEmit xml
    • methods

      protected HashMap<String,MethodBase.MethodInfo> methods
      Table of methods - set by servlet
    • existanceNot

      public static final int existanceNot
      Must not exist
      See Also:
    • existanceMust

      public static final int existanceMust
      Must exist.
      See Also:
    • existanceDoesExist

      public static final int existanceDoesExist
      We know it exists.
      See Also:
    • existanceMay

      public static final int existanceMay
      May exist
      See Also:
    • nodeTypeCollection

      public static final int nodeTypeCollection
      Must be collection
      See Also:
    • nodeTypeEntity

      public static final int nodeTypeEntity
      Must be entity.
      See Also:
    • nodeTypePrincipal

      public static final int nodeTypePrincipal
      Must be a principal.
      See Also:
    • nodeTypeUnknown

      public static final int nodeTypeUnknown
      Unknown.
      See Also:
  • Constructor Details

    • WebdavNsIntf

      public WebdavNsIntf()
  • Method Details

    • init

      public void init(WebdavServlet servlet, javax.servlet.http.HttpServletRequest req, HashMap<String,MethodBase.MethodInfo> methods, boolean dumpContent)
      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
    • 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
    • getDavHeader

      public String getDavHeader(WebdavNsNode node)
      Return DAV header
      Parameters:
      node - may be null for *
      Returns:
      String
    • getServerInfo

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

      public boolean syncTokenMatch(Headers.IfHeader ih)
      Parameters:
      ih - IfHeader
      Returns:
      false for a mismatch
      Throws:
      WebdavException - for invalid if header
    • emitError

      public void emitError(QName errorTag, String extra, org.bedework.util.xml.XmlEmit xml)
      Emit some failed precondition tag
      Parameters:
      errorTag - to identify error
      extra - optional extra info
      xml - emitter
    • getSysIntf

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

      public abstract AccessUtil getAccessUtil()
      Get an object suitable for use in parsing acls and generating access.
      Returns:
      AccessUtil implementation.
    • canPut

      public abstract boolean canPut(WebdavNsNode node)
      Return true if we can PUT this resource/entity
      Parameters:
      node - current node
      Returns:
      boolean
    • getAddMemberSuffix

      public abstract String getAddMemberSuffix()
      Returns:
      - null if DAV:add-member not supported
    • getMethodNames

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

      public MethodBase getMethod(String name)
      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
    • getAnonymous

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

      public String getUri(String href)
      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
    • 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 - to be converted
      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()
      Return true if the system disallows directory browsing.
      Returns:
      boolean
    • rollback

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

      public abstract void close()
      Called on the way out to allow resources to be freed.
    • 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)
      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.
    • putNode

      public abstract void putNode(WebdavNsNode node)
      Stores/updates an object.
      Parameters:
      node - node in question
    • delete

      public abstract void delete(WebdavNsNode node)
      Deletes a node from the namespace.
      Parameters:
      node - node in question
    • getChildren

      public abstract Collection<WebdavNsNode> getChildren(WebdavNsNode node, Supplier<Object> filterGetter)
      Returns the immediate children of a node.
      Parameters:
      node - node in question
      Returns:
      Collection of WebdavNsNode children
    • getParent

      public abstract WebdavNsNode getParent(WebdavNsNode node)
      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
    • prefetch

      public boolean prefetch(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, WebdavNsNode node)
      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
    • getContent

      public abstract WebdavNsIntf.Content getContent(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, String contentType, WebdavNsNode node)
      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.
    • getBinaryContent

      public abstract WebdavNsIntf.Content getBinaryContent(WebdavNsNode node)
      Returns a Content object for the binary content.
      Parameters:
      node - node in question
      Returns:
      content.
    • getAcceptContentType

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

      public WebdavNsIntf.PutContentResult putContent(javax.servlet.http.HttpServletRequest req, String resourceUri, javax.servlet.http.HttpServletResponse resp, boolean fromPost, Headers.IfHeaders ifHeaders)
      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
    • writeContent

      public void writeContent(Reader in, Writer out)
      Parameters:
      in -
      out -
    • streamContent

      public void streamContent(InputStream in, OutputStream out)
      Parameters:
      in -
      out -
    • normalizeUri

      public String normalizeUri(String uri)
      Parameters:
      uri - to check
      Returns:
      normalized form
    • 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)
      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
    • putBinaryContent

      public abstract WebdavNsIntf.PutContentResult putBinaryContent(javax.servlet.http.HttpServletRequest req, WebdavNsNode node, String[] contentTypePars, InputStream contentStream, Headers.IfHeaders ifHeaders)
      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
    • create

      public abstract void create(WebdavNsNode node)
      Create a new node.
      Parameters:
      node - node to create with new uri set
    • createAlias

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

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

      public abstract void makeCollection(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, WebdavNsNode node)
      Create an empty collection at the given location. Status is set on return
      Parameters:
      req - HttpServletRequest
      resp - HttpServletResponse
      node - node to create
    • 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)
      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.
    • specialUri

      public abstract boolean specialUri(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, String resourceUri)
      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
    • getSynchReport

      public abstract WdSynchReport getSynchReport(String path, String token, int limit, boolean recurse)
      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
    • getSyncToken

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

      public abstract Collection<WebdavNsNode> getGroups(String resourceUri, String principalUrl)
      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
    • getPrincipalCollectionSet

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

      public abstract Collection<? extends WebdavNsNode> getPrincipals(String resourceUri, PrincipalPropertySearch pps)
      Given a PrincipalPropertySearch returns a Collection of matching nodes.
      Parameters:
      resourceUri -
      pps - Collection of PrincipalPropertySearch
      Returns:
      Collection of WebdavNsNode
    • makeUserHref

      public abstract String makeUserHref(String id)
      Parameters:
      id -
      Returns:
      String href
    • makeServerInfoUrl

      public String makeServerInfoUrl(javax.servlet.http.HttpServletRequest req)
      TODO - make the url value configurable
      Parameters:
      req - http request
      Returns:
    • updateAccess

      public abstract void updateAccess(WebdavNsIntf.AclInfo ainfo)
      Parameters:
      ainfo -
    • emitAcl

      public abstract void emitAcl(WebdavNsNode node)
      Parameters:
      node - current node
    • getAclPrincipalInfo

      public abstract Collection<String> getAclPrincipalInfo(WebdavNsNode node)
      Return all the hrefs found in the access for th egiven node.
      Parameters:
      node - current node
      Returns:
      Collection of hrefs.
    • emitSupportedReportSet

      public void emitSupportedReportSet(WebdavNsNode node)
      Parameters:
      node - current node
    • 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
    • closePropstat

      public void closePropstat()
      Close a propstat response with an ok result.
    • parseProp

      public List<WebdavProperty> parseProp(Node nd)
      Parse a DAV:prop list of property names in any namespace.
      Parameters:
      nd - the props node
      Returns:
      Collection
    • makeProp

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

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

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

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

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

      public String getResourceUri(javax.servlet.http.HttpServletRequest req)
      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
    • fixPath

      public static String fixPath(String path)
      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
    • getReader

      public Reader getReader(javax.servlet.http.HttpServletRequest req)
      Parameters:
      req - http request
      Returns:
      possibly wrapped reader
    • getChildren

      public Element[] getChildren(Node nd)
      Get all the children if any
      Parameters:
      nd - current node
      Returns:
      array of Element
    • getOnlyChild

      public Element getOnlyChild(Node nd)
      We expect a single child
      Parameters:
      nd - current node
      Returns:
      Element
    • getElementContent

      public String getElementContent(Element el)
      Parameters:
      el - the element
      Returns:
      String
    • generateHtml

      protected String generateHtml(javax.servlet.http.HttpServletRequest req, WebdavNsNode node)
      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
    • getLogger

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