Skip Headers
Oracle® Content Services Application Developer's Guide
10g Release 1 (10.1.1)

Part Number B14494-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

2 Oracle Content Services Container Manager

Oracle Content Services Web Servies 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 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 container.

Creating a Container

Once authenticated with a 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 } });
 
    // create the Container
    return cm.createContainer(defaultDomain.getId(), cnDef, null);
}

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 Content Services. Typically, there will be only one domain, unless there are multiple sites being hosted in a single instance of Content Services. This example creates a Container in the default domain (the root, in this case), which is retrieved with the getDefaultDomain call.

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.

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

Deleting a Container

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

Running the Code

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
        {
            // URL to content services web services servlet
            String serverUrl = "http://yourserver.com:7777/content/ws";
 
            // authenticate to content services
            s_WsCon = WsConnection.login(serverUrl, "jon", "welcome1");
 
            // switch to domain admin mode
            SessionManager sm = s_WsCon.getSessionManager();
            sm.setSessionMode(FdkConstants.SESSION_MODE_DOMAIN_ADMINISTRATION,
                null);
 
            // create Container
            Item newContainer = createContainer("MyContainer", "This is a example
                container");
 
            // delete Container
            deleteContainer(newContainer);
        }
        finally
        {
            s_WsCon.logout();
        }
    }
    catch (Throwable t)
    {
        t.printStackTrace();
    }
}