2 Replies Latest reply on Jun 26, 2009 8:34 AM by claprun

    Programmatically modifying the PortalNode-Tree?

      Hi,

      we're tasked to integrate an existing cms into JBoss Portal, with the goal that the cms takes control over the portal structure. Thus, the cms (or rather the integration layer) has to modify the existing PortalNode-structure at runtime.

      The reference manual states


      It is not possible to use the API to modify the tree shape because it is not
      intended to be a management interface.


      Now my question: Does such a "management interface" exist?

        • 1. Found the management interface

          I downloaded the JBoss Portal source and had a thorough look at the admin portlets (core-admin project), in which the portal structure is modified. Then, I imitated it in my own portlet.

          Here is how it works:

          Entries in jboss-portlet.xml to get access to some JBoss-Services:

          <service>
           <service-name>PortalObjectContainer</service-name>
           <service-class>org.jboss.portal.core.model.portal.PortalObjectContainer</service-class>
           <service-ref>:container=PortalObject</service-ref>
          </service>
          <service>
           <service-name>InstanceContainer</service-name>
           <service-class>org.jboss.portal.core.model.instance.InstanceContainer</service-class>
           <service-ref>:container=Instance</service-ref>
          </service>
          <service>
           <service-name>AuthorizationDomainRegistry</service-name>
           <service-class>org.jboss.portal.security.AuthorizationDomainRegistry</service-class>
           <service-ref>:service=AuthorizationDomainRegistry</service-ref>
          </service>
          <service>
           <service-name>FederatingPortletInvoker</service-name>
           <service-class>org.jboss.portal.portlet.federation.FederatingPortletInvoker</service-class>
           <service-ref>:service=PortletInvoker,type=Federating</service-ref>
          </service>
          


          Java-Code example in the portlet, including iteration through all deployed portlets, creating a portal page, creating a portlet instance and putting in in a window on that page:

          PortalObjectContainer container = (PortalObjectContainer) getPortletContext().getAttribute("PortalObjectContainer");
           InstanceContainer instanceContainer = (InstanceContainer) getPortletContext().getAttribute("InstanceContainer");
           FederatingPortletInvoker portletInvoker = (FederatingPortletInvoker) getPortletContext().getAttribute("FederatingPortletInvoker");
           AuthorizationDomainRegistry registry = (AuthorizationDomainRegistry) getPortletContext().getAttribute("AuthorizationDomainRegistry");
          
           try {
           // create a portal page
           Page page = container.getContext().getDefaultPortal().createPage("MyPage" + counter);
          
           // iterate through existing portlets and select one
           List<Portlet> tmpPortlets = new ArrayList(portletInvoker.getFederatedInvoker("local").getPortlets());
           for (Portlet portlet : tmpPortlets) {
           if(portlet.getInfo().getName().equals("WeatherPortlet")){
           // create an instance of the selected portlet
           InstanceDefinition def = instanceContainer.createDefinition("MyPortlet" + counter, portlet.getContext().getId());
           // configuring security
           DomainConfigurator configurator = registry.getDomain("instance").getConfigurator();
           Set constraints = Collections.singleton(new RoleSecurityBinding("view", SecurityConstants.UNCHECKED_ROLE_NAME));
           configurator.setSecurityBindings(def.getId(), constraints);
           // create a window containing the portlet
           Window window = page.createWindow("MyWindow" + counter, ContentType.PORTLET, def.getId());
           window.setDeclaredProperty(ThemeConstants.PORTAL_PROP_REGION, "right");
           window.setDeclaredProperty(ThemeConstants.PORTAL_PROP_ORDER, "" + Integer.MAX_VALUE);
           }
           }
          
           } catch (IllegalArgumentException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
           } catch (DuplicatePortalObjectException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
           } catch (DuplicateInstanceException e1) {
           // TODO Auto-generated catch block
           e1.printStackTrace();
           } catch (PortletInvokerException e1) {
           // TODO Auto-generated catch block
           e1.printStackTrace();
           }


          • 2. Re: Programmatically modifying the PortalNode-Tree?
            claprun

            Use at your own risk! "With great power comes great responsibility!" ;)