it.could.util.http
Class WebDavClient

java.lang.Object
  extended byit.could.util.http.WebDavClient

public class WebDavClient
extends Object

A class implementing an extremely simple WebDAV Level 1 client based on the HttpClient.

Once opened this class will represent a WebDAV collection. Users of this class can then from an instance of this, deal with relative parent and children resources.

Author:
Pier Fumagalli

Constructor Summary
WebDavClient(Location location)
          Create a new WebDavClient instance opening the collection identified by the specified Location.
 
Method Summary
 WebDavClient delete(String child)
          Delete the child resource (or collection) of the collection represented by this WebDavClient instance.
 InputStream get(String child)
          Fetch the contents of the specified child resource of the collection represented by this WebDavClient instance.
 long getContentLength()
          Return the content length (in bytes) of the collection represented by this WebDavClient as passed to us by the WebDAV server.
 long getContentLength(String child)
          Return the content length (in bytes) associated with the specified child of the collection represented by this WebDavClient.
 String getContentType()
          Return the content type (mime-type) of the collection represented by this WebDavClient as passed to us by the WebDAV server.
 String getContentType(String child)
          Return the content type (mime-type) associated with the specified child of the collection represented by this WebDavClient.
 Date getCreationDate()
          Return the creation Date of the collection represented by this WebDavClient as passed to us by the WebDAV server.
 Date getCreationDate(String child)
          Return the creation Date associated with the specified child of the collection represented by this WebDavClient.
 Date getLastModified()
          Return the last modified Date of the collection represented by this WebDavClient as passed to us by the WebDAV server.
 Date getLastModified(String child)
          Return the last modified Date associated with the specified child of the collection represented by this WebDavClient.
 Location getLocation()
          Return the Location associated with the collection represented by this WebDavClient.
 Location getLocation(String child)
          Return the Location associated with the specified child of the collection represented by this WebDavClient.
 boolean hasChild(String child)
          Checks if the collection represented by this WebDavClient contains the specified child.
 boolean isCollection(String child)
          Checks if the specified child of the collection represented by this WebDavClient instance is a collection.
 Iterator iterator()
          Return an Iterator over Strings for all the children of the collection represented by this WebDavClient instance.
static void main(String[] args)
          A command-line interface to a WebDAV repository.
 WebDavClient mkcol(String child)
          Create a new collection as a child of the collection represented by this WebDavClient instance.
 WebDavClient open(String child)
          Open the specified child collection of the collection represented by this WebDavClient as a new WebDavClient instance.
 WebDavClient parent()
          Open the parent collection of the collection represented by this WebDavClient as a new WebDavClient instance.
 OutputStream put(String child)
          Create a new (or update the contents of a) child of of the collection represented by this WebDavClient instance.
 OutputStream put(String child, long length)
          Create a new (or update the contents of a) child of of the collection represented by this WebDavClient instance.
 WebDavClient refresh()
          Refresh this WebDavClient instance re-connecting to the remote collection and re-reading its properties.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WebDavClient

public WebDavClient(Location location)
             throws NullPointerException,
                    IOException

Create a new WebDavClient instance opening the collection identified by the specified Location.

Parameters:
location - the Location of the WebDAV collection to open.
Throws:
IOException - if an I/O or network error occurred, or if the Location specified does not point to a WebDAV collection.
NullPointerException - if the Location was null.
Method Detail

refresh

public WebDavClient refresh()
                     throws IOException

Refresh this WebDavClient instance re-connecting to the remote collection and re-reading its properties.

Returns:
this WebDavClient instance.
Throws:
IOException

get

public InputStream get(String child)
                throws NullPointerException,
                       IOException

Fetch the contents of the specified child resource of the collection represented by this WebDavClient instance.

Returns:
a non-null InputStream.
Throws:
IOException - if an I/O or network error occurred, or if the child specified represents a collection.
NullPointerException - if the child was null.
See Also:
isCollection(String)

delete

public WebDavClient delete(String child)
                    throws NullPointerException,
                           IOException

Delete the child resource (or collection) of the collection represented by this WebDavClient instance.

Returns:
this WebDavClient instance.
Throws:
IOException - if an I/O or network error occurred, or if the child specified represents a collection.
NullPointerException - if the child was null.

mkcol

public WebDavClient mkcol(String child)
                   throws NullPointerException,
                          IOException

Create a new collection as a child of the collection represented by this WebDavClient instance.

In comparison to put(String) and put(String, long) this method will fail if the specified child already exist.

Returns:
this WebDavClient instance.
Throws:
IOException - if an I/O or network error occurred, or if the child specified already exist.
NullPointerException - if the child was null.
See Also:
hasChild(String)

put

public OutputStream put(String child)
                 throws NullPointerException

Create a new (or update the contents of a) child of of the collection represented by this WebDavClient instance.

This method will behave exactly like the put(String, long) method, but the data written to the returned OutputStream will be buffered in memory and will be transmitted to the remote server only when the OutputStream.close() method is called.

If the returned OutputStream is garbage collected before the close() method is called, the entire transaction will be aborted and no connection to the remote server will be established.

Use this method in extreme cases. In normal circumstances always rely on the put(String, long) method.

Returns:
a non-null OutputStream instance.
Throws:
NullPointerException - if the child was null.
See Also:
put(String, long)

put

public OutputStream put(String child,
                        long length)
                 throws NullPointerException,
                        IOException

Create a new (or update the contents of a) child of of the collection represented by this WebDavClient instance.

If the specified child already exists on the remote server, it will be deleted before writing.

Returns:
a non-null OutputStream instance.
Throws:
NullPointerException - if the child was null.
IOException - if an I/O or network error occurred, or if the child specified already exist.

open

public WebDavClient open(String child)
                  throws NullPointerException,
                         IOException

Open the specified child collection of the collection represented by this WebDavClient as a new WebDavClient instance.

If the specified child is "." this method will behave exactly like refresh() and this instance will be returned.

If the specified child is ".." this method will behave exactly like parent().

Returns:
a non-null WebDavClient instance.
Throws:
NullPointerException - if the child was null.
IOException - if an I/O or network error occurred, or if the child specified did not exist.

parent

public WebDavClient parent()
                    throws IOException

Open the parent collection of the collection represented by this WebDavClient as a new WebDavClient instance.

Returns:
a non-null WebDavClient instance.
Throws:
IOException - if an I/O or network error occurred, or if the child specified did not exist.

iterator

public Iterator iterator()

Return an Iterator over Strings for all the children of the collection represented by this WebDavClient instance.


hasChild

public boolean hasChild(String child)

Checks if the collection represented by this WebDavClient contains the specified child.


getLocation

public Location getLocation()

Return the Location associated with the collection represented by this WebDavClient.

The returned Location can be different from the one specified at construction, in case the server redirected us upon connection.


getContentLength

public long getContentLength()

Return the content length (in bytes) of the collection represented by this WebDavClient as passed to us by the WebDAV server.


getContentType

public String getContentType()

Return the content type (mime-type) of the collection represented by this WebDavClient as passed to us by the WebDAV server.


getLastModified

public Date getLastModified()

Return the last modified Date of the collection represented by this WebDavClient as passed to us by the WebDAV server.


getCreationDate

public Date getCreationDate()

Return the creation Date of the collection represented by this WebDavClient as passed to us by the WebDAV server.


getLocation

public Location getLocation(String child)
                     throws IOException

Return the Location associated with the specified child of the collection represented by this WebDavClient.

Throws:
IOException - if the specified child does not exist.
NullPointerException - if the specified child was null.

isCollection

public boolean isCollection(String child)
                     throws IOException

Checks if the specified child of the collection represented by this WebDavClient instance is a collection.

Throws:
IOException

getContentLength

public long getContentLength(String child)
                      throws IOException

Return the content length (in bytes) associated with the specified child of the collection represented by this WebDavClient.

Throws:
IOException - if the specified child does not exist.
NullPointerException - if the specified child was null.

getContentType

public String getContentType(String child)
                      throws IOException

Return the content type (mime-type) associated with the specified child of the collection represented by this WebDavClient.

Throws:
IOException - if the specified child does not exist.
NullPointerException - if the specified child was null.

getLastModified

public Date getLastModified(String child)
                     throws IOException

Return the last modified Date associated with the specified child of the collection represented by this WebDavClient.

Throws:
IOException - if the specified child does not exist.
NullPointerException - if the specified child was null.

getCreationDate

public Date getCreationDate(String child)
                     throws IOException

Return the creation Date associated with the specified child of the collection represented by this WebDavClient.

Throws:
IOException - if the specified child does not exist.
NullPointerException - if the specified child was null.

main

public static void main(String[] args)
                 throws IOException

A command-line interface to a WebDAV repository.

When invoked from the command line, this class requires one only argument, the URL location of the WebDAV repository to connect to.

After connection this method will interact with the user using an extremely simple console-based interface.

Throws:
IOException