Okay experts, I need a little help here.
Using the article, [Accessing PCD content|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/6112ecb7-0a01-0010-ef90-941c70c9e401], I'm trying to find all iViews within a specifiec PCD location.
My problem is the code only seems to work for roles...? Every time I try to search for iViews I get the following error: cannot read object with ID=54681. There isnt an object there with that ID. Same thing happens if you search for worksets but it gives a different ID number.
Could someone please tell me what I'm missing or if there is a better way to search for the iviews in the PCD?
Points will be awarded! Thanks!!
See code below:
package com.company;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingEnumeration;
import javax.naming.directory.DirContext;
import com.sap.portal.directory.Constants;
import com.sap.portal.pcm.admin.PcmConstants;
import com.sap.portal.pcm.iview.IiView;
import com.sapportals.portal.pcd.gl.IPcdContext;
import com.sapportals.portal.pcd.gl.IPcdSearchResult;
import com.sapportals.portal.pcd.gl.PcdSearchControls;
import com.sapportals.portal.prt.component.AbstractPortalComponent;
import com.sapportals.portal.prt.component.IPortalComponentRequest;
import com.sapportals.portal.prt.component.IPortalComponentResponse;
import com.sapportals.portal.prt.component.PortalComponentContentType;
import com.sapportals.wcm.control.util.StringUtil;
public class pcd_layout_search extends AbstractPortalComponent
{
public void doContent(IPortalComponentRequest request, IPortalComponentResponse response)
{
response.setContentType(PortalComponentContentType.HTML);
try
{
String pcdStartLoc = "pcd:portal_content/com.fe.FE_folder/administration_folder/portalteam_folder/ken_folder/";
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 iViewList = null;
ctx = new InitialContext(env);
dirCtx = (DirContext) ctx.lookup(pcdStartLoc);
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.iview)",pcdSearchControls);
//NamingEnumeration ne = dirCtx.search("","",pcdSearchControls);
iViewList = new ArrayList();
while (ne.hasMoreElements())
{
IPcdSearchResult searchResult =(IPcdSearchResult) ne.nextElement();
String location = pcdStartLoc + searchResult.getName();
response.write(location + "<br>");
//Get the full pcd path of the iview.
iViewList.add(location);
//getProperties(request,response,location);
}
//return iViewList;
}
catch(Exception e )
{
response.write("ERROR: " + e.getMessage());
}
}
}