Novell exteNd
Director 5.2 API

com.sssw.webdav.client
Class EboDAVSwitch

java.lang.Object
 |
 +--com.sssw.webdav.client.EboDAVSwitch

public class EboDAVSwitch
extends Object

Class for constructing and issuing WebDAV requests, and fetching WebDAV responses. EboDAVSwitch provides the following capabilities:

EboDAVSwitch provides helper and utility methods to simplify access to low-level WebDAV functions, which are implemented via the Jakarta Slide content management framework. Helper methods expose less of the Slide API than utility methods. The advantage of helper methods is that you can send a complete WebDAV request in a single line of code. The advantage of utility methods is that you gain access to additional functionality provided by the Slide API.

Here is an example of how you might use utility methods to issue a WebDAV request to add a category to a document:

	try {
 	    EboDAVSwitch dav = new EboDAVSwitch();
	    dav.startSession("myhost.server.com",80);

	    Credentials credentials = dav.createCredentials("username","password");

	    dav.setCredentials(credentials);

	    State state = dav.getState();
	    state.setAuthenticateToken("Basic realm = \"AUTHENTICATION_REALM\"");
	    dav.setState(state);

	    PropPatchMethod ppm = (PropPatchMethod)dav.createWebdavMethod(dav.PROPPATCH_METHOD,document);

	    String uuid = "12345678901234567890123456789012";  // Some category UUID
	    String document = "/Director/WebDAVService/main/MyFolder/MyDocument.htm";  // Document's full path
	    ppm.addPropertyToSet(uuid, null, "AC", EboWebdavConstants.PROPPATCH_ADDCATEGORY);

		dav.executeCommand(ppm);

		Document res = ppm.getResponseDocument();

      // End the session
      dav.endSession();
	}
	catch (Exception e) {
		System.out.println(e.getMessage());
	}

 
Here is an example of how to issue the same WebDAV request using the helper method addCategoryToDocument():


	EboDAVSwitch dav = new EboDAVSwitch();
	// Start the session
	dav.startSession("jango.novell.com",80);

  int status = 0;
	String uuid = "12345678901234567890123456789012";  // Some category UUID
	String document = "/Director/WebDAVService/main/MyFolder/MyDocument.htm";  // Document's full path

  status = dav.addCategoryToDocument("username","password","Basic realm = \"AUTHENTICATION_REALM\"",document,uuid);

 // End the session
 dav.endSession();

 


Constructor Summary
EboDAVSwitch()
          EboDAVSwitch constructor.
 
Method Summary
 int addCategoryToDocument(String username, String password, String realm, String document, String category_uuid)
          Assigns a category reference to a document.
 String checkLockToken(String element)
          Checks who has an object locked.
 int copyElement(String username, String password, String realm, String element, String destination, boolean overwrite, boolean autoGenerate)
          Copies a resource or collection.
 org.apache.webdav.lib.Credentials createCredentials(String username, String password)
          Creates a new Slide Credentials object for authenticating users.
 int createNewDocument(String username, String password, String realm, String folder, String document, String document_type, byte[] content)
          Creates a new document.
 org.apache.webdav.lib.methods.WebdavMethod createWebdavMethod(int method, String path)
          Creates the Slide WebDAV method you want to execute as part of your WebDAV request.
 int deleteDocument(String username, String password, String realm, String document)
          Deletes a document.
 void endSession()
          Ends a WebDAV client session and cleans up any EboDAVSwitch objects.
 void executeCommand(org.apache.webdav.lib.methods.WebdavMethod method)
          Executes a WebDAV Command.
 Hashtable getCategories(String username, String password, String realm, String element)
          Gets category UUIDs and names.
 org.apache.webdav.lib.WebdavClient getClient()
          Gets the Slide WebDAV client.
 org.apache.webdav.lib.Credentials getCredentials()
          Gets credentials from the EboDAVSwitch client.
 boolean getDebug(boolean debug)
          This method returns the state of debug messages.
 Hashtable getFieldValues(String username, String password, String realm, String element)
          Returns a hashtable of custom fields and their values.
 String getPropValue(Document propsXML, String key)
          Gets the values of a particular node in an XML document object.
 String getRoot()
          Gets the root path for the WebDAV servlet.
 org.apache.webdav.lib.State getState()
          Gets state.
 boolean isDirectory(String element)
          Checks to see if an element is a directory (collection).
 int lockDocument(String username, String password, String realm, String document)
          Locks a document.
 int makeCollection(String username, String password, String realm, String parent_folder, String folder, boolean autoGenerate)
          Creates a folder (collection).
 int moveElement(String username, String password, String realm, String element, String destination, boolean autoGenerate)
          Moves or renames a resource or collection.
 void printXMLToConsole(Document doc)
          Prints the XML passed in to the console.
 int putDocument(String username, String password, String realm, String document, byte[] data)
          Updates a document.
 int removeAllCategoriesFromDocument(String username, String password, String realm, String document)
          Removes all category references from a document.
 int removeCategoryFromDocument(String username, String password, String realm, String document, String category_uuid)
          Removes a category reference from a document.
 String returnXMLAsString(Document doc)
          Gets the XML that was passed in and converts it to a string.
 void setCredentials(org.apache.webdav.lib.Credentials cred)
          Sets credentials on the EboDAVSwitch client.
 void setDebug(boolean flag)
          This method allows the user to turn console debug messages on and off.
 void setDebug(int level)
          Sets the debug level on the slide code.
 int setFieldValueForDocument(String username, String password, String realm, String document, String field_name, String field_value)
          Sets the value of a custom field in a document.
 void setRoot(String root)
          Sets the root path for the WebDAV servlet.
 void setState(org.apache.webdav.lib.State state)
          Sets state with your authentication token.
 void startSession(String url)
          Starts a WebDAV client session on the default port 80.
 void startSession(String url, int port)
          Starts a WebDAV client session.
 int unlockDocument(String username, String password, String realm, String document)
          Unlocks a document.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EboDAVSwitch

public EboDAVSwitch()
EboDAVSwitch constructor.
Method Detail

getClient

public org.apache.webdav.lib.WebdavClient getClient()
Gets the Slide WebDAV client.

createWebdavMethod

public org.apache.webdav.lib.methods.WebdavMethod createWebdavMethod(int method,
                                                                     String path)
Creates the Slide WebDAV method you want to execute as part of your WebDAV request. This is a utility method.
Parameters:
method - Method to create.
path - URL path that the method should be set to.
Returns:
Method requested (for example, PropFindMethod, CopyMethod, LockMethod)

startSession

public void startSession(String url,
                         int port)
Starts a WebDAV client session. This is a utility method.
Parameters:
url - URL of the server where WebDAV is implemented.
port - Port number for that server.

setDebug

public void setDebug(int level)
Sets the debug level on the slide code.
Parameters:
level - Level of debug to set into the WebDAV client.

setDebug

public void setDebug(boolean flag)
This method allows the user to turn console debug messages on and off.
Parameters:
flag - True turns debug messages on while false turns debug off.

getDebug

public boolean getDebug(boolean debug)
This method returns the state of debug messages.

startSession

public void startSession(String url)
Starts a WebDAV client session on the default port 80. This is a utility method.
Parameters:
url - URL of the server where WebDAV is implemented.

endSession

public void endSession()
Ends a WebDAV client session and cleans up any EboDAVSwitch objects. This is a utility method.

setState

public void setState(org.apache.webdav.lib.State state)
Sets state with your authentication token. This is a utility method.
Parameters:
state - State object used to maintain cookies, authentication, etc.

getState

public org.apache.webdav.lib.State getState()
Gets state. This is a utility method.
Returns:
State state object

setRoot

public void setRoot(String root)
Sets the root path for the WebDAV servlet.
Parameters:
root - Path to the WebDAV servlet.

getRoot

public String getRoot()
Gets the root path for the WebDAV servlet.
Returns:
Root path to the WebDAV servlet.

createCredentials

public org.apache.webdav.lib.Credentials createCredentials(String username,
                                                           String password)
Creates a new Slide Credentials object for authenticating users.
Parameters:
username - User name for the Credentials object.
password - Password for the Credentials object. This is a utility method.
Returns:
Credentials object.

setCredentials

public void setCredentials(org.apache.webdav.lib.Credentials cred)
Sets credentials on the EboDAVSwitch client.
Parameters:
cred - Credentials object to set.
See Also:
EboDAVSwitch.getCredentials()

getCredentials

public org.apache.webdav.lib.Credentials getCredentials()
Gets credentials from the EboDAVSwitch client.
Returns:
Credentials Credentials object
See Also:
EboDAVSwitch.setCredentials(Credentials cred)

executeCommand

public void executeCommand(org.apache.webdav.lib.methods.WebdavMethod method)
                    throws com.sssw.webdav.client.EboDAVException,
                           MalformedURLException,
                           IOException
Executes a WebDAV Command. This is a utility object.
Parameters:
method - WebDAV method to execute.

printXMLToConsole

public void printXMLToConsole(Document doc)
Prints the XML passed in to the console.

Primarily for debugging.

Parameters:
doc - XML to print.

returnXMLAsString

public String returnXMLAsString(Document doc)
Gets the XML that was passed in and converts it to a string.

Primarily for debugging.

Parameters:
doc - XML to return as a string.
Returns:
XML as a string.

getPropValue

public String getPropValue(Document propsXML,
                           String key)
                    throws com.sssw.webdav.client.EboDAVException
Gets the values of a particular node in an XML document object.
Parameters:
propsXML - XML Document object that contains the value.
key - Name of the target node.
Returns:
Value of the 'key'.

checkLockToken

public String checkLockToken(String element)
                      throws com.sssw.webdav.client.EboDAVException
Checks who has an object locked.
Parameters:
element - Full path of the element to check the lock on.
Returns:
Owner of the locked object, or null if it is unlocked.

getFieldValues

public Hashtable getFieldValues(String username,
                                String password,
                                String realm,
                                String element)
                         throws com.sssw.webdav.client.EboDAVException
Returns a hashtable of custom fields and their values.
Parameters:
username - User name for credentials.
password - Password for credentials.
realm - Realm in which to authenticate credentials.
element - Full path of the element to get the field values for.
Returns:
Hashtable Returns a hashtable of field names and their values.

getCategories

public Hashtable getCategories(String username,
                               String password,
                               String realm,
                               String element)
                        throws com.sssw.webdav.client.EboDAVException
Gets category UUIDs and names.
Parameters:
username - User name for credentials.
password - Password for credentials.
realm - Realm in which to authenticate credentials.
element - Full path of the element whose categories will be checked.
Returns:
Hashtable of category UUIDs and names.

isDirectory

public boolean isDirectory(String element)
                    throws com.sssw.webdav.client.EboDAVException
Checks to see if an element is a directory (collection).
Parameters:
xml - Full path of the element to be checked.
Returns:
True if the element is a directory.

addCategoryToDocument

public int addCategoryToDocument(String username,
                                 String password,
                                 String realm,
                                 String document,
                                 String category_uuid)
                          throws com.sssw.webdav.client.EboDAVException
Assigns a category reference to a document. This is a helper method.

** Note: If you need to exercise more control over credentials and state, it is recommended that you not use this method.

Parameters:
username - User name for credentials.
password - Password for credentials.
realm - Realm in which to authenticate credentials.
document - Full path of the target document.
category_uuid - UUID of the category to add.
Returns:
HTTP status code.

removeCategoryFromDocument

public int removeCategoryFromDocument(String username,
                                      String password,
                                      String realm,
                                      String document,
                                      String category_uuid)
                               throws com.sssw.webdav.client.EboDAVException
Removes a category reference from a document. This is a helper method.

** Note: If you need to exercise more control over credentials and state, it is recommended that you not use this method.

Parameters:
username - User name for credentials.
password - Password for credentials.
realm - Realm in which to authenticate credentials.
document - The full path of the target document.
category_uuid - UUID of the category to remove.
Returns:
HTTP status code.

removeAllCategoriesFromDocument

public int removeAllCategoriesFromDocument(String username,
                                           String password,
                                           String realm,
                                           String document)
                                    throws com.sssw.webdav.client.EboDAVException
Removes all category references from a document. This is a helper method.

** Note: If you need to exercise more control over credentials and state, it is recommended that you not use this method.

Parameters:
username - User name for credentials.
password - Password for credentials.
realm - Realm in which to authenticate credentials.
document - The full path of the target document.
Returns:
HTTP status code.

setFieldValueForDocument

public int setFieldValueForDocument(String username,
                                    String password,
                                    String realm,
                                    String document,
                                    String field_name,
                                    String field_value)
                             throws com.sssw.webdav.client.EboDAVException
Sets the value of a custom field in a document. This is a helper method.

** Note: If you need to exercise more control over credentials and state, it is recommended that you not use this method.

Parameters:
username - User name for credentials.
password - Password for credentials.
realm - Realm in which to authenticate credentials.
document - Full path of the target document.
field_name - Name of the field to update.
field_value - Value for the field.
Returns:
HTTP status code.

createNewDocument

public int createNewDocument(String username,
                             String password,
                             String realm,
                             String folder,
                             String document,
                             String document_type,
                             byte[] content)
                      throws com.sssw.webdav.client.EboDAVException
Creates a new document. This is a helper method.

** Note: If you need to exercise more control over credentials and state, it is recommended that you not use this method.

Parameters:
username - User name for credentials.
password - Password for credentials.
realm - Realm in which to authenticate credentials.
folder - Full path of the folder for the new document.
document - Name of the target document.
document_type - Name of the document type.
content - Content for the new document.
Returns:
HTTP status code.

lockDocument

public int lockDocument(String username,
                        String password,
                        String realm,
                        String document)
                 throws com.sssw.webdav.client.EboDAVException
Locks a document. This is a helper method.

** Note: If you need to exercise more control over credentials and state, it is recommended that you not use this method.

Parameters:
username - User name for credentials.
password - Password for credentials.
realm - Realm in which to authenticate credentials.
document - Full path of the document to lock.
Returns:
HTTP status code.

unlockDocument

public int unlockDocument(String username,
                          String password,
                          String realm,
                          String document)
                   throws com.sssw.webdav.client.EboDAVException
Unlocks a document. This is a helper method.

** Note: If you need to exercise more control over credentials and state, it is recommended that you not use this method.

Parameters:
username - User name for credentials.
password - Password for credentials.
realm - Realm in which to authenticate credentials.
document - Full path of the document to unlock.
Returns:
HTTP status code.

deleteDocument

public int deleteDocument(String username,
                          String password,
                          String realm,
                          String document)
                   throws com.sssw.webdav.client.EboDAVException
Deletes a document. This is a helper method.

** Note: If you need to exercise more control over credentials and state, it is recommended that you not use this method.

Parameters:
username - User name for credentials.
password - Password for credentials.
realm - Realm in which to authenticate credentials.
document - Full path of the document to delete.
Returns:
HTTP status code.

putDocument

public int putDocument(String username,
                       String password,
                       String realm,
                       String document,
                       byte[] data)
                throws com.sssw.webdav.client.EboDAVException
Updates a document. This is a helper method.

** Note: If you need to exercise more control over credentials and state, it is recommended that you not use this method.

Parameters:
username - User name for credentials.
password - Password for credentials.
realm - Realm in which to authenticate credentials.
document - Full path of the document to update.
data - Data for updating the document.
Returns:
HTTP status code.

makeCollection

public int makeCollection(String username,
                          String password,
                          String realm,
                          String parent_folder,
                          String folder,
                          boolean autoGenerate)
                   throws com.sssw.webdav.client.EboDAVException
Creates a folder (collection). This is a helper method.

** Note: If you need to exercise more control over credentials and state, it is recommended that you not use this method.

Parameters:
username - User name for credentials.
password - Password for credentials.
realm - Realm in which to authenticate credentials.
parent_folder - Name of parent folder relative to host.
folder - Name of folder to create under parent_folder.
autoGenerate - Flag indicating whether to generate all folders in the path if they don't already exist. True = generate the folders.
Returns:
HTTP status code.

moveElement

public int moveElement(String username,
                       String password,
                       String realm,
                       String element,
                       String destination,
                       boolean autoGenerate)
                throws com.sssw.webdav.client.EboDAVException
Moves or renames a resource or collection. To move an object, set the destination to a different path than the element. To rename an object, set the destination to the same path as the element, but give the element a different name in the destination path. This is a helper method.

** Note: If you need to exercise more control over credentials and state, it is recommended that you not use this method.

Parameters:
username - User name for credentials.
password - Password for credentials.
realm - Realm in which to authenticate credentials.
element - The full path of the object to move or rename.
destination - The full path of the desired new location, or the same path as element but with a new name.
autoGenerate - Flag indicating whether to generate folders that don't exist. True = generate the folders.
Returns:
HTTP status code

copyElement

public int copyElement(String username,
                       String password,
                       String realm,
                       String element,
                       String destination,
                       boolean overwrite,
                       boolean autoGenerate)
                throws com.sssw.webdav.client.EboDAVException
Copies a resource or collection. This is a helper method.

** Note: If you need to exercise more control over credentials and state, it is recommended that you not use this method.

Parameters:
username - User name for credentials.
password - Password for credentials.
realm - Realm in which to authenticate credentials.
element - The full path of the object to copy
destination - The full path of the desired new location
overwrite - Flag indicating whether or not to overwrite an existing element of the same name. True = overwrite the element.
autoGenerate - Flag indicating whether to generate folders that don't exist. True = generate the folders.
Returns:
HTTP status code

Novell exteNd
Director 5.2 API