From do-not-reply at jboss.org Tue Oct 12 10:50:07 2010 Content-Type: multipart/mixed; boundary="===============0914546473214657391==" MIME-Version: 1.0 From: do-not-reply at jboss.org To: gatein-commits at lists.jboss.org Subject: [gatein-commits] gatein SVN: r4643 - portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp. Date: Tue, 12 Oct 2010 10:50:07 -0400 Message-ID: <201010121450.o9CEo7tY012473@svn01.web.mwc.hst.phx2.redhat.com> --===============0914546473214657391== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: chris.laprun(a)jboss.com Date: 2010-10-12 10:50:06 -0400 (Tue, 12 Oct 2010) New Revision: 4643 Added: portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/MOPCons= umerStructureProvider.java Removed: portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/MOPPort= alStructureProvider.java Log: - Renamed to be more conform to interface name. Copied: portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/MO= PConsumerStructureProvider.java (from rev 4617, portal/trunk/component/wsrp= /src/main/java/org/gatein/portal/wsrp/MOPPortalStructureProvider.java) =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/MOPCon= sumerStructureProvider.java (rev 0) +++ portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/MOPCon= sumerStructureProvider.java 2010-10-12 14:50:06 UTC (rev 4643) @@ -0,0 +1,214 @@ +/* + * JBoss, a division of Red Hat + * Copyright 2010, Red Hat Middleware, LLC, and individual + * contributors as indicated by the @authors tag. See the + * copyright.txt in the distribution for a full listing of + * individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.gatein.portal.wsrp; + +import org.exoplatform.container.ExoContainer; +import org.exoplatform.portal.mop.Described; +import org.exoplatform.portal.pom.config.POMSession; +import org.exoplatform.portal.pom.config.POMSessionManager; +import org.exoplatform.portal.pom.data.PageKey; +import org.exoplatform.portal.pom.spi.wsrp.WSRP; +import org.gatein.common.util.ParameterValidation; +import org.gatein.mop.api.content.Customization; +import org.gatein.mop.api.workspace.ObjectType; +import org.gatein.mop.api.workspace.Page; +import org.gatein.mop.api.workspace.Site; +import org.gatein.mop.api.workspace.Workspace; +import org.gatein.mop.api.workspace.ui.UIComponent; +import org.gatein.mop.api.workspace.ui.UIContainer; +import org.gatein.mop.api.workspace.ui.UIWindow; +import org.gatein.pc.api.PortletContext; +import org.gatein.pc.api.PortletStateType; +import org.gatein.pc.api.StatefulPortletContext; +import org.gatein.wsrp.api.context.ConsumerStructureProvider; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +/** + * @author Chris Laprun + * @version $Revision$ + */ +public class MOPConsumerStructureProvider implements ConsumerStructureProv= ider +{ + private final POMSessionManager pomManager; + private Map pageInfos; + private Map windowIdToUUIDs; + + public MOPConsumerStructureProvider(ExoContainer container) + { + pomManager =3D (POMSessionManager)container.getComponentInstanceOfTy= pe(POMSessionManager.class); + windowIdToUUIDs =3D new HashMap(); + } + + public List getPageIdentifiers() + { + if (pageInfos =3D=3D null) + { + POMSession session =3D pomManager.getSession(); + Workspace workspace =3D session.getWorkspace(); + Collection sites =3D workspace.getSites(ObjectType.PORTAL_S= ITE); + + pageInfos =3D new HashMap(); + for (Site site : sites) + { + Page page =3D site.getRootPage().getChild("pages"); + if (page !=3D null) + { + processPage(page, true); + } + } + } + + LinkedList identifiers =3D new LinkedList(pageInfos.= keySet()); + Collections.sort(identifiers); + return identifiers; + } + + private void processPage(Page page, boolean ignoreCurrent) + { + if (!ignoreCurrent) + { + Described described =3D page.adapt(Described.class); + PageInfo pageInfo =3D new PageInfo(page.getObjectId()); + pageInfos.put(described.getName(), pageInfo); + UIContainer container =3D page.getRootComponent(); + processContainer(container, pageInfo); + } + + Collection children =3D page.getChildren(); + if (ParameterValidation.existsAndIsNotEmpty(children)) + { + for (Page child : children) + { + processPage(child, false); + } + } + } + + public List getWindowIdentifiersFor(String pageId) + { + PageInfo pageInfo =3D pageInfos.get(pageId); + ParameterValidation.throwIllegalArgExceptionIfNull(pageInfo, "PageIn= fo for " + pageId); + + return pageInfo.getChildrenWindows(); + } + + private void processContainer(UIContainer container, PageInfo pageInfo) + { + List components =3D container.getComponents(); + for (UIComponent component : components) + { + ObjectType type =3D component.getObjectTyp= e(); + if (ObjectType.WINDOW.equals(type)) + { + Described described =3D component.adapt(Described.class); + String name =3D described.getName(); + windowIdToUUIDs.put(name, component.getObjectId()); + pageInfo.addWindow(name); + } + else if (ObjectType.CONTAINER.equals(type)) + { + processContainer((UIContainer)component, pageInfo); + } + else + { + // ignore + } + } + } + + public void assignPortletToWindow(PortletContext portletContext, String= windowId, String pageId) + { + String uuid =3D windowIdToUUIDs.get(windowId); + ParameterValidation.throwIllegalArgExceptionIfNull(uuid, "UUID for "= + windowId); + + // get the window + POMSession session =3D pomManager.getSession(); + UIWindow window =3D session.findObjectById(ObjectType.WINDOW, uuid); + + // construct the new customization state + WSRP wsrp =3D new WSRP(); + String portletId =3D portletContext.getId(); + wsrp.setPortletId(portletId); + if (portletContext instanceof StatefulPortletContext) + { + StatefulPortletContext context =3D (StatefulPortletContext)portle= tContext; + if (PortletStateType.OPAQUE.equals(context.getType())) + { + wsrp.setState((byte[])context.getState()); + } + else + { + throw new IllegalArgumentException("Don't know how to deal wit= h state: " + context.getState()); + } + } + + // destroy existing customization as otherwise re-customizing will f= ail + Customization customization =3D window.getCustomization(); + customization.destroy(); + + // and re-customize + window.customize(WSRP.CONTENT_TYPE, portletId, wsrp); + + // mark page for cache invalidation otherwise DataCache will use the= previous customization id when trying to set + // the portlet state in UIPortlet.setState and will not find it resu= lting in an error + Page page =3D window.getPage(); + session.scheduleForEviction(new PageKey("portal", page.getSite().get= Name(), page.getName())); + + // save + session.close(true); + } + + private static class PageInfo + { + private String uuid; + private List childrenWindows; + + private PageInfo(String uuid) + { + this.uuid =3D uuid; + childrenWindows =3D new LinkedList(); + } + + public String getUUID() + { + return uuid; + } + + public List getChildrenWindows() + { + return childrenWindows; + } + + public void addWindow(String windowName) + { + childrenWindows.add(windowName); + } + } +} Deleted: portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/M= OPPortalStructureProvider.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/MOPPor= talStructureProvider.java 2010-10-12 14:49:04 UTC (rev 4642) +++ portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/MOPPor= talStructureProvider.java 2010-10-12 14:50:06 UTC (rev 4643) @@ -1,214 +0,0 @@ -/* - * JBoss, a division of Red Hat - * Copyright 2010, Red Hat Middleware, LLC, and individual - * contributors as indicated by the @authors tag. See the - * copyright.txt in the distribution for a full listing of - * individual contributors. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ - -package org.gatein.portal.wsrp; - -import org.exoplatform.container.ExoContainer; -import org.exoplatform.portal.mop.Described; -import org.exoplatform.portal.pom.config.POMSession; -import org.exoplatform.portal.pom.config.POMSessionManager; -import org.exoplatform.portal.pom.data.PageKey; -import org.exoplatform.portal.pom.spi.wsrp.WSRP; -import org.gatein.common.util.ParameterValidation; -import org.gatein.mop.api.content.Customization; -import org.gatein.mop.api.workspace.ObjectType; -import org.gatein.mop.api.workspace.Page; -import org.gatein.mop.api.workspace.Site; -import org.gatein.mop.api.workspace.Workspace; -import org.gatein.mop.api.workspace.ui.UIComponent; -import org.gatein.mop.api.workspace.ui.UIContainer; -import org.gatein.mop.api.workspace.ui.UIWindow; -import org.gatein.pc.api.PortletContext; -import org.gatein.pc.api.PortletStateType; -import org.gatein.pc.api.StatefulPortletContext; -import org.gatein.wsrp.api.context.ConsumerStructureProvider; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -/** - * @author Chris Laprun - * @version $Revision$ - */ -public class MOPPortalStructureProvider implements ConsumerStructureProvid= er -{ - private final POMSessionManager pomManager; - private Map pageInfos; - private Map windowIdToUUIDs; - - public MOPPortalStructureProvider(ExoContainer container) - { - pomManager =3D (POMSessionManager)container.getComponentInstanceOfTy= pe(POMSessionManager.class); - windowIdToUUIDs =3D new HashMap(); - } - - public List getPageIdentifiers() - { - if (pageInfos =3D=3D null) - { - POMSession session =3D pomManager.getSession(); - Workspace workspace =3D session.getWorkspace(); - Collection sites =3D workspace.getSites(ObjectType.PORTAL_S= ITE); - - pageInfos =3D new HashMap(); - for (Site site : sites) - { - Page page =3D site.getRootPage().getChild("pages"); - if (page !=3D null) - { - processPage(page, true); - } - } - } - - LinkedList identifiers =3D new LinkedList(pageInfos.= keySet()); - Collections.sort(identifiers); - return identifiers; - } - - private void processPage(Page page, boolean ignoreCurrent) - { - if (!ignoreCurrent) - { - Described described =3D page.adapt(Described.class); - PageInfo pageInfo =3D new PageInfo(page.getObjectId()); - pageInfos.put(described.getName(), pageInfo); - UIContainer container =3D page.getRootComponent(); - processContainer(container, pageInfo); - } - - Collection children =3D page.getChildren(); - if (ParameterValidation.existsAndIsNotEmpty(children)) - { - for (Page child : children) - { - processPage(child, false); - } - } - } - - public List getWindowIdentifiersFor(String pageId) - { - PageInfo pageInfo =3D pageInfos.get(pageId); - ParameterValidation.throwIllegalArgExceptionIfNull(pageInfo, "PageIn= fo for " + pageId); - - return pageInfo.getChildrenWindows(); - } - - private void processContainer(UIContainer container, PageInfo pageInfo) - { - List components =3D container.getComponents(); - for (UIComponent component : components) - { - ObjectType type =3D component.getObjectTyp= e(); - if (ObjectType.WINDOW.equals(type)) - { - Described described =3D component.adapt(Described.class); - String name =3D described.getName(); - windowIdToUUIDs.put(name, component.getObjectId()); - pageInfo.addWindow(name); - } - else if (ObjectType.CONTAINER.equals(type)) - { - processContainer((UIContainer)component, pageInfo); - } - else - { - // ignore - } - } - } - - public void assignPortletToWindow(PortletContext portletContext, String= windowId, String pageId) - { - String uuid =3D windowIdToUUIDs.get(windowId); - ParameterValidation.throwIllegalArgExceptionIfNull(uuid, "UUID for "= + windowId); - - // get the window - POMSession session =3D pomManager.getSession(); - UIWindow window =3D session.findObjectById(ObjectType.WINDOW, uuid); - - // construct the new customization state - WSRP wsrp =3D new WSRP(); - String portletId =3D portletContext.getId(); - wsrp.setPortletId(portletId); - if (portletContext instanceof StatefulPortletContext) - { - StatefulPortletContext context =3D (StatefulPortletContext)portle= tContext; - if (PortletStateType.OPAQUE.equals(context.getType())) - { - wsrp.setState((byte[])context.getState()); - } - else - { - throw new IllegalArgumentException("Don't know how to deal wit= h state: " + context.getState()); - } - } - - // destroy existing customization as otherwise re-customizing will f= ail - Customization customization =3D window.getCustomization(); - customization.destroy(); - - // and re-customize - window.customize(WSRP.CONTENT_TYPE, portletId, wsrp); - - // mark page for cache invalidation otherwise DataCache will use the= previous customization id when trying to set - // the portlet state in UIPortlet.setState and will not find it resu= lting in an error - Page page =3D window.getPage(); - session.scheduleForEviction(new PageKey("portal", page.getSite().get= Name(), page.getName())); - - // save - session.close(true); - } - - private static class PageInfo - { - private String uuid; - private List childrenWindows; - - private PageInfo(String uuid) - { - this.uuid =3D uuid; - childrenWindows =3D new LinkedList(); - } - - public String getUUID() - { - return uuid; - } - - public List getChildrenWindows() - { - return childrenWindows; - } - - public void addWindow(String windowName) - { - childrenWindows.add(windowName); - } - } -} --===============0914546473214657391==--