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();
| }
View the original post :
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4240212#4240212
Reply to the post :
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4240212
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user