org.abstracthorizon.danube.webdav
Class BaseWebDAVResourceConnectionHandler

java.lang.Object
  extended by org.abstracthorizon.danube.http.BaseReflectionHTTPConnectionHandler
      extended by org.abstracthorizon.danube.webdav.BaseWebDAVResourceConnectionHandler
All Implemented Interfaces:
ConnectionHandler
Direct Known Subclasses:
FileSystemWebDAVConnectionHandler, JavaWebDAVHandler, SpringResourceWebDAVConnectionHandler

public class BaseWebDAVResourceConnectionHandler
extends BaseReflectionHTTPConnectionHandler

Base WebDAV resource connection handler. This class uses supplied ResourceAdapter to read and write resource to/from.

Author:
Daniel Sendula

Field Summary
protected  ResourceAdapter adapter
          Resource adapter to be used
protected  int bufferSize
          Internal buffer size
protected  CollectionHTMLRenderer collectionRenderer
          Renderer of collection of items if GET method is invoked on a collection resource
protected  boolean readOnly
          Flag denoting will this class allow resources to be changed or not
static Status STATUS_FAILED_DEPENDENCY
          Status 424 Failed Dependency
static Status STATUS_LOCKED
          Status 423 Locked
 
Fields inherited from class org.abstracthorizon.danube.http.BaseReflectionHTTPConnectionHandler
cachedMethods, errorResponse, noDefaultHead, noDefaultTrace
 
Constructor Summary
BaseWebDAVResourceConnectionHandler()
          Constructor
BaseWebDAVResourceConnectionHandler(ResourceAdapter webDAVAdapter)
          Constructor
 
Method Summary
protected  void cacheMethods()
          Caches methods for quick invocation.
protected  Ranges collectRange(HTTPConnection connection)
          Collects range from the "Range" header.
protected  Timeout[] collectTimeouts(HTTPConnection connection)
          Collects timeouts from the "Timeout" header
protected  boolean deleteLeafImpl(MultiStatus multiStatus, String path, Object resource)
          Deletes a leaf (non-collection resource)
protected  boolean deleteRecursive(MultiStatus multiStatus, String path, Object resource)
          Deletes resouces recursively
protected  Object findResource(HTTPConnection httpConnection)
          Returns a resource.
protected  void fixUnknownPropsResponse(MultiStatus multiStatus)
          Patch to fix response without "known"l properties
 CollectionHTMLRenderer getCollectionHTMLRenderer()
          Returns collection HTML renderer
 ResourceAdapter getWebDAVResourceAdapter()
          Returns WebDAV resource adapter
protected  boolean isLockedRecursive(LockingMechanism lockingMechanism, IF lockDetails, MultiStatus multiStatus, HTTPConnection httpConnection, Object resource, String path)
          Checks recursively if resource is locked and all of it's children.
 boolean isReadOnly()
          Returns read only flag
protected  boolean lockImpl(Response response, Lock lock, LockingMechanism lockingMechanism, LockInfo lockInfo, Object owner, boolean recursive, Object resource)
          Locks the resource
protected  boolean lockRecursive(MultiStatus multiStatus, Lock lock, LockingMechanism lockingMechanism, LockInfo lockInfo, Object owner, Object resource, String path)
          Locks resource recursively.
 void methodCOPY(HTTPConnection httpConnection)
          Implements copy method
 void methodDELETE(HTTPConnection httpConnection)
          Following is hard to be maintained and is not followed stictly in this implementation:
 void methodGET(HTTPConnection httpConnection)
          GET method implementation
 void methodHEAD(HTTPConnection httpConnection)
          Implementation of the HEAD method.
 void methodLOCK(HTTPConnection httpConnection)
          Implements LOCK method.
 void methodMKCOL(HTTPConnection httpConnection)
          Implements MKCOL method (making collection).
 void methodMOVE(HTTPConnection httpConnection)
          Moves resource
 void methodOPTIONS(HTTPConnection httpConnection)
          This method adds DAV: 1,2 header.
 void methodPROPFIND(HTTPConnection httpConnection)
          Implements PROPFIND method
 void methodPROPPATCH(HTTPConnection httpConnection)
          Implements PROPPATH method
 void methodPUT(HTTPConnection httpConnection)
          Implements PUT method
 void methodUNLOCK(HTTPConnection httpConnection)
          Implements UNLOCK method.
protected  void obtainProps(Response response, Object resource, PropFind propFind)
          Obtain properties of a given resource
protected  void obtainPropsRecursive(MultiStatus multiStatus, Object resource, PropFind propFind, String path)
          Obtain properties recursively
protected  Object readRequestXML(Adaptable adaptable, Class<?> expectedClass)
          Reads request XML strcture and parses it returning an object based on WebDAVXMLHandler.
 void setCollectionHTMLRenterer(CollectionHTMLRenderer collectionHTMLRenderer)
          Sets collection HTML renderer
 void setReadOnly(boolean readOnly)
          Sets read only flag
 void setWebDAVResourceAdapter(ResourceAdapter webDAVAdapter)
          Sets WebDAV resource adapter
protected  void transmitResource(HTTPConnection httpConnection, Object resource, Adaptable output, Ranges ranges)
          Transmits resource.
protected  void updateProps(MultiStatus multiStatus, Object resource, int depth, PropertyUpdate propertyUpdate)
          Updates properties
protected  void updateProps(Response response, Object resource, PropertyUpdate propertyUpdate)
          Updates properties of a given resource (leaf)
protected  void updatePropsRecursive(MultiStatus multiStatus, Object resource, PropertyUpdate propertyUpdate, String path)
          Updates properties recursively
 
Methods inherited from class org.abstracthorizon.danube.http.BaseReflectionHTTPConnectionHandler
getErrorResponse, getNoDefaultHead, getNoDefaultTrace, handleConnection, invokeMethod, methodTRACE, returnError, returnSimpleContent, setErrorResponse, setNoDefaultHead, setNoDefaultTrace, updateDefaultHeadMethod, updateDefaultTraceMethod
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATUS_LOCKED

public static final Status STATUS_LOCKED
Status 423 Locked


STATUS_FAILED_DEPENDENCY

public static final Status STATUS_FAILED_DEPENDENCY
Status 424 Failed Dependency


adapter

protected ResourceAdapter adapter
Resource adapter to be used


bufferSize

protected int bufferSize
Internal buffer size


collectionRenderer

protected CollectionHTMLRenderer collectionRenderer
Renderer of collection of items if GET method is invoked on a collection resource


readOnly

protected boolean readOnly
Flag denoting will this class allow resources to be changed or not

Constructor Detail

BaseWebDAVResourceConnectionHandler

public BaseWebDAVResourceConnectionHandler()
Constructor


BaseWebDAVResourceConnectionHandler

public BaseWebDAVResourceConnectionHandler(ResourceAdapter webDAVAdapter)
Constructor

Parameters:
webDAVAdapter - web dav adapter
Method Detail

getWebDAVResourceAdapter

public ResourceAdapter getWebDAVResourceAdapter()
Returns WebDAV resource adapter

Returns:
WebDAV resource

setWebDAVResourceAdapter

public void setWebDAVResourceAdapter(ResourceAdapter webDAVAdapter)
Sets WebDAV resource adapter

Parameters:
webDAVAdapter - WebDAV resource

getCollectionHTMLRenderer

public CollectionHTMLRenderer getCollectionHTMLRenderer()
Returns collection HTML renderer

Returns:
collection HTML renderer

setCollectionHTMLRenterer

public void setCollectionHTMLRenterer(CollectionHTMLRenderer collectionHTMLRenderer)
Sets collection HTML renderer

Parameters:
collectionHTMLRenderer - collection HTML renderer

isReadOnly

public boolean isReadOnly()
Returns read only flag

Returns:
read only flag

setReadOnly

public void setReadOnly(boolean readOnly)
Sets read only flag

Parameters:
readOnly - read only flag

findResource

protected Object findResource(HTTPConnection httpConnection)
Returns a resource. This implementation obtains resource from the supplied adapter using component resource path as a resource's path. This method can be overriden if adapter is to cache resources or pre-process them in any way.

Parameters:
httpConnection - http connection
Returns:
resource

cacheMethods

protected void cacheMethods()
Caches methods for quick invocation. This implementation removes LOCK and UNLOCK method from the cache if adapter doesn't supply locking mechanism (lokcing mechanism is null).

Overrides:
cacheMethods in class BaseReflectionHTTPConnectionHandler

methodOPTIONS

public void methodOPTIONS(HTTPConnection httpConnection)
This method adds DAV: 1,2 header.

Overrides:
methodOPTIONS in class BaseReflectionHTTPConnectionHandler
Parameters:
httpConnection - connection

methodGET

public void methodGET(HTTPConnection httpConnection)
GET method implementation

Parameters:
httpConnection - connection

transmitResource

protected void transmitResource(HTTPConnection httpConnection,
                                Object resource,
                                Adaptable output,
                                Ranges ranges)
Transmits resource.

Parameters:
httpConnection - connection
resource - resource to be used
output - adaptable to be checked for the output stream
ranges - ranges. Can be null.

methodHEAD

public void methodHEAD(HTTPConnection httpConnection)
Implementation of the HEAD method.

Overrides:
methodHEAD in class BaseReflectionHTTPConnectionHandler
Parameters:
httpConnection - connection

methodPUT

public void methodPUT(HTTPConnection httpConnection)
Implements PUT method

Parameters:
httpConnection - connection

methodDELETE

public void methodDELETE(HTTPConnection httpConnection)

Following is hard to be maintained and is not followed stictly in this implementation:

" If any resource identified by a member URI cannot be deleted then all of the member's ancestors MUST NOT be deleted, so as to maintain namespace consistency. "

Delete will stop at the first problem but deleted resources will remain deleted.

Parameters:
httpConnection -

deleteRecursive

protected boolean deleteRecursive(MultiStatus multiStatus,
                                  String path,
                                  Object resource)
Deletes resouces recursively

Parameters:
multiStatus - multi status response
path - current path
resource - resource
Returns:
true if successful

deleteLeafImpl

protected boolean deleteLeafImpl(MultiStatus multiStatus,
                                 String path,
                                 Object resource)
Deletes a leaf (non-collection resource)

Parameters:
multiStatus - multi status response
path - current path
resource - resource
Returns:
true if successful

methodPROPFIND

public void methodPROPFIND(HTTPConnection httpConnection)
Implements PROPFIND method

Parameters:
httpConnection - http connection

obtainPropsRecursive

protected void obtainPropsRecursive(MultiStatus multiStatus,
                                    Object resource,
                                    PropFind propFind,
                                    String path)
Obtain properties recursively

Parameters:
multiStatus - multi status response
resource - resource
propFind - propfind structure
path - current path

obtainProps

protected void obtainProps(Response response,
                           Object resource,
                           PropFind propFind)
Obtain properties of a given resource

Parameters:
response - single response structure
resource - resource
propFind - propfind structure

methodPROPPATCH

public void methodPROPPATCH(HTTPConnection httpConnection)
Implements PROPPATH method

Parameters:
httpConnection - connection

updateProps

protected void updateProps(MultiStatus multiStatus,
                           Object resource,
                           int depth,
                           PropertyUpdate propertyUpdate)
Updates properties

Parameters:
multiStatus - multi status response
resource - resource
depth - depth structure
propertyUpdate - propertyupdate structure

updatePropsRecursive

protected void updatePropsRecursive(MultiStatus multiStatus,
                                    Object resource,
                                    PropertyUpdate propertyUpdate,
                                    String path)
Updates properties recursively

Parameters:
multiStatus - multi status response
resource - resource
propertyUpdate - propertyupdate structure
path - current path

updateProps

protected void updateProps(Response response,
                           Object resource,
                           PropertyUpdate propertyUpdate)
Updates properties of a given resource (leaf)

Parameters:
response - single response
resource - resource
propertyUpdate - propertyupdate structure

fixUnknownPropsResponse

protected void fixUnknownPropsResponse(MultiStatus multiStatus)
Patch to fix response without "known"l properties

Parameters:
multiStatus - multi status response

methodMKCOL

public void methodMKCOL(HTTPConnection httpConnection)
Implements MKCOL method (making collection).

Parameters:
httpConnection - connection

methodCOPY

public void methodCOPY(HTTPConnection httpConnection)
Implements copy method

Parameters:
httpConnection - connection

methodMOVE

public void methodMOVE(HTTPConnection httpConnection)
Moves resource

Note: property behaviour is ignored in this implementation!

Parameters:
httpConnection - connection

methodLOCK

public void methodLOCK(HTTPConnection httpConnection)
Implements LOCK method. This method relies that adapter has non-null lcoking mechanism defined.

Parameters:
httpConnection - connection

lockRecursive

protected boolean lockRecursive(MultiStatus multiStatus,
                                Lock lock,
                                LockingMechanism lockingMechanism,
                                LockInfo lockInfo,
                                Object owner,
                                Object resource,
                                String path)
Locks resource recursively.

Parameters:
multiStatus - multi status response
lock - lock
lockingMechanism - locking mechanism
lockInfo - lock info structure
owner - owner
resource - resource
path - path
Returns:
true if locking succeeded

lockImpl

protected boolean lockImpl(Response response,
                           Lock lock,
                           LockingMechanism lockingMechanism,
                           LockInfo lockInfo,
                           Object owner,
                           boolean recursive,
                           Object resource)
Locks the resource

Parameters:
response - single response
lock - lock
lockingMechanism - locking mechanism
lockInfo - lockinfo structure
owner - owner
recursive - is recursive
resource - resource
Returns:
true if succeeded

methodUNLOCK

public void methodUNLOCK(HTTPConnection httpConnection)
Implements UNLOCK method. Ir relies on adapter providing locking mechanism.

Parameters:
httpConnection - connection

isLockedRecursive

protected boolean isLockedRecursive(LockingMechanism lockingMechanism,
                                    IF lockDetails,
                                    MultiStatus multiStatus,
                                    HTTPConnection httpConnection,
                                    Object resource,
                                    String path)
Checks recursively if resource is locked and all of it's children.

Parameters:
lockingMechanism - locking mechanism
lockDetails - lock details
multiStatus - multi status response
httpConnection - connection
resource - resource
path - current path
Returns:
true if resource is locked

collectRange

protected Ranges collectRange(HTTPConnection connection)
Collects range from the "Range" header.

Parameters:
connection - http connection
Returns:
Ranges or null

collectTimeouts

protected Timeout[] collectTimeouts(HTTPConnection connection)
Collects timeouts from the "Timeout" header

Parameters:
connection - http connection
Returns:
Timeout structure or null

readRequestXML

protected Object readRequestXML(Adaptable adaptable,
                                Class<?> expectedClass)
                         throws SAXException
Reads request XML strcture and parses it returning an object based on WebDAVXMLHandler.

Parameters:
adaptable - adaptable object to be used for obtaining input stream
expectedClass - expected class
Returns:
an object of an expected class or null
Throws:
SAXException - if there was an expcetion while parsing


Copyright © 2005-2009 Abstract Horizon. All Rights Reserved.