Skip to Content
/* Built By: Prakash Singh * Universal System Technologies, Inc * M 407-474-2216 */ package com.ust.kmtree; import com.sapportals.htmlb.Form; import com.sapportals.htmlb.FormLayout; import com.sapportals.htmlb.FormLayoutRow; import com.sapportals.htmlb.Link; import com.sapportals.htmlb.Tree; import com.sapportals.htmlb.TreeNode; import com.sapportals.htmlb.page.DynPage; import com.sapportals.htmlb.page.PageException; import com.sapportals.portal.htmlb.page.PageProcessorComponent; import com.sapportals.portal.prt.component.IPortalComponentContext; import com.sapportals.portal.prt.component.IPortalComponentProfile; import com.sapportals.portal.prt.component.IPortalComponentRequest; import com.sapportals.portal.prt.component.IPortalComponentResponse; import com.sapportals.portal.prt.component.IPortalComponentURI; import com.sapportals.portal.security.usermanagement.IUser; import com.sapportals.wcm.repository.ICollection; import com.sapportals.wcm.repository.IResource; import com.sapportals.wcm.repository.IResourceList; import com.sapportals.wcm.repository.ResourceContext; import com.sapportals.wcm.repository.ResourceFactory; import com.sapportals.wcm.repository.enum.LinkType; import com.sapportals.wcm.repository.manager.IPermission; import com.sapportals.wcm.repository.manager.ISecurityManager; import com.sapportals.wcm.util.uri.RID; import com.sapportals.wcm.util.usermanagement.WPUMFactory;  public class display extends PageProcessorComponent {       /**  * calls the “real” page class.       */      public DynPage getPage() {           return new UsingDynPagePage();      }       public class UsingDynPagePage extends DynPage {           private final static int READ_ONLY = 0;           private final static int EDIT = 1;           private int flag = READ_ONLY;            private IResourceList reslist;           private String navigationURI;           private String fileURL;           private String docsURI;           private Form myForm;            private String colWidth;           private FormLayout fl;           /**  * Things to initialize once per session.            */           public void doInitialization() {                flag = READ_ONLY;                IPortalComponentRequest request =                     (IPortalComponentRequest) this.getRequest();                IPortalComponentResponse response =                     (IPortalComponentResponse) this.getResponse();                IPortalComponentContext myContext = request.getComponentContext();                IPortalComponentProfile profile = myContext.getProfile();                IPortalComponentURI componentURI =                     request.createPortalComponentURI();                componentURI.setContextName(“com.sap.km.cm.navigation”);                navigationURI = componentURI.toString();                componentURI.setContextName(“com.sap.km.cm.docs”);                docsURI = componentURI.toString();                try {                      fileURL = profile.getProperty(“path”);                     colWidth = profile.getProperty(“width”);                      //               create an ep5 user from the ep6 user in the request                     IUser user =                          WPUMFactory.getUserFactory().getEP5User(request.getUser());                     ResourceContext ctxt = new ResourceContext(user);                      RID rid = RID.getRID(fileURL);                      IResource resource =                          ResourceFactory.getInstance().getResource(rid, ctxt);                     //               get Security Manager                     ISecurityManager securityManager =                          resource.getRepositoryManager().getSecurityManager(                               resource);                     IPermission iperm =                          securityManager.getPermission(“leaf_write_content”);                     if (securityManager.isAllowed(resource, user, iperm)) {                          flag = EDIT;                     } else {                          flag = READ_ONLY;                     }                     ICollection collection = (ICollection) resource;                     reslist = collection.getChildren();                } catch (Exception e) {                     response.write(e.getMessage());                }           }            /**  * Will be called if forms with data was send.            */           public void doProcessAfterInput() throws PageException {            }            /**  * Will always be called before output. So this is the method in which  * the components will be placed and set.            */            public void doProcessBeforeOutput() throws PageException {                 myForm = getForm();                FormLayout fl = new FormLayout();                fl.setId(“fl”);                fl.setWidth(“94%”);                FormLayoutRow row1 = fl.addRow();                Tree tree = new Tree(“S_Tree”, “”);                tree.setRootNodeIsVisible(false);                 TreeNode root = new TreeNode(“e_root”, “Links”);                root.setOpen(true);                add_node(reslist, root);                tree.setRootNode(root);                fl.addComponent(1, 1, tree);                if (flag == EDIT) {                     String edit_url =                          navigationURI                               + fileURL                               + “?StartUri=”                               + fileURL                               + “&rndLayoutSet=LinkListMaintenance&layoutSetMode=exclusive”;                     Link link = new Link(“Edit”);                     link.setTarget(“_BLANK”);                     link.setReference(edit_url);                     link.addText(“Edit”);                     fl.addComponent(2, 1, link);                }                myForm.addComponent(fl);            }            public void add_node(IResourceList list, TreeNode name) {                String strtext;                String disname;                String strid;                IResourceList tmpreslist;                ICollection tmpcollection;                 for (int i = 0; i<list.size(); i++) {  IResource tmpres = list.get(i);   try {  strid = tmpres.getName();  disname = tmpres.getDisplayName();  if (disname == null) {  disname = “”;  }  if (disname.equals(“”) || disname == null) {  disname = strid;  }  strtext = disname;  if (tmpres.getLinkType() != LinkType.NONE) {  if (tmpres.getLinkType() == LinkType.EXTERNAL) {  strtext =  “”;  strtext = strtext + disname + ” (“%3Cbr%20/%3E%20%20%20%20%20%20%20%20%20+%20tmpres.getTargetURL().toString()%3Cbr%20/%3E%20%20%20%20%20%20%20%20%20+%20″)”;  } else {  if (tmpres.isCollection()) {  strtext =  “”;  strtext = strtext + disname + ” (“%3Cbr%20/%3E%20%20%20%20%20%20%20%20%20%20+%20navigationURI%3Cbr%20/%3E%20%20%20%20%20%20%20%20%20%20+%20tmpres.getTargetURL().toString()%3Cbr%20/%3E%20%20%20%20%20%20%20%20%20%20+%20″?StartUri=”%3Cbr%20/%3E%20%20%20%20%20%20%20%20%20%20+%20tmpres.getTargetURL()%3Cbr%20/%3E%20%20%20%20%20%20%20%20%20%20+%20″)”;  } else {  strtext =  “”;  strtext = strtext + disname + ” (“%3Cbr%20/%3E%20%20%20%20%20%20%20%20%20%20+%20docsURI%3Cbr%20/%3E%20%20%20%20%20%20%20%20%20%20+%20tmpres.getTargetURL().toString()%3Cbr%20/%3E%20%20%20%20%20%20%20%20%20%20+%20″)”;  }  }  } else if (!tmpres.isCollection()) {  strtext =  “”;  strtext = strtext + disname + ” (“%3Cbr%20/%3E%20%20%20%20%20%20%20%20+%20docsURI%3Cbr%20/%3E%20%20%20%20%20%20%20%20+%20tmpres.getAccessURI()%3Cbr%20/%3E%20%20%20%20%20%20%20%20+%20″)”;  }  TreeNode name1 = new TreeNode(strid, strtext, name);  name1.setTooltip(strid);  if (tmpres.isCollection()  && tmpres.getLinkType() == LinkType.NONE) {  tmpcollection = (ICollection) tmpres;  tmpreslist = tmpcollection.getChildren();  add_node(tmpreslist, name1);  }  } catch (Exception ex) {  IPortalComponentResponse response =  (IPortalComponentResponse) this.getResponse();  }  }  }   } }        Step 3:   Deploy your par and run it. BAM! you got yourself a nice tree that explodes all the content of a particular repository or foder.    image
To report this post you need to login first.

13 Comments

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

  1. Raluca L.
    Hi Prakash, thanks for your code. I have tried on my KM repository and it works. It will sure be useful to me.
    Best regards.
    (0) 
  2. Anonymous
    Sweet one, give a really nice tree.
    But: Have you thought of performing a lazy walktrough instead of a complete scan on each request? I.e. only retrieve subfolders if a user explicity opened a tree node (read: triggered the “onExpand” event. If you think of a more complex directory structure, I feel that performance will become a considerable issue here. Anyway, a good starting point for custom developments.

    Dominik

    (0) 
    1. Prakash Singh Post author
      Hi Dominik,
           I am glad you liked it. Thanks your your feedback. You are correct. Performance will definitely be an issue with the code if you try to explode a complex repository(deep heirarchy). I recommend using this code to do explosion of folders within repository. I have thought about modifying the code to explode KM Dynamically but haven’t worked on it. Maybe somebody you could take my code and modify it and write a weblog about it. 🙂
      (0) 
  3. Anonymous
    Hi.

    Concatenating a base URI with the resource’s RID is not going to work when the RID contains characters that need to be escaped in a URI, such as blanks or non-ASCII characters.

    You really should use KM’s IUrlGeneratorService interface instead.

    Best regards, Julian

    (0) 
    1. Prakash Singh Post author
      thanks for the feedbac. I am using this tool since last year and haven’t had any problem with escape characters. You should try my code and let me know of a situation when it crashes. thank you.
      (0) 
      1. Anonymous
        I didn’t say it crashes. I said it produces illegal URIs.

        For instance, how will an “A Umlaut” (“Ä”) that appears in a RID be translated to a legal URI (check RFC3986 for legal syntax).

        Best regards, Julian

        (0) 
        1. Steffen Bunzel
          Instead of using
          tempResource.getAccessURI() which is deprecated anyway, better use tempResource.getAccessRID().toExternalForm().

          The produced String is URLEncoded.

          Cheer,
          Steffen

          (0) 
  4. Sudheer K
    hi prakash….
    its really a nice blog..but..
    could u plz suggest me a place where i can get these 
    jar files u mentioned…
    bc.util.public_api.jar and bc.rf.framework_api.jar…

    i dint find them in the server….
    it would be great if u could mail them to me….at..
    sudheer.ace@gmail.com

    thankyou,
    Regards,
    Sudheer

    (0) 

Leave a Reply