How to programmatically add a portlet to the JBoss Portal toolbar

How can I programmatically add a portlet to a specific user's JBoss Portal ? Is there any remote API for JBoss Portal to do this? SOAP web service, maybe an MBean based API? Of course, as a last resort, I can implement such a service myself and deploy it to the JBoss Portal, but ideally it would not need to deploy anything to JBoss.

I need to do this from an application not deployed to JBoss. It runs on a separate Tomcat instance. The app knows the address of the portal, knows the username and credentials, I can establish whatever trust relationship I need between the app and the portal.

More detailed description: I have a Google Gadget and I want to create a button in my application that will add the gadget as a portlet to my portal. So the user opens my app, clicks the Add to Panel button, and the Google gadget is added to the portal's dashboard.

-1


source to share


1 answer


Hope this code helps:



   //container
    container = (CustomizationManager)MBeanProxy.get(CustomizationManager.class, new ObjectName("portal:service=CustomizationManager"), MBeanServerLocator.locateJBoss());

    //transaction manager
    tm = (TransactionManager) new InitialContext().lookup("java:/TransactionManager");      

    tm.begin();

    //dashboard
    dashboard = container.getDashboard(new org.jboss.portal.identity.User() {

        public boolean validatePassword(String arg0) {
            return false;
        }

        public void updatePassword(String arg0) throws IdentityException {
        }

        public String getUserName() {
            return userId;
        }

        public Object getId() {
            return null;
        }
    });     
    System.out.println("!!! Portlal: " + dashboard.toString());

    //default page
    defaultPage = dashboard.getPage("default");
    System.out.println("!!! Page: " + defaultPage.toString());

    //gets page windows
    Collection<PortalObject> objects = defaultPage.getChildren();
    if (objects != null && objects.size() > 0) {
        for (PortalObject object : objects) {
            System.out.println("!!! PageChild: " + object.getName());
            System.out.println("!!! WindowRegion: " + object.getDeclaredProperty("theme.region"));

            String windowPortletName = object.getDeclaredProperty("portletName");

            if (StringUtils.equals(object.getDeclaredProperty("theme.region"), "column1"))
            {
                column1Windows.add(object.getName());

                System.out.println("!!! Column1Window: " + object.getName());
                System.out.println("!!! Column1WindowPortletName: " + object.getDeclaredProperty("portletName"));

                //removes from portlets list if already exists
                Iterator iterator = portlets.iterator();
                while (iterator.hasNext())
                {
                    Portlet tempPortlet = (Portlet) iterator.next();
                    if (StringUtils.equals(tempPortlet.getSystemName(), windowPortletName))
                    {
                        iterator.remove();
                    }                       
                }
            }
            else if (StringUtils.equals(object.getDeclaredProperty("theme.region"), "column2"))
            {
                column2Windows.add(object.getName());
                System.out.println("!!! Column2Window: " + object.getName());

                //removes from portlets list if already exists
                Iterator iterator = portlets.iterator();
                while (iterator.hasNext())
                {
                    Portlet tempPortlet = (Portlet) iterator.next();
                    if (StringUtils.equals(tempPortlet.getSystemName(), windowPortletName))
                    {
                        iterator.remove();
                    }                       
                }

            }
        }
    }

    tm.commit();        

      

+3


source







All Articles