cancel
Showing results for 
Search instead for 
Did you mean: 

Objects inside PCD folder

Former Member
0 Kudos

Hi All,

I am using semantic API in my application for creating and managing PCD objects in the portal. Now, i need to get the list of all PCD objects present inside a specific PCD folder.

I have used javax.naming.Context for creating iviews or pages in a PCD folder. But, how to get the information about all the objects available inside a PCD folder?

Please help me in this regard. Code examples will be very much helpful..

Regards,

Vijay.K

Accepted Solutions (1)

Accepted Solutions (1)

Dan_Wroblewski
Developer Advocate
Developer Advocate
0 Kudos

Hi Vijay,

Here is the code snippet:

Hashtable env = new Hashtable();
env.put(IPcdContext.SECURITY_PRINCIPAL, request.getUser());
env.put(Context.INITIAL_CONTEXT_FACTORY, IPcdContext.PCD_INITIAL_CONTEXT_FACTORY); 
env.put(Constants.REQUESTED_ASPECT, PcmConstants.ASPECT_SEMANTICS);

InitialContext ctx = null;
DirContext dirCtx;

try {
    ctx = new InitialContext(env);
    dirCtx = (DirContext)ctx.lookup("pcd:portal_content/DanielContent");

    PcdSearchControls cons = new PcdSearchControls();
    cons.setReturningObjFlag(false); //set if will return an object (created by object factory) or only pcdContext

    cons.setSearchScope(PcdSearchControls.UNIT_ROOTS_ONLY_SCOPE);
    dirCtx.addToEnvironment(Constants.APPLY_ASPECT_TO_CONTEXTS, Constants.APPLY_ASPECT_TO_CONTEXTS);

    NamingEnumeration ne = dirCtx.search("", "", cons); 

    response.write ((ne==null)+"AAA<BR>");

    int i=0;
    while (ne.hasMoreElements()) {
        i++;
				
        IPcdSearchResult sr = (IPcdSearchResult) ne.nextElement();

        response.write(sr.getName()+"-----Attr<br>");
	response.write(sr.getAttributes().get("com.sap.portal.pcm.Title").get()+"-----Attr<br>");
	response.write(sr.getAttributes().get("com.sap.portal.pcd.gl.ObjectClass").get()+"-----Attr<br>");

	String location = "pcd:portal_content/DanielContent/"+sr.getName();
	response.write (location+"<BR>");

    }

} catch (NamingException e) {
    e.printStackTrace();
}

Check out the PCD Javadocs for more information on refining this search.

For example, if you only want the iViews, you can change the code to this:

NamingEnumeration ne = dirCtx.search("", "(com.sap.portal.pcd.gl.ObjectClass=com.sapportals.portal.iview)", cons);

Also, you ask the search to also include objects inside roles by changing the parameter in the

setSearchScope()

method.

Look at Detlev's link for some additional caveats.

Hope this helps.

Daniel

Former Member
0 Kudos

Hi Daniel

I would like to use the above code, in webdynpro,

can you provide the approriate code snippet,

Since i am planning to fetch the iview list by ONCLICK of a button.

Thanks

Kumar T

Answers (1)

Answers (1)

detlev_beutner
Active Contributor
0 Kudos

Hi Vijay,

lookup the folder and retrieve it's elements through <i>list</i>. See and for example.

Hope it helps

Detlev

PS: Please consider rewarding points for helpful answers on SDN - or at least give some feedback why it wasn't helpful; revisit for example these threads: and /thread/93740 [original link is broken]