Author: julien(a)jboss.com
Date: 2008-02-09 11:11:20 -0500 (Sat, 09 Feb 2008)
New Revision: 9902
Added:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/PortalResponse.java
Log:
PageEventControllerContext that use the page structure to route events (thanks Chris, I
totally missed the use case)
Added:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/PortalResponse.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/PortalResponse.java
(rev 0)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/PortalResponse.java 2008-02-09
16:11:20 UTC (rev 9902)
@@ -0,0 +1,122 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, 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.jboss.portal.portlet.test.jsp;
+
+import org.jboss.portal.portlet.Portlet;
+import org.jboss.portal.portlet.PortletInvoker;
+import org.jboss.portal.portlet.PortletInvokerException;
+import org.jboss.portal.portlet.info.PortletInfo;
+
+import javax.servlet.http.HttpServletResponseWrapper;
+import javax.servlet.http.HttpServletResponse;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class PortalResponse extends HttpServletResponseWrapper
+{
+
+ /** . */
+ private final PortletInvoker invoker;
+
+ /** . */
+ private final Map<Key, Portlet> portlets;
+
+ /** . */
+ private int count = 0;
+
+ public PortalResponse(
+ HttpServletResponse response,
+ PortletInvoker invoker) throws PortletInvokerException
+ {
+ super(response);
+
+ //
+ Map<Key, Portlet> portlets = new HashMap<Key, Portlet>();
+ for (Portlet portlet : invoker.getPortlets())
+ {
+ PortletInfo portletInfo = portlet.getInfo();
+ String portletName = portletInfo.getName();
+ String applicationName = portletInfo.getApplicationName();
+ Key key = new Key(applicationName, portletName);
+ portlets.put(key, portlet);
+ }
+
+ //
+ this.portlets = portlets;
+ this.invoker = invoker;
+ }
+
+ public PortletInvoker getInvoker()
+ {
+ return invoker;
+ }
+
+ public Portlet findPortlet(String applicationName, String portletName)
+ {
+ return portlets.get(new Key(applicationName, portletName));
+ }
+
+ public String nextId()
+ {
+ return "" + count++;
+ }
+
+ private static class Key
+ {
+
+ /** . */
+ private final String applicationName;
+
+ /** . */
+ private final String portletName;
+
+ private Key(String applicationName, String portletName)
+ {
+ this.applicationName = applicationName;
+ this.portletName = portletName;
+ }
+
+ public boolean equals(Object obj)
+ {
+ if (obj == this)
+ {
+ return true;
+ }
+ if (obj instanceof Key)
+ {
+ Key that = (Key)obj;
+ return applicationName.equals(that.applicationName) &&
portletName.equals(that.portletName);
+ }
+ return false;
+ }
+
+ public int hashCode()
+ {
+ return applicationName.hashCode() + portletName.hashCode();
+ }
+ }
+}