Content Management Guide
CHAPTER 10
This chapter describes an API provided with the exteNd Director WebDAV service for developing a custom WebDAV client that takes advantage of the specialized features of the exteNd Director Content Management (CM) subsystem to create and administer content.
The chapter covers the following topics:
The WebDAV client API is based on the Jakarta Slide content management framework and is designed to work with the exteNd Director CM subsystem. Slide is a low-level framework that can be used to develop a consistent interface for manipulating binary content in a variety of data stores using the WebDAV protocol.
Java client applications can access the Slide content management framework directly through a set of Java classes that implement WebDAV methods and other low-level logic in these functional areas:
The exteNd Director WebDAV client API adds a level of abstraction by providing wrapper classes around the Slide client API. These classes contain helper and utility methods that encapsulate the low-level Slide methods and add logic that tightly integrates with the specialized capabilities of the exteNd Director CM subsystem. For example, you can build a WebDAV client that assigns categories to documents, associates custom metadata with content, and creates content using custom templates called document types as defined in the CM subsystem.
For more information about Slide, see the Jakarta Slide project Web site. The following URL was valid at the time this chapter was published:
http://jakarta.apache.org/slide/
With so many commercial and open source WebDAV client applications now availableand more on the waywhy build your own WebDAV client to work with the exteNd Director CM subsystem?
Here is a key reason: to tailor an application to your unique authoring needs in terms of creating, updating, and managing content using the exteNd Director CM subsystem. With this objective in mind, the WebDAV client API allows you to develop applications that are more robust than most commercial and open-source WebDAV clients, because it provides:
Simplified access to all WebDAV methods, including PROPPATCH
An interface to the comprehensive content management features of the CM subsystem, including the ability to create documents using custom templates and manipulate custom metadata separately from content
To use the WebDAV client API, you must add the following JAR files to your project classpath:
JAR file |
Description |
---|---|
WebDAV_slide.jar |
Contains relevant Slide client API classes |
WebDAVClient.jar |
Contains exteNd Director WebDAV client API classes |
These JAR files are installed with exteNd Director in the following location in the exteNd Director Utilities\Client directory:
To run a WebDAV client, you must add the following JAR files to your client's classpath at runtime:
You use the WebDAV client API to design a custom authoring tool with WebDAV access to the exteNd Director CM subsystem for managing collaborative interactions with your content.
You need to build your own user interface, but the API provides the logical underpinnings for invoking key CM functions from your client:
The WebDAV client API provides methods that invoke CM functions by sending WebDAV requests. The result of each request is returned as a WebDAV response that includes a status code to indicate success or the reason for failure.
A WebDAV request consists of a header and a body. The request header contains the method, target resource, HTTP version, and a sequence of key/value pairs containing parameters for the method. The request body defines additionaland perhaps more complexparameters if necessary.
Similarly, a WebDAV response contains a header and optional body. The response header contains information about the response, such as the HTTP version used by the server, along with status codes and messages. The response body generally contains the result of method executionsuch as a document.
Classes in the WebDAV client API provide methods for easily constructing and sending specific WebDAV requests and processing responses.
For more information about WebDAV, search on the Web for rfc2518the WebDAV specification.
WebDAV requests act on Web resources, collections, and properties as described in Information elements for distributed Web authoring. When you issue a WebDAV request, you need to pass along a reference to the element of interest. This reference should be a URI, relative to the element's server in this format:
/database name/WebDAVService/main/path relative to default (root) folder
For example, assume your exteNd Director database is called Director. For a document called MyDocument that resides in a folder called Test in the default (root) folder, the URI looks like this:
/Director/WebDAVService/main/Test/MyDocument
The WebDAV client API consists of these key classes:
Class |
Description |
---|---|
Constructs WebDAV requests and fetches WebDAV responses |
|
EboDAVException |
Defines WebDAV exceptions |
EboDAVStatus |
Indicates the status code associated with WebDAV exceptions |
EboDAVSwitchthe heart of the matter The EboDAVSwitch object is the heart of the WebDAV client API, containing most of the functionality for communicating with the CM subsystem. EboDAVSwitch provides helper methods and utility methods that encapsulate much of the low-level Slide code required for transmitting WebDAV requests and responses.
The EboDAVSwitch object provides a set of helper methods for constructing WebDAV requests. Each helper method allows you to send a complete request in a single line of code.
Here is list of supported WebDAV requests that have associated helper methods. Click on the links in the table to get more information about how to code specific WebDAV requests in a Java client program.
Some WebDAV requests do not have associated helper methods and can be issued only by using Slide classes and utility methods, described next.
For information on how to use these helper methods in WebDAV client applications, see Programming practices using helper methods.
All WebDAV requests can be invoked using utility methods. Compared to helper methods, utility methods expose more of the Slide API than helper methods. The tradeoff is that while you gain access to the additional functionality offered by the Slide API, you'll have to write more lines of code to send a WebDAV request.
Utility methods also provide a mechanism for issuing WebDAV requests that do not have associated helper methods.
Here is list of commonly used utility methods that wrap Slide functions for constructing and issuing WebDAV requests:
For information about how to use these utility methods in WebDAV client applications, see Programming practices using utility methods.
When you work with utility methods, you need to use several Slide API classes:
For more information about these classes, see the Slide WebDAV client JavaDoc, available at this URL (valid at the time this chapter was published):
http://jakarta.apache.org/slide/clientjavadoc/index.html
Here is list of WebDAV requests that have no associated exteNd Director helper methods and therefore can be implemented only by using Slide classes and exteNd Director utility methods. Click on the links in the table to get more information about how to code these WebDAV requests in a Java client program:
WebDAV request |
Associated WebDAV method |
---|---|
GET |
|
HEAD |
|
Getting methods that can be called on a resource or collection |
OPTIONS |
PROPFIND |
This section describes best practices for using the client API to issue WebDAV requests and process WebDAV responses in custom Java client programs. The logic varies depending on whether you use helper methods or utility methods.
Here are the steps for using helper methods to issue WebDAV requests:
Here is sample code showing how to use the helper method deleteDocument() in a WebDAV client. In this example, assume server URL = localhost and port = 80. The document to be deleted is passed as an argument to the method.
Note that an EboDAVStatus object is also instantiated. This object is used to check the status of the request and inform the user of success or failure.
/** deleteADocument */ import com.sssw.webdav.client.*; public class deleteADocument { private static boolean m_debug = false; public void deleteADocument (String document) { //Define variables int statuscode = 0; String user = "contentadmin"; String password = "contentadmin"; String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\""; //Instantiate an EboDAVSwitch object EboDAVSwitch dav = new EboDAVSwitch(); //Instantiate an EboDAVStatus object EboDAVStatus status = new EboDAVStatus(); //Start a session dav.startSession("localhost", 80); try { //Lock document before trying to delete statuscode = dav.lockDocument(user, password, realm, document); if (statuscode==EboDAVStatus.SC_NO_CONTENT) System.out.println("Request succeeded: The document is now locked"); else System.out.println("Request failed: " + status.getStatusText(statuscode)); //Send the WebDAV request to delete document statuscode = dav.deleteDocument(user, password, realm, document); if (statuscode==EboDAVStatus.SC_OK) System.out.println("Request succeeded: The document was deleted."); else System.out.println("Request failed: " + status.getStatusText(statuscode)); } catch (EboDAVException e) { if (m_debug) e.printStackTrace(); else System.out.println(e.getMessage()); } //End session dav.endSession(); } }
To learn how to issue the same WebDAV request using utility methods, see Code example: deleting a document using utility methods.
Here are the steps for using utility methods to issue WebDAV requests:
The WebDAV Proppatch method is used with exteNd Director utility methods to issue a variety of WebDAV requests:
For each of these requests, you must instantiate a Slide PropPatchMethod object, then call the addPropertyToSet() method on the PropPatchMethod object using this signature:
addPropertyToSet( String property name, String property value, String namespace-abbr, String namespace )
Here are descriptions of the arguments to addPropertyToSet():
Setting values of standard fields You can also use the WebDAV Proppatch method to set values of standard fieldssuch as title and authorin a document. In this case, call addPropertyToSet() without the namespace-abbr and namespace arguments.
Here is sample code illustrating how to use utility methods with Slide classes in a WebDAV client to send a request to delete a document. In this example, assume server URL = localhost and port = 80. The example uses the following Slide classes:
/** deleteTheDocument */ import com.sssw.webdav.client.*; import org.apache.webdav.lib.*; import org.apache.webdav.lib.methods.*; public class deleteTheDocument { private static boolean m_debug = false; public void deleteTheDocument (String document) { //Define variables int statuscode = 0; String user = "contentadmin"; String password = "contentadmin"; String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\""; //Instantiate an EboDAVSwitch object EboDAVSwitch dav = new EboDAVSwitch(); //Instantiate an EboDAVStatus object EboDAVStatus status = new EboDAVStatus(); //Start a session dav.startSession("localhost", 80); //Get and set credentials Credentials credentials = dav.createCredentials(user, password); dav.setCredentials(credentials); //Get and set state and authentication realm State state = dav.getState(); state.setAuthenticateToken(realm); dav.setState(state); try { //Create the WebDAV method object LockMethod LockMethod lm = (LockMethod)dav.createWebdavMethod(dav.LOCK_METHOD,document); //Set the owner lm.setOwner(user); //Execute LockMethod dav.executeCommand(lm); statuscode = lm.getStatusCode(); if (statuscode == (EboDAVStatus.SC_NO_CONTENT)) System.out.println("Request succeeded: The document was locked."); else System.out.println("Request failed: " + status.getStatusText(statuscode)); //Create the WebDAV method object DeleteMethod DeleteMethod dm = (DeleteMethod)dav.createWebdavMethod(dav.DELETE_METHOD,document); //Execute DeleteMethod (send the WebDAV request to delete document) dav.executeCommand(dm); statuscode = dm.getStatusCode(); if (statuscode == (EboDAVStatus.SC_OK)) System.out.println("Request succeeded: The document was deleted."); else System.out.println("Request failed: " + status.getStatusText(statuscode)); } catch (EboDAVException e) { if (m_debug) e.printStackTrace(); else System.out.println(e.getMessage()); } catch (java.net.MalformedURLException murle) { if (m_debug) murle.printStackTrace(); else System.out.println(murle.getMessage()); } catch (java.io.IOException ioe) { if (m_debug) ioe.printStackTrace(); else System.out.println(ioe.getMessage()); } //End session dav.endSession(); } }
To learn how to issue the same WebDAV request using helper methods, see Code example: deleting a document using a helper method.
This section describes how to issue WebDAV requests from a Java client application. The following functions are covered:
The following code examples show how to add a category reference to a document. A category is a descriptive name used to group documents logically in the CM subsystem.
This example uses the helper method addCategoryToDocument():
/** addCategoryReferenceToDocument */ import com.sssw.webdav.client.*; public class addCategoryReferenceToDocument { private static boolean m_debug = false; public void addCategoryReferenceToDocument (String document, String categoryUUID) { //Define variables int statuscode = 0; String user = "contentadmin"; String password = "contentadmin"; String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\""; //Instantiate an EboDAVSwitch object EboDAVSwitch dav = new EboDAVSwitch(); //Instantiate an EboDAVStatus object EboDAVStatus status = new EboDAVStatus(); //Start a session dav.startSession("localhost", 80); try { //Lock the document statuscode = dav.lockDocument(user, password, realm, document); if (statuscode == EboDAVStatus.SC_NO_CONTENT) System.out.println("Request succeeded: The category was added to " + document); else System.out.println("Request failed: " + status.getStatusText(statuscode)); //Send the WebDAV request to add a category reference statuscode = dav.addCategoryToDocument(user, password, realm, document, categoryUUID); if (statuscode==EboDAVStatus.SC_MULTI_STATUS) System.out.println("Request succeeded: The category was added to " + document); else System.out.println("Request failed: " + status.getStatusText(statuscode)); //Unlock the document statuscode = dav.unlockDocument(user, password, realm, document); if (statuscode == EboDAVStatus.SC_NO_CONTENT) System.out.println("Request succeeded: The document was unlocked."); else System.out.println("Request failed: " + status.getStatusText(statuscode)); } catch (EboDAVException e) { if (m_debug) e.printStackTrace(); else System.out.println(e.getMessage()); } //End session dav.endSession(); } }
This example uses the Slide PropPatchMethod class and the exteNd Director utility methods startSession(), createCredentials(), setCredentials(), getState(), setState(), and createWebDAVMethod().
The method that adds the category reference is addPropertyToSet(), called on the PropPatchMethod object. Notice that the second argumentproperty valueis null (because the category UUID is passed as the first argumentproperty name). For more information about addPropertyToSet() and its arguments, see Constructing WebDAV requests that use Proppatch.
/** addCategoryReference */ import com.sssw.webdav.client.*; import com.sssw.webdav.common.EboWebdavConstants; import org.apache.webdav.lib.*; import org.apache.webdav.lib.methods.*; public class addCategoryReference { private static boolean m_debug = false; public void addCategoryReference (String document, String categoryUUID) { //Define variables int statuscode = 0; String user = "contentadmin"; String password = "contentadmin"; String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\""; String namespace-abbr = "AC"; //Instantiate an EboDAVSwitch object EboDAVSwitch dav = new EboDAVSwitch(); //Instantiate an EboDAVStatus object EboDAVStatus status = new EboDAVStatus(); //Start a session dav.startSession("localhost", 80); //Get and set credentials Credentials credentials = dav.createCredentials(user, password); dav.setCredentials(credentials); //Get and set state and authentication realm State state = dav.getState(); state.setAuthenticateToken(realm); dav.setState(state); try { //Lock the document //Create the WebDAV method object LockMethod LockMethod lm = (LockMethod)dav.createWebdavMethod(dav.LOCK_METHOD,document); //Set the owner lm.setOwner(user); //Execute the command dav.executeCommand(lm) statuscode = lm.getStatusCode(); if (statuscode == (EboDAVStatus.SC_NO_CONTENT)) System.out.println("Request succeeded: The document was locked."); else System.out.println("Request failed: " + status.getStatusText(statuscode)); //Create the WebDAV method object PropPatchMethod PropPatchMethod ppm = (PropPatchMethod)dav.createWebdavMethod(dav.PROPPATCH_METHOD,document); ppm.addPropertyToSet( categoryUUID, null, namespace-abbr, EboWebdavConstants.PROPPATCH_ADDCATEGORY); //Execute PropPatchMethod (send the WebDAV request to add category reference) dav.executeCommand(ppm); statuscode = ppm.getStatusCode(); if (statuscode == (EboDAVStatus.SC_MULTI_STATUS)) System.out.println("Request succeeded: The category was added to " + document + "."); else System.out.println("Request failed: " + status.getStatusText(statuscode)); //Create the WebDAV method object UnlockMethod UnlockMethod ulm = (UnlockMethod)dav.createWebdavMethod(dav.UNLOCK_METHOD,document); //Execute UnlockMethod dav.executeCommand(ulm); statuscode = ulm.getStatusCode(); if (statuscode == (EboDAVStatus.SC_NO_CONTENT)) System.out.println("Request succeeded: The document was unlocked."); else System.out.println("Request failed: " + status.getStatusText(statuscode)); } catch (EboDAVException e) { if (m_debug) e.printStackTrace(); else System.out.println(e.getMessage()); } catch (java.net.MalformedURLException murle) { if (m_debug) murle.printStackTrace(); else System.out.println(murle.getMessage()); } catch (java.io.IOException ioe) { if (m_debug) ioe.printStackTrace(); else System.out.println(ioe.getMessage()); } //End session dav.endSession(); } }
The following code shows how to copy a document from a source path to a destination path. In this case the source path points to a document. To copy other types of resources or collections, make sure the source path points to the element of interest.
The example uses the helper method copyElement():
/** copyADocument */ import com.sssw.webdav.client.*; public class copyADocument { private static boolean m_debug = false; public void copyADocument (String docsourcepath, String docdestinationpath) { //Define variables int statuscode = 0; String user = "contentadmin"; String password = "contentadmin"; String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\""; boolean overwrite = true; //Overwrite an existing document of the same name in the docdestinationpath boolean autogen = true; //Generate folders in the docdestinationpath if they don't exist //Instantiate an EboDAVSwitch object EboDAVSwitch dav = new EboDAVSwitch(); //Instantiate an EboDAVStatus object EboDAVStatus status = new EboDAVStatus(); //Start a session dav.startSession("localhost", 80); //Send the WebDAV request to copy document try { statuscode = dav.copyElement(user, password, realm, docsourcepath, docdestinationpath, overwrite, autogen); if (statuscode==EboDAVStatus.SC_CREATED) System.out.println("Request succeeded: The document " + docsourcepath + "was copied to " + docdestinationpath); else System.out.println("Request failed: " + status.getStatusText(statuscode)); } catch (EboDAVException e) { if (m_debug) e.printStackTrace(); else System.out.println(e.getMessage()); } //End session dav.endSession(); } }
You can also copy a resource or collection using the Slide CopyMethod class and exteNd Director utility methods. See Programming practices using utility methods.
The following code shows how to create a new collection. Recall that a collection is a container for other resources and collections. A folder is a an example of a collection.
This example uses the helper method makeCollection():
/** makeACollection */ import com.sssw.webdav.client.*; public class makeACollection { private static boolean m_debug = false; public void makeACollection (String parent_folder, String folder_name) { //Define variables int statuscode = 0; String user = "contentadmin"; String password = "contentadmin"; String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\""; //Instantiate an EboDAVSwitch object EboDAVSwitch dav = new EboDAVSwitch(); //Instantiate an EboDAVStatus object EboDAVStatus status = new EboDAVStatus(); //Start a session dav.startSession("localhost", 80); //Send the WebDAV request to make a collection try { statuscode = dav.makeCollection(user, password, realm, parent_folder, folder_name, true); if (statuscode==EboDAVStatus.SC_CREATED) System.out.println("Request succeeded: The collection " + parent_folder + "/" + folder_name + "was created."); else System.out.println("Request failed: " + status.getStatusText(statuscode)); } catch (EboDAVException e) { if (m_debug) e.printStackTrace(); else System.out.println(e.getMessage()); } //End session dav.endSession(); } }
You can also make a new collection using the Slide MkcolMethod class and exteNd Director utility methods. See Programming practices using utility methods.
The following code shows how to create a new document from a custom template. Custom templates are document types that you define in the exteNd Director CM subsystem using the CM API or CMS Administration Console.
The document that is created contains the content "Hello world!" along with any custom fields defined in the document type.
This example uses the helper method createNewDocument(). The document type is passed as an argument to createNewDocument, along with the user name, password, realm, containing folder, and content:
/** createADocument */ import com.sssw.webdav.client.*; public class createADocument { private static boolean m_debug = false; public void createADocument (String document, String folder, String documentType) { //Define variables int statuscode = 0; String user = "contentadmin"; String password = "contentadmin"; String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\""; String sourcetext = "Hello world!"; byte [] content = sourcetext.getBytes(); //Instantiate an EboDAVSwitch object EboDAVSwitch dav = new EboDAVSwitch(); //Instantiate an EboDAVStatus object EboDAVStatus status = new EboDAVStatus(); //Start a session dav.startSession("localhost", 80); //Send the WebDAV request to create a document try { statuscode = dav.createNewDocument(user, password, realm, folder, document, documentType, content); if (statuscode==EboDAVStatus.SC_CREATED) System.out.println("Request succeeded: The document " + document + "was created."); else System.out.println("Request failed: " + status.getStatusText(statuscode)); } catch (EboDAVException e) { if (m_debug) e.printStackTrace(); else System.out.println(e.getMessage()); } //End session dav.endSession(); } }
For examples of how to delete a document from a WebDAV client, see Code example: deleting a document using a helper method and Code example: deleting a document using utility methods.
The following code shows how to get the content of a document stored in the CM subsystem. The document is referenced as the second argument of the createWebDAVMethod() utility method. To get other types of resources or collections, modify this argument to point to the element of interest.
This example uses the Slide GetMethod class and the exteNd Director utility methods startSession(), createCredentials(), setCredentials(), getState(), setState(), and createWebDAVMethod().
By calling the getDataAsString() method on the GetMethod class, the client application retrieves the content of the document in HTML format.
There is no helper method for getting a resource or collection:
/** getTheDocument */ import com.sssw.webdav.client.*; import org.apache.webdav.lib.*; import org.apache.webdav.lib.methods.*; public class getTheDocument { private static boolean m_debug = false; public void getTheDocument (String document) { //Define variables int statuscode = 0; String user = "contentadmin"; String password = "contentadmin"; String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\""; //Instantiate an EboDAVSwitch object EboDAVSwitch dav = new EboDAVSwitch(); //Instantiate an EboDAVStatus object EboDAVStatus status = new EboDAVStatus(); //Start a session dav.startSession("localhost", 80); //Get and set credentials Credentials credentials = dav.createCredentials(user, password); dav.setCredentials(credentials); //Get and set state and authentication realm State state = dav.getState(); state.setAuthenticateToken(realm); dav.setState(state); //Create the WebDAV method object GetMethod GetMethod gm = (GetMethod)dav.createWebdavMethod(dav.GET_METHOD,document); //Execute GetMethod (send the WebDAV request to get document) try { dav.executeCommand(gm); statuscode = gm.getStatusCode(); if (statuscode == (EboDAVStatus.SC_OK)) { String html = gm.getDataAsString(); System.out.println("Request succeeded: Got the document and its content as html."); } else System.out.println("Request failed: " + status.getStatusText(statuscode)); } catch (EboDAVException e) { if (m_debug) e.printStackTrace(); else System.out.println(e.getMessage()); } catch (java.net.MalformedURLException murle) { if (m_debug) murle.printStackTrace(); else System.out.println(murle.getMessage()); } catch (java.io.IOException ioe) { if (m_debug) ioe.printStackTrace(); else System.out.println(ioe.getMessage()); } //End session dav.endSession(); } }
There is no exteNd Director helper method for getting a resource or collection.
The following code shows how to get the header information of a document stored in the CM subsystem. The document is referenced as the second argument of the createWebDAVMethod() utility method. To get other types of resources or collections, modify this argument to point to the element of interest.
This example uses the Slide HeadMethod class and the exteNd Director utility methods startSession(), createCredentials(), setCredentials(), getState(), setState(), and createWebDAVMethod().
There is no helper method for getting a resource or collection:
/** getDocumentHeader */ import com.sssw.webdav.client.*; import org.apache.webdav.lib.*; import org.apache.webdav.lib.methods.*; public class getDocumentHeader { private static boolean m_debug = false; public void getDocumentHeader (String document) { //Define variables int statuscode = 0; String user = "contentadmin"; String password = "contentadmin"; String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\""; String authtype = ""; //Instantiate an EboDAVSwitch object EboDAVSwitch dav = new EboDAVSwitch(); //Instantiate an EboDAVStatus object EboDAVStatus status = new EboDAVStatus(); //Start a session dav.startSession("localhost", 80); //Get and set credentials Credentials credentials = dav.createCredentials(user, password); dav.setCredentials(credentials); //Get and set state and authentication realm State state = dav.getState(); state.setAuthenticateToken(realm); dav.setState(state); //Create the WebDAV method object HeadMethod HeadMethod hm = (HeadMethod)dav.createWebdavMethod(dav.HEAD_METHOD,document); //Execute HeadMethod (send the WebDAV request to get document header) try { dav.executeCommand(hm); statuscode = hm.getStatusCode(); if (statuscode == (EboDAVStatus.SC_OK)) { //Get authorization type from header authtype = hm.getHeader ("authorization").toString(); System.out.println("Request succeeded: Got the document header. Authorization type is " + authtype); } else System.out.println("Request failed: " + status.getStatusText(statuscode)); } catch (EboDAVException e) { if (m_debug) e.printStackTrace(); else System.out.println(e.getMessage()); } catch (java.net.MalformedURLException murle) { if (m_debug) murle.printStackTrace(); else System.out.println(murle.getMessage()); } catch (java.io.IOException ioe) { if (m_debug) ioe.printStackTrace(); else System.out.println(ioe.getMessage()); } //End session dav.endSession(); } }
There is no exteNd Director helper method for getting header information from a resource or collection.
The following code shows how to get the methods that can be called on a document stored in the CM subsystem. The document is referenced as the second argument of the createWebDAVMethod() utility method. To get other types of resources or collections, modify this argument to point to the element of interest.
This example uses the Slide OptionsMethod class and the exteNd Director utility methods startSession(), createCredentials(), setCredentials(), getState(), setState(), and createWebDAVMethod().
There is no helper method for getting allowed methods on a resource or collection:
/** getAllowedMethods */ import com.sssw.webdav.client.*; import org.apache.webdav.lib.*; import org.apache.webdav.lib.methods.*; import java.util.*; public class getAllowedMethods { private static boolean m_debug = false; public void getAllowedMethods (String document) { //Define variables int statuscode = 0; String user = "contentadmin"; String password = "contentadmin"; String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\""; //Instantiate an EboDAVSwitch object EboDAVSwitch dav = new EboDAVSwitch(); //Instantiate an EboDAVStatus object EboDAVStatus status = new EboDAVStatus(); //Start a session dav.startSession("localhost", 80); //Get and set credentials Credentials credentials = dav.createCredentials(user, password); dav.setCredentials(credentials); //Get and set state and authentication realm State state = dav.getState(); state.setAuthenticateToken(realm); dav.setState(state); //Create the WebDAV method object HeadMethod OptionsMethod om = (OptionsMethod)dav.createWebdavMethod(dav.OPTIONS,document); //Execute OptionsMethod (send the WebDAV request to get the allowed methods on //the document) try { dav.executeCommand(om); statuscode = om.getStatusCode(); if (statuscode == (EboDAVStatus.SC_OK)) { System.out.println("Request succeeded: Got the document header.\n"); System.out.println("The allowed methods on " + document + " are:\n"); Enumeration methods = om.getAllowedMethods(); while (methods.hasMoreElements()) { System.out.println( methods.nextElement().toString() + "\n" ); } } else System.out.println("Request failed: " + status.getStatusText(statuscode)); } catch (EboDAVException e) { if (m_debug) e.printStackTrace(); else System.out.println(e.getMessage()); } catch (java.net.MalformedURLException murle) { if (m_debug) murle.printStackTrace(); else System.out.println(murle.getMessage()); } catch (java.io.IOException ioe) { if (m_debug) ioe.printStackTrace(); else System.out.println(ioe.getMessage()); } //End session dav.endSession(); } }
There is no exteNd Director helper method for getting methods that can be called on a resource or collection.
The following code shows how to get properties defined on a document stored in the CM subsystem. The document is referenced as the second argument of the createWebDAVMethod() utility method. To get other types of resources or collections, modify this argument to point to the element of interest.
This example uses the Slide PropFindMethod class and the exteNd Director utility methods startSession(), createCredentials(), setCredentials(), getState(), setState(), and createWebDAVMethod().
There is no helper method for getting properties defined on a resource or collection:
/** getProperties */ import com.sssw.webdav.client.*; import org.apache.webdav.lib.*; import org.apache.webdav.lib.methods.*; import java.util.*; public class getProperties { private static boolean m_debug = false; public void getProperties (String document) { //Define variables int statuscode = 0; String user = "contentadmin"; String password = "contentadmin"; String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\""; //Instantiate an EboDAVSwitch object EboDAVSwitch dav = new EboDAVSwitch(); //Instantiate an EboDAVStatus object EboDAVStatus status = new EboDAVStatus(); //Start a session dav.startSession("localhost", 80); //Get and set credentials Credentials credentials = dav.createCredentials(user, password); dav.setCredentials(credentials); //Get and set state and authentication realm State state = dav.getState(); state.setAuthenticateToken(realm); dav.setState(state); //Create the WebDAV method object PropFindMethod PropFindMethod pfm = (PropFindMethod)dav.createWebdavMethod(dav.PROPFIND_METHOD,document); //Execute PropFindMethod (send the WebDAV request to get the properties defined on //the document) try { dav.executeCommand(pfm); statuscode = pfm.getStatusCode(); if (statuscode == (EboDAVStatus.SC_MULTI_STATUS)) { System.out.println("Request succeeded: Got the properties.\n"); System.out.println("The properties defined on " + document + " are:\n"); Enumeration props = pfm.getResponseProperties(document); while (props.hasMoreElements()) { System.out.println( props.nextElement().toString() + "\n" ); } } else System.out.println("Request failed: " + status.getStatusText(statuscode)); } catch (EboDAVException e) { if (m_debug) e.printStackTrace(); else System.out.println(e.getMessage()); } catch (java.net.MalformedURLException murle) { if (m_debug) murle.printStackTrace(); else System.out.println(murle.getMessage()); } catch (java.io.IOException ioe) { if (m_debug) ioe.printStackTrace(); else System.out.println(ioe.getMessage()); } //End session dav.endSession(); } }
There is no exteNd Director helper method for getting methods that can be called on a resource or collection.
The following code shows how to lock a document for exclusive access in a collaborative environment. You might invoke this function in your WebDAV client application when a user checks out a document.
The example uses the helper method lockDocument(). This method throws an exception if the document of interest is already locked. To explicitly check for this condition, the code calls the checkLockToken() method:
/** lockADocument */ import com.sssw.webdav.client.*; public class lockADocument { private static boolean m_debug = false; public void lockADocument (String document) { //Define variables int statuscode = 0; String user = "contentadmin"; String password = "contentadmin"; String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\""; //Instantiate an EboDAVSwitch object EboDAVSwitch dav = new EboDAVSwitch(); //Instantiate an EboDAVStatus object EboDAVStatus status = new EboDAVStatus(); //Start a session dav.startSession("localhost", 80); try { //If document not already locked, send the WebDAV request to lock the document if ( dav.checkLockToken(document) == null) { statuscode = dav.lockDocument(user, password, realm, document); if (statuscode==EboDAVStatus.SC_NO_CONTENT) System.out.println("Request succeeded: The document " + document + "was locked."); else System.out.println("Request failed: " + status.getStatusText(statuscode)); } else System.out.println("Document is already locked."); } catch (EboDAVException e) { if (m_debug) e.printStackTrace(); else System.out.println(e.getMessage()); } //End session dav.endSession(); } }
You can also lock a document using the Slide LockMethod class and exteNd Director utility methods. See Programming practices using utility methods.
The following code shows how to move a folder from a source path to a destination path. In this case, the source path points to a folder. To move other types of resources or collections, make sure the source path points to the element of interest.
The example uses the helper method moveElement():
/** moveAFolder */ import com.sssw.webdav.client.*; public class moveAFolder { private static boolean m_debug = false; public void moveAFolder (String foldersourcepath, String folderdestinationpath) { //Define variables int statuscode = 0; String user = "contentadmin"; String password = "contentadmin"; String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\""; boolean autogen = true; //Generate folders in the folderdestinationpath if they don't exist //Instantiate an EboDAVSwitch object EboDAVSwitch dav = new EboDAVSwitch(); //Instantiate an EboDAVStatus object EboDAVStatus status = new EboDAVStatus(); //Start a session dav.startSession("localhost", 80); //Send the WebDAV request to move folder try { statuscode = dav.moveElement(user, password, realm, foldersourcepath, folderdestinationpath, autogen); if (statuscode==EboDAVStatus.SC_CREATED) System.out.println("Request succeeded: The folder " + foldersourcepath + "was moved to " + folderdestinationpath); else System.out.println("Request failed: " + status.getStatusText(statuscode)); } catch (EboDAVException e) { if (m_debug) e.printStackTrace(); else System.out.println(e.getMessage()); } //End session dav.endSession(); } }
You can also move a resource or collection using the Slide MoveMethod class and exteNd Director utility methods. See Programming practices using utility methods.
The following code examples show how to remove a category reference from a document. A category is a descriptive name used to group documents logically in the CM subsystem.
This example uses the helper method removeCategoryFromDocument():
/** removeCategoryReferenceFromDocument */ import com.sssw.webdav.client.*; public class removeCategoryReferenceFromDocument { private static boolean m_debug = false; public void removeCategoryReferenceFromDocument (String document, String categoryUUID) { //Define variables int statuscode = 0; String user = "contentadmin"; String password = "contentadmin"; String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\""; //Instantiate an EboDAVSwitch object EboDAVSwitch dav = new EboDAVSwitch(); //Instantiate an EboDAVStatus object EboDAVStatus status = new EboDAVStatus(); //Start a session dav.startSession("localhost", 80); //Send the WebDAV request to remove a category reference try { statuscode = dav.removeCategoryFromDocument(user, password, realm, document, categoryUUID); if (statuscode==EboDAVStatus.SC_MULTI_STATUS) System.out.println("Request succeeded: The category was removed from " + document); else System.out.println("Request failed: " + status.getStatusText(statuscode)); } catch (EboDAVException e) { if (m_debug) e.printStackTrace(); else System.out.println(e.getMessage()); } //End session dav.endSession(); } }
This example uses the Slide PropPatchMethod class and the exteNd Director utility methods startSession(), createCredentials(), setCredentials(), getState(), setState(), and createWebDAVMethod().
The method that removes the category reference is addPropertyToSet(), called on the PropPatchMethod object. Notice that the second argumentproperty valueis null because the category UUID is passed as the first argumentproperty name. For more information about addPropertyToSet() and its arguments, see Constructing WebDAV requests that use Proppatch.
/** removeCategoryReference */ import com.sssw.webdav.client.*; import com.sssw.webdav.common.EboWebdavConstants; import org.apache.webdav.lib.*; import org.apache.webdav.lib.methods.*; public class removeCategoryReference { private static boolean m_debug = false; public void removeCategoryReference (String document, String categoryUUID) { //Define variables int statuscode = 0; String user = "contentadmin"; String password = "contentadmin"; String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\""; String namespace-abbr = "RC"; //Instantiate an EboDAVSwitch object EboDAVSwitch dav = new EboDAVSwitch(); //Instantiate an EboDAVStatus object EboDAVStatus status = new EboDAVStatus(); //Start a session dav.startSession("localhost", 80); //Get and set credentials Credentials credentials = dav.createCredentials(user, password); dav.setCredentials(credentials); //Get and set state and authentication realm State state = dav.getState(); state.setAuthenticateToken(realm); dav.setState(state); //Create the WebDAV method object PropPatchMethod PropPatchMethod ppm = (PropPatchMethod)dav.createWebdavMethod(dav.PROPPATCH_METHOD,document); ppm.addPropertyToSet( categoryUUID, null, namespace-abbr, EboWebdavConstants.PROPPATCH_REMOVECATEGORY); //Execute PropPatchMethod (send the WebDAV request to remove category reference) try { dav.executeCommand(ppm); statuscode = ppm.getStatusCode(); if (statuscode == (EboDAVStatus.MULTI_STATUS)) System.out.println("Request succeeded: The category was removed from " + document + "."); else System.out.println("Request failed: " + status.getStatusText(statuscode)); } catch (EboDAVException e) { if (m_debug) e.printStackTrace(); else System.out.println(e.getMessage()); } catch (java.net.MalformedURLException murle) { if (m_debug) murle.printStackTrace(); else System.out.println(murle.getMessage()); } catch (java.io.IOException ioe) { if (m_debug) ioe.printStackTrace(); else System.out.println(ioe.getMessage()); } //End session dav.endSession(); } }
The following code examples show how to remove all category references from a document. A category is a descriptive name used to group documents logically in the CM subsystem.
This example uses the helper method removeAllCategoriesFromDocument():
/** removeAllCategoryReferencesFromDocument */ import com.sssw.webdav.client.*; public class removeAllCategoryReferencesFromDocument { private static boolean m_debug = false; public void removeAllCategoryReferencesFromDocument (String document) { //Define variables int statuscode = 0; String user = "contentadmin"; String password = "contentadmin"; String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\""; //Instantiate an EboDAVSwitch object EboDAVSwitch dav = new EboDAVSwitch(); //Instantiate an EboDAVStatus object EboDAVStatus status = new EboDAVStatus(); //Start a session dav.startSession("localhost", 80); //Send the WebDAV request to remove all category references from the document try { statuscode = dav.removeAllCategoriesFromDocument(user, password, realm, document); if (statuscode==EboDAVStatus.MULTI_STATUS) System.out.println("Request succeeded: All categories were removed from " + document); else System.out.println("Request failed: " + status.getStatusText(statuscode)); } catch (EboDAVException e) { if (m_debug) e.printStackTrace(); else System.out.println(e.getMessage()); } //End session dav.endSession(); } }
This example uses the Slide PropPatchMethod class and the exteNd Director utility methods startSession(), createCredentials(), setCredentials(), getState(), setState(), and createWebDAVMethod().
The method that removes all category references is addPropertyToSet(), called on the PropPatchMethod object. Notice that the second argumentproperty valueis null because the document UUID is passed as the first argumentproperty name. For more information about addPropertyToSet() and its arguments, see Constructing WebDAV requests that use Proppatch.
/** removeAllCategoryReferences */ import com.sssw.webdav.client.*; import com.sssw.webdav.common.EboWebdavConstants; import org.apache.webdav.lib.*; import org.apache.webdav.lib.methods.*; public class removeAllCategoryReferences { private static boolean m_debug = false; public void removeAllCategoryReferences (String documentUUID) { //Define variables int statuscode = 0; String user = "contentadmin"; String password = "contentadmin"; String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\""; String namespace-abbr = "RAC"; //Instantiate an EboDAVSwitch object EboDAVSwitch dav = new EboDAVSwitch(); //Instantiate an EboDAVStatus object EboDAVStatus status = new EboDAVStatus(); //Start a session dav.startSession("localhost", 80); //Get and set credentials Credentials credentials = dav.createCredentials(user, password); dav.setCredentials(credentials); //Get and set state and authentication realm State state = dav.getState(); state.setAuthenticateToken(realm); dav.setState(state); //Create the WebDAV method object PropPatchMethod PropPatchMethod ppm = (PropPatchMethod)dav.createWebdavMethod(dav.PROPPATCH_METHOD,document); ppm.addPropertyToSet( documentUUID, null, namespace-abbr, EboWebdavConstants.PROPPATCH_REMOVEALLCATEGORIES); //Execute PropPatchMethod (send the WebDAV request to remove all category references) try { dav.executeCommand(ppm); statuscode = ppm.getStatusCode(); if (statuscode == (EboDAVStatus.SC_OK)) System.out.println("Request succeeded: All categories were removed."); else System.out.println("Request failed: " + status.getStatusText(statuscode)); } catch (EboDAVException e) { if (m_debug) e.printStackTrace(); else System.out.println(e.getMessage()); } catch (java.net.MalformedURLException murle) { if (m_debug) murle.printStackTrace(); else System.out.println(murle.getMessage()); } catch (java.io.IOException ioe) { if (m_debug) ioe.printStackTrace(); else System.out.println(ioe.getMessage()); } //End session dav.endSession(); } }
The following code shows how to rename a document. In this case, the source path points to a document. The destination path is identical to the source path, except for a different document name.
To rename other types of resources or collections, make sure the source path points to the element of interest and the destination path points to the same element, but with a different name.
The example uses the helper method moveElement():
//** renameADocument */ import com.sssw.webdav.client.*; public class renameADocument { private static boolean m_debug = false; public void renameADocument (String docsourcepath, String docdestinationpath) { //Define variables int statuscode = 0; String user = "contentadmin"; String password = "contentadmin"; String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\""; boolean autogen = false; //Do not generate folders in the docdestinationpath if they don't exist //Instantiate an EboDAVSwitch object EboDAVSwitch dav = new EboDAVSwitch(); //Instantiate an EboDAVStatus object EboDAVStatus status = new EboDAVStatus(); //Start a session dav.startSession("localhost", 80); //Send the WebDAV request to rename the document try { statuscode = dav.moveElement(user, password, realm, docsourcepath, docdestinationpath, autogen); if (statuscode==EboDAVStatus.SC_CREATED) System.out.println("Request succeeded: The document " + docsourcepath + "was renamed to " + docdestinationpath); else System.out.println("Request failed: " + status.getStatusText(statuscode)); } catch (EboDAVException e) { if (m_debug) e.printStackTrace(); else System.out.println(e.getMessage()); } //End session dav.endSession(); } }
You can also rename a resource or collection using the Slide MoveMethod class and exteNd Director utility methods. See Programming practices using utility methods.
The following code examples show how to update the custom metadata in a document by setting the value of a custom field. Custom fields are fields that you define as part of a custom document type created in the CM subsystem using the CM API or the CMS Administration Console.
To update standard metadata in a document, use the addPropertyToSet() method on a Proppatch method object, as described in Constructing WebDAV requests that use Proppatch.
This example uses the helper method setFieldValueForDocument(). This method overwrites existing values of custom fields:
/** setFieldValueOfADocument */ import com.sssw.webdav.client.*; public class setFieldValueOfADocument { private static boolean m_debug = false; public void setFieldValueOfADocument (String document, String field_name, String field_value) { //Define variables int statuscode = 0; String user = "contentadmin"; String password = "contentadmin"; String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\""; //Instantiate an EboDAVSwitch object EboDAVSwitch dav = new EboDAVSwitch(); //Instantiate an EboDAVStatus object EboDAVStatus status = new EboDAVStatus(); //Start a session dav.startSession("localhost", 80); //Send the WebDAV request to update the custom field try { statuscode = dav.setFieldValueForDocument(user, password, realm, document, field_name, field_value); if (statuscode==EboDAVStatus.SC_MULTI_STATUS) System.out.println("Request succeeded: The field " + field_name + " of document " + document + "was changed to " + field_value); else System.out.println("Request failed: " + status.getStatusText(statuscode)); } catch (EboDAVException e) { if (m_debug) e.printStackTrace(); else System.out.println(e.getMessage()); } //End session dav.endSession(); } }
This example uses the Slide PropPatchMethod class and the exteNd Director utility methods startSession(), createCredentials(), setCredentials(), getState(), setState(), and createWebDAVMethod():
/** setTheFieldValue */ import com.sssw.webdav.client.*; import com.sssw.webdav.common.EboWebdavConstants; import org.apache.webdav.lib.*; import org.apache.webdav.lib.methods.*; public class setTheFieldValue { private static boolean m_debug = false; public void setTheFieldValue (String document) { //Define variables int statuscode = 0; String user = "contentadmin"; String password = "contentadmin"; String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\""; String fieldname = "Department"; String fieldvalue = "Human Resources"; String namespace-abbr = "SFV"; //Instantiate an EboDAVSwitch object EboDAVSwitch dav = new EboDAVSwitch(); //Instantiate an EboDAVStatus object EboDAVStatus status = new EboDAVStatus(); //Start a session dav.startSession("localhost", 80); //Get and set credentials Credentials credentials = dav.createCredentials(user, password); dav.setCredentials(credentials); //Get and set state and authentication realm State state = dav.getState(); state.setAuthenticateToken(realm); dav.setState(state); //Create the WebDAV method object PropPatchMethod PropPatchMethod ppm = (PropPatchMethod)dav.createWebdavMethod(dav.PROPPATCH_METHOD,document); ppm.addPropertyToSet( fieldname, fieldvalue, namespace-abbr, EboWebdavConstants.PROPPATCH_SETFIELDVALUE); //Execute PropPatchMethod (send the WebDAV request to set field value) try { dav.executeCommand(ppm); statuscode = ppm.getStatusCode(); if (statuscode == (EboDAVStatus.SC_MULTI_STATUS)) System.out.println("Request succeeded: The field " + fieldname + " was set to " + fieldvalue + "."); else System.out.println("Request failed: " + status.getStatusText(statuscode)); } catch (EboDAVException e) { if (m_debug) e.printStackTrace(); else System.out.println(e.getMessage()); } catch (java.net.MalformedURLException murle) { if (m_debug) murle.printStackTrace(); else System.out.println(murle.getMessage()); } catch (java.io.IOException ioe) { if (m_debug) ioe.printStackTrace(); else System.out.println(ioe.getMessage()); } //End session dav.endSession(); } }
The following code shows how to unlock a document, making it available to other authors in a collaborative environment. You might invoke this function in your WebDAV client application when a user checks in a document.
The example uses the helper method unlockDocument(). This method throws an exception if the document of interest is already unlocked. To explicitly check for this condition, the code calls the checkLockToken() method:
/** unlockADocument */ import com.sssw.webdav.client.*; public class unlockADocument { private static boolean m_debug = false; public void unlockADocument (String document) { //Define variables int statuscode = 0; String user = "contentadmin"; String password = "contentadmin"; String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\""; //Instantiate an EboDAVSwitch object EboDAVSwitch dav = new EboDAVSwitch(); //Instantiate an EboDAVStatus object EboDAVStatus status = new EboDAVStatus(); //Start a session dav.startSession("localhost", 80); try { //If document is locked, unlock it if (dav.checkLockToken(document) != null) { //Send the WebDAV request to unlock the document statuscode = dav.unlockDocument(user, password, realm, document); if (statuscode==EboDAVStatus.SC_NO_CONTENT) System.out.println("Request succeeded: The document " + document + "was unlocked."); else System.out.println("Request failed: " + status.getStatusText(statuscode)); } else { System.out.println("The document is already unlocked."); } } catch (EboDAVException e) { if (m_debug) e.printStackTrace(); else System.out.println(e.getMessage()); } } //End session dav.endSession(); } }
You can also unlock a document using the Slide UnlockMethod class and exteNd Director utility methods. See Programming practices using utility methods.
The following code example shows how to update the content of a document.
The example uses the helper method putDocument(). This method updates the contentnot the metadataof a document by creating and publishing a new version. To update document metadata, see Setting the value of a custom field in a document.
/** updateADocument */ import com.sssw.webdav.client.*; public class updateADocument { private static boolean m_debug = false; public void updateADocument (String document) { //Define variables int statuscode = 0; String user = "contentadmin"; String password = "contentadmin"; String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\""; String updatetext = "Hello earth!"; byte [] newcontent = updatetext.getBytes(); //Instantiate an EboDAVSwitch object EboDAVSwitch dav = new EboDAVSwitch(); //Instantiate an EboDAVStatus object EboDAVStatus status = new EboDAVStatus(); //Start a session dav.startSession("localhost", 80); //Send the WebDAV request to update the document try { statuscode = dav.putDocument(user, password, realm, document, newcontent); if (statuscode==EboDAVStatus.SC_OK) System.out.println("Request succeeded: The document " + document + "was updated."); else System.out.println("Request failed: " + status.getStatusText(statuscode)); } catch (EboDAVException e) { if (m_debug) e.printStackTrace(); else System.out.println(e.getMessage()); } //End session dav.endSession(); } }
You can also update a document or create a new document using the Slide PutMethod class and exteNd Director utility methods. See Programming practices using utility methods.
Copyright © 2004 Novell, Inc. All rights reserved. Copyright © 1997, 1998, 1999, 2000, 2001, 2002, 2003 SilverStream Software, LLC. All rights reserved. more ...