Oracle® Content Services Application Developer's Guide 10g Release 1 (10.1.2.2) Part Number B25277-02 |
|
|
View PDF |
Oracle Content Services Web Services allow you to create Containers, which are a special type of folder used to organize Workspaces. Containers cannot contain documents, only other containers and workspaces. They have no quota and no trash.
The Container Manager is one of the simplest managers in Oracle Content Services. It allows you to create, delete, and update containers. For this example you will need to use the Container Manager to create the containers, and the Domain Manager to retrieve the root directory in which to create the containers.
Once authenticated with an Oracle Content Services instance, you can create a Container using the createContainer()
method as follows.
/** * Creates a Container in the default Domain. * * Note: The logged-in user must have the ContainerAdministrator role and the * logged-in session must be in domain-administration mode. */ public static Item createContainer(String containerName, String description) throws FdkException, RemoteException { // get the Manager instances we need ContainerManager cm = WsConnection.getContainerManager(); DomainManager dm = WsConnection.getDomainManager(); // get default domain Item defaultDomain = dm.getDefaultDomain(null); // create the Container definition NamedValue[] cnDef = WsUtility.newNamedValueArray(new Object[][] { { Attributes.NAME, containerName }, { Attributes.DESCRIPTION, description } }); // container attribute request AttributeRequest[] cont_attr = new AttributeRequest[] { WsUtility.newAttributeRequest(Attributes.PATH), WsUtility.newAttributeRequest(Attributes.DESCRIPTION) }; // create the Container Item container = cm.createContainer(domain.getId(), cnDef, cont_attr); WsUtility.log("container attributes"); WsUtility.log(WsUtility.INDENT, container); return container; }
First, the WsConnection
class is used to retrieve the Container and Domain Managers.
The Domain Manager is used to retrieve a domain, which is a root folder in Oracle Content Services. Typically, there will be only one domain, unless there are multiple sites being hosted in a single instance. This example creates a Container in the default domain (the root, in this case), which is retrieved with the getDefaultDomain
call.
To create a container the logged-in user must be in domain administration mode. This mode is used when you want to perform high-level actions such as adding, deleting, or modifying a Container. This mode is used throughout Oracle Content Services, and allows different operations on each Manager. In the case of Containers, all operations must be made in administrator mode. Switching to this mode will be shown later in this chapter.
Oracle Content Services returns the domain object in the form of an Item
, which is a type representing any kind of persistent repository object, such as a Document, Folder, User, Group, or Category. An Item
always has 3 default attributes:
id
(long) - the ID of the object in the repository.
name
(String) - the name of the item as stored in the repository. This value is null if the item does not have a name.
type
(String) - the type of the object. All available type constants are defined in oracle.ifs.fdk.ItemTypes
.
When creating a new container using the ContainerManager.createContainer()
method, you must pass in a set of attributes describing the properties of the container, such as the name and description. This set is passed in an array of NamedValue
objects.
The cont_attr
parameter has special importance. An item may also contain a set of optional attributes that are filled in when the item object is created only if the caller requests them. These are called attribute requests. An attribute request is performed by creating an AttributeRequest
array, and populating it with a list of attributes. Using attribute requests, you can fetch additional attributes about the item by passing (possibly nested) arrays of attribute requests. This allows for retrieval of entire trees of related objects and their attributes in one call. When the call containing the attribute request is made (in this case the createContainer
call), it returns the requested attributes into an Item
object (in this case container
). The attributes in the item can then be retrieved using the Item method getRequestedAttributes()
. Attribute requests are used throughout Oracle Content Services, and are discussed in more detail in Chapter 7.
In the last line before returning, the returned attributes are passed to a log method belonging to the WsUtility
class, which writes a log entry for the action that took place. Inside the log method, the attributes are retrieved using the getRequestedAttributes
method, which returns an array of NamedValue
pairs (each containing an Attribute
and a value).
public static void log(String indent, Item item) { if (item == null) { log(indent, "Item is null "); return; } log(indent, "Item [name = " + item.getName() + "]"); NamedValue[] attributes = item.getRequestedAttributes(); int len = (attributes == null) ? 0 : attributes.length; if (len > 0) { log(indent, "Requested Attributes"); } for (int i = 0; i < len; i++) { log(indent + INDENT, attributes[i]); } }
To delete a container, simply call the deleteContainer()
method on the ContainerManager
, passing in the Container ID as an argument. Note that this example assumes the session is still in administrator mode.
/** * Deletes the specified Container. * * Note: The logged-in user must have the ContainerAdministrator role and the * logged-in session must be in domain administration mode. */ public static void deleteContainer(Item container) throws FdkException, RemoteException { // delete Container ContainerManager cm = WsConnection.getContainerManager(); cm.deleteContainer(container.getId(), null); }
Before calling these methods, remember that you must be in domain administration mode. To switch to this mode, connect to the Session Manager and call the setSessionMode()
method as shown below.
Be sure to log out from the Web Services instance at the end using the WsConnection.logout()
method.
private static WsConnection s_WsCon; public static void main(String[] args) { try { try { // get property object Properties prop = WsUtility.getProperty(args[0]); // URL to content services web services servlet String serverUrl = "http://" + prop.getProperty("hostname") + ":" + prop.getProperty("port") + "/content/ws"; // authenticate to content services s_WsCon = WsConnection.login(serverUrl, prop.getProperty("user"), prop.getProperty("password")); // create Container Item newContainer = createContainer("MyContainer", "This is a example container"); // delete Container deleteContainer(newContainer); } finally { s_WsCon.logout(); } } catch (Throwable t) { t.printStackTrace(); } }