Show TOC Start of Content Area

Background documentation Contexts and Attributes  Locate the document in its SAP Library structure

Using the standard JNDI APIs, you can add and remove contexts and modify context attributes.

However, when working with portal objects, it is easier to use the semantic or administration objects, as described in Working with Semantic Objects and Working with Administration (PCM) Objects, or to create delta links with the PCD API, as described in Delta Links.

Storing Data in the PCD

Using the standard JNDI APIs, you can create contexts and add attributes in order to store information in the PCD unrelated to the portal objects that administrators work with in the Portal Catalog.

Caution

It is recommended not to store large amounts of data in the PCD, as this can significantly reduce performance.

The following is an example of creating a top-level context (not under portal_content), and adding a multi-value attribute to the context:

Hashtable env = new Hashtable();

 

env.put(Context.INITIAL_CONTEXT_FACTORY,

    IPcdContext.PCD_INITIAL_CONTEXT_FACTORY);

env.put(Context.SECURITY_PRINCIPAL, request.getUser());

env.put(Constants.REQUESTED_ASPECT, IPcdAttribute.PERSISTENCY_ASPECT);

 

InitialContext   iCtx = null;

 

try {

    iCtx = new InitialContext(env);

 

    // Get the top-level context

    IPcdContext myPcdContext = (IPcdContext) iCtx.lookup("");

        

    // Create an attribute and set its value to {"Value1","Value2"}

    Attribute myAttr = new BasicAttribute("myAttribute","Value1");

    myAttr.add("Value2");

    Attributes myAttrs = new BasicAttributes();

    myAttrs.put(myAttr);

        

    // Create a subcontext with the predefined attributes

    myPcdContext.createSubcontext("myContext",myAttrs);

} catch (NamingException e) {}

 

End of Content Area