be.re.webdav
Class Util

java.lang.Object
  extended by be.re.webdav.Util

public class Util
extends Object

A collection of utility methods for working with a WebDAV server. Some methods return localized names or messages. If you want to add translations for this, you have to add the file Res_<language_tag>.properties to the package be.re.webdav.res.

Author:
Werner Donné

Nested Class Summary
static interface Util.DisplayNameHandler
          This is for handling DAV:displayname properties in a multistatus response one by one.
static interface Util.PropertyHandler
          This is for handling all properties in a multistatus response one by one.
static interface Util.ReportMultistatus
          This is for handling state and error information in a multistatus response per entry.
static interface Util.UrlHandler
          This is for handling DAV:href elements in a multistatus response one by one.
 
Method Summary
static Client.ACE[] getAces(URL baseUrl, Element aclProperty)
          Extracts the Access Control Entries from a DAV:acl property element.
static String getAutoVersion(URL url)
          Returns the DAV:auto-version property.
static String getAutoVersion(URL url, Client client)
          Returns the DAV:auto-version property.
static String getAutoVersionValueDisplayName(String value)
          Returns the localized display name for the value of the DAV:auto-version property.
static URL getHome(URL user)
          Returns the home folder of a user.
static URL getHome(URL user, Client client)
          Returns the home folder of a user.
static URL getHref(URL url, Element response)
           
static URL getOwner(URL url)
          Returns the owner of a resource.
static URL getOwner(URL url, Client client)
          Returns the owner of a resource.
static String getPassword(URL user)
          Returns the password of a user.
static String getPassword(URL user, Client client)
          Returns the password of a user.
static String getPreconditionMessage(Client.Response response)
          Returns the localized message that corresponds to the preconditions in the response.
static String getPreconditionMessage(Node error)
          Extracts the localized message that corresponds to the preconditions in the DAV:error element.
static String getPreconditionMessage(String precondition)
          Returns the localized message that corresponds to the precondition or the empty string if there is no such message.
static String getPrivilegeDescription(ExpandedName privilege)
          Returns the localized description of a privilege.
static String getPrivilegeDescription(Node privilege)
          Returns the localized description of a privilege.
static String getPrivilegeDescription(String privilege)
          Returns the localized description of a privilege using the local name.
static ExpandedName[] getPrivileges()
          Returns all known privileges.
static String getPropertyDisplayName(String property)
          Returns the localized display name of a property.
static int getPropertyStatusCode(Node propElement)
          Extracts the status code from a property element.
static long getQuotaAvailableBytes(URL user)
          Returns the available number of bytes for a user.
static long getQuotaAvailableBytes(URL user, Client client)
          Returns the available number of bytes for a user.
static long getQuotaTotalBytes(URL user)
          Returns the total number of bytes a user can use.
static long getQuotaTotalBytes(URL user, Client client)
          Returns the total number of bytes a user can use.
static long getQuotaUsedBytes(URL user)
          Returns the number of bytes a user is using.
static long getQuotaUsedBytes(URL user, Client client)
          Returns the number of bytes a user is using.
static String getReasonPhrase(Client.Response response)
          Returns the localized reason message that corresponds to the response.
static String getReasonPhrase(String method, int statusCode)
          Returns the localized reason message that corresponds to the method/status code combination.
static String getResource(String key)
          A low-level method to retrieve localized strings from the be.re.webdav.res.Res bundle.
static ExpandedName[] getResourceTypes(URL url)
          Returns all the resource types a resource has.
static ExpandedName[] getResourceTypes(URL url, Client client)
          Returns all the resource types a resource has.
static int getStatusCode(Element response)
          Extracts the status code from a multistatus reponse entry.
static boolean isActivity(URL url)
          Tests if the resource is an activity.
static boolean isActivity(URL url, Client client)
          Tests if the resource is an activity.
static boolean isCheckedOut(URL url)
          Returns the checked-out state.
static boolean isCheckedOut(URL url, Client client)
          Returns the checked-out state.
static boolean isCollection(URL url)
          Tests if the resource is a collection.
static boolean isCollection(URL url, Client client)
          Tests if the resource is a collection.
static boolean isMemberOfOne(URL url, URL[] collections)
          Tests if url is a member of one of the collections.
static boolean isOwner(URL url, URL user)
          Tests if user owns the resource.
static boolean isOwner(URL url, URL user, Client client)
          Tests if user owns the resource.
static boolean isPrincipal(URL url)
          Tests if the resource is a principal.
static boolean isPrincipal(URL url, Client client)
          Tests if the resource is a principal.
static boolean isVersion(URL url)
          Tests if the resource is a version.
static boolean isVersion(URL url, Client client)
          Tests if the resource is a version.
static boolean isView(URL url)
          Tests if the resource is a view.
static boolean isView(URL url, Client client)
          Tests if the resource is a view.
static void mkcols(URL url)
          Creates the collection resource denoted by url and all of the parent collection resources if they don't already exist.
static String[] readDisplayNameList(URL collection)
          Returns the values of the DAV:displayname properties of the members of the collection.
static void readDisplayNameList(URL url, Client.Response response, Util.DisplayNameHandler handler, boolean includeCollection)
          Processes the values of the DAV:displayname properties in the entries in a multistatus response.
static void readPropertyList(URL url, Client.Response response, Util.PropertyHandler handler, boolean includeCollection)
          Processes all the properties in the entries in a multistatus response.
static void readPropertyList(URL url, Client.Response response, Util.PropertyHandler handler, Util.ReportMultistatus report, boolean includeCollection)
          Processes all the properties in the entries in a multistatus response.
static void readUrlList(URL url, Client.Response response, Util.UrlHandler handler)
          Processes the DAV:href element in the entries in a multistatus response.
static void reportMultistatus(Client.Response response, Util.ReportMultistatus report)
          Processes the entries in a multistatus response one by one.
static void setAutoVersion(URL url, String mode)
          Sets the auto-version mode for a resource.
static void setAutoVersion(URL url, String mode, Client client)
          Sets the auto-version mode for a resource.
static void setHome(URL user, URL home)
          Sets the home folder for a user.
static void setHome(URL user, URL home, Client client)
          Sets the home folder for a user.
static void setOwner(URL url, URL owner)
          Sets the owner of a resource.
static void setOwner(URL url, URL owner, Client client)
          Sets the owner of a resource.
static void setPassword(URL user, String password)
          Sets the password for a user.
static void setPassword(URL user, String password, Client client)
          Sets the password for a user.
static void setQuotaTotalBytes(URL user, long total)
          Sets the total number of bytes a user can use.
static void setQuotaTotalBytes(URL user, long total, Client client)
          Sets the total number of bytes a user can use.
static void throwException(Client.Response response)
          Throw an exception with a localized message that is extracted from the response.
static void throwException(URL url, String method, int statusCode)
          Throw an exception with a localized message that corresponds to the method/status code combination.
static void throwException(URL url, String method, int statusCode, Node error)
          Throw an exception with a localized message that corresponds to the method/status code combination.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getAces

public static Client.ACE[] getAces(URL baseUrl,
                                   Element aclProperty)
Extracts the Access Control Entries from a DAV:acl property element.

Parameters:
baseUrl - the URL to resolve relative URLs in the aclProperty against.
aclProperty - a DAV:acl property element.
Returns:
The Acces Control Entries in the order of appearance.

getAutoVersion

public static String getAutoVersion(URL url)
                             throws IOException
Returns the DAV:auto-version property.

Parameters:
url - the URL of the resource.
Returns:
The value of the DAV:auto-version property, which may be null.
Throws:
IOException

getAutoVersion

public static String getAutoVersion(URL url,
                                    Client client)
                             throws IOException
Returns the DAV:auto-version property.

Parameters:
url - the URL of the resource.
client - the Client object used for the connection.
Returns:
The value of the DAV:auto-version property, which may be null.
Throws:
IOException

getAutoVersionValueDisplayName

public static String getAutoVersionValueDisplayName(String value)
Returns the localized display name for the value of the DAV:auto-version property.

Parameters:
value - the value of the DAV:auto-version property.
Returns:
The localized display name.

getHome

public static URL getHome(URL user)
                   throws IOException
Returns the home folder of a user.

Parameters:
user - the URL for the user.
Returns:
The URL of the home folder or null.
Throws:
IOException

getHome

public static URL getHome(URL user,
                          Client client)
                   throws IOException
Returns the home folder of a user.

Parameters:
user - the URL for the user.
client - the Client object used for the connection.
Returns:
The URL of the home folder or null.
Throws:
IOException

getHref

public static URL getHref(URL url,
                          Element response)

getOwner

public static URL getOwner(URL url)
                    throws IOException
Returns the owner of a resource.

Parameters:
url - the URL of the resource.
Returns:
The URL of the owner or null.
Throws:
IOException

getOwner

public static URL getOwner(URL url,
                           Client client)
                    throws IOException
Returns the owner of a resource.

Parameters:
url - the URL of the resource.
client - the Client object used for the connection.
Returns:
The URL of the owner or null.
Throws:
IOException

getPassword

public static String getPassword(URL user)
                          throws IOException
Returns the password of a user.

Parameters:
user - the URL of the user.
Returns:
The password or null.
Throws:
IOException

getPassword

public static String getPassword(URL user,
                                 Client client)
                          throws IOException
Returns the password of a user.

Parameters:
user - the URL of the user.
client - the Client object used for the connection.
Returns:
The password or null.
Throws:
IOException

getPropertyStatusCode

public static int getPropertyStatusCode(Node propElement)
Extracts the status code from a property element.

Parameters:
propElement - the property element.
Returns:
The status code or -1.

getQuotaAvailableBytes

public static long getQuotaAvailableBytes(URL user)
                                   throws IOException
Returns the available number of bytes for a user.

Parameters:
user - the URL of the user.
Returns:
The number of bytes or -1.
Throws:
IOException

getQuotaAvailableBytes

public static long getQuotaAvailableBytes(URL user,
                                          Client client)
                                   throws IOException
Returns the available number of bytes for a user.

Parameters:
user - the URL of the user.
client - the Client object used for the connection.
Returns:
The number of bytes or -1.
Throws:
IOException

getQuotaTotalBytes

public static long getQuotaTotalBytes(URL user)
                               throws IOException
Returns the total number of bytes a user can use.

Parameters:
user - the URL of the user.
Returns:
The number of bytes or -1.
Throws:
IOException

getQuotaTotalBytes

public static long getQuotaTotalBytes(URL user,
                                      Client client)
                               throws IOException
Returns the total number of bytes a user can use.

Parameters:
user - the URL of the user.
client - the Client object used for the connection.
Returns:
The number of bytes or -1.
Throws:
IOException

getQuotaUsedBytes

public static long getQuotaUsedBytes(URL user)
                              throws IOException
Returns the number of bytes a user is using.

Parameters:
user - the URL of the user.
Returns:
The number of bytes or -1.
Throws:
IOException

getQuotaUsedBytes

public static long getQuotaUsedBytes(URL user,
                                     Client client)
                              throws IOException
Returns the number of bytes a user is using.

Parameters:
user - the URL of the user.
client - the Client object used for the connection.
Returns:
The number of bytes or -1.
Throws:
IOException

getPreconditionMessage

public static String getPreconditionMessage(String precondition)
Returns the localized message that corresponds to the precondition or the empty string if there is no such message.

Parameters:
precondition - the local name of the precondition element.
Returns:
The localized message or the empty string.

getPreconditionMessage

public static String getPreconditionMessage(Client.Response response)
Returns the localized message that corresponds to the preconditions in the response.

Parameters:
response - the response from the server.
Returns:
The localized message or the empty string.

getPreconditionMessage

public static String getPreconditionMessage(Node error)
Extracts the localized message that corresponds to the preconditions in the DAV:error element.

Parameters:
error - the error element.
Returns:
The localized message or the empty string.

getPrivilegeDescription

public static String getPrivilegeDescription(Node privilege)
Returns the localized description of a privilege.

Parameters:
privilege - the privilege element.
Returns:
The localized privilege desciption or null.

getPrivilegeDescription

public static String getPrivilegeDescription(ExpandedName privilege)
Returns the localized description of a privilege.

Parameters:
privilege - the qualified name of the privilege.
Returns:
The localized privilege desciption or null.

getPrivilegeDescription

public static String getPrivilegeDescription(String privilege)
Returns the localized description of a privilege using the local name.

Parameters:
privilege - the local name of the privilege.
Returns:
The localized privilege desciption or null.

getPrivileges

public static ExpandedName[] getPrivileges()
Returns all known privileges. The result shouldn't be altered.


getPropertyDisplayName

public static String getPropertyDisplayName(String property)
Returns the localized display name of a property.

Parameters:
property - the property.
Returns:
The localized display name or the property itself if it doesn't exist.

getReasonPhrase

public static String getReasonPhrase(Client.Response response)
Returns the localized reason message that corresponds to the response.

Parameters:
response - the response from the server.
Returns:
The localized message.

getReasonPhrase

public static String getReasonPhrase(String method,
                                     int statusCode)
Returns the localized reason message that corresponds to the method/status code combination.

Parameters:
method - the method.
statusCode - the status code.
Returns:
The localized message.

getResource

public static String getResource(String key)
A low-level method to retrieve localized strings from the be.re.webdav.res.Res bundle.

Parameters:
key - the key.
Returns:
The localized string.

getResourceTypes

public static ExpandedName[] getResourceTypes(URL url)
                                       throws IOException
Returns all the resource types a resource has.

Parameters:
url - the URL of the resource.
Returns:
An array of the qualified names of the resource types.
Throws:
IOException

getResourceTypes

public static ExpandedName[] getResourceTypes(URL url,
                                              Client client)
                                       throws IOException
Returns all the resource types a resource has.

Parameters:
url - the URL of the resource.
client - the Client object used for the connection.
Returns:
An array of the qualified names of the resource types. The array will be empty when no resource types were returned.
Throws:
IOException

getStatusCode

public static int getStatusCode(Element response)
Extracts the status code from a multistatus reponse entry.

Parameters:
response - the response element.
Returns:
The status code or -1.

isActivity

public static boolean isActivity(URL url)
                          throws IOException
Tests if the resource is an activity.

Parameters:
url - the URL of the resource.
Returns:
true if it is an activity, false otherwise.
Throws:
IOException

isActivity

public static boolean isActivity(URL url,
                                 Client client)
                          throws IOException
Tests if the resource is an activity.

Parameters:
url - the URL of the resource.
client - the Client object used for the connection.
Returns:
true if it is an activity, false otherwise.
Throws:
IOException

isCheckedOut

public static boolean isCheckedOut(URL url)
                            throws IOException
Returns the checked-out state.

Parameters:
url - the URL of the resource.
Returns:
true if it is checked out, false otherwise.
Throws:
IOException

isCheckedOut

public static boolean isCheckedOut(URL url,
                                   Client client)
                            throws IOException
Returns the checked-out state.

Parameters:
url - the URL of the resource.
client - the Client object used for the connection.
Returns:
true if it is checked out, false otherwise.
Throws:
IOException

isCollection

public static boolean isCollection(URL url)
                            throws IOException
Tests if the resource is a collection.

Parameters:
url - the URL of the resource.
Returns:
true if it is a collection, false otherwise.
Throws:
IOException

isCollection

public static boolean isCollection(URL url,
                                   Client client)
                            throws IOException
Tests if the resource is a collection.

Parameters:
url - the URL of the resource.
client - the Client object used for the connection.
Returns:
true if it is a collection, false otherwise.
Throws:
IOException

isMemberOfOne

public static boolean isMemberOfOne(URL url,
                                    URL[] collections)
                             throws IOException
Tests if url is a member of one of the collections.

Parameters:
url - the URL of the resource.
collections - the collections to test against.
Returns:
true if it is a member, false otherwise.
Throws:
IOException

isOwner

public static boolean isOwner(URL url,
                              URL user)
                       throws IOException
Tests if user owns the resource.

Parameters:
url - the URL of the resource.
user - the URL of the user.
Returns:
true if the user owns it, false otherwise.
Throws:
IOException

isOwner

public static boolean isOwner(URL url,
                              URL user,
                              Client client)
                       throws IOException
Tests if user owns the resource.

Parameters:
url - the URL of the resource.
user - the URL of the user.
client - the Client object used for the connection.
Returns:
true if the user owns it, false otherwise.
Throws:
IOException

isPrincipal

public static boolean isPrincipal(URL url)
                           throws IOException
Tests if the resource is a principal.

Parameters:
url - the URL of the resource.
Returns:
true if it is a principal, false otherwise.
Throws:
IOException

isPrincipal

public static boolean isPrincipal(URL url,
                                  Client client)
                           throws IOException
Tests if the resource is a principal.

Parameters:
url - the URL of the resource.
client - the Client object used for the connection.
Returns:
true if it is a principal, false otherwise.
Throws:
IOException

isVersion

public static boolean isVersion(URL url)
                         throws IOException
Tests if the resource is a version.

Parameters:
url - the URL of the resource.
Returns:
true if it is a version, false otherwise.
Throws:
IOException

isVersion

public static boolean isVersion(URL url,
                                Client client)
                         throws IOException
Tests if the resource is a version.

Parameters:
url - the URL of the resource.
client - the Client object used for the connection.
Returns:
true if it is a version, false otherwise.
Throws:
IOException

isView

public static boolean isView(URL url)
                      throws IOException
Tests if the resource is a view. This is specific to Pincette.

Parameters:
url - the URL of the resource.
Returns:
true if it is a view, false otherwise.
Throws:
IOException

isView

public static boolean isView(URL url,
                             Client client)
                      throws IOException
Tests if the resource is a view. This is specific to Pincette.

Parameters:
url - the URL of the resource.
client - the Client object used for the connection.
Returns:
true if it is a view, false otherwise.
Throws:
IOException

mkcols

public static void mkcols(URL url)
                   throws IOException
Creates the collection resource denoted by url and all of the parent collection resources if they don't already exist.

Parameters:
url - the URL of the new collection.
Throws:
IOException

readDisplayNameList

public static String[] readDisplayNameList(URL collection)
                                    throws IOException
Returns the values of the DAV:displayname properties of the members of the collection. This is useful to show directory listings or to extract values from functional collections such as those that contain activities, principals, etc.

Parameters:
collection - the URL of the resource.
Returns:
The array of display names, which will be empty if the collection is empty.
Throws:
IOException

readDisplayNameList

public static void readDisplayNameList(URL url,
                                       Client.Response response,
                                       Util.DisplayNameHandler handler,
                                       boolean includeCollection)
                                throws IOException
Processes the values of the DAV:displayname properties in the entries in a multistatus response.

Parameters:
url - the request URL.
response - the multistatus response.
handler - the handler that is called for each occurrence of a DAV:displayname property.
includeCollection - if set to true the request URL will also be considered in case it is a collection.
Throws:
IOException

readPropertyList

public static void readPropertyList(URL url,
                                    Client.Response response,
                                    Util.PropertyHandler handler,
                                    boolean includeCollection)
                             throws IOException
Processes all the properties in the entries in a multistatus response.

Parameters:
url - the request URL.
response - the multistatus response.
handler - the handler that is called for each occurrence of the DAV:propstat element. The handler will receive the properties in it. If there are no properties at all for a response entry the handler is called once with an empty property array.
includeCollection - if set to true the request URL will also be considered in case it is a collection.
Throws:
IOException

readPropertyList

public static void readPropertyList(URL url,
                                    Client.Response response,
                                    Util.PropertyHandler handler,
                                    Util.ReportMultistatus report,
                                    boolean includeCollection)
                             throws IOException
Processes all the properties in the entries in a multistatus response.

Parameters:
url - the request URL.
response - the multistatus response.
handler - the handler that is called for each occurrence of the DAV:propstat element. The handler will receive the properties in it. If there no properties at all for a response entry the handler is called once with an empty property array.
report - the handler that is called when the status code for an entry is present but not 200.
includeCollection - if set to true the request URL will also be considered in case it is a collection.
Throws:
IOException

readUrlList

public static void readUrlList(URL url,
                               Client.Response response,
                               Util.UrlHandler handler)
                        throws IOException
Processes the DAV:href element in the entries in a multistatus response.

Parameters:
url - the request URL.
response - the multistatus response.
handler - the handler that is called for each entry.
Throws:
IOException

reportMultistatus

public static void reportMultistatus(Client.Response response,
                                     Util.ReportMultistatus report)
                              throws IOException
Processes the entries in a multistatus response one by one.

Parameters:
response - the multistatus response.
report - the handler to process one entry.
Throws:
IOException

setAutoVersion

public static void setAutoVersion(URL url,
                                  String mode)
                           throws IOException
Sets the auto-version mode for a resource.

Parameters:
url - the URL of the resource.
mode - see the WebDAV values for the "auto-version" property.
Throws:
IOException

setAutoVersion

public static void setAutoVersion(URL url,
                                  String mode,
                                  Client client)
                           throws IOException
Sets the auto-version mode for a resource.

Parameters:
url - the URL of the resource.
mode - see the WebDAV values for the "auto-version" property.
client - the Client object used for the connection.
Throws:
IOException

setHome

public static void setHome(URL user,
                           URL home)
                    throws IOException
Sets the home folder for a user.

Parameters:
user - the URL of the user.
home - the URL of the home folder.
Throws:
IOException

setHome

public static void setHome(URL user,
                           URL home,
                           Client client)
                    throws IOException
Sets the home folder for a user.

Parameters:
user - the URL of the user.
home - the URL of the home folder.
client - the Client object used for the connection.
Throws:
IOException

setOwner

public static void setOwner(URL url,
                            URL owner)
                     throws IOException
Sets the owner of a resource.

Parameters:
url - the URL of the resource.
owner - the URL of owner.
Throws:
IOException

setOwner

public static void setOwner(URL url,
                            URL owner,
                            Client client)
                     throws IOException
Sets the owner of a resource.

Parameters:
url - the URL of the resource.
owner - the URL of owner.
client - the Client object used for the connection.
Throws:
IOException

setPassword

public static void setPassword(URL user,
                               String password)
                        throws IOException
Sets the password for a user.

Parameters:
user - the URL of the user.
password - the password.
Throws:
IOException

setPassword

public static void setPassword(URL user,
                               String password,
                               Client client)
                        throws IOException
Sets the password for a user.

Parameters:
user - the URL of the user.
password - the password.
client - the Client object used for the connection.
Throws:
IOException

setQuotaTotalBytes

public static void setQuotaTotalBytes(URL user,
                                      long total)
                               throws IOException
Sets the total number of bytes a user can use.

Parameters:
user - the URL of the user.
total - the number of logical bytes.
Throws:
IOException

setQuotaTotalBytes

public static void setQuotaTotalBytes(URL user,
                                      long total,
                                      Client client)
                               throws IOException
Sets the total number of bytes a user can use.

Parameters:
user - the URL of the user.
total - the number of logical bytes.
client - the Client object used for the connection.
Throws:
IOException

throwException

public static void throwException(Client.Response response)
                           throws IOException,
                                  be.re.net.ProtocolException
Throw an exception with a localized message that is extracted from the response.

Parameters:
response - the response from the server.
Throws:
IOException
be.re.net.ProtocolException

throwException

public static void throwException(URL url,
                                  String method,
                                  int statusCode)
                           throws be.re.net.ProtocolException
Throw an exception with a localized message that corresponds to the method/status code combination.

Parameters:
url - the URL of the resource.
method - the method.
statusCode - the status code.
Throws:
be.re.net.ProtocolException

throwException

public static void throwException(URL url,
                                  String method,
                                  int statusCode,
                                  Node error)
                           throws be.re.net.ProtocolException
Throw an exception with a localized message that corresponds to the method/status code combination. If an error element is provided the message will be extracted from it.

Parameters:
url - the URL of the resource.
method - the method.
statusCode - the status code.
error - the error element. It may be null.
Throws:
be.re.net.ProtocolException