cancel
Showing results for 
Search instead for 
Did you mean: 

Access Parent Context of PCD object

0 Kudos
150

Hi

I am trying to access the PCD via JNDI. I basically need to search the PCD for any iViews that contain a certain property. This bit is working fine. However, I now need to be able to retrieve the parent context (i.e. a Page) so that I can then retrieve a particular property from the page (as long as it is a page). Therefore, does anyone know how to get the parent IPcdContext of the current iview or even getting the IPortalPage object that the iview is on.

Thanks

Darrell

Message was edited by: Darrell Merryweather

Accepted Solutions (1)

Accepted Solutions (1)

Dan_Wroblewski
Developer Advocate
Developer Advocate
0 Kudos

Hi Darrell,

If you found an iView, you have its PCD address. Just remove that last part and do a lookup.

For example: you found iView pcd:portal_content/myFolder/myRole/myPage/myiView. Remove /myiView and you get the parent, then do a lookup to get the IPcdContent (or IPage) or whatever. You must check first if it is in fact a page.

Hope this helps.

Daniel

Former Member
0 Kudos

Hi Darrell Merryweather,

Daniel is exactly correct and i implement this as well.

To explain more about Daniel's solution..

See this code..

Hashtable env = new Hashtable();

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

env.put(Context.INITIAL_CONTEXT_FACTORY,IPcdContext.PCD_INITIAL_CONTEXT_FACTORY);

env.put(com.sap.portal.directory.Constants.REQUESTED_ASPECT, PcmConstants.ASPECT_SEMANTICS);

InitialContext ctx = null;

DirContext dirCtx;

List pageList = null;

try {

ctx = new InitialContext(env);

// Pass the iView location here...as Daniel said..

dirCtx =(DirContext) ctx.lookup("pcd:portal_content/myFolder/myRole/myPage/");

PcdSearchControls pcdSearchControls = new PcdSearchControls();

pcdSearchControls.setReturningObjFlag(false);

pcdSearchControls.setSearchScope(PcdSearchControls.SUBTREE_WITH_UNIT_ROOTS_SCOPE);

dirCtx.addToEnvironment(Constants.APPLY_ASPECT_TO_CONTEXTS,Constants.APPLY_ASPECT_TO_CONTEXTS);

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

pcdSearchControls);

pageList = new ArrayList();

int i = 0;

while (ne.hasMoreElements()) {

i++;

IPcdSearchResult searchResult =

(IPcdSearchResult) ne.nextElement();

// This location will give you the full path of the page with page name

String location = "pcd:portal_content/myFolder/myRole/myPage/" + searchResult.getName();

pageList.add(location);

}

} catch (NamingException e) {

throw new NamingException();

}catch (Exception e) {

throw new Exception();

}

Regards,

Karthick

0 Kudos

Thanks for comments. I decided to have a look at how the PCD browser does this exact thing. I was trying to avoid using string manipulation, as I don't believe that this is very nice coding, however, after looking at how the PCD browser does it, it also uses string manipulation to retrieve the parent context. Therefore, if it isn't broken, then don't fix it. I have decided to use the same method

thanks for the postings guys

Former Member
0 Kudos

Hi,

Could you please explain me more, with code sample ,how to achieve this using string manipulation?

Regards,

Karthick

0 Kudos

No problem. The code is


public String getParentNameInNamespace(String pNameInNamespace){
  if ( pNameInNamespace == null )
    return null;
  if ( pNameInNamespace.equals("pcd:") )
    return null;
  if ( pNameInNamespace.startsWith("pcd:") )
    if ( pNameInNamespace.lastIndexOf("/") == -1 )
      return "pcd:";		
    else
      return pNameInNamespace.substring(0, pNameInNamespace.lastIndexOf("/"));
  if ( pNameInNamespace.equals("") )
    return null;
  if ( pNameInNamespace.lastIndexOf("/") == -1 )	
    return "";
  else
    return pNameInNamespace.substring(0, pNameInNamespace.lastIndexOf("/"));
}

To retrieve the parent context name of the current context you simply use


getParentNameInNamespace(pcdContext.getNameInNamespace())

I hope this helps

Darrell

Answers (0)