Show TOC

Contexts and AttributesLocate this document in the navigation structure

Use

Using the PCD 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 .

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"}
    IPcdAttribute myAttr = PcdAccess.getPcdUtils().
        createPcdAttribute(PcdAttributeValueType.STRING, "myAttributeId");
    myAttr.add("Value1");
    myAttr.add("Value2");
    IPcdAttributes myAttrs = PcdAccess.getPcdUtils().createPcdAttributes();
    myAttrs.put(myAttr);
         
    // Create a subcontext with the predefined attributes
    myPcdContext.createSubcontext("myContext",myAttrs);
} catch (NamingException e) {}