Author: julien(a)jboss.com
Date: 2008-02-06 17:12:01 -0500 (Wed, 06 Feb 2008)
New Revision: 9811
Added:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/AbstractPortletControllerContext.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/Page.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/PagePortletControllerContext.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/Window.java
Removed:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/taglib/
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerPortletInfo.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PortletControllerContextImpl.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/ControllerServlet.java
modules/portlet/trunk/test/src/test/resources/simple-portal-war/index.jsp
Log:
more implementation of the taglib
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerPortletInfo.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerPortletInfo.java 2008-02-06
21:56:20 UTC (rev 9810)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/info/ContainerPortletInfo.java 2008-02-06
22:12:01 UTC (rev 9811)
@@ -163,7 +163,7 @@
public String getApplicationName()
{
- return null;
+ return applicationName;
}
public Map<String, ContainerOptionInfo> getOptions()
Added:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/AbstractPortletControllerContext.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/AbstractPortletControllerContext.java
(rev 0)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/AbstractPortletControllerContext.java 2008-02-06
22:12:01 UTC (rev 9811)
@@ -0,0 +1,357 @@
+/******************************************************************************
+ * 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.controller;
+
+import org.jboss.portal.Mode;
+import org.jboss.portal.WindowState;
+import org.jboss.portal.common.io.IOTools;
+import org.jboss.portal.common.util.MarkupInfo;
+import org.jboss.portal.common.util.MediaType;
+import org.jboss.portal.common.util.ParameterMap;
+import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.portlet.ContainerURL;
+import org.jboss.portal.portlet.ParametersStateString;
+import org.jboss.portal.portlet.Portlet;
+import org.jboss.portal.portlet.PortletInvokerException;
+import org.jboss.portal.portlet.StateString;
+import org.jboss.portal.portlet.cache.CacheLevel;
+import org.jboss.portal.portlet.controller.PortletControllerContext;
+import org.jboss.portal.portlet.controller.event.EventControllerContext;
+import org.jboss.portal.portlet.controller.impl.state.StateControllerContextImpl;
+import org.jboss.portal.portlet.controller.request.ControllerRequest;
+import
org.jboss.portal.portlet.controller.request.FullScopedCacheablePortletResourceRequest;
+import org.jboss.portal.portlet.controller.request.PageScopedFullPortletResourceRequest;
+import org.jboss.portal.portlet.controller.request.PortletActionRequest;
+import org.jboss.portal.portlet.controller.request.PortletRenderRequest;
+import org.jboss.portal.portlet.controller.request.PortletScopedPortletResourceRequest;
+import org.jboss.portal.portlet.controller.state.PageNavigationalState;
+import org.jboss.portal.portlet.controller.state.StateControllerContext;
+import org.jboss.portal.portlet.controller.state.WindowNavigationalState;
+import org.jboss.portal.portlet.impl.spi.AbstractClientContext;
+import org.jboss.portal.portlet.impl.spi.AbstractRequestContext;
+import org.jboss.portal.portlet.impl.spi.AbstractSecurityContext;
+import org.jboss.portal.portlet.impl.spi.AbstractServerContext;
+import org.jboss.portal.portlet.impl.spi.AbstractUserContext;
+import org.jboss.portal.portlet.impl.spi.AbstractWindowContext;
+import org.jboss.portal.portlet.info.PortletInfo;
+import org.jboss.portal.portlet.invocation.ActionInvocation;
+import org.jboss.portal.portlet.invocation.EventInvocation;
+import org.jboss.portal.portlet.invocation.PortletInvocation;
+import org.jboss.portal.portlet.invocation.ResourceInvocation;
+import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
+import org.jboss.portal.portlet.spi.PortletInvocationContext;
+import org.jboss.portal.portlet.test.StringCodec;
+import static org.jboss.portal.portlet.test.URLParameterConstants.*;
+import org.jboss.portal.web.Body;
+import org.jboss.portal.web.IllegalRequestException;
+import org.jboss.portal.web.WebRequest;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractPortletControllerContext implements
PortletControllerContext
+{
+
+ /** . */
+ public static final MarkupInfo MARKUP_INFO = new MarkupInfo(MediaType.HTML,
"UTF8");
+
+ /** . */
+ public static final int NAV_SCOPE = 0;
+
+ /** . */
+ public static final int SESSION_SCOPE = 1;
+
+ /** . */
+ private final HttpServletRequest req;
+
+ /** . */
+ private final HttpServletResponse resp;
+
+ /** . */
+ private final ServletContext servletContext;
+
+ /** . */
+ private final ControllerRequest request;
+
+ /** . */
+ private final StateControllerContextImpl stateControllerContext;
+
+ public AbstractPortletControllerContext(
+ HttpServletRequest req,
+ HttpServletResponse resp,
+ ServletContext servletContext)
+ throws IllegalRequestException, IOException, ClassNotFoundException
+ {
+ StateControllerContextImpl tmp = new StateControllerContextImpl(this);
+
+ // The nav state provided with the request
+ PageNavigationalState pageState = null;
+
+ // The request decoded if not null
+ ControllerRequest request = null;
+
+ // Process
+ String pathInfo = req.getPathInfo();
+ if (pathInfo != null && pathInfo.startsWith("/") &&
pathInfo.length() > 1)
+ {
+ // Get the target portlet
+ String targetId = StringCodec.decode(pathInfo.substring(1));
+
+ // Helper
+ WebRequest ri = new WebRequest(req);
+
+ // Unmarshall portal navigational state if it is provided
+ String context = req.getParameter(PAGE_STATE);
+ if (context != null)
+ {
+ byte[] bytes = Tools.fromHexString(context);
+ pageState = tmp.unserialize(bytes);
+ }
+
+ //
+ Mode mode = null;
+ if (req.getParameter(MODE) != null)
+ {
+ mode = Mode.create(req.getParameter(MODE));
+ }
+
+ //
+ WindowState windowState = null;
+ if (req.getParameter(WINDOW_STATE) != null)
+ {
+ windowState = WindowState.create(req.getParameter(WINDOW_STATE));
+ }
+
+ //
+ String navigationalStateString = req.getParameter(NAVIGATIONAL_STATE);
+ StateString navigationalState = null;
+ if (navigationalStateString != null)
+ {
+ navigationalState = ParametersStateString.create(navigationalStateString);
+ }
+
+ //
+ WindowNavigationalState windowNavigationalState = new
WindowNavigationalState(navigationalState, mode, windowState);
+
+ //
+ String type = req.getParameter(LIFECYCLE_TYPE);
+ if (RESOURCE_LIFECYCLE.equals(type))
+ {
+ StateString resourceState =
ParametersStateString.create(req.getParameter(RESOURCE_STATE));
+ String resourceId = req.getParameter(RESOURCE_ID);
+
+ //
+ ParameterMap formParameters = null;
+ if (ri.getBody() instanceof Body.Form)
+ {
+ formParameters = ((Body.Form)ri.getBody()).getParameters();
+ }
+
+ //
+ CacheLevel resourceCacheLevel =
CacheLevel.valueOf(req.getParameter(RESOURCE_CACHEABILITY));
+
+ //
+ switch (resourceCacheLevel)
+ {
+ case FULL:
+ request = new FullScopedCacheablePortletResourceRequest(
+ this,
+ targetId,
+ resourceId,
+ resourceState,
+ formParameters);
+ break;
+ case PORTLET:
+ request = new PortletScopedPortletResourceRequest(
+ this,
+ targetId,
+ resourceId,
+ resourceState,
+ formParameters,
+ windowNavigationalState);
+ break;
+ case PAGE:
+ request = new PageScopedFullPortletResourceRequest(
+ this,
+ targetId,
+ resourceId,
+ resourceState,
+ formParameters,
+ pageState,
+ windowNavigationalState);
+ break;
+ }
+ }
+ else
+ {
+ if (ACTION_LIFECYCLE.equals(type))
+ {
+ ParameterMap formParameters = null;
+ if (ri.getBody() instanceof Body.Form)
+ {
+ formParameters = ((Body.Form)ri.getBody()).getParameters();
+ }
+
+ //
+ StateString interactionState =
ParametersStateString.create(req.getParameter(INTERACTION_STATE));
+
+ //
+ request = new PortletActionRequest(
+ this,
+ targetId,
+ interactionState,
+ formParameters,
+ windowNavigationalState,
+ pageState);
+ }
+ else
+ {
+ Map<String, String[]> publicNavigationalStateChanges =
(Map<String,
String[]>)IOTools.unserialize(Tools.fromHexString(req.getParameter(PUBLIC_NAVIGATIONAL_STATE_CHANGES)));
+
+ //
+ request = new PortletRenderRequest(
+ this,
+ targetId,
+ windowNavigationalState,
+ publicNavigationalStateChanges,
+ pageState);
+ }
+ }
+ }
+
+ //
+ this.request = request;
+ this.req = req;
+ this.resp = resp;
+ this.servletContext = servletContext;
+ this.stateControllerContext = tmp;
+ }
+
+ public ControllerRequest getRequest()
+ {
+ return request;
+ }
+
+ public ServletContext getServletContext()
+ {
+ return servletContext;
+ }
+
+ public HttpServletRequest getClientRequest()
+ {
+ return req;
+ }
+
+ public HttpServletResponse getClientResponse()
+ {
+ return resp;
+ }
+
+ public PortletInfo getPortletInfo(String windowId) throws PortletInvokerException
+ {
+ return getPortlet(windowId).getInfo();
+ }
+
+ protected abstract Portlet getPortlet(String windowId) throws
PortletInvokerException;
+
+ protected abstract PortletInvocationResponse invoke(PortletInvocation invocation)
throws PortletInvokerException;
+
+ public abstract EventControllerContext getEventControllerContext();
+
+ public StateControllerContext getStateControllerContext()
+ {
+ return stateControllerContext;
+ }
+
+ public PortletInvocationResponse invoke(String windowId, ActionInvocation
actionInvocation) throws PortletInvokerException
+ {
+
+ Portlet portlet = getPortlet(windowId);
+
+ TestInstanceContext instanceContext = new TestInstanceContext(req,
portlet.getContext(), true);
+
+ actionInvocation.setClientContext(new AbstractClientContext(req));
+ actionInvocation.setServerContext(new AbstractServerContext(req, resp));
+ actionInvocation.setInstanceContext(instanceContext);
+ actionInvocation.setUserContext(new AbstractUserContext(req));
+ actionInvocation.setWindowContext(new
AbstractWindowContext(portlet.getContext().getId()));
+ actionInvocation.setPortalContext(new TestPortalContext());
+ actionInvocation.setSecurityContext(new AbstractSecurityContext(req));
+ actionInvocation.setRequestContext(new AbstractRequestContext(req));
+ actionInvocation.setTarget(instanceContext.getTarget());
+
+ return invoke(actionInvocation);
+ }
+
+ public PortletInvocationResponse invoke(String windowId, List<Cookie>
requestCookies, EventInvocation eventInvocation) throws PortletInvokerException
+ {
+ Portlet portlet = getPortlet(windowId);
+
+ TestInstanceContext instanceContext = new TestInstanceContext(req,
portlet.getContext(), true);
+
+ eventInvocation.setClientContext(new AbstractClientContext(req, requestCookies));
+ eventInvocation.setServerContext(new AbstractServerContext(req, resp));
+ eventInvocation.setInstanceContext(instanceContext);
+ eventInvocation.setUserContext(new AbstractUserContext(req));
+ eventInvocation.setWindowContext(new AbstractWindowContext(windowId));
+ eventInvocation.setPortalContext(new TestPortalContext());
+ eventInvocation.setSecurityContext(new AbstractSecurityContext(req));
+ eventInvocation.setTarget(instanceContext.getTarget());
+
+ return invoke(eventInvocation);
+ }
+
+ public PortletInvocationResponse invoke(String windowId, ResourceInvocation
resourceInvocation) throws PortletInvokerException
+ {
+ Portlet portlet = getPortlet(windowId);
+
+ TestInstanceContext instanceContext = new TestInstanceContext(req,
portlet.getContext(), true);
+
+ resourceInvocation.setClientContext(new AbstractClientContext(req));
+ resourceInvocation.setServerContext(new AbstractServerContext(req, resp));
+ resourceInvocation.setInstanceContext(instanceContext);
+ resourceInvocation.setUserContext(new AbstractUserContext(req));
+ resourceInvocation.setWindowContext(new
AbstractWindowContext(portlet.getContext().getId()));
+ resourceInvocation.setPortalContext(new TestPortalContext());
+ resourceInvocation.setSecurityContext(new AbstractSecurityContext(req));
+ resourceInvocation.setRequestContext(new AbstractRequestContext(req));
+ resourceInvocation.setTarget(instanceContext.getTarget());
+
+ return invoke(resourceInvocation);
+ }
+
+ public PortletInvocationContext createPortletInvocationContext(String windowId,
PageNavigationalState pageState)
+ {
+ return new TestPortletInvocationContext(stateControllerContext, req, resp,
windowId, pageState, MARKUP_INFO);
+ }
+}
\ No newline at end of file
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PortletControllerContextImpl.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PortletControllerContextImpl.java 2008-02-06
21:56:20 UTC (rev 9810)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PortletControllerContextImpl.java 2008-02-06
22:12:01 UTC (rev 9811)
@@ -83,312 +83,43 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
-public class PortletControllerContextImpl implements PortletControllerContext
+public class PortletControllerContextImpl extends AbstractPortletControllerContext
{
/** . */
- public static final MarkupInfo MARKUP_INFO = new MarkupInfo(MediaType.HTML,
"UTF8");
-
- /** . */
- public static final int NAV_SCOPE = 0;
-
- /** . */
- public static final int SESSION_SCOPE = 1;
-
- /** . */
- private final HttpServletRequest req;
-
- /** . */
- private final HttpServletResponse resp;
-
- /** . */
- private final ServletContext servletContext;
-
- /** . */
- private final ControllerRequest request;
-
- /** . */
private final PortletInvoker invoker;
-
+
/** . */
private final EventControllerContext eventControllerContext;
- /** . */
- private final StateControllerContextImpl stateControllerContext;
-
- public PortletControllerContextImpl(
- HttpServletRequest req,
- HttpServletResponse resp,
- ServletContext servletContext)
+ public PortletControllerContextImpl(HttpServletRequest req, HttpServletResponse resp,
ServletContext servletContext)
throws IllegalRequestException, IOException, ClassNotFoundException
{
- PortletInvoker invoker =
(PortletInvoker)servletContext.getAttribute("ConsumerPortletInvoker");
+ super(req, resp, servletContext);
//
- StateControllerContextImpl tmp = new StateControllerContextImpl(this);
-
- // The nav state provided with the request
- PageNavigationalState pageState = null;
-
- // The request decoded if not null
- ControllerRequest request = null;
-
- // Process
- String pathInfo = req.getPathInfo();
- if (pathInfo != null && pathInfo.startsWith("/") &&
pathInfo.length() > 1)
- {
- // Get the target portlet
- String targetId = StringCodec.decode(pathInfo.substring(1));
-
- // Helper
- WebRequest ri = new WebRequest(req);
-
- // Unmarshall portal navigational state if it is provided
- String context = req.getParameter(PAGE_STATE);
- if (context != null)
- {
- byte[] bytes = Tools.fromHexString(context);
- pageState = tmp.unserialize(bytes);
- }
-
- //
- Mode mode = null;
- if (req.getParameter(MODE) != null)
- {
- mode = Mode.create(req.getParameter(MODE));
- }
-
- //
- WindowState windowState = null;
- if (req.getParameter(WINDOW_STATE) != null)
- {
- windowState = WindowState.create(req.getParameter(WINDOW_STATE));
- }
-
- //
- String navigationalStateString = req.getParameter(NAVIGATIONAL_STATE);
- StateString navigationalState = null;
- if (navigationalStateString != null)
- {
- navigationalState = ParametersStateString.create(navigationalStateString);
- }
-
- //
- WindowNavigationalState windowNavigationalState = new
WindowNavigationalState(navigationalState, mode, windowState);
-
- //
- String type = req.getParameter(LIFECYCLE_TYPE);
- if (RESOURCE_LIFECYCLE.equals(type))
- {
- StateString resourceState =
ParametersStateString.create(req.getParameter(RESOURCE_STATE));
- String resourceId = req.getParameter(RESOURCE_ID);
-
- //
- ParameterMap formParameters = null;
- if (ri.getBody() instanceof Body.Form)
- {
- formParameters = ((Body.Form)ri.getBody()).getParameters();
- }
-
- //
- CacheLevel resourceCacheLevel =
CacheLevel.valueOf(req.getParameter(RESOURCE_CACHEABILITY));
-
- //
- switch (resourceCacheLevel)
- {
- case FULL:
- request = new FullScopedCacheablePortletResourceRequest(
- this,
- targetId,
- resourceId,
- resourceState,
- formParameters);
- break;
- case PORTLET:
- request = new PortletScopedPortletResourceRequest(
- this,
- targetId,
- resourceId,
- resourceState,
- formParameters,
- windowNavigationalState);
- break;
- case PAGE:
- request = new PageScopedFullPortletResourceRequest(
- this,
- targetId,
- resourceId,
- resourceState,
- formParameters,
- pageState,
- windowNavigationalState);
- break;
- }
- }
- else
- {
- if (ACTION_LIFECYCLE.equals(type))
- {
- ParameterMap formParameters = null;
- if (ri.getBody() instanceof Body.Form)
- {
- formParameters = ((Body.Form)ri.getBody()).getParameters();
- }
-
- //
- StateString interactionState =
ParametersStateString.create(req.getParameter(INTERACTION_STATE));
-
- //
- request = new PortletActionRequest(
- this,
- targetId,
- interactionState,
- formParameters,
- windowNavigationalState,
- pageState);
- }
- else
- {
- Map<String, String[]> publicNavigationalStateChanges =
(Map<String,
String[]>)IOTools.unserialize(Tools.fromHexString(req.getParameter(PUBLIC_NAVIGATIONAL_STATE_CHANGES)));
-
- //
- request = new PortletRenderRequest(
- this,
- targetId,
- windowNavigationalState,
- publicNavigationalStateChanges,
- pageState);
- }
- }
- }
-
- //
- this.request = request;
- this.req = req;
- this.resp = resp;
- this.servletContext = servletContext;
- this.invoker = invoker;
+ this.invoker =
(PortletInvoker)servletContext.getAttribute("ConsumerPortletInvoker");
this.eventControllerContext = new EventControllerContextImpl(invoker);
- this.stateControllerContext = tmp;
}
- public ControllerRequest getRequest()
+ protected Portlet getPortlet(String windowId) throws PortletInvokerException
{
- return request;
- }
-
- public ServletContext getServletContext()
- {
- return servletContext;
- }
-
- public HttpServletRequest getClientRequest()
- {
- return req;
- }
-
- public HttpServletResponse getClientResponse()
- {
- return resp;
- }
-
- public PortletInfo getPortletInfo(String windowId) throws PortletInvokerException
- {
- return _getPortlet(windowId).getInfo();
- }
-
- private Portlet _getPortlet(String windowId) throws PortletInvokerException
- {
return invoker.getPortlet(PortletContext.createPortletContext(windowId));
}
- public PortletInvocationResponse invoke(PortletInvocation invocation) throws
PortletInvokerException
+ protected PortletInvocationResponse invoke(PortletInvocation invocation) throws
PortletInvokerException
{
return invoker.invoke(invocation);
}
- public Collection<Portlet> getPortlets() throws PortletInvokerException
- {
- return invoker.getPortlets();
- }
-
public EventControllerContext getEventControllerContext()
{
return eventControllerContext;
}
- public StateControllerContext getStateControllerContext()
+ public Collection<Portlet> getPortlets() throws PortletInvokerException
{
- return stateControllerContext;
+ return invoker.getPortlets();
}
- public String renderURL(String windowId, PageNavigationalState pageState, ContainerURL
containerURL, Boolean wantSecure, Boolean wantAuthenticated, boolean relative)
- {
- PortletURLRenderer renderer = new PortletURLRenderer(stateControllerContext,
pageState, windowId, req, resp);
-
- //
- return renderer.renderURL(containerURL, wantSecure, wantAuthenticated, relative);
- }
-
- public PortletInvocationResponse invoke(String windowId, ActionInvocation
actionInvocation) throws PortletInvokerException
- {
-
- Portlet portlet = _getPortlet(windowId);
-
- TestInstanceContext instanceContext = new TestInstanceContext(req,
portlet.getContext(), true);
-
- actionInvocation.setClientContext(new AbstractClientContext(req));
- actionInvocation.setServerContext(new AbstractServerContext(req, resp));
- actionInvocation.setInstanceContext(instanceContext);
- actionInvocation.setUserContext(new AbstractUserContext(req));
- actionInvocation.setWindowContext(new
AbstractWindowContext(portlet.getContext().getId()));
- actionInvocation.setPortalContext(new TestPortalContext());
- actionInvocation.setSecurityContext(new AbstractSecurityContext(req));
- actionInvocation.setRequestContext(new AbstractRequestContext(req));
- actionInvocation.setTarget(instanceContext.getTarget());
-
- return invoke(actionInvocation);
- }
-
- public PortletInvocationResponse invoke(String windowId, List<Cookie>
requestCookies, EventInvocation eventInvocation) throws PortletInvokerException
- {
- Portlet portlet = _getPortlet(windowId);
-
- TestInstanceContext instanceContext = new TestInstanceContext(req,
portlet.getContext(), true);
-
- eventInvocation.setClientContext(new AbstractClientContext(req, requestCookies));
- eventInvocation.setServerContext(new AbstractServerContext(req, resp));
- eventInvocation.setInstanceContext(instanceContext);
- eventInvocation.setUserContext(new AbstractUserContext(req));
- eventInvocation.setWindowContext(new AbstractWindowContext(windowId));
- eventInvocation.setPortalContext(new TestPortalContext());
- eventInvocation.setSecurityContext(new AbstractSecurityContext(req));
- eventInvocation.setTarget(instanceContext.getTarget());
-
- return invoke(eventInvocation);
- }
-
- public PortletInvocationResponse invoke(String windowId, ResourceInvocation
resourceInvocation) throws PortletInvokerException
- {
- Portlet portlet = _getPortlet(windowId);
-
- TestInstanceContext instanceContext = new TestInstanceContext(req,
portlet.getContext(), true);
-
- resourceInvocation.setClientContext(new AbstractClientContext(req));
- resourceInvocation.setServerContext(new AbstractServerContext(req, resp));
- resourceInvocation.setInstanceContext(instanceContext);
- resourceInvocation.setUserContext(new AbstractUserContext(req));
- resourceInvocation.setWindowContext(new
AbstractWindowContext(portlet.getContext().getId()));
- resourceInvocation.setPortalContext(new TestPortalContext());
- resourceInvocation.setSecurityContext(new AbstractSecurityContext(req));
- resourceInvocation.setRequestContext(new AbstractRequestContext(req));
- resourceInvocation.setTarget(instanceContext.getTarget());
-
- return invoke(resourceInvocation);
- }
-
- public PortletInvocationContext createPortletInvocationContext(String windowId,
PageNavigationalState pageState)
- {
- return new TestPortletInvocationContext(stateControllerContext, req, resp,
windowId, pageState, MARKUP_INFO);
- }
}
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/ControllerServlet.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/ControllerServlet.java 2008-02-06
21:56:20 UTC (rev 9810)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/ControllerServlet.java 2008-02-06
22:12:01 UTC (rev 9811)
@@ -28,6 +28,16 @@
import org.jboss.portal.portlet.test.jsp.response.CharsChunk;
import org.jboss.portal.portlet.test.jsp.response.PortletChunk;
import org.jboss.portal.portlet.test.jsp.response.BufferingResponse;
+import org.jboss.portal.portlet.PortletInvoker;
+import org.jboss.portal.portlet.Portlet;
+import org.jboss.portal.portlet.PortletInvokerException;
+import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
+import org.jboss.portal.portlet.invocation.response.FragmentResponse;
+import org.jboss.portal.portlet.controller.PortletController;
+import org.jboss.portal.portlet.controller.response.ControllerResponse;
+import org.jboss.portal.portlet.controller.response.PageUpdateResponse;
+import org.jboss.portal.portlet.controller.state.PageNavigationalState;
+import org.jboss.portal.portlet.info.PortletInfo;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
@@ -36,6 +46,7 @@
import javax.servlet.RequestDispatcher;
import java.io.IOException;
import java.io.PrintWriter;
+import java.util.Map;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -44,9 +55,23 @@
public class ControllerServlet extends HttpServlet
{
-
protected void service(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException
{
+ try
+ {
+ _service(req, resp);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new ServletException(e);
+ }
+ }
+
+ protected void _service(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException, ClassNotFoundException
+ {
+ PortletInvoker invoker =
(PortletInvoker)getServletContext().getAttribute("ConsumerPortletInvoker");
+
+ //
RequestDispatcher dispatcher = req.getRequestDispatcher("/index.jsp");
//
@@ -59,9 +84,75 @@
ResponseBuffer buffer = bufferingResponse.getBuffer();
buffer.close();
+ // Collect portlets to create the page
+ int counter = 0;
+ Page page = new Page();
+ for (Chunk chunk : buffer.getChunks())
+ {
+ if (chunk instanceof PortletChunk)
+ {
+ PortletChunk portletChunk = (PortletChunk)chunk;
+ String windowId = "" + counter++;
+
+ //
+ try
+ {
+ for (Portlet portlet : invoker.getPortlets())
+ {
+ PortletInfo portletInfo = portlet.getInfo();
+ String portletName = portletInfo.getName();
+ String applicationName = portletInfo.getApplicationName();
+
+ //
+ if (applicationName.equals(portletChunk.getApplicationName())
&& portletName.equals(portletChunk.getPortletName()))
+ {
+ page.addWindow(new Window(windowId, portlet));
+ }
+ }
+ }
+ catch (PortletInvokerException e)
+ {
+ throw new ServletException(e);
+ }
+ }
+ }
+
//
+ PagePortletControllerContext context = new PagePortletControllerContext(req, resp,
getServletContext(), page, invoker);
+
+ //
+ PageNavigationalState pageState = null;
+ if (context.getRequest() != null)
+ {
+ ControllerResponse controllerResponse;
+ try
+ {
+ controllerResponse = new PortletController().process(context.getRequest());
+ }
+ catch (PortletInvokerException e)
+ {
+ throw new ServletException(e);
+ }
+
+ //
+ if (controllerResponse instanceof PageUpdateResponse)
+ {
+ PageUpdateResponse pageUpdate = (PageUpdateResponse)controllerResponse;
+ pageState = pageUpdate.getPageState();
+ }
+ }
+ else
+ {
+ pageState = context.getStateControllerContext().createPageState();
+ }
+
+ //
+ Map<String, PortletInvocationResponse> responses = page.render(context,
pageState);
+
+ //
resp.setContentType("text/html");
PrintWriter writer = resp.getWriter();
+ int count = 0;
for (Chunk chunk : buffer.getChunks())
{
if (chunk instanceof BytesChunk)
@@ -77,7 +168,39 @@
else if (chunk instanceof PortletChunk)
{
PortletChunk portletChunk = (PortletChunk)chunk;
- writer.write("Portlet[" + portletChunk.getPortletName() +
"," + portletChunk.getApplicationName() + "]");
+ String windowId = "" + count++;
+
+ PortletInvocationResponse response = responses.get(windowId);
+ if (response != null)
+ {
+ if (response instanceof FragmentResponse)
+ {
+ FragmentResponse fragment = (FragmentResponse)response;
+ if (fragment.getType() != FragmentResponse.TYPE_EMPTY)
+ {
+ String frag;
+ if (fragment.getType() == FragmentResponse.TYPE_BYTES)
+ {
+ frag = fragment.getBytes().toString();
+ }
+ else
+ {
+ frag = fragment.getChars().toString();
+ }
+
+ //
+ writer.write(frag);
+ }
+ }
+ else
+ {
+ writer.write(response.getClass().getSimpleName() + "[" +
portletChunk.getPortletName() + "," + portletChunk.getApplicationName() +
"]");
+ }
+ }
+ else
+ {
+ writer.write("Empty[" + portletChunk.getPortletName() +
"," + portletChunk.getApplicationName() + "]");
+ }
}
}
Added:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/Page.java
===================================================================
--- modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/Page.java
(rev 0)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/Page.java 2008-02-06
22:12:01 UTC (rev 9811)
@@ -0,0 +1,76 @@
+/******************************************************************************
+ * 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.invocation.response.PortletInvocationResponse;
+import org.jboss.portal.portlet.controller.PortletControllerContext;
+import org.jboss.portal.portlet.controller.state.PageNavigationalState;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class Page
+{
+
+ /** . */
+ private Map<String, Window> windows;
+
+ public Page()
+ {
+ this.windows = new HashMap<String, Window>();
+ }
+
+ public void addWindow(Window window)
+ {
+ windows.put(window.getId(), window);
+ }
+
+ public Window getWindow(String windowId)
+ {
+ return windows.get(windowId);
+ }
+
+ public Map<String, PortletInvocationResponse> render(PortletControllerContext
context, PageNavigationalState pageState)
+ {
+ Map<String, PortletInvocationResponse> responses = new HashMap<String,
PortletInvocationResponse>();
+
+ //
+ for (Window window : windows.values())
+ {
+ PortletInvocationResponse response = window.render(context, pageState);
+
+ //
+ if (response != null)
+ {
+ responses.put(window.getId(), response);
+ }
+ }
+
+ //
+ return responses;
+ }
+}
Added:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/PagePortletControllerContext.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/PagePortletControllerContext.java
(rev 0)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/PagePortletControllerContext.java 2008-02-06
22:12:01 UTC (rev 9811)
@@ -0,0 +1,87 @@
+/******************************************************************************
+ * 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.test.controller.AbstractPortletControllerContext;
+import org.jboss.portal.portlet.Portlet;
+import org.jboss.portal.portlet.PortletInvokerException;
+import org.jboss.portal.portlet.PortletInvoker;
+import org.jboss.portal.portlet.controller.event.EventControllerContext;
+import org.jboss.portal.portlet.controller.impl.event.EventControllerContextImpl;
+import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
+import org.jboss.portal.portlet.invocation.PortletInvocation;
+import org.jboss.portal.web.IllegalRequestException;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.ServletContext;
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class PagePortletControllerContext extends AbstractPortletControllerContext
+{
+
+ /** . */
+ private final Page page;
+
+ /** . */
+ private final PortletInvoker invoker;
+
+ /** . */
+ private final EventControllerContext eventControllerContext;
+
+ public PagePortletControllerContext(
+ HttpServletRequest req,
+ HttpServletResponse resp,
+ ServletContext servletContext,
+ Page page,
+ PortletInvoker invoker)
+ throws IllegalRequestException, IOException, ClassNotFoundException
+ {
+ super(req, resp, servletContext);
+
+ //
+ this.page = page;
+ this.invoker = invoker;
+ this.eventControllerContext = new EventControllerContextImpl(invoker);
+ }
+
+ protected Portlet getPortlet(String windowId) throws PortletInvokerException
+ {
+ Window window = page.getWindow(windowId);
+ return window.getPortlet();
+ }
+
+ protected PortletInvocationResponse invoke(PortletInvocation invocation) throws
PortletInvokerException
+ {
+ return invoker.invoke(invocation);
+ }
+
+ public EventControllerContext getEventControllerContext()
+ {
+ return eventControllerContext;
+ }
+}
Added:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/Window.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/Window.java
(rev 0)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/Window.java 2008-02-06
22:12:01 UTC (rev 9811)
@@ -0,0 +1,137 @@
+/******************************************************************************
+ * 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.StateString;
+import org.jboss.portal.portlet.PortletInvokerException;
+import org.jboss.portal.portlet.test.controller.TestInstanceContext;
+import org.jboss.portal.portlet.test.controller.TestPortalContext;
+import org.jboss.portal.portlet.impl.spi.AbstractClientContext;
+import org.jboss.portal.portlet.impl.spi.AbstractServerContext;
+import org.jboss.portal.portlet.impl.spi.AbstractUserContext;
+import org.jboss.portal.portlet.impl.spi.AbstractWindowContext;
+import org.jboss.portal.portlet.impl.spi.AbstractSecurityContext;
+import org.jboss.portal.portlet.spi.PortletInvocationContext;
+import org.jboss.portal.portlet.controller.PortletControllerContext;
+import org.jboss.portal.portlet.controller.state.WindowNavigationalState;
+import org.jboss.portal.portlet.controller.state.PageNavigationalState;
+import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
+import org.jboss.portal.portlet.invocation.RenderInvocation;
+import org.jboss.portal.Mode;
+import org.jboss.portal.WindowState;
+import org.jboss.portal.common.util.ParameterMap;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class Window
+{
+
+ /** . */
+ private final String id;
+
+ /** . */
+ private final Portlet portlet;
+
+ public Window(String id, Portlet portlet)
+ {
+ this.id = id;
+ this.portlet = portlet;
+ }
+
+ public String getId()
+ {
+ return id;
+ }
+
+ public Portlet getPortlet()
+ {
+ return portlet;
+ }
+
+ public PortletInvocationResponse render(
+ PortletControllerContext context,
+ PageNavigationalState pageState)
+ {
+ WindowNavigationalState windowNS = pageState.getWindowNavigationalState(id);
+
+ //
+ Mode mode = Mode.VIEW;
+ WindowState windowState = WindowState.NORMAL;
+ StateString portletNS = null;
+
+ //
+ if (windowNS != null)
+ {
+ if (windowNS.getMode() != null)
+ {
+ mode = windowNS.getMode();
+ }
+ if (windowNS.getWindowState() != null)
+ {
+ windowState = windowNS.getWindowState();
+ }
+ if (windowNS.getPortletNavigationalState() != null)
+ {
+ portletNS = windowNS.getPortletNavigationalState();
+ }
+ }
+
+ //
+ ParameterMap publicNS = pageState.getPublicNavigationalState(id);
+
+ //
+ PortletInvocationContext renderContext = context.createPortletInvocationContext(id,
pageState);
+ RenderInvocation render = new RenderInvocation(renderContext);
+ render.setClientContext(new AbstractClientContext(context.getClientRequest()));
+ render.setServerContext(new AbstractServerContext(context.getClientRequest(),
context.getClientResponse()));
+ render.setInstanceContext(new TestInstanceContext(context.getClientRequest(),
portlet.getContext(), false));
+ render.setUserContext(new AbstractUserContext(context.getClientRequest()));
+ render.setWindowContext(new AbstractWindowContext(id));
+ render.setPortalContext(new TestPortalContext());
+ render.setSecurityContext(new
AbstractSecurityContext(context.getClientRequest()));
+ render.setTarget(portlet.getContext());
+ render.setMode(mode);
+ render.setWindowState(windowState);
+ render.setNavigationalState(portletNS);
+ render.setPublicNavigationalState(publicNS);
+
+ //
+ try
+ {
+ return ((PagePortletControllerContext)context).invoke(render);
+
+ }
+ catch (PortletInvokerException e)
+ {
+ e.printStackTrace();
+
+ // todo
+
+ //
+ return null;
+ }
+ }
+}
Modified: modules/portlet/trunk/test/src/test/resources/simple-portal-war/index.jsp
===================================================================
--- modules/portlet/trunk/test/src/test/resources/simple-portal-war/index.jsp 2008-02-06
21:56:20 UTC (rev 9810)
+++ modules/portlet/trunk/test/src/test/resources/simple-portal-war/index.jsp 2008-02-06
22:12:01 UTC (rev 9811)
@@ -5,11 +5,15 @@
<html>
<body>
<portal:page>
- BEFORE
+ ONE
<portal:portlet
+ name="GoogleWeather"
+ applicationName="google-weather-portlet"/>
+ TWO
+ <portal:portlet
name="GoogleMap"
applicationName="google-map-portlet"/>
- AFTER
+ THREE
</portal:page>
</body>
</html>