on 01-27-2006 11:16 AM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.