it.could.webdav
Class DAVResource

java.lang.Object
  extended byit.could.webdav.DAVResource
All Implemented Interfaces:
Comparable

public class DAVResource
extends Object
implements Comparable

A simple representation of a WebDAV resource based on Files.

Author:
Pier Fumagalli

Field Summary
static String COLLECTION_MIME_TYPE
          The mime type when isCollection() is true.
protected static String PREFIX
          The prefix for all temporary resources.
protected static String SUFFIX
          The suffix for all temporary resources.
 
Constructor Summary
protected DAVResource(DAVRepository repo, File file)
          Create a new DAVResource instance.
 
Method Summary
 int compareTo(Object object)
          Compare this instance to another object for sorting.
 void copy(DAVResource dest, boolean overwrite, boolean recursive)
          Copy this resource to the specified destination.
 void delete()
          Delete this resource.
 boolean equals(Object object)
          Compare this instance to another object for equality.
 Iterator getChildren()
          Return an Iterator over all children of this instance.
 Long getContentLength()
          Return the MIME Content-Length of this DAVResource.
 String getContentType()
          Return the MIME Content-Type of this DAVResource.
 Date getCreationDate()
          Return the creation date of this DAVResource.
 String getDisplayName()
          Return the display name of this resource (with an added "/" slash at the end if it is a collection).
 String getEntityTag()
          Return a String representing the Entity Tag of this DAVResource as described by the HTTP RFC.
protected  File getFile()
          Return the File associated with this resource.
 Date getLastModified()
          Return the last modification date of this DAVResource.
 String getName()
          Return the bare name of this resource (without any "/" slashes at the end if it is a collection).
 DAVResource getParent()
          Return the parent DAVResource of this instance.
 String getRelativePath()
          Return the path of this DAVResource relative to the root of the associated DAVRepository.
 URI getRelativeURI()
          Return the URI of this DAVResource relative to the root of the associated DAVRepository.
 DAVRepository getRepository()
          Return the DAVRepository associated with this resource.
 int hashCode()
          Return an integer number for the hash value of this instance.
 boolean isCollection()
          Checks if this DAVResource is a collection.
 boolean isNull()
          Checks if this DAVResource is a null (non existant) one.
 boolean isResource()
          Checks if this DAVResource is an existing resource.
 void makeCollection()
          Create a collection identified by this DAVResource.
 DAVInputStream read()
          Return an InputStream reading the resource.
 DAVOutputStream write()
          Return a DAVOutputStream writing to this DAVResource instance.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COLLECTION_MIME_TYPE

public static final String COLLECTION_MIME_TYPE

The mime type when isCollection() is true.

See Also:
Constant Field Values

PREFIX

protected static final String PREFIX

The prefix for all temporary resources.

See Also:
Constant Field Values

SUFFIX

protected static final String SUFFIX

The suffix for all temporary resources.

See Also:
Constant Field Values
Constructor Detail

DAVResource

protected DAVResource(DAVRepository repo,
                      File file)

Create a new DAVResource instance.

Method Detail

hashCode

public int hashCode()

Return an integer number for the hash value of this instance.


equals

public boolean equals(Object object)

Compare this instance to another object for equality.


compareTo

public int compareTo(Object object)

Compare this instance to another object for sorting.

Specified by:
compareTo in interface Comparable

isNull

public boolean isNull()

Checks if this DAVResource is a null (non existant) one.

Returns:
true if this resource does not esist (is a null resource).

isCollection

public boolean isCollection()

Checks if this DAVResource is a collection.

Returns:
true if this resource is a collection.

isResource

public boolean isResource()

Checks if this DAVResource is an existing resource.

Returns:
true if this resource is a collection.

getFile

protected File getFile()

Return the File associated with this resource.


getRepository

public DAVRepository getRepository()

Return the DAVRepository associated with this resource.


getName

public String getName()

Return the bare name of this resource (without any "/" slashes at the end if it is a collection).

Returns:
a non null String.

getDisplayName

public String getDisplayName()

Return the display name of this resource (with an added "/" slash at the end if it is a collection).

Returns:
a non null String.

getRelativePath

public String getRelativePath()

Return the path of this DAVResource relative to the root of the associated DAVRepository.

Returns:
a non null String.

getRelativeURI

public URI getRelativeURI()

Return the URI of this DAVResource relative to the root of the associated DAVRepository.

Returns:
a non-null URI instance.

getParent

public DAVResource getParent()

Return the parent DAVResource of this instance.

Returns:
a non-null DAVResource instance or null if this DAVResource is the repository root.

getChildren

public Iterator getChildren()

Return an Iterator over all children of this instance.

Returns:
a non-null Iterator instance or null if this DAVResource is not a collection.
Throws:
IOException - If the resource could not be resolved.

getContentType

public String getContentType()

Return the MIME Content-Type of this DAVResource.

If the isCollection() method returns true this method always returns text/html.

Returns:
a String instance or null if this resource does not exist.

getContentLength

public Long getContentLength()

Return the MIME Content-Length of this DAVResource.

Returns:
a Long instance or null if this resource does not exist or is a collection.

getCreationDate

public Date getCreationDate()

Return the creation date of this DAVResource.

As this implementation relies on a File backend, this method will always return the same as getLastModified().

Returns:
a String instance or null if this resource does not exist.

getLastModified

public Date getLastModified()

Return the last modification date of this DAVResource.

Returns:
a String instance or null if this resource does not exist.

getEntityTag

public String getEntityTag()

Return a String representing the Entity Tag of this DAVResource as described by the HTTP RFC.

Returns:
a String instance or null if this resource does not exist.

delete

public void delete()
            throws DAVMultiStatus

Delete this resource.

Throws:
DAVException - If for any reason this resource cannot be deleted.
DAVMultiStatus

copy

public void copy(DAVResource dest,
                 boolean overwrite,
                 boolean recursive)
          throws DAVMultiStatus

Copy this resource to the specified destination.

Throws:
DAVException - If for any reason this resource cannot be deleted.
DAVMultiStatus

makeCollection

public void makeCollection()

Create a collection identified by this DAVResource.

This resource must be non-null and its parent must be accessible and be a collection.

Throws:
DAVException - If for any reason a collection identified by this resource cannot be created.

read

public DAVInputStream read()

Return an InputStream reading the resource.

Returns:
a non-null InputStream instance.

write

public DAVOutputStream write()

Return a DAVOutputStream writing to this DAVResource instance.

Returns:
a non-null DAVOutputStream instance.