Skip to Content

Introduction

In this weblog i am going to present a Dynpage that display content assigned to a user in a nice htmlb tree display.

image

Jar files required

com.sap.portal.usermanagementapi.jar,com.sap.portal.pcd.glserviceapi.jar,com.sap.portal.pcmbuilderserviceapi.jar

Step1

Create a Dynpage project using NWDS or Eclipse wizard. Add the following source code to your

dynpage

component.

package com.ust.browserole;

/* Built By: Prakash Singh

  • Universal System Technologies, Inc

  • M 407-474-2216

*/

import java.util.Hashtable;

import java.util.Iterator;

import javax.naming.Context;

import javax.naming.NameClassPair;

import javax.naming.NamingEnumeration;

import com.sap.ip.portal.service.ume.IUserManagementEngine;

import com.sap.security.api.IRole;

import com.sap.security.api.IUser;

import com.sap.security.api.UMException;

import com.sap.security.api.UMFactory;

import com.sap.security.api.srvUser.IServiceUserFactory;

import com.sapportals.htmlb.Button;

import com.sapportals.htmlb.Form;

import com.sapportals.htmlb.GridLayout;

import com.sapportals.htmlb.Group;

import com.sapportals.htmlb.InputField;

import com.sapportals.htmlb.Label;

import com.sapportals.htmlb.Tree;

import com.sapportals.htmlb.TreeNode;

import com.sapportals.htmlb.enum.GroupDesign;

import com.sapportals.htmlb.event.Event;

import com.sapportals.htmlb.page.DynPage;

import com.sapportals.htmlb.page.PageException;

import com.sapportals.portal.htmlb.page.PageProcessorComponent;

import com.sapportals.portal.pcd.gl.IPcdContext;

import com.sapportals.portal.pcd.pcm.builder.IPcmEditObject;

import com.sapportals.portal.pcd.pcm.builder.IPcmObjectBuilder;

import com.sapportals.portal.pcd.pcm.builder.IPcmObjectService;

import com.sapportals.portal.prt.component.IPortalComponentRequest;

import com.sapportals.portal.prt.component.IPortalComponentResponse;

import com.sapportals.portal.prt.runtime.PortalRuntime;

public class display extends PageProcessorComponent {

     public DynPage getPage() {

          return new displayDynPage();

     }

     public static class displayDynPage extends DynPage {

          /**

          

  • Initialization code executed once per user.

           */

          String userid;

          public void doInitialization() {

               userid = “”;

          }

          /**

          

  • Input handling code. In general called the first time with the second page request from the user.

           */

          public void doProcessAfterInput() throws PageException {

          }

          /**

          

  • Create output. Called once per request.

           */

          public void doProcessBeforeOutput() throws PageException {

               Form myForm = this.getForm(); // get the form from DynPage

               // create your GUI here….     

               Group myGroup = new Group();

               myForm.addComponent(myGroup);

               myGroup.setWidth(“350”);

               myGroup.setDesign(GroupDesign.SAPCOLOR);

               myGroup.setTitle(“Browse assigned content for a user”);

               GridLayout gl = new GridLayout();

               myGroup.addComponent(gl);

               gl.setCellSpacing(5);

               GridLayout gl1 = new GridLayout();

               gl.addComponent(1, 1, gl1);

               Label lbluserid = new Label(“Userid”);

               gl1.addComponent(1, 1, lbluserid);

               InputField inpuserid = new InputField(“userid”);

               inpuserid.setValue(userid);

               gl1.addComponent(1, 2, inpuserid);

               Button buttondisplay = new Button(“Display”);

               buttondisplay.setText(“Display”);

               buttondisplay.setOnClick(“Display”);

               gl1.addComponent(2, 1, buttondisplay);

               if (!userid.equals(“”)) {

                    Tree tree = new Tree(“S_Tree”, “”);

                    tree.setRootNodeIsVisible(false);

                    TreeNode root = new TreeNode(“e_root”, “Role Content”);

                    root.setOpen(true);

                    tree.setRootNode(root);

                    IPortalComponentResponse response =

                         (IPortalComponentResponse) this.getResponse();

                    IPortalComponentRequest request =

                         (IPortalComponentRequest) this.getRequest();

                    IPcmObjectService pcdFactory =

                         (IPcmObjectService) PortalRuntime

                              .getRuntimeResources()

                              .getService(

                              IPcmObjectService.KEY);

                    Hashtable env = new Hashtable();

                    env.put(

                         Context.INITIAL_CONTEXT_FACTORY,

                         IPcdContext.PCD_INITIAL_CONTEXT_FACTORY);

                    env.put(

                         Context.SECURITY_PRINCIPAL,

                         this.getServiceUser(“pcd_service”));

                    try {

                         IUser user =

                              UMFactory.getUserFactory().getUserByLogonID(userid);

                         Iterator role = user.getRoles(true);

                         String roleroot;

                         String imgrolepath =

                              request.getWebResourcePath() + “/images/role.gif”;

                         while (role.hasNext()) {

                              String rolestr = (String) role.next();

                              IRole r = UMFactory.getRoleFactory().getRole(rolestr);

                              roleroot = r.getUniqueName();

                              String text =

                                   “!!”

                                        + r.getDescription();

                              TreeNode name =

                                   new TreeNode(r.getDisplayName(), text, root);

                              name.setEncode(false);

                              recursive_role_content(

                                   roleroot,

                                   pcdFactory,

                                   env,

                                   name,

                                   request);

                         }

                    } catch (Exception e) {

                         response.write(e.getMessage());

                    }

                    gl.addComponent(2, 1, tree);

               }

          }

          public void onDisplay(Event event) throws PageException {

               InputField useridfld = (InputField) getComponentByName(“userid”);

               userid = useridfld.getValueAsDataType().toString().toUpperCase();

          }

          public void recursive_role_content(

               String root,

               IPcmObjectService pcdFactory,

               Hashtable env,

               TreeNode name,

               IPortalComponentRequest request)

               throws Exception {

               IPcmObjectBuilder pcmSrv = pcdFactory.getInitialContext(env);

               NamingEnumeration names = pcmSrv.list(root);

               while (names.hasMore()) {

                    NameClassPair nameclass = (NameClassPair) names.next();

                    String pcdurl = root + “/” + nameclass.getName();

                    IPcmEditObject pcmObj = (IPcmEditObject) pcmSrv.lookup(pcdurl);

                    String img = “”;

                    if (pcmObj

                         .getObjectClassName()

                         .equals(“com.sapportals.portal.workset”))

                         img = request.getWebResourcePath() + “/images/workset.gif”;

                    else if (

                         pcmObj.getObjectClassName().equals(

                              “com.sapportals.portal.rolefolder”))

                         img = request.getWebResourcePath() + “/images/folder.gif”;

                    else if (

                         pcmObj.getObjectClassName().equals(

                              “com.sapportals.portal.page”))

                         img = request.getWebResourcePath() + “/images/page.gif”;

                    else if (

                         pcmObj.getObjectClassName().equals(

                              “com.sapportals.portal.iview”))

                         img = request.getWebResourcePath() + “/images/iView.gif”;

                    else if (

                         pcmObj.getObjectClassName().equals(

                              “com.sapportals.portal.layout”))

                         img =

                              request.getWebResourcePath()

                                   + “/images/page_layout.gif”;

                    String text = “!!” + pcmObj.getTitle();

                    TreeNode name1 = new TreeNode(pcmObj.getTitle(), text, name);

                    name1.setEncode(false);

                    NamingEnumeration newnames = pcmSrv.list(pcdurl);

                    if (newnames.hasMore()) {

                         recursive_role_content(

                              pcdurl,

                              pcdFactory,

                              env,

                              name1,

                              request);

                    }

               }

          }

          public IUser getServiceUser(String username) {

               IPortalComponentResponse response =

                    (IPortalComponentResponse) this.getResponse();

               IUser serviceUser = null;

               IUserManagementEngine ume =

                    (IUserManagementEngine) PortalRuntime

                         .getRuntimeResources()

                         .getService(

                         IUserManagementEngine.KEY);

               IServiceUserFactory sufactory = ume.getServiceUserFactory();

               try {

                    serviceUser = sufactory.getServiceUser(username);

               } catch (UMException e) {

                    response.write(e.getMessage());

               }

               return serviceUser;

          }

     }

}

Step2

Step 3

Save the following images and add it to your

dist->images

folder.

!https://weblogs.sdn.sap.com/weblogs/images/11062/role.gif|height=16|alt=image|width=16|src=https://weblogs.sdn.sap.com/weblogs/images/11062/role.gif|border=0!

image

image

image

image

image

Step 4

Deploy your application in your portal. h5. BAM! you got yourself a nice utility iView that display all the content assigned to a user.

image

To report this post you need to login first.

15 Comments

You must be Logged on to comment or reply to a post.

      1. Senthilkumar Radhakrishnan
        Hi Prakash,

        Good blog..I like to know where i can find the JAR files for this import statements.

        import com.sapportals.portal.pcd.gl.IPcdContext;
        import com.sapportals.portal.pcd.pcm.builder.IPcmEditObject;
        import com.sapportals.portal.pcd.pcm.builder.IPcmObjectBuilder;
        import com.sapportals.portal.pcd.pcm.builder.IPcmObjectService;

        (0) 
  1. Daniel Wroblewski
    Hi Prakash,

    Very nice weblog. One question, where is PCM API documented? How did you get info on this? For example, IPcmObjectService interface.

    Thanks.

    Daniel

    (0) 
    1. Prakash Singh Post author
      Thank you Daniel. PCMP API is not documented at all, This code is built from code snippets that i got from SDN and the code i had from RIG.
      (0) 
  2. Ritu Hunjan
    Hi Prakash,

    This code is really very useful.
    Im working on EP6 SP9 and am not able find the IPcm* classes.
    Is there a way I can get them?

    Moreover, your code is really a very useful one.

    Ritu R Hunjan

    (0) 
  3. Renaud Theuillon
    I get a java.lang.ClassCastException at the following cast in the recursive_role_content() method :

    IPcmEditObject pcmObj = (IPcmEditObject) pcmSrv.lookup(pcdurl);

    All the PCM classes are said to be deprecated. My portal is SP9, do you know how to fix this?

    (0) 
    1. Prakash Singh Post author
      I am working on a code that will work for EP6 SP9 and above. Give a day or two.. i will update my weblog. thank you.

      Prakash

      (0) 
  4. Sridhar k
    Hi Prakash,

    Kindly tell me where can I download the following jar files.

    1)com.sap.portal.usermanagementapi.jar
    2)com.sap.portal.pcd.glserviceapi.jar
    3)com.sap.portal.pcmbuilderserviceapi.jar

    (0) 
  5. Raj Peddisetty
    Hi Prakash,
      This blog is wonderful. This came to me as an oasis in desert. Can you please tell me where I can get documentation on using these java APIs. I want to develop filtering role and workset content. How do I know which API I need to pick, which method, etc stuff.
    I will be thankful if you can help me.
    Thanks,
    Raj.
    (0) 
  6. Raphael Barboza
    Hello,

    I can’t find class com.sapportals.portal.pcd.gl.IPcdContext in NW04s. This role browsing mechanism is still valid for nw04s?

    Thanks in advance.

    Best regards,
    Raphael

    (0) 
  7. Sushil Kumar Jain
    I have ended up with this error … ?
    Exception ID:02:30_22/08/08_0019_103594650
    [EXCEPTION]
    com.sapportals.portal.prt.component.PortalComponentException: Error in service call of Portal Component
    Component : pcd:portal_content/con.test.Test_1_101/com.bar.browserole.iviewlist
    Component class : com.ust.browserole.display
    User : BASIS
         at com.sapportals.portal.prt.core.PortalRequestManager.handlePortalComponentException(PortalRequestManager.java:969)
         at com.sapportals.portal.prt.core.PortalRequestManager.callPortalComponent(PortalRequestManager.java:343)
         at com.sapportals.portal.prt.core.PortalRequestManager.dispatchRequest(PortalRequestManager.java:136)
         at com.sapportals.portal.prt.core.PortalRequestManager.dispatchRequest(PortalRequestManager.java:189)
         at com.sapportals.portal.prt.component.PortalComponentResponse.include(PortalComponentResponse.java:215)
         at com.sapportals.portal.prt.pom.PortalNode.service(PortalNode.java:645)
         at com.sapportals.portal.prt.core.PortalRequestManager.callPortalComponent(PortalRequestManager.java:328)
         at com.sapportals.portal.prt.core.PortalRequestManager.dispatchRequest(PortalRequestManager.java:136)
         at com.sapportals.portal.prt.core.PortalRequestManager.dispatchRequest(PortalRequestManager.java:189)
         at com.sapportals.portal.prt.core.PortalRequestManager.runRequestCycle(PortalRequestManager.java:753)
         at com.sapportals.portal.prt.connection.ServletConnection.handleRequest(ServletConnection.java:240)
         at com.sapportals.portal.prt.dispatcher.Dispatcher$doService.run(Dispatcher.java:522)
         at java.security.AccessController.doPrivileged(Native Method)
         at com.sapportals.portal.prt.dispatcher.Dispatcher.service(Dispatcher.java:405)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at com.sap.engine.services.servlets_jsp.server.servlet.InvokerServlet.service(InvokerServlet.java:156)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:401)
         at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:266)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:387)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:365)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:944)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:266)
         at com.sap.engine.services.httpserver.server.Client.handle(Client.java:95)
         at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:160)
         at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:33)
         at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41)
         at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
         at java.security.AccessController.doPrivileged(Native Method)
         at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:100)
         at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:170)
    Caused by: java.lang.NullPointerException
    (0) 

Leave a Reply