Author: thomas.heute(a)jboss.com
Date: 2010-10-22 11:31:45 -0400 (Fri, 22 Oct 2010)
New Revision: 4772
Added:
epp/portal/branches/EPP_5_1_Branch/component/wsrp/src/main/java/org/gatein/portal/wsrp/MOPConsumerStructureProvider.java
Removed:
epp/portal/branches/EPP_5_1_Branch/component/wsrp/src/main/java/org/gatein/portal/wsrp/MOPPortalStructureProvider.java
Modified:
epp/portal/branches/EPP_5_1_Branch/component/pc/src/main/java/org/exoplatform/portal/pc/ExoKernelIntegration.java
epp/portal/branches/EPP_5_1_Branch/component/wsrp/src/main/java/org/gatein/portal/wsrp/WSRPServiceIntegration.java
epp/portal/branches/EPP_5_1_Branch/pom.xml
epp/portal/branches/EPP_5_1_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortlet.java
epp/portal/branches/EPP_5_1_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortletActionListener.java
Log:
JBEPP-557: WSRP update
Modified:
epp/portal/branches/EPP_5_1_Branch/component/pc/src/main/java/org/exoplatform/portal/pc/ExoKernelIntegration.java
===================================================================
---
epp/portal/branches/EPP_5_1_Branch/component/pc/src/main/java/org/exoplatform/portal/pc/ExoKernelIntegration.java 2010-10-22
14:58:50 UTC (rev 4771)
+++
epp/portal/branches/EPP_5_1_Branch/component/pc/src/main/java/org/exoplatform/portal/pc/ExoKernelIntegration.java 2010-10-22
15:31:45 UTC (rev 4772)
@@ -159,4 +159,9 @@
portletApplicationRegistry.stop();
}
}
+
+ public PortletApplicationDeployer getPortletApplicationRegistry()
+ {
+ return portletApplicationRegistry;
+ }
}
Copied:
epp/portal/branches/EPP_5_1_Branch/component/wsrp/src/main/java/org/gatein/portal/wsrp/MOPConsumerStructureProvider.java
(from rev 4643,
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/MOPConsumerStructureProvider.java)
===================================================================
---
epp/portal/branches/EPP_5_1_Branch/component/wsrp/src/main/java/org/gatein/portal/wsrp/MOPConsumerStructureProvider.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_Branch/component/wsrp/src/main/java/org/gatein/portal/wsrp/MOPConsumerStructureProvider.java 2010-10-22
15:31:45 UTC (rev 4772)
@@ -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 <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class MOPConsumerStructureProvider implements ConsumerStructureProvider
+{
+ private final POMSessionManager pomManager;
+ private Map<String, PageInfo> pageInfos;
+ private Map<String, String> windowIdToUUIDs;
+
+ public MOPConsumerStructureProvider(ExoContainer container)
+ {
+ pomManager =
(POMSessionManager)container.getComponentInstanceOfType(POMSessionManager.class);
+ windowIdToUUIDs = new HashMap<String, String>();
+ }
+
+ public List<String> getPageIdentifiers()
+ {
+ if (pageInfos == null)
+ {
+ POMSession session = pomManager.getSession();
+ Workspace workspace = session.getWorkspace();
+ Collection<Site> sites = workspace.getSites(ObjectType.PORTAL_SITE);
+
+ pageInfos = new HashMap<String, PageInfo>();
+ for (Site site : sites)
+ {
+ Page page = site.getRootPage().getChild("pages");
+ if (page != null)
+ {
+ processPage(page, true);
+ }
+ }
+ }
+
+ LinkedList<String> identifiers = new
LinkedList<String>(pageInfos.keySet());
+ Collections.sort(identifiers);
+ return identifiers;
+ }
+
+ private void processPage(Page page, boolean ignoreCurrent)
+ {
+ if (!ignoreCurrent)
+ {
+ Described described = page.adapt(Described.class);
+ PageInfo pageInfo = new PageInfo(page.getObjectId());
+ pageInfos.put(described.getName(), pageInfo);
+ UIContainer container = page.getRootComponent();
+ processContainer(container, pageInfo);
+ }
+
+ Collection<Page> children = page.getChildren();
+ if (ParameterValidation.existsAndIsNotEmpty(children))
+ {
+ for (Page child : children)
+ {
+ processPage(child, false);
+ }
+ }
+ }
+
+ public List<String> getWindowIdentifiersFor(String pageId)
+ {
+ PageInfo pageInfo = pageInfos.get(pageId);
+ ParameterValidation.throwIllegalArgExceptionIfNull(pageInfo, "PageInfo for
" + pageId);
+
+ return pageInfo.getChildrenWindows();
+ }
+
+ private void processContainer(UIContainer container, PageInfo pageInfo)
+ {
+ List<UIComponent> components = container.getComponents();
+ for (UIComponent component : components)
+ {
+ ObjectType<? extends UIComponent> type = component.getObjectType();
+ if (ObjectType.WINDOW.equals(type))
+ {
+ Described described = component.adapt(Described.class);
+ String name = 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 = windowIdToUUIDs.get(windowId);
+ ParameterValidation.throwIllegalArgExceptionIfNull(uuid, "UUID for " +
windowId);
+
+ // get the window
+ POMSession session = pomManager.getSession();
+ UIWindow window = session.findObjectById(ObjectType.WINDOW, uuid);
+
+ // construct the new customization state
+ WSRP wsrp = new WSRP();
+ String portletId = portletContext.getId();
+ wsrp.setPortletId(portletId);
+ if (portletContext instanceof StatefulPortletContext)
+ {
+ StatefulPortletContext context = (StatefulPortletContext)portletContext;
+ if (PortletStateType.OPAQUE.equals(context.getType()))
+ {
+ wsrp.setState((byte[])context.getState());
+ }
+ else
+ {
+ throw new IllegalArgumentException("Don't know how to deal with
state: " + context.getState());
+ }
+ }
+
+ // destroy existing customization as otherwise re-customizing will fail
+ Customization<?> customization = 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 resulting in an
error
+ Page page = window.getPage();
+ session.scheduleForEviction(new PageKey("portal",
page.getSite().getName(), page.getName()));
+
+ // save
+ session.close(true);
+ }
+
+ private static class PageInfo
+ {
+ private String uuid;
+ private List<String> childrenWindows;
+
+ private PageInfo(String uuid)
+ {
+ this.uuid = uuid;
+ childrenWindows = new LinkedList<String>();
+ }
+
+ public String getUUID()
+ {
+ return uuid;
+ }
+
+ public List<String> getChildrenWindows()
+ {
+ return childrenWindows;
+ }
+
+ public void addWindow(String windowName)
+ {
+ childrenWindows.add(windowName);
+ }
+ }
+}
Deleted:
epp/portal/branches/EPP_5_1_Branch/component/wsrp/src/main/java/org/gatein/portal/wsrp/MOPPortalStructureProvider.java
===================================================================
---
epp/portal/branches/EPP_5_1_Branch/component/wsrp/src/main/java/org/gatein/portal/wsrp/MOPPortalStructureProvider.java 2010-10-22
14:58:50 UTC (rev 4771)
+++
epp/portal/branches/EPP_5_1_Branch/component/wsrp/src/main/java/org/gatein/portal/wsrp/MOPPortalStructureProvider.java 2010-10-22
15:31:45 UTC (rev 4772)
@@ -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 <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
- * @version $Revision$
- */
-public class MOPPortalStructureProvider implements ConsumerStructureProvider
-{
- private final POMSessionManager pomManager;
- private Map<String, PageInfo> pageInfos;
- private Map<String, String> windowIdToUUIDs;
-
- public MOPPortalStructureProvider(ExoContainer container)
- {
- pomManager =
(POMSessionManager)container.getComponentInstanceOfType(POMSessionManager.class);
- windowIdToUUIDs = new HashMap<String, String>();
- }
-
- public List<String> getPageIdentifiers()
- {
- if (pageInfos == null)
- {
- POMSession session = pomManager.getSession();
- Workspace workspace = session.getWorkspace();
- Collection<Site> sites = workspace.getSites(ObjectType.PORTAL_SITE);
-
- pageInfos = new HashMap<String, PageInfo>();
- for (Site site : sites)
- {
- Page page = site.getRootPage().getChild("pages");
- if (page != null)
- {
- processPage(page, true);
- }
- }
- }
-
- LinkedList<String> identifiers = new
LinkedList<String>(pageInfos.keySet());
- Collections.sort(identifiers);
- return identifiers;
- }
-
- private void processPage(Page page, boolean ignoreCurrent)
- {
- if (!ignoreCurrent)
- {
- Described described = page.adapt(Described.class);
- PageInfo pageInfo = new PageInfo(page.getObjectId());
- pageInfos.put(described.getName(), pageInfo);
- UIContainer container = page.getRootComponent();
- processContainer(container, pageInfo);
- }
-
- Collection<Page> children = page.getChildren();
- if (ParameterValidation.existsAndIsNotEmpty(children))
- {
- for (Page child : children)
- {
- processPage(child, false);
- }
- }
- }
-
- public List<String> getWindowIdentifiersFor(String pageId)
- {
- PageInfo pageInfo = pageInfos.get(pageId);
- ParameterValidation.throwIllegalArgExceptionIfNull(pageInfo, "PageInfo for
" + pageId);
-
- return pageInfo.getChildrenWindows();
- }
-
- private void processContainer(UIContainer container, PageInfo pageInfo)
- {
- List<UIComponent> components = container.getComponents();
- for (UIComponent component : components)
- {
- ObjectType<? extends UIComponent> type = component.getObjectType();
- if (ObjectType.WINDOW.equals(type))
- {
- Described described = component.adapt(Described.class);
- String name = 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 = windowIdToUUIDs.get(windowId);
- ParameterValidation.throwIllegalArgExceptionIfNull(uuid, "UUID for " +
windowId);
-
- // get the window
- POMSession session = pomManager.getSession();
- UIWindow window = session.findObjectById(ObjectType.WINDOW, uuid);
-
- // construct the new customization state
- WSRP wsrp = new WSRP();
- String portletId = portletContext.getId();
- wsrp.setPortletId(portletId);
- if (portletContext instanceof StatefulPortletContext)
- {
- StatefulPortletContext context = (StatefulPortletContext)portletContext;
- if (PortletStateType.OPAQUE.equals(context.getType()))
- {
- wsrp.setState((byte[])context.getState());
- }
- else
- {
- throw new IllegalArgumentException("Don't know how to deal with
state: " + context.getState());
- }
- }
-
- // destroy existing customization as otherwise re-customizing will fail
- Customization<?> customization = 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 resulting in an
error
- Page page = window.getPage();
- session.scheduleForEviction(new PageKey("portal",
page.getSite().getName(), page.getName()));
-
- // save
- session.close(true);
- }
-
- private static class PageInfo
- {
- private String uuid;
- private List<String> childrenWindows;
-
- private PageInfo(String uuid)
- {
- this.uuid = uuid;
- childrenWindows = new LinkedList<String>();
- }
-
- public String getUUID()
- {
- return uuid;
- }
-
- public List<String> getChildrenWindows()
- {
- return childrenWindows;
- }
-
- public void addWindow(String windowName)
- {
- childrenWindows.add(windowName);
- }
- }
-}
Modified:
epp/portal/branches/EPP_5_1_Branch/component/wsrp/src/main/java/org/gatein/portal/wsrp/WSRPServiceIntegration.java
===================================================================
---
epp/portal/branches/EPP_5_1_Branch/component/wsrp/src/main/java/org/gatein/portal/wsrp/WSRPServiceIntegration.java 2010-10-22
14:58:50 UTC (rev 4771)
+++
epp/portal/branches/EPP_5_1_Branch/component/wsrp/src/main/java/org/gatein/portal/wsrp/WSRPServiceIntegration.java 2010-10-22
15:31:45 UTC (rev 4772)
@@ -27,12 +27,15 @@
import org.exoplatform.container.ExoContainerContext;
import org.exoplatform.container.configuration.ConfigurationManager;
import org.exoplatform.container.xml.InitParams;
+import org.exoplatform.portal.pc.ExoKernelIntegration;
import org.exoplatform.services.jcr.ext.hierarchy.NodeHierarchyCreator;
import org.exoplatform.services.listener.ListenerService;
import org.gatein.common.logging.Logger;
import org.gatein.common.logging.LoggerFactory;
import org.gatein.pc.api.PortletInvoker;
import org.gatein.pc.federation.FederatingPortletInvoker;
+import org.gatein.pc.portlet.PortletInvokerInterceptor;
+import org.gatein.pc.portlet.aspects.EventPayloadInterceptor;
import org.gatein.pc.portlet.container.ContainerPortletInvoker;
import org.gatein.pc.portlet.impl.state.StateConverterV0;
import org.gatein.pc.portlet.impl.state.StateManagementPolicyService;
@@ -58,6 +61,7 @@
import org.gatein.wsrp.consumer.migration.MigrationService;
import org.gatein.wsrp.consumer.registry.ActivatingNullInvokerHandler;
import org.gatein.wsrp.consumer.registry.ConsumerRegistry;
+import org.gatein.wsrp.payload.WSRPEventPayloadInterceptor;
import org.gatein.wsrp.producer.ProducerHolder;
import org.gatein.wsrp.producer.WSRPPortletInvoker;
import org.gatein.wsrp.producer.WSRPProducer;
@@ -85,11 +89,12 @@
private ConsumerRegistry consumerRegistry;
private ExoContainer container;
+ private final ExoKernelIntegration exoKernelIntegration;
private final boolean bypass;
private static final String WSRP_ADMIN_GUI_CONTEXT_PATH =
"/wsrp-admin-gui";
public WSRPServiceIntegration(ExoContainerContext context, InitParams params,
ConfigurationManager configurationManager,
- org.exoplatform.portal.pc.ExoKernelIntegration pc,
NodeHierarchyCreator nhc) throws Exception
+ ExoKernelIntegration pc, NodeHierarchyCreator nhc)
throws Exception
{
// IMPORTANT: even though PC ExoKernelIntegration and NodeHierarchyCreator is not
used anywhere in the code, it's still needed for pico
// to properly make sure that this service is started after the PC one. Yes, Pico
is crap. :/
@@ -114,6 +119,8 @@
container = context.getContainer();
+ exoKernelIntegration = pc;
+
bypass = false;
}
else
@@ -124,6 +131,7 @@
producerConfigLocation = null;
consumersConfigLocation = null;
configurationIS = null;
+ exoKernelIntegration = null;
bypass = true;
}
}
@@ -177,6 +185,39 @@
ContainerPortletInvoker containerPortletInvoker =
(ContainerPortletInvoker)container.getComponentInstanceOfType(ContainerPortletInvoker.class);
+ // iterate over the container stack so that we can insert the WSRP-specific event
payload interceptor
+ PortletInvokerInterceptor previous = containerPortletInvoker;
+ PortletInvokerInterceptor next = previous;
+ do
+ {
+ PortletInvoker invoker = previous.getNext();
+ if (invoker instanceof EventPayloadInterceptor)
+ {
+ // create a new WSRPEventPayloadInterceptor and make its next one the current
event payload invoker
+ WSRPEventPayloadInterceptor eventPayloadInterceptor = new
WSRPEventPayloadInterceptor();
+ eventPayloadInterceptor.setNext(invoker);
+
+ // replace the current event payload interceptor by the WSRP-specific one
+ previous.setNext(eventPayloadInterceptor);
+
+ // we're done
+ break;
+ }
+ else
+ {
+ previous = next;
+ if (invoker instanceof PortletInvokerInterceptor)
+ {
+ next = (PortletInvokerInterceptor)invoker;
+ }
+ else
+ {
+ next = null;
+ }
+ }
+ }
+ while (next != null);
+
// The producer persistence manager
PortletStatePersistenceManager producerPersistenceManager;
try
@@ -201,17 +242,18 @@
producerPortletInvoker.setPersistenceManager(producerPersistenceManager);
producerPortletInvoker.setStateManagementPolicy(producerStateManagementPolicy);
producerPortletInvoker.setStateConverter(producerStateConverter);
-
+
WSRPPortletInvoker wsrpPortletInvoker = new WSRPPortletInvoker();
wsrpPortletInvoker.setNext(producerPortletInvoker);
wsrpPortletInvoker.setRegistrationManager(registrationManager);
-
+
// create and wire WSRP producer
producer = ProducerHolder.getProducer(true);
producer.setPortletInvoker(wsrpPortletInvoker);
producer.setRegistrationManager(registrationManager);
producer.setConfigurationService(producerConfigurationService);
+ exoKernelIntegration.getPortletApplicationRegistry().addListener(producer);
producer.start();
}
@@ -238,7 +280,7 @@
// migration service
MigrationService migrationService = new JCRMigrationService(container);
- migrationService.setStructureProvider(new
MOPPortalStructureProvider(container));
+ migrationService.setStructureProvider(new
MOPConsumerStructureProvider(container));
consumerRegistry.setMigrationService(migrationService);
consumerRegistry.start();
Modified: epp/portal/branches/EPP_5_1_Branch/pom.xml
===================================================================
--- epp/portal/branches/EPP_5_1_Branch/pom.xml 2010-10-22 14:58:50 UTC (rev 4771)
+++ epp/portal/branches/EPP_5_1_Branch/pom.xml 2010-10-22 15:31:45 UTC (rev 4772)
@@ -46,9 +46,9 @@
<nl.captcha.simplecaptcha.version>1.1.1-GA-Patch01</nl.captcha.simplecaptcha.version>
<org.gatein.common.version>2.0.3-GA</org.gatein.common.version>
<org.gatein.wci.version>2.0.2-GA</org.gatein.wci.version>
- <org.gatein.pc.version>2.2.0-Beta05</org.gatein.pc.version>
+ <org.gatein.pc.version>2.2.0-Beta06</org.gatein.pc.version>
<org.picketlink.idm>1.1.6.GA</org.picketlink.idm>
- <org.gatein.wsrp.version>2.0.0-Beta01</org.gatein.wsrp.version>
+ <org.gatein.wsrp.version>2.0.0-Beta03</org.gatein.wsrp.version>
<org.gatein.mop.version>1.0.3-GA</org.gatein.mop.version>
<org.slf4j.version>1.5.6</org.slf4j.version>
<rhino.version>1.6R5</rhino.version>
Modified:
epp/portal/branches/EPP_5_1_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortlet.java
===================================================================
---
epp/portal/branches/EPP_5_1_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortlet.java 2010-10-22
14:58:50 UTC (rev 4771)
+++
epp/portal/branches/EPP_5_1_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortlet.java 2010-10-22
15:31:45 UTC (rev 4772)
@@ -50,6 +50,7 @@
import org.exoplatform.webui.event.Event.Phase;
import org.gatein.common.i18n.LocalizedString;
import org.gatein.common.net.media.MediaType;
+import org.gatein.common.util.ParameterValidation;
import org.gatein.pc.api.Mode;
import org.gatein.pc.api.NoSuchPortletException;
import org.gatein.pc.api.PortletContext;
@@ -78,6 +79,11 @@
import org.gatein.pc.portlet.impl.spi.AbstractServerContext;
import org.gatein.pc.portlet.impl.spi.AbstractWindowContext;
+import javax.portlet.PortletMode;
+import javax.portlet.WindowState;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.xml.namespace.QName;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
@@ -88,16 +94,10 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
-import java.util.Map.Entry;
-import javax.portlet.PortletMode;
-import javax.portlet.WindowState;
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletRequest;
-import javax.xml.namespace.QName;
-
/** May 19, 2006 */
@ComponentConfig(lifecycle = UIPortletLifecycle.class, template =
"system:/groovy/portal/webui/application/UIPortlet.gtmpl", events = {
@EventConfig(listeners = RenderActionListener.class),
@@ -114,6 +114,10 @@
protected static final Log log = ExoLogger.getLogger("portal:UIPortlet");
static final public String DEFAULT_THEME =
"Default:DefaultTheme::Vista:VistaTheme::Mac:MacTheme";
+ private static final String WSRP_URL = "wsrp-url";
+ private static final String WSRP_PREFER_OPERATION = "wsrp-preferOperation";
+ private static final String WSRP_REQUIRES_REWRITE = "wsrp-requiresRewrite";
+ private static final String WSRP_NAVIGATIONAL_VALUES =
"wsrp-navigationalValues";
/** . */
private String storageId;
@@ -161,9 +165,9 @@
private StateString navigationalState;
- /** A field storing localized value of javax.portlet.title **/
+ /** A field storing localized value of javax.portlet.title * */
private String configuredTitle;
-
+
public UIPortlet()
{
// That value will be overriden when it is mapped onto a data storage
@@ -395,19 +399,17 @@
}
else
{
- String value = null;
- if (displayName != null)
+ RequestContext i = PortalRequestContext.getCurrentInstance();
+ Locale locale = i.getLocale();
+ String value = displayName.getString(locale, true);
+
+ if (ParameterValidation.isNullOrEmpty(value))
{
- RequestContext i = PortalRequestContext.getCurrentInstance();
- Locale locale = i.getLocale();
- value = displayName.getString(locale, true);
- }
- if (value == null || value.length() == 0)
- {
org.gatein.pc.api.Portlet portlet = getProducedOfferedPortlet();
PortletInfo info = portlet.getInfo();
value = info.getName();
}
+
return value;
}
}
@@ -435,11 +437,9 @@
}
Set<ModeInfo> modes =
portlet.getInfo().getCapabilities().getModes(MediaType.create("text/html"));
- Iterator<ModeInfo> modeIter = modes.iterator();
- while (modeIter.hasNext())
+ for (ModeInfo mode : modes)
{
- ModeInfo info = modeIter.next();
- supportModes.add(info.getModeName());
+ supportModes.add(mode.getModeName());
}
if (supportModes.size() > 0)
@@ -485,16 +485,21 @@
supportedProcessingEvents_ = new
ArrayList<QName>(consumedEvents.keySet());
}
- for (Iterator<QName> iter = supportedProcessingEvents_.iterator();
iter.hasNext();)
+ for (QName eventName : supportedProcessingEvents_)
{
- QName eventName = iter.next();
if (eventName.equals(name))
{
- log.info("The Portlet " + producerOfferedPortletContext + "
supports comsuming the event : " + name);
+ if (log.isDebugEnabled())
+ {
+ log.debug("The Portlet " + producerOfferedPortletContext +
" supports comsuming the event : " + name);
+ }
return true;
}
}
- log.info("The portlet " + producerOfferedPortletContext + "
doesn't support consuming the event : " + name);
+ if (log.isDebugEnabled())
+ {
+ log.debug("The portlet " + producerOfferedPortletContext + "
doesn't support consuming the event : " + name);
+ }
return false;
}
@@ -521,16 +526,21 @@
supportedPublishingEvents_ = new
ArrayList<QName>(producedEvents.keySet());
}
- for (Iterator<QName> iter = supportedPublishingEvents_.iterator();
iter.hasNext();)
+ for (QName eventName : supportedPublishingEvents_)
{
- QName eventName = iter.next();
if (eventName.equals(name))
{
- log.info("The Portlet " + producerOfferedPortletContext + "
supports producing the event : " + name);
+ if (log.isDebugEnabled())
+ {
+ log.debug("The Portlet " + producerOfferedPortletContext +
" supports producing the event : " + name);
+ }
return true;
}
}
- log.info("The portlet " + producerOfferedPortletContext + "
doesn't support producing the event : " + name);
+ if (log.isDebugEnabled())
+ {
+ log.debug("The portlet " + producerOfferedPortletContext + "
doesn't support producing the event : " + name);
+ }
return false;
}
@@ -654,7 +664,7 @@
Map<String, String[]> publicParams = uiPortal.getPublicParameters();
Set<String> allPublicParamsNames = publicParams.keySet();
List<String> supportedPublicParamNames = getPublicRenderParamNames();
-
+
for (String oneOfAllParams : allPublicParamsNames)
{
if (supportedPublicParamNames.contains(oneOfAllParams))
@@ -662,14 +672,14 @@
publicParamsMap.put(oneOfAllParams, publicParams.get(oneOfAllParams));
}
}
-
+
// Handle exposed portal contextual properties
ContextualPropertyManager propertyManager =
this.getApplicationComponent(ContextualPropertyManager.class);
Map<QName, String[]> exposedPortalState =
propertyManager.getProperties(this);
- for(QName prpQName : exposedPortalState.keySet())
+ for (QName prpQName : exposedPortalState.keySet())
{
String prpId = supportsPublicParam(prpQName);
- if(prpId != null)
+ if (prpId != null)
{
publicParamsMap.put(prpId, exposedPortalState.get(prpQName));
}
@@ -704,7 +714,6 @@
if (type.equals(ActionInvocation.class))
{
ActionInvocation actionInvocation = new ActionInvocation(pic);
- actionInvocation.setForm(allParams);
actionInvocation.setRequestContext(new AbstractRequestContext(servletRequest));
String interactionState =
@@ -712,8 +721,12 @@
if (interactionState != null)
{
actionInvocation.setInteractionState(StateString.create(interactionState));
+ // remove the interaction state from remaining params
+ allParams.remove(ExoPortletInvocationContext.INTERACTION_STATE_PARAM_NAME);
}
+ actionInvocation.setForm(allParams);
+
invocation = type.cast(actionInvocation);
}
else if (type.equals(ResourceInvocation.class))
@@ -722,23 +735,49 @@
resourceInvocation.setRequestContext(new
AbstractRequestContext(servletRequest));
String resourceId =
servletRequest.getParameter(Constants.RESOURCE_ID_PARAMETER);
- if (resourceId != null)
+ if (!ParameterValidation.isNullOrEmpty(resourceId))
{
resourceInvocation.setResourceId(resourceId);
}
String cachability =
servletRequest.getParameter(Constants.CACHELEVEL_PARAMETER);
- if (cachability != null)
+ if (!ParameterValidation.isNullOrEmpty(cachability))
{
- resourceInvocation.setCacheLevel(CacheLevel.valueOf(cachability));
+ // we need to convert the given value to upper case as it might come from
WSRP in lower case
+
resourceInvocation.setCacheLevel(CacheLevel.create(cachability.toUpperCase(Locale.ENGLISH)));
}
String resourceState =
servletRequest.getParameter(ExoPortletInvocationContext.RESOURCE_STATE_PARAM_NAME);
- if (resourceState != null)
+ if (!ParameterValidation.isNullOrEmpty(resourceState))
{
resourceInvocation.setResourceState(StateString.create(resourceState));
}
+ // remove the resource state from remaining params
+ allParams.remove(ExoPortletInvocationContext.RESOURCE_STATE_PARAM_NAME);
+ // deal with WSRP-specific parameters: add them to the invocation attributes if
they exist and remove them from form params
+ String url = servletRequest.getParameter(WSRP_URL);
+ if (!ParameterValidation.isNullOrEmpty(url))
+ {
+ resourceInvocation.setAttribute(WSRP_URL, url);
+ }
+ allParams.remove(WSRP_URL);
+
+ String preferOperation = servletRequest.getParameter(WSRP_PREFER_OPERATION);
+ if (!ParameterValidation.isNullOrEmpty(preferOperation))
+ {
+ resourceInvocation.setAttribute(WSRP_PREFER_OPERATION, preferOperation);
+ }
+ allParams.remove(WSRP_PREFER_OPERATION);
+
+ String requiresRewrite = servletRequest.getParameter(WSRP_REQUIRES_REWRITE);
+ if (!ParameterValidation.isNullOrEmpty(requiresRewrite))
+ {
+ resourceInvocation.setAttribute(WSRP_REQUIRES_REWRITE, requiresRewrite);
+ }
+ allParams.remove(WSRP_REQUIRES_REWRITE);
+ // End WSRP-specific parameters handling
+
resourceInvocation.setForm(allParams);
invocation = type.cast(resourceInvocation);
@@ -759,9 +798,19 @@
// Navigational state
invocation.setNavigationalState(navigationalState);
- // Public navigational state
+ // Public navigational state
invocation.setPublicNavigationalState(this.getPublicParameters());
+ // WSRP-specific public navigational state handling needed when we have a URL
coming from template
+ String navigationalValues = servletRequest.getParameter(WSRP_NAVIGATIONAL_VALUES);
+ if(!ParameterValidation.isNullOrEmpty(navigationalValues))
+ {
+ // add to the invocation attributes so that it can be retrieved and used by the
WSRP component
+ invocation.setAttribute(WSRP_NAVIGATIONAL_VALUES, navigationalValues);
+ }
+ allParams.remove(WSRP_NAVIGATIONAL_VALUES);
+ // End WSRP-specific public navigational state handling
+
// Mode
invocation.setMode(Mode.create(getCurrentPortletMode().toString()));
@@ -770,7 +819,7 @@
StatefulPortletContext<C> preferencesPortletContext = getPortletContext();
if (preferencesPortletContext == null)
- {
+ {
return null;
}
@@ -859,22 +908,24 @@
ModelAdapter<S, C> adapter =
ModelAdapter.getAdapter(state.getApplicationType());
PortletContext producerOfferedPortletContext =
adapter.getProducerOfferedPortletContext(applicationId);
org.gatein.pc.api.Portlet producedOfferedPortlet;
-
+
try
{
- producedOfferedPortlet =
portletInvoker.getPortlet(producerOfferedPortletContext);
+ producedOfferedPortlet =
portletInvoker.getPortlet(producerOfferedPortletContext);
}
catch (NoSuchPortletException nspe)
{
- producedOfferedPortlet = null;
- nspe.printStackTrace();
+ producedOfferedPortlet = null;
+ nspe.printStackTrace();
}
-
+
this.adapter = adapter;
this.producerOfferedPortletContext = producerOfferedPortletContext;
this.producedOfferedPortlet = producedOfferedPortlet;
this.applicationId = applicationId;
- } catch(NoSuchDataException de){
+ }
+ catch (NoSuchDataException de)
+ {
log.error(de.getMessage());
throw de;
}
@@ -966,37 +1017,38 @@
{
this.navigationalState = navigationalState;
}
-
+
protected void setConfiguredTitle(String _configuredTitle)
{
- this.configuredTitle = _configuredTitle;
+ this.configuredTitle = _configuredTitle;
}
-
+
/**
* Returns the title showed on the InfoBar. The title is computed in following
manner.
- *
- * 1. First, the method getTitle(), inherited from UIPortalComponent is called. The
getTitle() returns
- * what users set in the PortletSetting tab, the current method returns call result if
it is not null.
- *
+ * <p/>
+ * 1. First, the method getTitle(), inherited from UIPortalComponent is called. The
getTitle() returns what users set
+ * in the PortletSetting tab, the current method returns call result if it is not
null.
+ * <p/>
* 2. configuredTitle, which is the localized value of javax.portlet.title is returned
if it is not null.
- *
- * 3. If the method does not terminate at neither (1) nor (2), the configured display
name is returned.
+ * <p/>
+ * 3. If the method does not terminate at neither (1) nor (2), the configured display
name is returned.
+ *
* @return
*/
public String getDisplayTitle()
{
- String displayedTitle = getTitle();
- if(displayedTitle != null && displayedTitle.trim().length() > 0)
- {
- return displayedTitle;
- }
-
- if(configuredTitle != null)
- {
- return configuredTitle;
- }
-
- return getDisplayName();
-
+ String displayedTitle = getTitle();
+ if (displayedTitle != null && displayedTitle.trim().length() > 0)
+ {
+ return displayedTitle;
+ }
+
+ if (configuredTitle != null)
+ {
+ return configuredTitle;
+ }
+
+ return getDisplayName();
+
}
}
\ No newline at end of file
Modified:
epp/portal/branches/EPP_5_1_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortletActionListener.java
===================================================================
---
epp/portal/branches/EPP_5_1_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortletActionListener.java 2010-10-22
14:58:50 UTC (rev 4771)
+++
epp/portal/branches/EPP_5_1_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortletActionListener.java 2010-10-22
15:31:45 UTC (rev 4772)
@@ -1,5 +1,9 @@
-/**
- * Copyright (C) 2009 eXo Platform SAS.
+/*
+ * 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
@@ -59,7 +63,6 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.namespace.QName;
-
import java.io.IOException;
import java.io.OutputStream;
import java.io.Serializable;
@@ -97,10 +100,19 @@
HttpServletRequest request = prcontext.getRequest();
setupPublicRenderParams(uiPortlet, request.getParameterMap());
+ // set the navigational state
+ String navState =
prcontext.getRequestParameter(ExoPortletInvocationContext.NAVIGATIONAL_STATE_PARAM_NAME);
+ if (navState != null)
+ {
+ uiPortlet.setNavigationalState(ParametersStateString.create(navState));
+ }
+
//
ActionInvocation actionInvocation = uiPortlet.create(ActionInvocation.class,
prcontext);
if (actionInvocation == null)
+ {
return;
+ }
//
PortletInvocationResponse portletResponse = uiPortlet.invoke(actionInvocation);
@@ -131,7 +143,7 @@
uiPortlet.update((C)wsrp);
}
}
-
+
if (portletResponse instanceof UpdateNavigationalStateResponse)
{
handleUpdateNavigationalStateResponse((UpdateNavigationalStateResponse)portletResponse,
uiPortlet, prcontext);
@@ -151,17 +163,17 @@
else
{
throw new Exception("Unexpected response type [" + portletResponse
+ "]. Expected an UpdateNavigationResponse" +
- ", a HTTPRedirectionResponse or an ErrorResponse.");
+ ", a HTTPRedirectionResponse or an ErrorResponse.");
}
}
-
-
+
+
private void handleRedirectionResponse(HTTPRedirectionResponse redirectionResponse,
HttpServletResponse response) throws IOException
{
String redirectionURL = redirectionResponse.getLocation();
response.sendRedirect(redirectionURL);
}
-
+
private void handleUpdateNavigationalStateResponse(UpdateNavigationalStateResponse
navStateResponse, UIPortlet<S, C> uiPortlet, PortalRequestContext prcontext) throws
Exception
{
/*
@@ -187,7 +199,10 @@
//
StateString navigationalState = navStateResponse.getNavigationalState();
- uiPortlet.setNavigationalState(navigationalState);
+ if (navigationalState != null)
+ {
+ uiPortlet.setNavigationalState(navigationalState);
+ }
// update the public render parameters with the changes from the invocation
setupPublicRenderParams(uiPortlet,
navStateResponse.getPublicNavigationalStateUpdates());
@@ -248,12 +263,12 @@
}
}
-
+
private void handleErrorResponse(ErrorResponse response) throws Exception
{
- throw (Exception)response.getCause();
+ throw (Exception)response.getCause();
}
-
+
private void handleSecurityResponse(SecurityResponse response) throws Exception
{
if (response instanceof SecurityErrorResponse)
@@ -344,14 +359,26 @@
{
UIPortlet<S, C> uiPortlet = event.getSource();
log.trace("Serve Resource for portlet: " +
uiPortlet.getPortletContext());
+ String resourceId = null;
+
try
{
PortalRequestContext context =
(PortalRequestContext)event.getRequestContext();
HttpServletResponse response = context.getResponse();
+ //Set the NavigationalState
+ String navState =
context.getRequestParameter(ExoPortletInvocationContext.NAVIGATIONAL_STATE_PARAM_NAME);
+ if (navState != null)
+ {
+ uiPortlet.setNavigationalState(ParametersStateString.create(navState));
+ }
+
//
ResourceInvocation resourceInvocation =
uiPortlet.create(ResourceInvocation.class, context);
+ // set the resourceId to be used in case of a problem
+ resourceId = resourceInvocation.getResourceId();
+
//
PortletInvocationResponse portletResponse =
uiPortlet.invoke(resourceInvocation);
@@ -408,29 +435,29 @@
response.setContentType(contentType);
if (piResponse.getBytes() != null)
{
- OutputStream stream = response.getOutputStream();
- stream.write(piResponse.getBytes());
+ OutputStream stream = response.getOutputStream();
+ stream.write(piResponse.getBytes());
}
else
{
- if (piResponse.getChars() != null)
- {
- log.error("Received a content type of " + contentType + "
but it contains no bytes of data. Chars were unexpectantly returned instead : " +
piResponse.getChars());
- }
- else
- {
- log.error("Received a content type of " + contentType + "
but it contains no bytes of data.");
- }
+ if (piResponse.getChars() != null)
+ {
+ log.error("Received a content type of " + contentType +
" but it contains no bytes of data. Chars were unexpectantly returned instead :
" + piResponse.getChars());
+ }
+ else
+ {
+ log.error("Received a content type of " + contentType +
" but it contains no bytes of data.");
+ }
}
-
-
+
+
}
context.getResponse().flushBuffer();
}
catch (Exception e)
{
- log.error("Problem while serving resource for the portlet: " +
uiPortlet.getPortletContext().getId(), e);
+ log.error("Problem while serving resource " + (resourceId != null ?
resourceId : "") + " for the portlet: " +
uiPortlet.getPortletContext().getId(), e);
}
finally
{
@@ -509,7 +536,7 @@
* ProcessEventsActionListener once again
*/
public static <S, C extends Serializable, I> List<javax.portlet.Event>
processEvent(UIPortlet<S, C> uiPortlet,
- javax.portlet.Event event)
+
javax.portlet.Event event)
{
log.trace("Process Event: " + event.getName() + " for portlet:
" + uiPortlet.getState());
try
@@ -567,8 +594,12 @@
// update the portlet with the next mode to display
PortletMode mode = new PortletMode(getPortletModeOrDefault(navResponse));
setNextMode(uiPortlet, mode);
-
- uiPortlet.setNavigationalState(navResponse.getNavigationalState());
+
+ StateString navState = navResponse.getNavigationalState();
+ if (navState != null)
+ {
+ uiPortlet.setNavigationalState(navResponse.getNavigationalState());
+ }
setupPublicRenderParams(uiPortlet,
navResponse.getPublicNavigationalStateUpdates());
//TODO: (mwringe) add this to the UpdateNavigationStateResponse.Event class
instead of here
@@ -790,11 +821,11 @@
}
else if (portletMode.equals(PortletMode.VIEW.toString()))
{
- uiPortlet.setCurrentPortletMode(PortletMode.VIEW);
+ uiPortlet.setCurrentPortletMode(PortletMode.VIEW);
}
else
{
- PortletMode customMode = new PortletMode(portletMode);
+ PortletMode customMode = new PortletMode(portletMode);
uiPortlet.setCurrentPortletMode(customMode);
}
event.getRequestContext().addUIComponentToUpdateByAjax(uiPortlet);