Web Publishing API Reference
Table of Contents | Previous | Next |

Web Publishing Client API Guide


Chapter 3
Web Publishing API Reference

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:

WebPubResource

Represents information relevant to any resource.

Subclasses

WebPubComponent, WebPubContainer

Syntax

class WebPubResource

Description

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.

Method Summary

WebPubResource

Creates a resource object with the given URL. Does not verify that the object referenced by the URL exists.

copy

Requests the server to copy the resource from its current URL location to a new location.

getAttributeNames

Requests the server to provide a list of attribute names currently set for the resource.

getAttributes

Requests the server to return the values for one of a resource's attributes.

move

Requests the server to move the resource from its current URL location to a new location.

setAttributes

Requests the server to set attributes in a list to their corresponding values.

Constructors and Methods

This section describes the constructors and methods of the WebPubResource class.

WebPubResource

Creates a resource object with the given URL. Does not verify that the object referenced by the URL exists.

Syntax

WebPubResource (URL url, WPAuthentication authentication)
WebPubResource (URL url, WPAuthentication authentication, WPVersionInfo info) 

Parameters

The parameters of the WebPubResource constructor are as follows:
url

A URL object specifying a resource, such as:

http://yourserver/docs/plan1.html
authentication

An authentication object representing the authentication string used by the client, using a previously agreed upon authentication scheme between the server and the client, to access a certain resource. This parameter can be null.

To create an authentication object, call new on the class WPAuthentication.

info

(Optional) An object containing information about the resource, such as its version. This parameter is used only for components such as files, not for containers such as directories.

Example

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);

copy

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).

Method of

WebPubResource

Syntax

WPStatus copy (URL destURL)

Parameters

The copy method takes the following parameter:
destURL

The new location for the resource, for example:

http://yourserver/docs/plan1b.html

Returns

A WPStatus object.

Description

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.

Example

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);

getAttributeNames

Requests that the server provide a list of all of the attribute names supported by the server.

Method of

WebPubResource

Syntax

WPStatus getAttributeNames (Vector vec) 

Parameters

The getAttributeNames method has the following parameter:
vec

On return, a list of String objects representing the attribute names.

Returns

A WPStatus object.

Example

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());
   }

getAttributes

Requests that the server return the values for one or all of a resource's attributes.

Method of

WebPubResource

Syntax

WPStatus getAttributes (WPAttributeValue attrs, String attribute)

Parameters

The getAttributes method has the following parameters:
attrs

On return, a WPAttributeValue, representing one or more attribute name/value pairs.

attribute

An attribute name. You can supply any legal attribute name or an asterisk ( * ) to get all attributes and their values.

Returns

A WPStatus object.

Description

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.

Example

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));
}

move

Requests that the server schedule moving the resource from its current URL location to a new location.

Method of

WebPubResource

Syntax

WPStatus move (URL destURL)

Parameters

The move method takes the following parameter:
destURL

The new location for the resource, for example:

http://yourserver/plan1B.html

Returns

A WPStatus object.

Description

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."

setAttributes

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.

Method of

WebPubResource

Syntax

WPStatus setAttributes(String attribute, String value)

Parameters

The setAttributes method has the following parameter:
attribute

A string indicating the name of the attribute. Make sure that a custom attribute is valid (predefined through the Administrator interface) before setting that attribute's value.

value

A string indicating the value of the attribute.

Returns

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");

WebPubContainer

Represents a container (a resource that can contain other resources). An example of a container is a directory.

Superclasses

WebPubResource

Syntax

class WebPubContainer 
   extends
WebPubResource

Description

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.

Method Summary

WebPubContainer

Creates a container object with the specified URL and no version information.

create

Requests the server to creates a new physical container. This corresponds the mkdir remote file manipulation command.

delete

Requests the server to schedules the removal of empty containers. This corresponds to the content management delete command.

index

Obtains an index of all resources (components and containers) and resource properties in the server that are associated with this container.

rmdir

Sends a remote file manipulation rmdir command to the server.

The WebPubContainer class also inherits the following methods from its superclass WebPubResource:

Constructor and Methods

This section describes the constructor and methods of the WebPubContainer class.

WebPubContainer

Creates a container object with the specified URL and no version information.

Syntax

WebPubContainer (URL url, WPAuthentication authentication)

Parameters

The WebPubContainer constructor has the following parameters:
url

A URL object specifying a container. This parameter identifies the physical container for which an object is being created.

authentication

An authentication object representing the authentication string used by the client, using a previously agreed upon authentication scheme between the server and the client, to access a certain resource. This parameter can be null.

Example

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);

create

Creates a new physical container.

Method of

WebPubContainer

Syntax

WPStatus create()

Parameters

None.

Returns

A WPStatus object.

Example

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();

delete

Schedules the removal of empty containers.

Method of

WebPubContainer

Syntax

WPStatus delete()

Parameters

None.

Returns

A WPStatus object.

Description

After calling the delete method, you cannot call any other methods of this object.

index

Obtains an index of all resources (components and containers) and resource properties in the server that are associated with this container.

Method of

WebPubContainer

Syntax

WPStatus index (WPIndexResource indexResource)

Parameters

The index method takes the following parameter:
indexResource

On return, contains the index information for the container.

Returns

A WPStatus object.

Description

The server can return the following fields for each resource:

See WPIndexResource for a list of the methods available on the WPIndexResource class.

Example

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);
}

rmdir

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.

Method of

WebPubContainer

Syntax

WPStatus rmdir()

Parameters

None.

Returns

A WPStatus object.

WebPubComponent

Represents a component (a resource that contains content but not other resources). A file is an example of a component.

Superclasses

WebPubResource

Syntax

class WebPubComponent 
   extends
WebPubResource

Description

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).

Method Summary

WebPubComponent

Creates a component object.

delete

Requests that the server delete the resource, making it unavailable for further editing by any client.

download

Downloads a resource from the remote server to the client.

edit

Marks the specified resource for editing, possibly locking it on the server, and downloading it to the client.

formPost

Posts data expressed as name/value pairs to a specific URL on the remote server.

lock

Requests that the server lock the resource.

revNum

Requests that the server retrieve a list of available versions of the resource.

save

Saves the specified resource to the server.

startRev

Requests that the server initiate version control on a resource that already exists on the server.

stopRev

Requests that the server take a resource out of version control.

unedit

Requests that the server unlocks the resource and removes the edit flag from the resource.

unlock

Requests that the server unlock the resource.

upload

Uploads a resource to the remote server from the client.

The WebPubComponent class also inherits the following methods from its superclass WebPubResource:

Constructors and Methods

This section describes the constructors and methods of the WebPubComponent class.

WebPubComponent

Creates a component object.

Syntax

WebPubComponent (URL url, WPAuthentication authentication)
WebPubComponent (URL url, WPAuthentication authentication, WPVersionInfo info)

Parameters

The parameters of the WebPubComponent constructors are as follows:
url

A URL object specifying a component.

authentication

An authentication object representing the authentication string used by the client, using a previously agreed upon authentication scheme between the server and the client, to access a certain resource. This parameter can be null.

info

(Optional) A WPVersionInfo object representing information about the resource.

Description

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.

Example

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);

delete

Requests that the server delete the resource, making it unavailable for further editing by any client.

Method of

WebPubComponent

Syntax

WPStatus delete()

Parameters

None.

Returns

A WPStatus object.

Description

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.

download

Downloads a resource from the remote server to the client.

Method of

WebPubComponent

Syntax

WPStatus download (File file) 
WPStatus download (ByteArrayOutputStream buffer) 

Parameters

The download method takes the following parameters:
file

A File object that, on return, contains the body of the resource.

buffer

A ByteArrayOutputStream object that, on return, contains the body of the resource.

Returns

A WPStatus object.

Description

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.

edit

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.)

Method of

WebPubComponent

Syntax

WPStatus edit (File file) 
WPStatus edit (ByteArrayOutputStream buffer) 

Parameters

The edit method takes the following parameters:
file

A File object that, on return, contains the body of the resource to be edited.

buffer

A ByteArrayOutputStream object that, on return, contains the body of the resource to be edited.

Returns

A WPStatus object.

Description

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.

formPost

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.

Method of

WebPubComponent

Syntax

formPost(WPAttributeValue attributeList, File file)
formPost(WPAttributeValue attributeList, ByteArrayOutputStream stream)

Parameters

The formPost method takes the following parameters:
attributeList

A list of name/value pairs expressed as a WPAttributeValue object.

file

A File object to contain the output generated by invoking the component (such as CGI program) with the name-value pairs in the attribute list.

stream

A ByteArrayOutputStream object to contain the output generated by invoking the component (such as CGI program) with the name-value pairs in the attribute list.

Returns

A WPStatus object.

Example

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);

lock

Requests that the server lock the resource, making it unavailable for editing by anyone else.

Method of

WebPubComponent

Syntax

WPStatus lock()

Parameters

None.

Returns

A WPStatus object.

Description

While locked, another client cannot lock or make changes to the resource.

revNum

Requests that the server retrieve a list of available versions of the resource.

Method of

WebPubComponent

Syntax

WPStatus revNum (Vector vec)

Parameters

The revNum method takes the following parameter:
vec

On return, the vector contains a list, returned by the server, of the existing versions of the resource. Each element in the vector is a String object.

Returns

A WPStatus object.

Description

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());
   }
}

save

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.

Method of

WebPubComponent

Syntax

WPStatus save (File file) 
WPStatus save (ByteArrayInputStream buffer, int buffLength)

Parameters

The save method takes the following parameters:
file

A File object that contains the content to be saved to the component.

buffer

A ByteArrayInputStream object that contains the content to be saved to the component.

buffLength

The length of the buffer.

Returns

A WPStatus object.

Description

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.

startRev

Requests that the server initiate version control on a resource that already exists on the server.

Method of

WebPubComponent

Syntax

WPStatus startRev()

Parameters

None.

Returns

A WPStatus object.

Description

The resource must already exist on the remote server.

stopRev

Requests that the server take a resource out of version control.

Method of

WebPubComponent

Syntax

WPStatus stopRev()

Parameters

None.

Returns

A WPStatus object.

Description

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).

unedit

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).

Method of

WebPubComponent

Syntax

WPStatus unedit()

Parameters

None.

Returns

A WPStatus object.

Description

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.

unlock

Requests that the server unlock the resource.

Method of

WebPubComponent

Syntax

WPStatus unlock()

Parameters

None.

Returns

A WPStatus object.

upload

Uploads a resource from the client to the remote server.

Method of

WebPubComponent

Syntax

WPStatus upload (File file) 
WPStatus upload (ByteArrayOutputStream buffer, int buffLength)

Parameters

The upload method takes the following parameters:
file

A File object containing the data to store.

buffer

A ByteArrayOutputStream object containing the data to store.

buffLength

The length of the buffer.

Returns

A WPStatus object.

Description

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.)

WPAttributeValue

Represents a list of attribute name/value pairs.

Syntax

class WPAttribute

Description

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.

Method Summary

WPAttributeValue

Creates an attribute object.

add

Adds an attribute name/value pair to this object.

attributeExists

Tests whether the specified attribute is contained in this object.

getAttributeNames

Returns an enumerated list of all of the attribute names contained in this object.

getAttributeValue

Returns the value of a specified attribute.

numberOfAttributes

Returns the number of attribute name/value pairs contained in this object.

Constructor and Methods

This section describes the constructor and methods of the WPAttributeValue class.

WPAttributeValue

Creates an attribute list object. After creating the attribute list, use the add method to add name/value pairs to the list.

Syntax

WPAttribute () 

Parameters

None.

Example:

WPAttribute attributeList = new WPAttribute();

add

Adds an attribute name/value pair to this object.

Method of

WPAttributeValue

Syntax

void add(String attribute, String value)

Parameters

The add method has the following parameters:
attribute

A String object containing the name of the attribute to add.

value

A String object containing the value for the specified attribute.

Returns

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");

attributeExists

Tests whether the specified attribute is contained in this object.

Method of

WPAttributeValue

Syntax

boolean attributeExists(String attribute)

Parameters

The attributeExists method has the following parameter:
attribute

A String object containing the name of an attribute.

Returns

True if the attribute is in this object; otherwise, false.

Example

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");

getAttributeNames

Returns an enumerated list of all of the attribute names contained in this object.

Method of

WPAttributeValue

Syntax

Enumeration getAttributeNames()

Parameters

None.

Returns

An enumerated list of attribute names. These names should be cast to String objects.

Example

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));
}

getAttributeValue

Returns the value of a specified attribute.

Method of

WPAttributeValue

Syntax

String getAttributeValue(String attribute)

Parameters

The getAttributeValue method has the following parameters:
attribute

A String object containing the name of an attribute.

Returns

A String object containing the value of the specified attribute.

Description

This method assumes that you have already verified that the specified attribute exists in this object. You can verify this with the attributeExists method.

Example

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.

numberOfAttributes

Returns the number of attribute name/value pairs contained in this object.

Method of

WPAttributeValue

Syntax

int numberOfAttributes()

Parameters

None.

Returns

The number of attributes contained in this object.

WPAuthentication

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.

Syntax

class WPAuthentication

Method Summary

WPAuthentication

Creates an authentication object based on the user ID and password.

getAuthentication

Returns the computed authentication string.

getUserID

Returns the associated user ID.

getPassword

Returns the associated user password.

Constructor and Methods

This section describes the constructor and methods of the WPAuthentication class.

WPAuthentication

Creates an authentication object based on the user ID and password.

Syntax

WPAuthentication (String userID, String passWord) 

Parameters

The parameters to the WPAuthentication constructor are as follows:
userID

The ID of the associated user.

passWord

The user's password.

Description

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.

Example

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);

getAuthentication

Returns the computed authentication string.

Method of

WPAuthentication

Syntax

String getAuthentication()

Parameters

None.

Returns

An authentication string.

Description

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.

getPassword

Returns the associated user password.

Method of

WPAuthentication

Syntax

String getPassword()

Parameters

None.

Returns

The password string set in the constructor.

getUserID

Returns the associated user ID.

Method of

WPAuthentication

Syntax

String getUserID()

Parameters

None.

Returns

The user ID string set in the constructor.

WPIndexResource

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.

Syntax

public class WPIndexResource

Method Summary

WPIndexResource

Creates an index resource object.

getAllFieldNamesForFile

Returns a list of fields available for a particular file.

getAllFieldValuesForFile

Retrieves the values of all the fields returned by the server for the specified file.

getAllFileNames

Retrieves the names of all of the files contained in the resource, as returned by the server.

getFieldValueForFile

Retrieves the value for a specific field of a specific file.

Constructor and Methods

This section describes the constructor and methods of the WPIndexResource class.

WPIndexResource

Creates an index resource object.

Syntax

WPIndexResource()

Parameters

None.

Description

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.

Example

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.

getAllFieldNamesForFile

Returns a list of the fields available for a particular file.

Syntax

Enumeration getAllFieldNamesForFile(String filename)

Parameters

The parameter to the getAllFieldNamesForFile method is as follows:
filename
A String object containing the name of the file for which the information is requested.

Returns

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.

Description

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.

Example

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() + " ");
}

getAllFieldValuesForFile

Retrieves the values of all the fields returned by the server for the specified file.

Syntax

Enumeration getAllFieldValuesForFile(String filename)

Parameters

The parameter to the getAllFieldValuesForFile method is as follows:
filename
A String object containing the name of the file for which the information is requested.

Returns

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.

Example

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() + " ");
}

getAllFileNames

Retrieves the names of all of the files contained in the resource, as returned by the server.

Syntax

Enumeration getAllFileNames()

Parameters

None.

Returns

An enumerated list of all the filenames returned by the server. These filenames should be cast to String objects before use.

Example

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() + " ");
}

getFieldValueForFile

Retrieves the value for a specific field of a specific file.

Syntax

String getFieldValueForFile(String filename, String fieldname)

Parameters

The parameters to the getFieldValueForFile method are as follows:
filename
A String object containing the name of the file for which the information is requested.

fieldname
A String object containing the name of the field whose value is requested.

Returns

A String object containing the value of the requested field for the specified file.

Description

Before calling this method, you can call getAllFieldNamesForFile to see if the field you're interested in is available.

Example

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));
}

WPVersionInfo

Represents information about a resource, such as its version.

Syntax

class WPVersionInfo

Description

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:

Method Summary

WPVersionInfo

Creates a version-information object.

getComments

Retrieves the associated user comments.

getLock

Retrieves the resource's current lock status.

getVersion

Retrieves the version tag referring to a specific version of the resource.

setLock

Sets the resource's lock status.

Constructor and Methods

This section describes the constructor and methods of the WPVersionInfo class.

WPVersionInfo

Creates a version-information object.

Syntax

WPVersionInfo (String version, String label, String lock, String comment)

Parameters

The parameters to the WPVersionInfo constructor are as follows:

version

The actual version string used to refer to a particular version of the resource. For the latest version at the head of the version tree, use the String "head".

label

This parameter must be null. Labels are not supported in this release.

lock

One of WPVersionInfo.locked or WPVersionInfo.unlocked.

comment

A string of user comments for the resource.

Description

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);

getComments

Retrieves the associated user comments.

Method of

WPVersionInfo

Syntax

String getComments()

Parameters

None.

Returns

User comments.

Description

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.

getLock

Retrieves the resource's current lock status.

Method of

WPVersionInfo

Syntax

String getLock()

Parameters

None.

Returns

One of WPVersionInfo.locked or WPVersionInfo.unlocked.

Description

You lock a resource so that other users cannot modify it.

getVersion

Retrieves the version tag referring to a specific version of the resource.

Method of

WPVersionInfo

Syntax

String getVersion()

Parameters

None.

Returns

A version string.

Description

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.

setLock

Sets the resource's lock status.

Method of

WPVersionInfo

Syntax

void setLock (String lock)

Parameters

The parameter to the setLock method is as follows:
lock

One of WPVersionInfo.locked or WPVersionInfo.unlocked.

Description

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.

Example

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);

WPStatus

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.

Syntax

interface WPStatus

Description

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.

Method Summary

getStatusCode

Returns the status code, depicting the status of the response as it comes back from the server.

getStatusString

Returns the status message, an explanation of the status code as provided by the server.

getHeaders

Returns all the headers returned by the server in a Java properties structure.

Methods

This section describes the methods of the WPStatus interface.

getHeaders

Returns all the headers returned by the server in a Java properties structure.

Method of

WPStatus

Syntax

Properties getHeaders()

Returns

The Java properties.

Example

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");

getStatusCode

Returns the status code, depicting the status of the response as it comes back from the server.

Method of

WPStatus

Syntax

int getStatusCode()

Returns

An integer status code.

getStatusString

Returns the status message, an explanation of the status code as provided by the server.

Method of

WPStatus

Syntax

String getStatusString()

Returns

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