Web Publishing API Reference
Table of Contents | Previous
| Next
|
Web Publishing Client API Guide
This chapter provides API reference material for the Web Publishing classes.
The primary classes in the Web Publishing API are:
The utility classes are:
The interfaces are:
Represents information relevant to any resource.
WebPubComponent, WebPubContainer
class WebPubResource
This class defines methods common to both containers (such as directories) and components (such as files). It has methods for moving and copying resources and for working with resource attributes.
An attribute is a name/value pair containing information regarding a resource, such as the resource's creator, the date of its completion, and so on. An attribute can be used to describe, search, and index the resource.
This section describes the constructors and methods of the WebPubResource class.
Creates a resource object with the given URL. Does not verify that the object referenced by the URL exists.
WebPubResource (URL url, WPAuthentication authentication)
WebPubResource (URL url, WPAuthentication authentication, WPVersionInfo info)
The parameters of the WebPubResource constructor are as follows:
This example creates an object that represents the resource at http://yourserver/docs/plan1.html. In this case, the user gilligan with the password 3HourTour is known to the Enterprise Server.
WPAuthentication auth = new WPAuthentication ("gilligan", "3HourTour");URL url=null;
try
{
url = new URL ("http://yourserver/docs/plan1.html");
}
catch(Exception e)
{
System.out.println("Exception while creating URL: "+e.toString());
return;
}
WebPubResource resource = new WebPubResource (url, auth);
Requests that the server copies the resource from its current URL location to a destination location.If the destination location includes directories that do not exist, this method creates them (if the client application has the correct privileges).
If a resource already exists at the destination location, this method overwrites the existing resource at the destination location.
The result of the copy operation is returned as a WPStatus object. You can get the result code by calling getStatusCode on the returned WPStatus object. For example, a successful copy returns a status code of 200 (OK). If the invoking application is not allowed to perform the copy operation the status code is 410 (unauthorized).
WebPubResource
WPStatus copy (URL destURL)
The copy method takes the following parameter:
A WPStatus object.
Copies the resource at the location specified when creating the resource to the URL specified as the destination location. The destination location must be on the same server as the originating location.
If the resource is a component resource under version control, you can specify a particular version when creating the WebPubResource object.
This example copies the resource at http://aceindustry/draft/apidoc.html to http://aceindustry/release/apidoc.html. For a step by step discussion of this code sample, see Copying a Resource in the previous chapter.
WPAuthentication auth = new WPAuthentication ("gilligan", "3HourTour");URL url=null;
URL destURL=null;
try
{
url = new URL ("http://aceindustry/draft/apidoc.html");
destURL = new URL("http://aceindustry/release/apidoc.html");
}
catch(Exception e)
{
System.out.println("Exception while creating URL: "+e.toString());
return;
}
WebPubResource resource = new WebPubResource (url, auth);
WPStatus status = resource.copy (destURL);
Requests that the server provide a list of all of the attribute names supported by the server.
WebPubResource
WPStatus getAttributeNames (Vector vec)
The getAttributeNames method has the following parameter:
A WPStatus object.
The following code prints all the attributes for a resource resource1 in the Java output window.
// resource1 is an existing WebPubResource object.
resource1.getAttributeNames(attrvec));
Vector attributeVec = new Vector();
Enumeration enum = attributeVec.elements();
while (enum.hasMoreElements())
{
System.out.println ("Attribute name: " + enum.nextElement());
}
Requests that the server return the values for one or all of a resource's attributes.
WebPubResource
WPStatus getAttributes (WPAttributeValue attrs, String attribute)
The getAttributes method has the following parameters:
A WPStatus object.
If you use an asterisk to retrieve all attributes and their values, you should use the getAttributeNames method of the WPAttributeValue object to find the names of the legal attributes for this resource.
The first example gets a specific attribute value for a resource and displays the value in the Java output window.
/* Create the WPAttributeValue to hold the results */
WPAttributeValue attributeValueList = new WPAttributeValue();
/* resource is an existing WebPubResource object.
Get a specific attribute value of the resource and
put it in attributeValueList
*/
WPStatus status1 = resource.getAttributes(attributeValueList, "Title");
System.out.println("The title is " +
attributeValueList.getAttributeValue("Title"));
The second example gets all attribute values then displays all attributes and values in the Java output window.
/* Create the WPAttributeValue to hold the results */
WPAttributeValue attributeValueList = new WPAttributeValue();
/* resource is an existing WebPubComponent object
Get all attributes of the resource and put them into attributeValueList
*/
WPStatus status2 = resource.getAttributes(attributeValueList, "*");
/* To see all the attributes, get an enumerated list of all attributes.
Print the attribute and value for each element in the list.
*/
Enumeration enum1 = attributeValueList.getAttributeNames();
while (enum1.hasMoreElements())
{
String attribute = (String) enum1.nextElement();
System.out.println ("Attribute: " + attribute +
" Value: " + attributeValueList.getAttributeValue(attribute));
}
Requests that the server schedule moving the resource from its current URL location to a new location.
WebPubResource
WPStatus move (URL destURL)
The move method takes the following parameter:
A WPStatus object.
Moves the resource at the location specified when creating the resource to the URL specified as the destination location. The destination location must be on the same server as the originating location. All directories specified in the destination location must exist, otherwise this method fails and sets the status string of the returned WPStatus object to "server error."
Sets a list of attributes to their corresponding values.Make sure that a custom attribute is valid (predefined through the Administrator interface) before setting that attribute's value.
WebPubResource
WPStatus setAttributes(String attribute, String value)
The setAttributes method has the following parameter:
A WPStatus object.
Example
This example sets the value of the CM_DESCRIPTION attribute to "Plans for version B9."
resource.setAttributes("CM_DESCRIPTION", "Plans for version B9");
Represents a container (a resource that can contain other resources). An example of a container is a directory.
WebPubResource
class WebPubContainer
extends WebPubResource
A container object has methods for performing container-related functions. Creating a container object identifies the physical container of interest. You can call one of that object's methods to perform the appropriate action on the physical container.
For many servers, a container is a filesystem directory from the underlying operating system. Remember that simply creating the container object does not automatically create the actual container.
Containers do not have versions.
The WebPubContainer class also inherits the following methods from its superclass WebPubResource:
This section describes the constructor and methods of the WebPubContainer class.
Creates a container object with the specified URL and no version information.
WebPubContainer (URL url, WPAuthentication authentication)
The WebPubContainer constructor has the following parameters:
This example creates a container object that represents the directory http://yourserver/docs/. In this case, the user gilligan with the password 3HourTour is known to the Enterprise Server.
WPAuthentication auth = new WPAuthentication ("gilligan", "3HourTour");URL url=null;
try
{
url = new URL ("http://yourserver/docs/");
}
catch(Exception e)
{
System.out.println("Exception while creating URL: "+e.toString());
return;
}
WebPubContainer dir = new WebPubContainer (url, auth);
Creates a new physical container.
WebPubContainer
WPStatus create()
None.
A WPStatus object.
This example creates a new directory at http://yourserver/docs/drafts/reviews/.
WPAuthentication auth = new WPAuthentication ("gilligan", "3HourTour");URL url;
try {
url = new URL ("http://yourserver/docs/drafts/reviews/");
}
catch(Exception e) {
System.out.println("Exception while creating URL: "+ e.toString());
return;
}/* Create the WebPubComponent object */
WebPubContainer dir = new WebPubContainer (url, auth);
/* Create a new directory */
WPStatus status = dir.create();
Schedules the removal of empty containers.
WebPubContainer
WPStatus delete()
None.
A WPStatus object.
After calling the delete method, you cannot call any other methods of this object.
Obtains an index of all resources (components and containers) and resource properties in the server that are associated with this container.
WebPubContainer
WPStatus index (WPIndexResource indexResource)
The index method takes the following parameter:
A WPStatus object.
The server can return the following fields for each resource:
See WPIndexResource for a list of the methods available on the WPIndexResource class.
This example prints the name of all files in the container in the Java output window.
/* Create the authentication object */
WPAuthentication auth =new WPAuthentication ("gilligan", "3HourTour");
/* Get the URL for the directory */
URL url;
try {
url = new URL ("http://yourserver/netshare/user1/");
}
catch(Exception e) {
System.out.println("Exception while creating URL: "+e.toString());
return;
}
/* Get the WebPubContainer object for the directory */
WebPubContainer dir = new WebPubContainer (url, auth);
/* Get an index of all resources in the directory */
WPIndexResource index = new WPIndexResource();
WPStatus status = dir.index(index);
// Print the last-modification value for each file
Enumeration enum = index.getAllFileNames();
while (enum.hasMoreElements())
{
String filename = (String) enum.nextElement();
String lastmod = index.getFieldValueForFile(
filename, "last-modification");
System.out.println ("File name: " + filename +
" Last modified: " + lastmod);
}
Removes an existing physical container. This method sends a rmdir command to delete containers. This allows you to use the Web Publishing API with server-side remote file manipulation.
WebPubContainer
WPStatus rmdir()
None.
A WPStatus object.
Represents a component (a resource that contains content but not other resources). A file is an example of a component.
WebPubResource
class WebPubComponent
extends WebPubResource
Components directly contain the actual information. Frequently a component is something like an HTML file. A component can have multiple versions, so you can keep track of the history of the resource. (This feature is known as version control.) To aid in multiple users working with the same resource, you can use locking to temporarily restrict access to a component.
You create a WebPubComponent object when you need to perform actions associated with components.When creating a WebPubComponent object, you specify the URL that corresponds to the physical resource and possibly some information (in a WPVersionInfo object) about the resource.
You can then call one of the resource object's methods to perform the action you need. Remember that simply creating the component object does not automatically create the physical component.
Most component methods optionally use a version tag (expressed in a WPVersionInfo object) to identify a particular version of the component. For such methods, if you do not supply a WPVersionInfo object in the component object's constructor, the method works on the head of the version tree (that is, the most recent version).
The WebPubComponent class also inherits the following methods from its superclass WebPubResource:
This section describes the constructors and methods of the WebPubComponent class.
Creates a component object.
WebPubComponent (URL url, WPAuthentication authentication)
WebPubComponent (URL url, WPAuthentication authentication, WPVersionInfo info)
The parameters of the WebPubComponent constructors are as follows:
The first form of the constructor creates a WebPubComponent object with the given URL. If you use this form for a resource under version control and then call a method that needs a particular version, that method works on the most recent version.
The second form is the more common. In this case, you supply a WPVersionInfo object. This object usually supplies information to identify the resource (its version tag) and may also supply other information needed by a method you plan to call.
This example creates a WebPubComponent object that represents the file at http://yourserver/docs/doc1.html. In this case, the user gilligan with password 3HourTour is known to the Enterprise Server.
/* Create the authentication object */
WPAuthentication auth = new WPAuthentication ("gilligan", "3HourTour");
/* Create the version info object */
WPVersionInfo vi;
vi = new WPVersionInfo ("head", null, WPVersionInfo.locked, null);/* Create the URL object for the file */
URL url;
try
{ url = new URL ("http://yourserver/docs/doc1.html");
}
catch(Exception e)
{ System.out.println("Exception while creating URL: "+e.toString());
return;
}
/* Create the WebPubComponent object */
WebPubComponent obj = new WebPubComponent (url, auth, vi);
Requests that the server delete the resource, making it unavailable for further editing by any client.
WebPubComponent
WPStatus delete()
None.
A WPStatus object.
If you want to delete a specific version of the resource, you must have specified a WPVersionInfo object that has a version tag when creating the WebPubComponent object. If the resource is under version control and you do not specify a particular version, this method deletes all versions of the component.
Downloads a resource from the remote server to the client.
WebPubComponent
WPStatus download (File file)
WPStatus download (ByteArrayOutputStream buffer)
The download method takes the following parameters:
A WPStatus object.
The only difference between the two forms is whether the resource is written to a file or to a buffer.
This method downloads a resource to the specified file or buffer. You can then edit the file or buffer. To upload the changed contents back to the resource, use the upload method.
Use this method to download resources that are not under version control. If you want to change a resource that is under version control, do not use this method. Instead, use the edit method.
Marks the specified resource for editing, possibly locking it on the server, and downloads it to the client to either a file or a buffer.(This method does not make any changes to the original resource -- instead, it makes the contents of the resource available for editing in another file or buffer.)
WebPubComponent
WPStatus edit (File file)
WPStatus edit (ByteArrayOutputStream buffer)
The edit method takes the following parameters:
A WPStatus object.
The only difference between the two forms is whether the resource is written to a file or to a buffer.
This method downloads a resource to the specified file or buffer. You can then edit the file or buffer. To upload the changed contents back to the resource, use the save method.
If the resource is under version control, you must edit a particular version of a resource. If you do not specify a particular version when creating the WebPubComponent object, by specifying a version tag in a WPVersionInfo object, this method edits the most recent version.
This method performs three actions in an atomic fashion:
If you want to change a resource that is not under version control, you can either use this method or the download method.
Posts data expressed as name/value pairs to a URL on the remote server using the POST method. You would use this method to send data to resources such as CGI programs that accept form input sent with the POST method.
The formPost method sends the input information in a data body that is available on stdin with the data length set in the environment variable CONTENT_LENGTH. The receiving resource (such as the CGI program or servlet) would need to read the input from stdin. The response generated by the resource goes into the specified file or stream.
WebPubComponent
formPost(WPAttributeValue attributeList, File file)
formPost(WPAttributeValue attributeList, ByteArrayOutputStream stream)
The formPost method takes the following parameters:
A WPStatus object.
In this example, the formPost method posts the following name value pairs:
fruit=apple
color=green
uses=pie
to the component at
http://yourserver/cgidir/yourcgi.cgi
This component would be a resource (such as a CGI program) that reads its input from stdin. The output from yourcgi.cgi goes is written to the file myFile.
// url is a URL object for http://yourserver/cgidir/yourcgi.cgi
// auth is an existing authentication object
// Create the WebPubComponent
WebPubComponent mycomponent = new WebPubComponent(url, auth);
// Create the attribute list
WPAttributeValue myAttributeList = new WPAttributeValue();
// Add some name/value pairs to the attribute list
myAttributeList.add("fruit", "apple");
myAttributeList.add("color", "green");
myAttributeList.add("uses", "pie");
// Post the name/value pairs to the component
// In this case, the component is a CGI program
// myFile is an existing File object
// The results of running yourcgi.cgi are sent to myFile
mycomponent.formPost(myAttributeList, myFile);
Requests that the server lock the resource, making it unavailable for editing by anyone else.
WebPubComponent
WPStatus lock()
None.
A WPStatus object.
While locked, another client cannot lock or make changes to the resource.
Requests that the server retrieve a list of available versions of the resource.
WebPubComponent
WPStatus revNum (Vector vec)
The revNum method takes the following parameter:
A WPStatus object.
This method lets you find out what versions of the resource exist on the server.
You do not need to specify a particular version when creating the object to use with this method.
Example
This example prints the version numbers of a component in the Java output window.
// Create the vector
Vector vec = new Vector();
// component is an existing WebPubComponent object
WPStatus status = component.revNum (vec);
// If component has revision numbers, the status is 200 (OK)
// If status is OK, print all revision numbers
if (status.getStatusCode() == 200)
{
Enumeration enum = vec.elements();
while (enum.hasMoreElements())
{
System.out.println ("Rev Number: " + enum.nextElement());
}
}
Saves the contents of the specified file or buffer to the component with a particular version number (as specified in the WPVersionInfo object given when the component object was created). The content of the existing component on the server is completely replaced by the new content. If the component was locked, it is unlocked after the save operation completes.
WebPubComponent
WPStatus save (File file)
WPStatus save (ByteArrayInputStream buffer, int buffLength)
The save method takes the following parameters:
A WPStatus object.
The only difference between the two forms of this method is whether the resource to be saved is in a file or in a buffer.
If the resource is under version control, this method assumes you have previously called the edit method to lock the resource before you called this method.
If the resource is under version control and you do not specify the version to save in the object's constructor, then this method saves a new version as the head of the version tree (most recent version) in the resource. The WPVersionInfo object can specify user comments to store with the resource.
This method performs three actions in an atomic fashion:
This method provides a means of saving resources that are under version control back to the server. If you want to save a resource that is not under version control, you can also use the upload method.
Requests that the server initiate version control on a resource that already exists on the server.
WebPubComponent
WPStatus startRev()
None.
A WPStatus object.
The resource must already exist on the remote server.
Requests that the server take a resource out of version control.
WebPubComponent
WPStatus stopRev()
None.
A WPStatus object.
This method causes the latest version of the resource to be taken out of version control and put into the regular file system.
After you have called this method, calls to upload and save do not result in new versions of the resource. Instead, any modifications you save with these methods cause the file to be overwritten. In addition, all the previous versions are lost (and hence all the history is destroyed).
Requests that the server unlock the resource and removes the edit flag from the resource. (This method does not undo any changes that have been made to the resource).
WebPubComponent
WPStatus unedit()
None.
A WPStatus object.
Call this method after invoking the component's edit method if you change your mind and decide not to make any changes to the component. In this case, you need to call the unedit method to remove the edit flag and to unlock the resource if it was locked.
Requests that the server unlock the resource.
WebPubComponent
WPStatus unlock()
None.
A WPStatus object.
Uploads a resource from the client to the remote server.
WebPubComponent
WPStatus upload (File file)
WPStatus upload (ByteArrayOutputStream buffer, int buffLength)
The upload method takes the following parameters:
A WPStatus object.
The only difference between the two forms is whether the resource is uploaded from a file or a buffer.
This method provides a means of saving resources that are not under version control back to the server. If you want to save a resource that is under version control, use the save method instead so that the system unlocks the resource and unsets the edit flag. (However, if you do use the upload method to save a resource that is under version control, a new version of the resource will be saved at the head of the version tree.)
Represents a list of attribute name/value pairs.
class WPAttribute
Use this class to pass attribute name and value information about a resource to and from a WebPubResource object.
An attribute is a name/value pair containing information regarding a resource, such as the resource's creator, the date of its completion, and so on. An attribute can be used to describe, search, and index the resource. This class allows you to store a list of attributes for the resource.
This section describes the constructor and methods of the WPAttributeValue class.
Creates an attribute list object. After creating the attribute list, use the add method to add name/value pairs to the list.
WPAttribute ()
None.
WPAttribute attributeList = new WPAttribute();
Adds an attribute name/value pair to this object.
WPAttributeValue
void add(String attribute, String value)
The add method has the following parameters:
Nothing.
Example
This example adds three name/value pairs to an attribute list.
/* Get the attribute list */
WPAttributeValue attributeList = new WPAttributeValue();
/* Add some attributes to the list */
attributeList.add("attr1", "value1");
attributeList.add("attr2", "value2");
attributeList.add("attr3", "value3");
Tests whether the specified attribute is contained in this object.
WPAttributeValue
boolean attributeExists(String attribute)
The attributeExists method has the following parameter:
True if the attribute is in this object; otherwise, false.
This example prints the value of the attribute Title if the attribute exists.
// attributeList is an existing WPAttributeValue object
if (attributeList.attributeExists("Title"))
System.out.println("The title is " +
attributeList.getAttributeValue("Title"));
else
System.out.println("The attribute Title does not exist");
Returns an enumerated list of all of the attribute names contained in this object.
WPAttributeValue
Enumeration getAttributeNames()
None.
An enumerated list of attribute names. These names should be cast to String objects.
This example gets all attribute values of a resource then prints all attributes and values in the Java output window. This code shows how to use a WPAttributeValue object to get the attributes of a resource such as a file.
/* Create the WPAttributeValue to hold the results */
WPAttributeValue attributeList = new WPAttributeValue();
/* resource is an existing WebPubComponent object
Get all attributes of the resource and put them into attributeList
*/
WPStatus status = resource.getAttributes(attributeList, "*");
/* To see all the attributes, get an enumerated list of all attributes.
Print the attribute and value for each element in the list.
*/
Enumeration enum1 = attributeList.getAttributeNames();
while (enum1.hasMoreElements())
{
String attribute = (String) enum1.nextElement();
System.out.println ("Attribute: " + attribute +
" Value: " + attributeList.getAttributeValue(attribute));
}
Returns the value of a specified attribute.
WPAttributeValue
String getAttributeValue(String attribute)
The getAttributeValue method has the following parameters:
A String object containing the value of the specified attribute.
This method assumes that you have already verified that the specified attribute exists in this object. You can verify this with the attributeExists method.
This example prints the value of the attribute Title if the attribute exists.
// attributeList is an existing WPAttributeValue object
if (attributeList.attributeExists("Title"))
System.out.println("The title is " +
attributeList.getAttributeValue("Title"));
else
System.out.println("The attribute Title does not exist");
For an example of how to use a WPAttributeValue object to get all the attributes of a resource, see the example shown for the getAttributeNames method of the WPAttributeValue class.
Returns the number of attribute name/value pairs contained in this object.
WPAttributeValue
int numberOfAttributes()
None.
The number of attributes contained in this object.
You use an authentication object when Web Publishing transactions need to be associated with a particular user that is known to the Enterprise Server and is authorized to perform the transactions. An authentication object creates a tag based on the provided user ID and password with the authentication scheme of the low level protocol. The actual implementation of the authentication scheme used by the server is hidden from you.
An example of an authentication scheme is the "Basic Authentication Scheme" where a server associates a certain realm with an authentication string. If a client attempts to access any resource in that realm, the server challenges the client. The client then provides the authentication string to the server.
If a client attempts to access any resource that requires authentication without providing a valid authentication object, the server challenges the client. The client may then provide the authentication object.
class WPAuthentication
This section describes the constructor and methods of the WPAuthentication class.
Creates an authentication object based on the user ID and password.
WPAuthentication (String userID, String passWord)
The parameters to the WPAuthentication constructor are as follows:
Creates a WPAuthentication object for the given userID and passWord. To improve security, the client application should retrieve the userID and passWord interactively from the user rather than hardcoding the userID and password in the code.
This example creates a WPAuthentication object for the user user1 whose password is password1.
// user1 is a String indicating the userID
// password1 is a String indicating the user's password
WPAuthentication auth=new WPAuthenticatino(user1, password1);
Returns the computed authentication string.
WPAuthentication
String getAuthentication()
None.
An authentication string.
This string is used by the server to authenticate access to the resource. The content of the authentication string depends on the authentication scheme agreed upon between the server and the client.
Returns the associated user password.
WPAuthentication
String getPassword()
None.
The password string set in the constructor.
Returns the associated user ID.
WPAuthentication
String getUserID()
None.
The user ID string set in the constructor.
Contains the index information for a particular container resource (usually a directory). When you request index information, the server returns a list of files contained in the directory. You can then retrieve a subset of the following fields of information for each file:
The server does not return all these fields for every file. For example, the lock-owner field is returned only if the resource is currently locked.
To request information for a directory, create a container object, specifying the URL of the directory in the constructor for WebPubContainer. You then call that object's index method to obtain a WPIndexResource object containing the information. You can then access that information with the object's methods.
You cannot use a WPIndexResource object to change any of the index information for the resource.
public class WPIndexResource
This section describes the constructor and methods of the WPIndexResource class.
Creates an index resource object.
WPIndexResource()
None.
Creates a WPIndexResource object. After creating this object, you can use it to retrieve an index of all resources in a container such as a directory.
WPIndexResource index = new WPIndexResource();
For a more complete example of how to use a WPIndexResource object to obtain an index of resources in a container, see the example for the index method of the WebPubContainer class.
Returns a list of the fields available for a particular file.
Enumeration getAllFieldNamesForFile(String filename)
The parameter to the getAllFieldNamesForFile method is as follows:
An enumerated list of the names of all the fields for the specified file. These field names should be cast to String objects before use.
The complete list of possible fields is as follows:
The server does not return all these fields for every file. For example, the lock-owner field is returned only if the resource is currently locked.
This example prints the field names for the file test1.html.
// Create the WPIndexResource object
WPIndexResource index1 = new WPIndexResource();
// dir1 is an existing WebPubContainer object for a directory.
// Index the directory.
WPStatus status = dir1.index(index1);
// Print all the field names for the file "test1.html"
// in the directory dir1
Enumeration enum1 = index1.getAllFieldNamesForFile("test1.html");
System.out.println("The field names are: ");
while (enum1.hasMoreElements())
{
System.out.println (enum1.nextElement() + " ");
}
Retrieves the values of all the fields returned by the server for the specified file.
Enumeration getAllFieldValuesForFile(String filename)
The parameter to the getAllFieldValuesForFile method is as follows:
An enumerated list of the value of all the fields for this file. These field names should be cast to String objects before use. Note that this method returns the values only -- it does not indicate which field the value applies to.
Not all fields are returned for every file and hence not all field values are available. For example, the lock-owner field is only returned for files that are currently locked. To determine which fields were returned for the specified file, use the getAllFieldNamesForFile method.
This example prints the field values for the file test1.html. The results do not indicate which field each value applies to. (For an example of retrieving field names and associated values see the second example for the method getFieldValueForFile for this class.)
// Create the WPIndexResource object
WPIndexResource index1 = new WPIndexResource();
// dir1 is an existing WebPubContainer object for a directory.
// Index the directory.
WPStatus status = dir1.index(index1);
// Print all the field names for the file "test1.html"
// in the directory dir1
Enumeration enum1 = index1.getAllFieldValuesForFile("test1.html");
System.out.println("The field values are: ");
while (enum1.hasMoreElements())
{
System.out.println (enum1.nextElement() + " ");
}
Retrieves the names of all of the files contained in the resource, as returned by the server.
Enumeration getAllFileNames()
None.
An enumerated list of all the filenames returned by the server. These filenames should be cast to String objects before use.
This example prints the names of the files in a directory.
// Create the WPIndexResource object
WPIndexResource index1 = new WPIndexResource();
// dir1 is an existing WebPubContainer object for a directory.
// Index the directory.
WPStatus status = dir1.index(index1);
// Print the names of all files in the directory dir1
Enumeration enum1 = index1.getAllFileNames();
System.out.println("The files are: ");
while (enum1.hasMoreElements())
{
System.out.println (enum1.nextElement() + " ");
}
Retrieves the value for a specific field of a specific file.
String getFieldValueForFile(String filename, String fieldname)
The parameters to the getFieldValueForFile method are as follows:
A String object containing the value of the requested field for the specified file.
Before calling this method, you can call getAllFieldNamesForFile to see if the field you're interested in is available.
The following statement returns the value of the Title field for the file plan1.html (assuming that index1 includes a file of that name with that field.)
// index1 is an existing WPIndexResource
String title = index1.getFieldValueForFile("plan1.html", "Title");
The second example prints the value of each field in the resource for the file test1.html.
// dir1 is an existing WebPubContainer object for a directory
// Get an index of all resources in the directory
WPIndexResource index1 = new WPIndexResource();
WPStatus status = dir1.index(index1);
// Print the values of each field in the file test1.html
// (We assume that this file exists in the directory)
Enumeration enum = index1.getAllFieldNamesForFile("test1.html");
System.out.println("The fields in test1.html are: ");
while (enum5.hasMoreElements())
{
String fieldname = (String) enum.nextElement();
System.out.println ("Field " + fieldname + " has the value " +
index1.getFieldValueForFile("test1.html", fieldname));
}
Represents information about a resource, such as its version.
class WPVersionInfo
You optionally pass a WPVersionInfo object as a parameter to the constructors of WebPubResource and WebPubComponent objects. You do not pass one to the constructor of a WebPubContainer object.
A WPVersionInfo object stores information about the resource. Many methods of other objects use this information to identify a particular version of the resource by its version tag. The information in these objects is as follows:
This section describes the constructor and methods of the WPVersionInfo class.
Creates a version-information object.
WPVersionInfo (String version, String label, String lock, String comment)
The parameters to the WPVersionInfo constructor are as follows:
Although none of the parameters to this constructor are optional, you can supply a null value when the action to be performed doesn't require that parameter. For example, you provide comments only when you save a physical component. For other actions, you should provide a null value for the comment parameter.
See the general description of the WPVersionInfo object for a description of the meaning of these parameters.
Example
This example creates a WPVersionInfo object indicating the latest version, with no label, in a locked state, and with no comment.
WPVersionInfo vi = new WPVersionInfo ("head", null, WPVersionInfo.locked, null);
Retrieves the associated user comments.
WPVersionInfo
String getComments()
None.
User comments.
You include comments in a WPVersionInfo object when using a component object's save method to save a physical resource. The comment can explain changes or provide information about a certain aspect of the resource. For example, the comment might be a description of all differences between the current version and the previous version.
Retrieves the resource's current lock status.
WPVersionInfo
String getLock()
None.
One of WPVersionInfo.locked or WPVersionInfo.unlocked.
You lock a resource so that other users cannot modify it.
Retrieves the version tag referring to a specific version of the resource.
WPVersionInfo
String getVersion()
None.
A version string.
The version tag can refer to any specific version of the resource including the head of the version tree (that is, the most recent version). You can use versions to maintain a history of a resource, by keeping old versions.
For Enterprise Server 3.0, the version tag can either be the keyword head or it can be of the form:
(Numeral)+ ("." (Numeral)+)+
where Numeral is a single digit. That is, a version tag is one or more digits, followed a dot and at least one more digit, then optionally followed by more dot-digit groups. For example, 3.0 or 3.1.02.
Sets the resource's lock status.
WPVersionInfo
void setLock (String lock)
The parameter to the setLock method is as follows:
Sets the locked status of the version info object to either locked or unlocked. When the version info object is used in the creation of a new WebPubComponent object, it indicates whether to lock or unlock the resource that the component object represents.
After creating a WebPubComponent object, you can use its lock and download methods to lock it. You can use its unlock and save methods to unlock it.
This example creates a WebPubComponent object that represent a locked resource.
// Create the version info object
WPVersionInfo vi = new WPVersionInfo ("head", null, WPVersionInfo.locked, null);
// auth is an existing WPAuthentication object
// url is an existing URL object that points to a resource
// Create a WebPubComponent object that points to
// the latest version of the resource at URL.
// The resource will become locked.
WebPubComponent obj = new WebPubComponent (url, auth, vi);
Represents a status response coming back from the server. All the methods of the WebPubContainer, WebPubComponent, and WebPubResource classes return a WPStatus object. This status object indicates whether the method executed successfully or not, and if not, then gives a hint as to why not. For example, a status code of 200 means the method executed successfully whereas a status code of 401 means that the application was not authorized to execute the method.
interface WPStatus
All the methods of the WebPubContainer, WebPubComponent, and WebPubResource classes return a WPStatus object to indicate the results of executing the method.
This software does not dictate a specific format for the response coming from the server. However, regardless of the underlying low level protocol, the software expects the server to return at least a status code and an associated string explaining that status code.
This section describes the methods of the WPStatus interface.
Returns all the headers returned by the server in a Java properties structure.
WPStatus
Properties getHeaders()
The Java properties.
This example gets the headers a WPStatus object. It prints the value of the location and date headers in the Java output window, then prints all headers in the output window.
// component is an existing WebPubComponent object
// attributeList is a WPAttributeValue object
// that contains name/value pairs
// myFile is a File object
// Perform an operation on the component
WPStatus status = component.formPost(attributeList, myFile);
// Print the location header
String location = status.getHeaders().getProperty("location");
System.out.println("The location of the request is " + location);
// Print the date header
String date = status.getHeaders().getProperty("date");
System.out.println("The date of the request is " + date);
// Print all headers in the Java output window
status.getHeaders().save(System.out, "Headers");
Returns the status code, depicting the status of the response as it comes back from the server.
WPStatus
int getStatusCode()
An integer status code.
Returns the status message, an explanation of the status code as provided by the server.
WPStatus
String getStatusString()
A status message.
Example
This example prints the status code and status string for a delete operation.
/* Get the WebPubContainer object for the resource
url1 is an existing URL object
auth1 is an existing WPAuthentication object
*/
WebPubComponent resource1 = new WebPubComponent (url1, auth1);
/* Attempt to delete the resource */
WPStatus status = resource1.delete();
/* Was the delete operation successful?
Print the status code and string
*/
System.out.println("Status is: " + status.getStatusCode() +
": " + status.getStatusString());
Table of Contents | Previous
| Next
| Index
Last Updated: 03/10/99 13:42:02