This content has been marked as final.
Show 2 replies
-
1. Found the management interface
tomhombergs Jun 26, 2009 3:13 AM (in response to tomhombergs)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 Jun 26, 2009 8:34 AM (in response to tomhombergs)Use at your own risk! "With great power comes great responsibility!" ;)