Author: julien(a)jboss.com
Date: 2008-02-16 14:09:16 -0500 (Sat, 16 Feb 2008)
New Revision: 10001
Added:
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/impl/request/
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/impl/request/ControllerRequestFactory.java
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/impl/request/ControllerRequestParameterMapFactory.java
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/impl/request/ControllerRequestParameterNames.java
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/PortletEventRequest.java
Modified:
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/PortletController.java
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/PortletControllerContext.java
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/PortletRequestHandler.java
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/PortletResourceRequestHandler.java
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/RequestHandler.java
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/event/Event.java
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/impl/state/PageNavigationalStateImpl.java
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/ContainerRequest.java
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/ControllerRequest.java
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/FullScopedCacheablePortletResourceRequest.java
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/PageScopedFullPortletResourceRequest.java
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/PortletActionRequest.java
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/PortletRenderRequest.java
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/PortletRequest.java
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/PortletResourceRequest.java
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/PortletScopedPortletResourceRequest.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortalServlet.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/URLParameterConstants.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/AbstractMarkupRenderer.java
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/ErrorResponseRenderer.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PageRenderer.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/controller/PortletURLRenderer.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/RedirectResponseRenderer.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/Renderer.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/TestPortletInvocationContext.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/ControllerFilter.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/taglib/PortletURLTag.java
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/controller/StateControllerContextTestCase.java
Log:
- extract default common request parameter encoding/decoding for reuse
Modified:
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/PortletController.java
===================================================================
---
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/PortletController.java 2008-02-16
06:20:27 UTC (rev 10000)
+++
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/PortletController.java 2008-02-16
19:09:16 UTC (rev 10001)
@@ -46,7 +46,7 @@
*/
public class PortletController
{
- public ControllerResponse process(ControllerRequest controllerRequest) throws
IOException, PortletInvokerException
+ public ControllerResponse process(PortletControllerContext controllerContext,
ControllerRequest controllerRequest) throws IOException, PortletInvokerException
{
RequestHandler handler;
@@ -63,6 +63,6 @@
throw new PortletInvokerException("Unknown request type: " +
controllerRequest.getClass().getName());
}
- return handler.handle(controllerRequest);
+ return handler.handle(controllerContext, controllerRequest);
}
}
Modified:
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/PortletControllerContext.java
===================================================================
---
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/PortletControllerContext.java 2008-02-16
06:20:27 UTC (rev 10000)
+++
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/PortletControllerContext.java 2008-02-16
19:09:16 UTC (rev 10001)
@@ -48,21 +48,28 @@
public interface PortletControllerContext
{
- ServletContext getServletContext();
+ /**
+ * Returns the portet info for a specified window.
+ *
+ * @param windowId the window id
+ * @return the portlet info or null if none can be found
+ */
+ PortletInfo getPortletInfo(String windowId);
- HttpServletRequest getClientRequest();
-
- HttpServletResponse getClientResponse();
-
- PortletInfo getPortletInfo(String windowId) throws PortletInvokerException;
-
+ /**
+ * Create a portlet invocation context for the specified window id.
+ *
+ * @param windowId the window id
+ * @param pageState
+ * @return
+ */
PortletInvocationContext createPortletInvocationContext(String windowId,
PageNavigationalState pageState);
- PortletInvocationResponse invoke(String windowId, ActionInvocation actionInvocation)
throws PortletInvokerException;
+ PortletInvocationResponse invoke( ActionInvocation actionInvocation) throws
PortletInvokerException;
- PortletInvocationResponse invoke(String windowId, List<Cookie> requestCookies,
EventInvocation eventInvocation) throws PortletInvokerException;
+ PortletInvocationResponse invoke(List<Cookie> requestCookies, EventInvocation
eventInvocation) throws PortletInvokerException;
- PortletInvocationResponse invoke(String windowId, ResourceInvocation
resourceInvocation) throws PortletInvokerException;
+ PortletInvocationResponse invoke(ResourceInvocation resourceInvocation) throws
PortletInvokerException;
EventControllerContext getEventControllerContext();
Modified:
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/PortletRequestHandler.java
===================================================================
---
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/PortletRequestHandler.java 2008-02-16
06:20:27 UTC (rev 10000)
+++
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/PortletRequestHandler.java 2008-02-16
19:09:16 UTC (rev 10001)
@@ -30,7 +30,6 @@
import org.jboss.portal.portlet.StateString;
import org.jboss.portal.portlet.controller.event.Event;
import org.jboss.portal.portlet.controller.event.EventControllerContext;
-import org.jboss.portal.portlet.controller.request.ControllerRequest;
import org.jboss.portal.portlet.controller.request.PortletActionRequest;
import org.jboss.portal.portlet.controller.request.PortletRenderRequest;
import org.jboss.portal.portlet.controller.request.PortletRequest;
@@ -63,23 +62,11 @@
public PortletRequestHandler(PortletController controller)
{
- super(controller);
+ super(PortletRequest.class, controller);
}
- protected PortletRequest downcastRequest(ControllerRequest request)
+ ControllerResponse processResponse(PortletControllerContext context, PortletRequest
portletRequest, PortletInvocationResponse response) throws IOException,
PortletInvokerException
{
- if (!(request instanceof PortletRequest))
- {
- throw new IllegalArgumentException("Request " + request + "
cannot be handled by this handler");
- }
-
- return (PortletRequest)request;
- }
-
- ControllerResponse processResponse(PortletRequest portletRequest,
PortletInvocationResponse response) throws IOException, PortletInvokerException
- {
- PortletControllerContext context = portletRequest.getControllerContext();
-
StateControllerContext stateContext = context.getStateControllerContext();
// The page navigational state we will operate on during the request
@@ -175,11 +162,8 @@
}
}
- PortletInvocationResponse invoke(PortletRequest portletRequest) throws
PortletInvokerException
+ PortletInvocationResponse invoke(PortletControllerContext context, PortletRequest
portletRequest) throws PortletInvokerException
{
- PortletControllerContext context = portletRequest.getControllerContext();
-
- //
if (portletRequest instanceof PortletRenderRequest)
{
PortletRenderRequest portletRenderRequest =
(PortletRenderRequest)portletRequest;
@@ -229,7 +213,7 @@
actionInvocation.setForm(portletActionRequest.getBodyParameters() != null ?
ParameterMap.clone(portletActionRequest.getBodyParameters()) : null);
//
- return context.invoke(portletRequest.getWindowId(), actionInvocation);
+ return context.invoke(actionInvocation);
}
}
@@ -261,7 +245,7 @@
eventInvocation.setPayload(event.getPayload());
//
- return context.invoke(event.getWindowId(), requestCookies, eventInvocation);
+ return context.invoke(requestCookies, eventInvocation);
}
private void updateNavigationalState(
Modified:
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/PortletResourceRequestHandler.java
===================================================================
---
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/PortletResourceRequestHandler.java 2008-02-16
06:20:27 UTC (rev 10000)
+++
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/PortletResourceRequestHandler.java 2008-02-16
19:09:16 UTC (rev 10001)
@@ -32,7 +32,6 @@
import org.jboss.portal.portlet.cache.CacheLevel;
import org.jboss.portal.portlet.invocation.ResourceInvocation;
import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
-import org.jboss.portal.portlet.controller.request.ControllerRequest;
import org.jboss.portal.portlet.controller.request.PageScopedFullPortletResourceRequest;
import org.jboss.portal.portlet.controller.request.PortletResourceRequest;
import org.jboss.portal.portlet.controller.request.PortletScopedPortletResourceRequest;
@@ -48,17 +47,18 @@
*/
class PortletResourceRequestHandler extends RequestHandler<PortletResourceRequest>
{
+
public PortletResourceRequestHandler(PortletController controller)
{
- super(controller);
+ super(PortletResourceRequest.class, controller);
}
- ControllerResponse processResponse(PortletResourceRequest request,
PortletInvocationResponse response) throws IOException, PortletInvokerException
+ ControllerResponse processResponse(PortletControllerContext controllerContext,
PortletResourceRequest request, PortletInvocationResponse response) throws IOException,
PortletInvokerException
{
return new ResourceResponse(response);
}
- PortletInvocationResponse invoke(PortletResourceRequest portletResourceRequest) throws
PortletInvokerException
+ PortletInvocationResponse invoke(PortletControllerContext context,
PortletResourceRequest portletResourceRequest) throws PortletInvokerException
{
//
@@ -69,8 +69,6 @@
StateString portletNS = null;
CacheLevel cacheability;
- PortletControllerContext context = portletResourceRequest.getControllerContext();
-
//
if (portletResourceRequest instanceof PortletScopedPortletResourceRequest)
{
@@ -129,21 +127,11 @@
//
try
{
- return context.invoke(portletResourceRequest.getWindowId(),
resourceInvocation);
+ return context.invoke(resourceInvocation);
}
catch (PortletInvokerException e)
{
return null;
}
}
-
- PortletResourceRequest downcastRequest(ControllerRequest request)
- {
- if (!(request instanceof PortletResourceRequest))
- {
- throw new IllegalArgumentException("Request " + request + "
cannot be handled by this handler");
- }
-
- return (PortletResourceRequest)request;
- }
}
Modified:
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/RequestHandler.java
===================================================================
---
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/RequestHandler.java 2008-02-16
06:20:27 UTC (rev 10000)
+++
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/RequestHandler.java 2008-02-16
19:09:16 UTC (rev 10001)
@@ -37,26 +37,36 @@
*/
abstract class RequestHandler<T extends ControllerRequest>
{
+ /** . */
+ protected static final Logger log = Logger.getLogger(RequestHandler.class);
+
+ /** . */
protected PortletController controller;
- protected static final Logger log = Logger.getLogger(RequestHandler.class);
+ /** . */
+ protected final Class<T> t;
- public RequestHandler(PortletController controller)
+ protected RequestHandler(Class<T> t, PortletController controller)
{
+ this.t = t;
this.controller = controller;
}
- public ControllerResponse handle(ControllerRequest request) throws
PortletInvokerException, IOException
+ public ControllerResponse handle(PortletControllerContext controllerContext,
ControllerRequest request) throws PortletInvokerException, IOException
{
- T req = downcastRequest(request);
- PortletInvocationResponse response = invoke(req);
+ if (!t.isInstance(request))
+ {
+ throw new IllegalArgumentException("Request " + request + "
cannot be handled by this handler");
+ }
- return processResponse(req, response);
+ //
+ T req = t.cast(request);
+ PortletInvocationResponse response = invoke(controllerContext, req);
+
+ return processResponse(controllerContext, req, response);
}
- abstract ControllerResponse processResponse(T request, PortletInvocationResponse
response) throws IOException, PortletInvokerException;
+ abstract ControllerResponse processResponse(PortletControllerContext
controllerContext, T request, PortletInvocationResponse response) throws IOException,
PortletInvokerException;
- abstract PortletInvocationResponse invoke(T controllerRequest) throws
PortletInvokerException;
-
- abstract T downcastRequest(ControllerRequest request);
+ abstract PortletInvocationResponse invoke(PortletControllerContext controllerContext,
T controllerRequest) throws PortletInvokerException;
}
Modified:
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/event/Event.java
===================================================================
---
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/event/Event.java 2008-02-16
06:20:27 UTC (rev 10000)
+++
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/event/Event.java 2008-02-16
19:09:16 UTC (rev 10001)
@@ -26,7 +26,7 @@
import java.io.Serializable;
/**
- * An event associated with a portlet.
+ * An event associated with a portlet window.
*
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 630 $
Added:
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/impl/request/ControllerRequestFactory.java
===================================================================
---
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/impl/request/ControllerRequestFactory.java
(rev 0)
+++
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/impl/request/ControllerRequestFactory.java 2008-02-16
19:09:16 UTC (rev 10001)
@@ -0,0 +1,191 @@
+/******************************************************************************
+ * 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.controller.impl.request;
+
+import org.jboss.portal.portlet.controller.state.StateControllerContext;
+import org.jboss.portal.portlet.controller.state.PageNavigationalStateSerialization;
+import org.jboss.portal.portlet.controller.state.PageNavigationalState;
+import org.jboss.portal.portlet.controller.state.WindowNavigationalState;
+import org.jboss.portal.portlet.controller.request.ControllerRequest;
+import
org.jboss.portal.portlet.controller.request.FullScopedCacheablePortletResourceRequest;
+import org.jboss.portal.portlet.controller.request.PortletScopedPortletResourceRequest;
+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.StateString;
+import org.jboss.portal.portlet.ParametersStateString;
+import org.jboss.portal.portlet.cache.CacheLevel;
+import org.jboss.portal.common.util.Base64;
+import org.jboss.portal.common.util.ParameterMap;
+import org.jboss.portal.common.io.IOTools;
+import org.jboss.portal.common.io.SerializationFilter;
+import org.jboss.portal.common.io.Serialization;
+import org.jboss.portal.web.WebRequest;
+import org.jboss.portal.web.Body;
+import org.jboss.portal.Mode;
+import org.jboss.portal.WindowState;
+
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class ControllerRequestFactory
+{
+
+ /** . */
+ private final StateControllerContext stateControllerContext;
+
+ /** . */
+ private final PageNavigationalStateSerialization serialization;
+
+ public ControllerRequestFactory(StateControllerContext stateControllerContext)
+ {
+ this.stateControllerContext = stateControllerContext;
+ this.serialization = new
PageNavigationalStateSerialization(stateControllerContext);
+ }
+
+ public ControllerRequest createRequest(WebRequest req)
+ {
+
+ // The nav state provided with the request
+ // Unmarshall portal navigational state if it is provided
+ PageNavigationalState pageState = null;
+ String context = req.getParameter(ControllerRequestParameterNames.PAGE_STATE);
+ if (context != null)
+ {
+ byte[] bytes = Base64.decode(context, true);
+ pageState = IOTools.unserialize(serialization, SerializationFilter.COMPRESSOR,
bytes);
+ }
+
+ // Get the window id
+ String windowId = req.getParameter(ControllerRequestParameterNames.WINDOW_ID);
+
+ //
+ Mode mode = null;
+ if (req.getParameter(ControllerRequestParameterNames.MODE) != null)
+ {
+ mode = Mode.create(req.getParameter(ControllerRequestParameterNames.MODE));
+ }
+
+ //
+ WindowState windowState = null;
+ if (req.getParameter(ControllerRequestParameterNames.WINDOW_STATE) != null)
+ {
+ windowState =
WindowState.create(req.getParameter(ControllerRequestParameterNames.WINDOW_STATE));
+ }
+
+ //
+ String navigationalStateString =
req.getParameter(ControllerRequestParameterNames.NAVIGATIONAL_STATE);
+ StateString navigationalState = null;
+ if (navigationalStateString != null)
+ {
+ navigationalState = ParametersStateString.create(navigationalStateString);
+ }
+
+ //
+ WindowNavigationalState windowNavigationalState = new
WindowNavigationalState(navigationalState, mode, windowState);
+
+ //
+ String phase = req.getParameter(ControllerRequestParameterNames.LIFECYCLE_PHASE);
+ if (ControllerRequestParameterNames.RESOURCE_PHASE.equals(phase))
+ {
+ StateString resourceState =
ParametersStateString.create(req.getParameter(ControllerRequestParameterNames.RESOURCE_STATE));
+ String resourceId =
req.getParameter(ControllerRequestParameterNames.RESOURCE_ID);
+
+ //
+ ParameterMap formParameters = null;
+ if (req.getBody() instanceof Body.Form)
+ {
+ formParameters = ((Body.Form)req.getBody()).getParameters();
+ }
+
+ //
+ CacheLevel resourceCacheLevel =
CacheLevel.valueOf(req.getParameter(ControllerRequestParameterNames.RESOURCE_CACHEABILITY));
+
+ //
+ switch (resourceCacheLevel)
+ {
+ case FULL:
+ return new FullScopedCacheablePortletResourceRequest(
+ windowId,
+ resourceId,
+ resourceState,
+ formParameters);
+ case PORTLET:
+ return new PortletScopedPortletResourceRequest(
+ windowId,
+ resourceId,
+ resourceState,
+ formParameters,
+ windowNavigationalState);
+ case PAGE:
+ return new PageScopedFullPortletResourceRequest(
+ windowId,
+ resourceId,
+ resourceState,
+ formParameters,
+ pageState,
+ windowNavigationalState);
+ default:
+ throw new AssertionError();
+ }
+ }
+ else
+ {
+ if (ControllerRequestParameterNames.ACTION_PHASE.equals(phase))
+ {
+ ParameterMap formParameters = null;
+ if (req.getBody() instanceof Body.Form)
+ {
+ formParameters = ((Body.Form)req.getBody()).getParameters();
+ }
+
+ //
+ StateString interactionState =
ParametersStateString.create(req.getParameter(ControllerRequestParameterNames.INTERACTION_STATE));
+
+ //
+ return new PortletActionRequest(
+ windowId,
+ interactionState,
+ formParameters,
+ windowNavigationalState,
+ pageState);
+ }
+ else
+ {
+ byte[] bytes =
Base64.decode(req.getParameter(ControllerRequestParameterNames.PUBLIC_NAVIGATIONAL_STATE_CHANGES),
true);
+ Map<String, String[]> publicNavigationalStateChanges =
IOTools.unserialize(Serialization.PARAMETER_MAP, SerializationFilter.COMPRESSOR, bytes);
+
+ //
+ return new PortletRenderRequest(
+ windowId,
+ windowNavigationalState,
+ publicNavigationalStateChanges,
+ pageState);
+ }
+ }
+ }
+
+}
Added:
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/impl/request/ControllerRequestParameterMapFactory.java
===================================================================
---
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/impl/request/ControllerRequestParameterMapFactory.java
(rev 0)
+++
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/impl/request/ControllerRequestParameterMapFactory.java 2008-02-16
19:09:16 UTC (rev 10001)
@@ -0,0 +1,202 @@
+/******************************************************************************
+ * 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.controller.impl.request;
+
+import org.jboss.portal.portlet.controller.state.StateControllerContext;
+import org.jboss.portal.portlet.controller.state.PageNavigationalStateSerialization;
+import org.jboss.portal.portlet.controller.state.PageNavigationalState;
+import org.jboss.portal.portlet.ContainerURL;
+import org.jboss.portal.portlet.ActionURL;
+import org.jboss.portal.portlet.RenderURL;
+import org.jboss.portal.portlet.ResourceURL;
+import org.jboss.portal.portlet.PortletURL;
+import org.jboss.portal.portlet.StateString;
+import org.jboss.portal.portlet.cache.CacheLevel;
+import org.jboss.portal.common.io.IOTools;
+import org.jboss.portal.common.io.SerializationFilter;
+import org.jboss.portal.common.io.Serialization;
+import org.jboss.portal.common.util.Base64;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class ControllerRequestParameterMapFactory
+{
+
+ /** . */
+ private final StateControllerContext stateControllerContext;
+
+ /** . */
+ private final PageNavigationalStateSerialization serialization;
+
+ public ControllerRequestParameterMapFactory(StateControllerContext
stateControllerContext)
+ {
+ this.stateControllerContext = stateControllerContext;
+ this.serialization = new
PageNavigationalStateSerialization(stateControllerContext);
+ }
+
+ public Map<String, String> blah(PageNavigationalState pageNS, String windowId,
ContainerURL containerURL)
+ {
+ Map<String, String> parameters = new HashMap<String, String>();
+
+ //
+ parameters.put(ControllerRequestParameterNames.WINDOW_ID, windowId);
+
+ //
+ String type;
+ if (containerURL instanceof ActionURL)
+ {
+ type = ControllerRequestParameterNames.ACTION_PHASE;
+ }
+ else if (containerURL instanceof RenderURL)
+ {
+ type = ControllerRequestParameterNames.RENDER_PHASE;
+ }
+ else if (containerURL instanceof ResourceURL)
+ {
+ type = ControllerRequestParameterNames.RESOURCE_PHASE;
+ }
+ else
+ {
+ throw new Error();
+ }
+ parameters.put(ControllerRequestParameterNames.LIFECYCLE_PHASE, type);
+
+
+ //
+ String pageState = null;
+ if (pageNS != null)
+ {
+ byte[] bytes = IOTools.serialize(serialization, SerializationFilter.COMPRESSOR,
pageNS);
+ pageState = Base64.encodeBytes(bytes, true);
+ }
+
+ //
+ if (containerURL instanceof PortletURL)
+ {
+ PortletURL portletURL = (PortletURL)containerURL;
+
+ if (portletURL.getMode() != null)
+ {
+ parameters.put(ControllerRequestParameterNames.MODE,
portletURL.getMode().toString());
+ }
+
+ //
+ if (portletURL.getWindowState() != null)
+ {
+ parameters.put(ControllerRequestParameterNames.WINDOW_STATE,
portletURL.getWindowState().toString());
+ }
+
+ //
+ if (pageState != null)
+ {
+ parameters.put(ControllerRequestParameterNames.PAGE_STATE, pageState);
+ }
+
+ //
+ if (containerURL instanceof ActionURL)
+ {
+ ActionURL actionURL = (ActionURL)containerURL;
+
+ //
+ if (actionURL.getNavigationalState() != null)
+ {
+ parameters.put(ControllerRequestParameterNames.NAVIGATIONAL_STATE,
actionURL.getNavigationalState().getStringValue());
+ }
+
+ //
+ StateString interactionState = actionURL.getInteractionState();
+ parameters.put(ControllerRequestParameterNames.INTERACTION_STATE,
interactionState.getStringValue());
+ }
+ else
+ {
+ RenderURL renderURL = (RenderURL)containerURL;
+
+ //
+ Map<String, String[]> changes =
renderURL.getPublicNavigationalStateChanges();
+ byte[] bytes = IOTools.serialize(Serialization.PARAMETER_MAP,
SerializationFilter.COMPRESSOR, changes);
+ String ns = Base64.encodeBytes(bytes, true);
+
parameters.put(ControllerRequestParameterNames.PUBLIC_NAVIGATIONAL_STATE_CHANGES, ns);
+
+ //
+ StateString navigationalState = renderURL.getNavigationalState();
+ if (navigationalState != null)
+ {
+ parameters.put(ControllerRequestParameterNames.NAVIGATIONAL_STATE,
navigationalState.getStringValue());
+ }
+ }
+ }
+ else
+ {
+ ResourceURL resourceURL = (ResourceURL)containerURL;
+
+ //
+ StateString resourceState = resourceURL.getResourceState();
+ parameters.put(ControllerRequestParameterNames.RESOURCE_STATE,
resourceState.getStringValue());
+
+ //
+ String resourceId = resourceURL.getResourceId();
+ if (resourceId != null)
+ {
+ parameters.put(ControllerRequestParameterNames.RESOURCE_ID, resourceId);
+ }
+
+ //
+ CacheLevel cacheability = resourceURL.getCacheability();
+ parameters.put(ControllerRequestParameterNames.RESOURCE_CACHEABILITY,
cacheability.name());
+
+ //
+ if (cacheability != CacheLevel.FULL)
+ {
+ if (resourceURL.getNavigationalState() != null)
+ {
+ parameters.put(ControllerRequestParameterNames.NAVIGATIONAL_STATE,
resourceURL.getNavigationalState().getStringValue());
+ }
+
+ //
+ if (resourceURL.getMode() != null)
+ {
+ parameters.put(ControllerRequestParameterNames.MODE,
resourceURL.getMode().toString());
+ }
+
+ //
+ if (resourceURL.getWindowState() != null)
+ {
+ parameters.put(ControllerRequestParameterNames.WINDOW_STATE,
resourceURL.getWindowState().toString());
+ }
+
+ if (cacheability == CacheLevel.PAGE && pageState != null)
+ {
+ parameters.put(ControllerRequestParameterNames.PAGE_STATE, pageState);
+ }
+ }
+ }
+
+ //
+ return parameters;
+ }
+}
Added:
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/impl/request/ControllerRequestParameterNames.java
===================================================================
---
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/impl/request/ControllerRequestParameterNames.java
(rev 0)
+++
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/impl/request/ControllerRequestParameterNames.java 2008-02-16
19:09:16 UTC (rev 10001)
@@ -0,0 +1,62 @@
+/******************************************************************************
+ * 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.controller.impl.request;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class ControllerRequestParameterNames
+{
+ /**
+ * The life cycle type of the invocation. The values accepted are
<code>ACTION_LIFECYCLE</code>,
+ * <code>RENDER_LIFECYCLE</code> and
<code>RESOURCE_LIFECYCLE</code>.
+ */
+ public static final String LIFECYCLE_PHASE = "lifecycle";
+ /** The window id. */
+ public static final String WINDOW_ID = "windowid";
+ /** The portlet mode. */
+ public static final String MODE = "mode";
+ /** The window state. */
+ public static final String WINDOW_STATE = "windowstate";
+ /** The portlet navigational state for any type of lifecycle. */
+ public static final String NAVIGATIONAL_STATE = "navigationalstate";
+ /** The portlet resource state for lifecycle of type
<code>RENDER_LIFECYCLE</code>. */
+ public static final String RESOURCE_STATE = "resourcestate";
+ /** The portlet interaction state for lifecycle of type
<code>ACTION_LIFECYCLE</code>. */
+ public static final String INTERACTION_STATE = "interactionstate";
+ /** The page state for any kind of lifecycle. */
+ public static final String PAGE_STATE = "pagestate";
+ /** The public navigational state changes of a portlet for lifecycle of type
<code>RENDER_LIFECYCLE</code>. */
+ public static final String PUBLIC_NAVIGATIONAL_STATE_CHANGES =
"publicnavigationalstatechanges";
+ /** The resource id for lifecycle of type <code>RESOURCE_LIFECYCLE</code>.
*/
+ public static final String RESOURCE_ID = "resourceid";
+ /** The resource cacheability for lifecycle of type
<code>RENDER_LIFECYCLE</code>. */
+ public static final String RESOURCE_CACHEABILITY = "resourcecacheability";
+ /** Denotes an action lifecycle operation. */
+ public static final String ACTION_PHASE = "action";
+ /** Denotes a render lifecycle operation. */
+ public static final String RENDER_PHASE = "render";
+ /** Denotes a resource lifecycle operation. */
+ public static final String RESOURCE_PHASE = "resource";
+}
Modified:
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/impl/state/PageNavigationalStateImpl.java
===================================================================
---
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/impl/state/PageNavigationalStateImpl.java 2008-02-16
06:20:27 UTC (rev 10000)
+++
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/impl/state/PageNavigationalStateImpl.java 2008-02-16
19:09:16 UTC (rev 10001)
@@ -23,7 +23,6 @@
package org.jboss.portal.portlet.controller.impl.state;
import org.jboss.portal.common.util.ParameterMap;
-import org.jboss.portal.portlet.PortletInvokerException;
import org.jboss.portal.portlet.controller.state.PageNavigationalState;
import org.jboss.portal.portlet.controller.state.WindowNavigationalState;
import org.jboss.portal.portlet.info.ParameterInfo;
@@ -83,10 +82,12 @@
public ParameterMap getPublicNavigationalState(String windowId)
{
- ParameterMap publicNavigationalState = null;
- try
+ PortletInfo info = context.portletControllerContext.getPortletInfo(windowId);
+
+ //
+ if (info != null)
{
- PortletInfo info = context.portletControllerContext.getPortletInfo(windowId);
+ ParameterMap publicNavigationalState = new ParameterMap();
for (ParameterInfo parameterInfo : info.getNavigation().getPublicParameters())
{
String[] parameterValue = page.get(parameterInfo.getName());
@@ -96,24 +97,17 @@
{
String parameterId = parameterInfo.getId();
- // Lazy create
- if (publicNavigationalState == null)
- {
- publicNavigationalState = new ParameterMap();
- }
-
// We clone the value here so we keep the internal state not potentially
changed
publicNavigationalState.put(parameterId, parameterValue.clone());
}
}
+
+ //
+ return publicNavigationalState;
}
- catch (PortletInvokerException e)
- {
- e.printStackTrace();
- }
//
- return publicNavigationalState;
+ return null;
}
public Set<QName> getPublicNames()
@@ -146,10 +140,11 @@
}
//
- try
- {
- PortletInfo info = context.portletControllerContext.getPortletInfo(windowId);
+ PortletInfo info = context.portletControllerContext.getPortletInfo(windowId);
+ //
+ if (info != null)
+ {
NavigationInfo navigationInfo = info.getNavigation();
for (Map.Entry<String, String[]> entry : update.entrySet())
{
@@ -174,10 +169,6 @@
}
}
}
- catch (PortletInvokerException e)
- {
- e.printStackTrace();
- }
}
public void setPublicNavigationalState(QName name, String[] value)
Modified:
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/ContainerRequest.java
===================================================================
---
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/ContainerRequest.java 2008-02-16
06:20:27 UTC (rev 10000)
+++
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/ContainerRequest.java 2008-02-16
19:09:16 UTC (rev 10001)
@@ -22,8 +22,6 @@
******************************************************************************/
package org.jboss.portal.portlet.controller.request;
-import org.jboss.portal.portlet.controller.PortletControllerContext;
-
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 630 $
@@ -34,9 +32,9 @@
/** . */
private final String windowId;
- ContainerRequest(PortletControllerContext controllerContext, String windowId)
+ ContainerRequest(String windowId)
{
- super(controllerContext);
+ super();
//
this.windowId = windowId;
Modified:
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/ControllerRequest.java
===================================================================
---
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/ControllerRequest.java 2008-02-16
06:20:27 UTC (rev 10000)
+++
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/ControllerRequest.java 2008-02-16
19:09:16 UTC (rev 10001)
@@ -22,7 +22,7 @@
******************************************************************************/
package org.jboss.portal.portlet.controller.request;
-import org.jboss.portal.portlet.controller.PortletControllerContext;
+import org.jboss.portal.portlet.controller.state.PageNavigationalState;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -31,16 +31,17 @@
public class ControllerRequest
{
- /** . */
- private final PortletControllerContext controllerContext;
-
- ControllerRequest(PortletControllerContext controllerContext)
+ ControllerRequest()
{
- this.controllerContext = controllerContext;
}
- public PortletControllerContext getControllerContext()
+ /**
+ * Returns the page state or null if that kind of request cannot have one.
+ *
+ * @return the page state
+ */
+ public PageNavigationalState getPageState()
{
- return controllerContext;
+ return null;
}
}
Modified:
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/FullScopedCacheablePortletResourceRequest.java
===================================================================
---
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/FullScopedCacheablePortletResourceRequest.java 2008-02-16
06:20:27 UTC (rev 10000)
+++
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/FullScopedCacheablePortletResourceRequest.java 2008-02-16
19:09:16 UTC (rev 10001)
@@ -24,7 +24,6 @@
import org.jboss.portal.common.util.ParameterMap;
import org.jboss.portal.portlet.StateString;
-import org.jboss.portal.portlet.controller.PortletControllerContext;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -34,12 +33,11 @@
{
public FullScopedCacheablePortletResourceRequest(
- PortletControllerContext controllerContext,
String windowId,
String resourceId,
StateString resourceState,
ParameterMap bodyParameters)
{
- super(controllerContext, windowId, resourceId, resourceState, bodyParameters);
+ super(windowId, resourceId, resourceState, bodyParameters);
}
}
Modified:
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/PageScopedFullPortletResourceRequest.java
===================================================================
---
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/PageScopedFullPortletResourceRequest.java 2008-02-16
06:20:27 UTC (rev 10000)
+++
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/PageScopedFullPortletResourceRequest.java 2008-02-16
19:09:16 UTC (rev 10001)
@@ -39,7 +39,6 @@
private final PageNavigationalState pageState;
public PageScopedFullPortletResourceRequest(
- PortletControllerContext controllerContext,
String windowId,
String resourceId,
StateString resourceState,
@@ -47,7 +46,7 @@
PageNavigationalState pageState,
WindowNavigationalState windowNavigationalState)
{
- super(controllerContext, windowId, resourceId, resourceState, bodyParameters,
windowNavigationalState);
+ super(windowId, resourceId, resourceState, bodyParameters,
windowNavigationalState);
//
this.pageState = pageState;
Modified:
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/PortletActionRequest.java
===================================================================
---
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/PortletActionRequest.java 2008-02-16
06:20:27 UTC (rev 10000)
+++
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/PortletActionRequest.java 2008-02-16
19:09:16 UTC (rev 10001)
@@ -24,7 +24,6 @@
import org.jboss.portal.common.util.ParameterMap;
import org.jboss.portal.portlet.StateString;
-import org.jboss.portal.portlet.controller.PortletControllerContext;
import org.jboss.portal.portlet.controller.state.PageNavigationalState;
import org.jboss.portal.portlet.controller.state.WindowNavigationalState;
@@ -42,14 +41,13 @@
private final ParameterMap bodyParameters;
public PortletActionRequest(
- PortletControllerContext controllerContext,
String windowId,
StateString interactionState,
ParameterMap bodyParameters,
WindowNavigationalState windowNavigationalState,
PageNavigationalState pageState)
{
- super(controllerContext, windowId, windowNavigationalState, pageState);
+ super(windowId, windowNavigationalState, pageState);
//
this.interactionState = interactionState;
Added:
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/PortletEventRequest.java
===================================================================
---
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/PortletEventRequest.java
(rev 0)
+++
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/PortletEventRequest.java 2008-02-16
19:09:16 UTC (rev 10001)
@@ -0,0 +1,70 @@
+/******************************************************************************
+ * 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.controller.request;
+
+import org.jboss.portal.portlet.controller.state.WindowNavigationalState;
+import org.jboss.portal.portlet.controller.state.PageNavigationalState;
+
+import javax.xml.namespace.QName;
+import java.io.Serializable;
+
+/**
+ * An event request. The purpose of this type of request is to allow
+ * the portal to fire events to a portlet.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class PortletEventRequest extends PortletRequest
+{
+
+ /** . */
+ private final QName name;
+
+ /** . */
+ private final Serializable payload;
+
+ public PortletEventRequest(
+ String windowId,
+ WindowNavigationalState windowNavigationalState,
+ PageNavigationalState pageState,
+ QName name,
+ Serializable payload)
+ {
+ super(windowId, windowNavigationalState, pageState);
+
+ //
+ this.name = name;
+ this.payload = payload;
+ }
+
+ public QName getName()
+ {
+ return name;
+ }
+
+ public Serializable getPayload()
+ {
+ return payload;
+ }
+}
Modified:
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/PortletRenderRequest.java
===================================================================
---
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/PortletRenderRequest.java 2008-02-16
06:20:27 UTC (rev 10000)
+++
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/PortletRenderRequest.java 2008-02-16
19:09:16 UTC (rev 10001)
@@ -39,13 +39,12 @@
private final Map<String, String[]> publicNavigationalStateChanges;
public PortletRenderRequest(
- PortletControllerContext controllerContext,
String windowId,
WindowNavigationalState windowNavigationalState,
Map<String, String[]> publicNavigationalStateChanges,
PageNavigationalState pageState)
{
- super(controllerContext, windowId, windowNavigationalState, pageState);
+ super(windowId, windowNavigationalState, pageState);
//
this.publicNavigationalStateChanges = publicNavigationalStateChanges;
Modified:
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/PortletRequest.java
===================================================================
---
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/PortletRequest.java 2008-02-16
06:20:27 UTC (rev 10000)
+++
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/PortletRequest.java 2008-02-16
19:09:16 UTC (rev 10001)
@@ -40,12 +40,11 @@
private final WindowNavigationalState windowNavigationalState;
PortletRequest(
- PortletControllerContext controllerContext,
String windowId,
WindowNavigationalState windowNavigationalState,
PageNavigationalState pageState)
{
- super(controllerContext, windowId);
+ super(windowId);
//
this.windowNavigationalState = windowNavigationalState;
Modified:
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/PortletResourceRequest.java
===================================================================
---
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/PortletResourceRequest.java 2008-02-16
06:20:27 UTC (rev 10000)
+++
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/PortletResourceRequest.java 2008-02-16
19:09:16 UTC (rev 10001)
@@ -25,7 +25,6 @@
import org.jboss.portal.common.util.ParameterMap;
import org.jboss.portal.portlet.StateString;
import org.jboss.portal.portlet.cache.CacheLevel;
-import org.jboss.portal.portlet.controller.PortletControllerContext;
import java.util.HashMap;
import java.util.Map;
@@ -57,14 +56,13 @@
private final ParameterMap bodyParameters;
PortletResourceRequest(
- PortletControllerContext controllerContext,
String windowId,
String resourceId,
StateString resourceState,
ParameterMap bodyParameters
)
{
- super(controllerContext, windowId);
+ super(windowId);
//
this.resourceId = resourceId;
Modified:
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/PortletScopedPortletResourceRequest.java
===================================================================
---
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/PortletScopedPortletResourceRequest.java 2008-02-16
06:20:27 UTC (rev 10000)
+++
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/PortletScopedPortletResourceRequest.java 2008-02-16
19:09:16 UTC (rev 10001)
@@ -38,14 +38,13 @@
private final WindowNavigationalState windowNavigationalState;
public PortletScopedPortletResourceRequest(
- PortletControllerContext controllerContext,
String windowId,
String resourceId,
StateString resourceState,
ParameterMap bodyParameters,
WindowNavigationalState windowNavigationalState)
{
- super(controllerContext, windowId, resourceId, resourceState, bodyParameters);
+ super(windowId, resourceId, resourceState, bodyParameters);
//
this.windowNavigationalState = windowNavigationalState;
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortalServlet.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortalServlet.java 2008-02-16
06:20:27 UTC (rev 10000)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/PortalServlet.java 2008-02-16
19:09:16 UTC (rev 10001)
@@ -23,12 +23,15 @@
package org.jboss.portal.portlet.test;
import org.jboss.portal.portlet.controller.PortletController;
+import org.jboss.portal.portlet.controller.impl.request.ControllerRequestFactory;
+import org.jboss.portal.portlet.controller.request.ControllerRequest;
import org.jboss.portal.portlet.controller.response.ControllerResponse;
import org.jboss.portal.portlet.invocation.response.ResponseProperties;
import org.jboss.portal.portlet.test.controller.ControllerResponseRendererFactory;
import org.jboss.portal.portlet.test.controller.PageRenderer;
import org.jboss.portal.portlet.test.controller.PortletControllerContextImpl;
import org.jboss.portal.portlet.test.controller.Renderer;
+import org.jboss.portal.web.WebRequest;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
@@ -74,10 +77,17 @@
//
PortletController controller = new PortletController();
- if (context.getRequest() != null)
+ String type = req.getParameter(URLParameterConstants.TYPE);
+
+ //
+ if (URLParameterConstants.PORTLET_TYPE.equals(type))
{
+ WebRequest wr = new WebRequest(req);
+ ControllerRequestFactory factory = new
ControllerRequestFactory(context.getStateControllerContext());
+ ControllerRequest request = factory.createRequest(wr);
+
//
- ControllerResponse response = controller.process(context.getRequest());
+ ControllerResponse response = controller.process(context, request);
//
Renderer renderer = ControllerResponseRendererFactory.getRenderer(response);
@@ -87,6 +97,7 @@
}
else
{
+
PageRenderer renderer = new PageRenderer(new ResponseProperties(),
context.getStateControllerContext().createPageState(false));
//
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/URLParameterConstants.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/URLParameterConstants.java 2008-02-16
06:20:27 UTC (rev 10000)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/URLParameterConstants.java 2008-02-16
19:09:16 UTC (rev 10001)
@@ -44,49 +44,4 @@
*/
public static final String PORTLET_TYPE = "portlet";
- /**
- * The life cycle type of the invocation. The values accepted are
<code>ACTION_LIFECYCLE</code>,
- * <code>RENDER_LIFECYCLE</code> and
<code>RESOURCE_LIFECYCLE</code>.
- */
- public static final String LIFECYCLE_PHASE = "lifecycle";
-
- /** The window id. */
- public static final String WINDOW_ID = "windowid";
-
- /** The portlet mode. */
- public static final String MODE = "mode";
-
- /** The window state. */
- public static final String WINDOW_STATE = "windowstate";
-
- /** The portlet navigational state for any type of lifecycle. */
- public static final String NAVIGATIONAL_STATE = "navigationalstate";
-
- /** The portlet resource state for lifecycle of type
<code>RENDER_LIFECYCLE</code>. */
- public static final String RESOURCE_STATE = "resourcestate";
-
- /** The portlet interaction state for lifecycle of type
<code>ACTION_LIFECYCLE</code>. */
- public static final String INTERACTION_STATE = "interactionstate";
-
- /** The page state for any kind of lifecycle. */
- public static final String PAGE_STATE = "pagestate";
-
- /** The public navigational state changes of a portlet for lifecycle of type
<code>RENDER_LIFECYCLE</code>. */
- public static final String PUBLIC_NAVIGATIONAL_STATE_CHANGES =
"publicnavigationalstatechanges";
-
- /** The resource id for lifecycle of type <code>RESOURCE_LIFECYCLE</code>.
*/
- public static final String RESOURCE_ID = "resourceid";
-
- /** The resource cacheability for lifecycle of type
<code>RENDER_LIFECYCLE</code>. */
- public static final String RESOURCE_CACHEABILITY = "resourcecacheability";
-
- /** Denotes an action lifecycle operation. */
- public static final String ACTION_PHASE = "action";
-
- /** Denotes a render lifecycle operation. */
- public static final String RENDER_PHASE = "render";
-
- /** Denotes a resource lifecycle operation. */
- public static final String RESOURCE_PHASE = "resource";
-
}
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/AbstractMarkupRenderer.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/AbstractMarkupRenderer.java 2008-02-16
06:20:27 UTC (rev 10000)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/AbstractMarkupRenderer.java 2008-02-16
19:09:16 UTC (rev 10001)
@@ -47,7 +47,7 @@
this.properties = properties;
}
- public void render(PortletControllerContext context) throws IOException
+ public void render(PortletControllerContextImpl context) throws IOException
{
prepareRendering(context);
HttpServletResponse resp = context.getClientResponse();
@@ -85,7 +85,7 @@
}
}
- protected void prepareRendering(PortletControllerContext context)
+ protected void prepareRendering(PortletControllerContextImpl context)
{
// default behavior does nothing
}
Modified:
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 2008-02-16
06:20:27 UTC (rev 10000)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/AbstractPortletControllerContext.java 2008-02-16
19:09:16 UTC (rev 10001)
@@ -23,33 +23,12 @@
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.io.Serialization;
-import org.jboss.portal.common.io.SerializationFilter;
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.Base64;
-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.controller.state.PageNavigationalStateSerialization;
import org.jboss.portal.portlet.impl.spi.AbstractClientContext;
import org.jboss.portal.portlet.impl.spi.AbstractRequestContext;
import org.jboss.portal.portlet.impl.spi.AbstractSecurityContext;
@@ -63,18 +42,14 @@
import org.jboss.portal.portlet.invocation.ResourceInvocation;
import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
import org.jboss.portal.portlet.spi.PortletInvocationContext;
-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 org.apache.log4j.Logger;
-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>
@@ -84,6 +59,9 @@
{
/** . */
+ private static Logger log = Logger.getLogger(AbstractPortletControllerContext.class);
+
+ /** . */
public static final MarkupInfo MARKUP_INFO = new MarkupInfo(MediaType.HTML,
"UTF8");
/** . */
@@ -98,189 +76,14 @@
/** . */
private final HttpServletResponse resp;
- /** . */
- private final ServletContext servletContext;
-
- /** . */
- private final ControllerRequest request;
-
- /** . */
- private final StateControllerContextImpl stateControllerContext;
-
- /** . */
- private final PageNavigationalState pageState;
-
- public AbstractPortletControllerContext(
- HttpServletRequest req,
- HttpServletResponse resp,
- ServletContext servletContext)
+ public AbstractPortletControllerContext(HttpServletRequest req, HttpServletResponse
resp
+ )
throws IllegalRequestException, IOException
{
- StateControllerContextImpl tmp = new StateControllerContextImpl(this);
-
- //
- PageNavigationalStateSerialization serialization = new
PageNavigationalStateSerialization(tmp);
-
- // The nav state provided with the request
- // Unmarshall portal navigational state if it is provided
- PageNavigationalState pageState = null;
- String context = req.getParameter(PAGE_STATE);
- if (context != null)
- {
- byte[] bytes = Base64.decode(context, true);
- pageState = IOTools.unserialize(serialization, SerializationFilter.COMPRESSOR,
bytes);
- }
-
- // The type of invocation
- String type = req.getParameter(TYPE);
-
- // Process only portlet type
- // The request decoded if not null
- ControllerRequest request = null;
- if (PORTLET_TYPE.equals(type))
- {
- // Get the window id
- String windowId = req.getParameter(WINDOW_ID);
-
- // Helper
- WebRequest ri = new WebRequest(req);
-
- //
- 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 phase = req.getParameter(LIFECYCLE_PHASE);
- if (RESOURCE_PHASE.equals(phase))
- {
- 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,
- windowId,
- resourceId,
- resourceState,
- formParameters);
- break;
- case PORTLET:
- request = new PortletScopedPortletResourceRequest(
- this,
- windowId,
- resourceId,
- resourceState,
- formParameters,
- windowNavigationalState);
- break;
- case PAGE:
- request = new PageScopedFullPortletResourceRequest(
- this,
- windowId,
- resourceId,
- resourceState,
- formParameters,
- pageState,
- windowNavigationalState);
- break;
- }
- }
- else
- {
- if (ACTION_PHASE.equals(phase))
- {
- 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,
- windowId,
- interactionState,
- formParameters,
- windowNavigationalState,
- pageState);
- }
- else
- {
- byte[] bytes =
Base64.decode(req.getParameter(PUBLIC_NAVIGATIONAL_STATE_CHANGES), true);
- Map<String, String[]> publicNavigationalStateChanges =
IOTools.unserialize(Serialization.PARAMETER_MAP, SerializationFilter.COMPRESSOR, bytes);
-
- //
- request = new PortletRenderRequest(
- this,
- windowId,
- windowNavigationalState,
- publicNavigationalStateChanges,
- pageState);
- }
- }
- }
-
- //
- this.request = request;
this.req = req;
this.resp = resp;
- this.servletContext = servletContext;
- this.stateControllerContext = tmp;
- this.pageState = pageState;
}
- public PageNavigationalState getPageState()
- {
- return pageState;
- }
-
- public ControllerRequest getRequest()
- {
- return request;
- }
-
- public ServletContext getServletContext()
- {
- return servletContext;
- }
-
public HttpServletRequest getClientRequest()
{
return req;
@@ -291,24 +94,30 @@
return resp;
}
- public PortletInfo getPortletInfo(String windowId) throws PortletInvokerException
+ public PortletInfo getPortletInfo(String windowId)
{
- return getPortlet(windowId).getInfo();
+ try
+ {
+ return getPortlet(windowId).getInfo();
+ }
+ catch (PortletInvokerException e)
+ {
+ log.error("Could not access portlet invoker for locating window " +
windowId, e);
+
+ //
+ return null;
+ }
}
protected abstract Portlet getPortlet(String windowId) throws
PortletInvokerException;
protected abstract PortletInvocationResponse invoke(PortletInvocation invocation)
throws PortletInvokerException;
- public abstract EventControllerContext getEventControllerContext();
-
- public StateControllerContext getStateControllerContext()
+ public PortletInvocationResponse invoke(ActionInvocation actionInvocation) throws
PortletInvokerException
{
- return stateControllerContext;
- }
- public PortletInvocationResponse invoke(String windowId, ActionInvocation
actionInvocation) throws PortletInvokerException
- {
+ TestPortletInvocationContext context =
(TestPortletInvocationContext)actionInvocation.getContext();
+ String windowId = context.getWindowId();
Portlet portlet = getPortlet(windowId);
@@ -324,11 +133,14 @@
actionInvocation.setRequestContext(new AbstractRequestContext(req));
actionInvocation.setTarget(instanceContext.getTarget());
- return invoke(actionInvocation);
+ return invoke((PortletInvocation)actionInvocation);
}
- public PortletInvocationResponse invoke(String windowId, List<Cookie>
requestCookies, EventInvocation eventInvocation) throws PortletInvokerException
+ public PortletInvocationResponse invoke(List<Cookie> requestCookies,
EventInvocation eventInvocation) throws PortletInvokerException
{
+ TestPortletInvocationContext context =
(TestPortletInvocationContext)eventInvocation.getContext();
+ String windowId = context.getWindowId();
+
Portlet portlet = getPortlet(windowId);
TestInstanceContext instanceContext = new TestInstanceContext(req,
portlet.getContext(), true);
@@ -345,8 +157,11 @@
return invoke(eventInvocation);
}
- public PortletInvocationResponse invoke(String windowId, ResourceInvocation
resourceInvocation) throws PortletInvokerException
+ public PortletInvocationResponse invoke(ResourceInvocation resourceInvocation) throws
PortletInvokerException
{
+ TestPortletInvocationContext context =
(TestPortletInvocationContext)resourceInvocation.getContext();
+ String windowId = context.getWindowId();
+
Portlet portlet = getPortlet(windowId);
TestInstanceContext instanceContext = new TestInstanceContext(req,
portlet.getContext(), true);
@@ -361,12 +176,12 @@
resourceInvocation.setRequestContext(new AbstractRequestContext(req));
resourceInvocation.setTarget(instanceContext.getTarget());
- return invoke(resourceInvocation);
+ //
+ return invoke((PortletInvocation)resourceInvocation);
}
public PortletInvocationContext createPortletInvocationContext(String windowId,
PageNavigationalState pageState)
{
- return new TestPortletInvocationContext(stateControllerContext, req, resp,
windowId, pageState, MARKUP_INFO);
+ return new TestPortletInvocationContext(getStateControllerContext(), 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/ErrorResponseRenderer.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/ErrorResponseRenderer.java 2008-02-16
06:20:27 UTC (rev 10000)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/ErrorResponseRenderer.java 2008-02-16
19:09:16 UTC (rev 10001)
@@ -24,7 +24,6 @@
package org.jboss.portal.portlet.test.controller;
import org.apache.log4j.Logger;
-import org.jboss.portal.portlet.controller.PortletControllerContext;
import org.jboss.portal.portlet.invocation.response.ErrorResponse;
import java.io.IOException;
@@ -47,7 +46,7 @@
this.response = response;
}
- public void render(PortletControllerContext context) throws IOException
+ public void render(PortletControllerContextImpl context) throws IOException
{
if (response.getCause() != null)
{
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PageRenderer.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PageRenderer.java 2008-02-16
06:20:27 UTC (rev 10000)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PageRenderer.java 2008-02-16
19:09:16 UTC (rev 10001)
@@ -125,7 +125,7 @@
writer.print("</body></html>");
}
- protected void prepareRendering(PortletControllerContext context)
+ protected void prepareRendering(PortletControllerContextImpl context)
{
// What we collect during the different renders
@@ -216,7 +216,7 @@
}
protected RenderInvocation createRenderInvocation(
- PortletControllerContext context, ResponseProperties pageProperties,
PageNavigationalState pageNS, Portlet portlet,
+ PortletControllerContextImpl context, ResponseProperties pageProperties,
PageNavigationalState pageNS, Portlet portlet,
WindowNavigationalState windowNS, Mode mode, WindowState windowState, StateString
portletNS, ParameterMap publicNS)
{
HttpServletRequest req = context.getClientRequest();
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-16
06:20:27 UTC (rev 10000)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PortletControllerContextImpl.java 2008-02-16
19:09:16 UTC (rev 10001)
@@ -23,61 +23,23 @@
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.PortletContext;
import org.jboss.portal.portlet.PortletInvoker;
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.event.EventControllerContextImpl;
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.Collection;
-import java.util.List;
-import java.util.Map;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -92,14 +54,18 @@
/** . */
private final EventControllerContext eventControllerContext;
+ /** . */
+ private final StateControllerContext stateControllerContext;
+
public PortletControllerContextImpl(HttpServletRequest req, HttpServletResponse resp,
ServletContext servletContext)
throws IllegalRequestException, IOException, ClassNotFoundException
{
- super(req, resp, servletContext);
+ super(req, resp);
//
this.invoker =
(PortletInvoker)servletContext.getAttribute("ConsumerPortletInvoker");
this.eventControllerContext = new EventControllerContextImpl(invoker);
+ this.stateControllerContext = new StateControllerContextImpl(this);
}
protected Portlet getPortlet(String windowId) throws PortletInvokerException
@@ -107,6 +73,11 @@
return invoker.getPortlet(PortletContext.createPortletContext(windowId));
}
+ public StateControllerContext getStateControllerContext()
+ {
+ return stateControllerContext;
+ }
+
protected PortletInvocationResponse invoke(PortletInvocation invocation) throws
PortletInvokerException
{
return invoker.invoke(invocation);
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PortletURLRenderer.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PortletURLRenderer.java 2008-02-16
06:20:27 UTC (rev 10000)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PortletURLRenderer.java 2008-02-16
19:09:16 UTC (rev 10001)
@@ -24,26 +24,20 @@
package org.jboss.portal.portlet.test.controller;
import org.jboss.portal.common.io.IOTools;
-import org.jboss.portal.common.io.Serialization;
import org.jboss.portal.common.io.SerializationFilter;
import org.jboss.portal.common.text.CharBuffer;
import org.jboss.portal.common.text.FastURLEncoder;
import org.jboss.portal.common.util.Base64;
-import org.jboss.portal.portlet.ActionURL;
import org.jboss.portal.portlet.ContainerURL;
-import org.jboss.portal.portlet.PortletURL;
-import org.jboss.portal.portlet.RenderURL;
-import org.jboss.portal.portlet.ResourceURL;
-import org.jboss.portal.portlet.StateString;
-import org.jboss.portal.portlet.cache.CacheLevel;
-import org.jboss.portal.portlet.controller.impl.state.StateControllerContextImpl;
import org.jboss.portal.portlet.controller.state.PageNavigationalState;
import org.jboss.portal.portlet.controller.state.PageNavigationalStateSerialization;
+import org.jboss.portal.portlet.controller.state.StateControllerContext;
+import org.jboss.portal.portlet.controller.impl.request.ControllerRequestParameterNames;
+import
org.jboss.portal.portlet.controller.impl.request.ControllerRequestParameterMapFactory;
import static org.jboss.portal.portlet.test.URLParameterConstants.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import java.util.HashMap;
import java.util.Map;
import java.util.Collections;
@@ -55,7 +49,7 @@
{
/** . */
- final StateControllerContextImpl stateContext;
+ final StateControllerContext stateContext;
/** . */
final PageNavigationalStateSerialization serialization;
@@ -70,7 +64,7 @@
final PageNavigationalState pageNS;
public PortletURLRenderer(
- StateControllerContextImpl stateContext,
+ StateControllerContext stateContext,
PageNavigationalState pageNS,
HttpServletRequest clientReq,
HttpServletResponse clientResp)
@@ -130,7 +124,7 @@
Map<String, String> parameters;
if (pageState != null)
{
- parameters = Collections.singletonMap(PAGE_STATE, pageState);
+ parameters =
Collections.singletonMap(ControllerRequestParameterNames.PAGE_STATE, pageState);
}
else
{
@@ -143,144 +137,15 @@
public String renderURL(String windowId, ContainerURL containerURL, Boolean
wantSecure, Boolean wantAuthenticated, boolean relative)
{
- Map<String, String> parameters = new HashMap<String, String>();
+ ControllerRequestParameterMapFactory factory = new
ControllerRequestParameterMapFactory(stateContext);
//
- parameters.put(TYPE, PORTLET_TYPE);
+ Map<String, String> parameters = factory.blah(pageNS, windowId,
containerURL);
//
- parameters.put(WINDOW_ID, windowId);
+ parameters.put(TYPE, PORTLET_TYPE);
//
- String type;
- if (containerURL instanceof ActionURL)
- {
- type = ACTION_PHASE;
- }
- else if (containerURL instanceof RenderURL)
- {
- type = RENDER_PHASE;
- }
- else if (containerURL instanceof ResourceURL)
- {
- type = RESOURCE_PHASE;
- }
- else
- {
- throw new Error();
- }
- parameters.put(LIFECYCLE_PHASE, type);
-
- //
- String pageState = null;
- if (pageNS != null)
- {
- byte[] bytes = IOTools.serialize(serialization, SerializationFilter.COMPRESSOR,
pageNS);
- pageState = Base64.encodeBytes(bytes, true);
- }
-
- //
- if (containerURL instanceof PortletURL)
- {
- PortletURL portletURL = (PortletURL)containerURL;
-
- if (portletURL.getMode() != null)
- {
- parameters.put(MODE, portletURL.getMode().toString());
- }
-
- //
- if (portletURL.getWindowState() != null)
- {
- parameters.put(WINDOW_STATE, portletURL.getWindowState().toString());
- }
-
- //
- if (pageState != null)
- {
- parameters.put(PAGE_STATE, pageState);
- }
-
- //
- if (containerURL instanceof ActionURL)
- {
- ActionURL actionURL = (ActionURL)containerURL;
-
- //
- if (actionURL.getNavigationalState() != null)
- {
- parameters.put(NAVIGATIONAL_STATE,
actionURL.getNavigationalState().getStringValue());
- }
-
- //
- StateString interactionState = actionURL.getInteractionState();
- parameters.put(INTERACTION_STATE, interactionState.getStringValue());
- }
- else
- {
- RenderURL renderURL = (RenderURL)containerURL;
-
- //
- Map<String, String[]> changes =
renderURL.getPublicNavigationalStateChanges();
- byte[] bytes = IOTools.serialize(Serialization.PARAMETER_MAP,
SerializationFilter.COMPRESSOR, changes);
- String ns = Base64.encodeBytes(bytes, true);
- parameters.put(PUBLIC_NAVIGATIONAL_STATE_CHANGES, ns);
-
- //
- StateString navigationalState = renderURL.getNavigationalState();
- if (navigationalState != null)
- {
- parameters.put(NAVIGATIONAL_STATE, navigationalState.getStringValue());
- }
- }
- }
- else
- {
- ResourceURL resourceURL = (ResourceURL)containerURL;
-
- //
- StateString resourceState = resourceURL.getResourceState();
- parameters.put(RESOURCE_STATE, resourceState.getStringValue());
-
- //
- String resourceId = resourceURL.getResourceId();
- if (resourceId != null)
- {
- parameters.put(RESOURCE_ID, resourceId);
- }
-
- //
- CacheLevel cacheability = resourceURL.getCacheability();
- parameters.put(RESOURCE_CACHEABILITY, cacheability.name());
-
- //
- if (cacheability != CacheLevel.FULL)
- {
- if (resourceURL.getNavigationalState() != null)
- {
- parameters.put(NAVIGATIONAL_STATE,
resourceURL.getNavigationalState().getStringValue());
- }
-
- //
- if (resourceURL.getMode() != null)
- {
- parameters.put(MODE, resourceURL.getMode().toString());
- }
-
- //
- if (resourceURL.getWindowState() != null)
- {
- parameters.put(WINDOW_STATE, resourceURL.getWindowState().toString());
- }
-
- if (cacheability == CacheLevel.PAGE && pageState != null)
- {
- parameters.put(PAGE_STATE, pageState);
- }
- }
- }
-
- //
return renderURL(parameters, wantSecure, wantAuthenticated, relative);
}
}
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/RedirectResponseRenderer.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/RedirectResponseRenderer.java 2008-02-16
06:20:27 UTC (rev 10000)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/RedirectResponseRenderer.java 2008-02-16
19:09:16 UTC (rev 10001)
@@ -23,7 +23,6 @@
package org.jboss.portal.portlet.test.controller;
-import org.jboss.portal.portlet.controller.PortletControllerContext;
import org.jboss.portal.portlet.invocation.response.HTTPRedirectionResponse;
import java.io.IOException;
@@ -43,7 +42,7 @@
this.response = response;
}
- public void render(PortletControllerContext context) throws IOException
+ public void render(PortletControllerContextImpl context) throws IOException
{
context.getClientResponse().sendRedirect(response.getLocation());
}
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/Renderer.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/Renderer.java 2008-02-16
06:20:27 UTC (rev 10000)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/Renderer.java 2008-02-16
19:09:16 UTC (rev 10001)
@@ -33,5 +33,5 @@
*/
public interface Renderer
{
- void render(PortletControllerContext context) throws IOException;
+ void render(PortletControllerContextImpl context) throws IOException;
}
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/TestPortletInvocationContext.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/TestPortletInvocationContext.java 2008-02-16
06:20:27 UTC (rev 10000)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/TestPortletInvocationContext.java 2008-02-16
19:09:16 UTC (rev 10001)
@@ -29,6 +29,7 @@
import org.jboss.portal.portlet.ContainerURL;
import org.jboss.portal.portlet.controller.impl.state.StateControllerContextImpl;
import org.jboss.portal.portlet.controller.state.PageNavigationalState;
+import org.jboss.portal.portlet.controller.state.StateControllerContext;
import org.jboss.portal.portlet.impl.spi.AbstractPortletInvocationContext;
import org.jboss.portal.portlet.invocation.PortletInvocation;
@@ -43,7 +44,7 @@
{
/** . */
- private final StateControllerContextImpl stateContext;
+ private final StateControllerContext stateContext;
/** . */
private final PortletURLRenderer urlRenderer;
@@ -61,7 +62,7 @@
private final HttpServletResponse clientResponse;
public TestPortletInvocationContext(
- StateControllerContextImpl stateContext,
+ StateControllerContext stateContext,
HttpServletRequest clientRequest,
HttpServletResponse clientResponse,
String windowId,
@@ -86,6 +87,11 @@
addResolver(PortletInvocation.REQUEST_SCOPE, new MapAttributeResolver());
}
+ public String getWindowId()
+ {
+ return windowId;
+ }
+
public HttpServletRequest getClientRequest() throws IllegalStateException
{
return clientRequest;
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/ControllerFilter.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/ControllerFilter.java 2008-02-16
06:20:27 UTC (rev 10000)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/ControllerFilter.java 2008-02-16
19:09:16 UTC (rev 10001)
@@ -23,6 +23,7 @@
package org.jboss.portal.portlet.test.jsp;
import org.jboss.portal.portlet.test.controller.PortletURLRenderer;
+import org.jboss.portal.portlet.test.URLParameterConstants;
import org.jboss.portal.portlet.PortletInvoker;
import org.jboss.portal.portlet.PortletInvokerException;
import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
@@ -30,13 +31,20 @@
import org.jboss.portal.portlet.invocation.response.ErrorResponse;
import org.jboss.portal.portlet.controller.PortletController;
import org.jboss.portal.portlet.controller.request.PortletActionRequest;
+import org.jboss.portal.portlet.controller.impl.request.ControllerRequestFactory;
+import org.jboss.portal.portlet.controller.request.ControllerRequest;
+import org.jboss.portal.portlet.controller.impl.request.ControllerRequestParameterNames;
import org.jboss.portal.portlet.controller.impl.state.StateControllerContextImpl;
import org.jboss.portal.portlet.controller.response.ControllerResponse;
import org.jboss.portal.portlet.controller.response.PageUpdateResponse;
import org.jboss.portal.portlet.controller.response.ResourceResponse;
import org.jboss.portal.portlet.controller.response.PortletResponse;
import org.jboss.portal.portlet.controller.state.PageNavigationalState;
+import org.jboss.portal.portlet.controller.state.PageNavigationalStateSerialization;
import org.jboss.portal.common.io.IOTools;
+import org.jboss.portal.common.io.SerializationFilter;
+import org.jboss.portal.common.util.Base64;
+import org.jboss.portal.web.WebRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -96,14 +104,22 @@
// Now we can create a populated context
PagePortletControllerContext context = new PagePortletControllerContext(req, resp,
invoker, getServletContext(), prepareResponse);
- //
+ // The type of invocation
+ String type = req.getParameter(URLParameterConstants.TYPE);
+
+ // Process only portlet type
+ // The request decoded if not null
PageNavigationalState pageState = null;
- if (context.getRequest() != null)
+ if (URLParameterConstants.PORTLET_TYPE.equals(type))
{
+ WebRequest wr = new WebRequest(req);
+ ControllerRequestFactory factory = new
ControllerRequestFactory(context.getStateControllerContext());
+ ControllerRequest request = factory.createRequest(wr);
+
ControllerResponse controllerResponse;
try
{
- controllerResponse = new PortletController().process(context.getRequest());
+ controllerResponse = new PortletController().process(context, request);
}
catch (PortletInvokerException e)
{
@@ -116,7 +132,7 @@
PageUpdateResponse pageUpdate = (PageUpdateResponse)controllerResponse;
// We perform a send redirect on actions
- if (context.getRequest() instanceof PortletActionRequest)
+ if (request instanceof PortletActionRequest)
{
//
PortletURLRenderer renderer = new PortletURLRenderer(
@@ -231,7 +247,16 @@
}
else
{
- pageState = context.getPageState();
+ PageNavigationalStateSerialization serialization = new
PageNavigationalStateSerialization(context.getStateControllerContext());
+ // The nav state provided with the request
+ // Unmarshall portal navigational state if it is provided
+ pageState = null;
+ String blah = req.getParameter(ControllerRequestParameterNames.PAGE_STATE);
+ if (blah != null)
+ {
+ byte[] bytes = Base64.decode(blah, true);
+ pageState = IOTools.unserialize(serialization,
SerializationFilter.COMPRESSOR, bytes);
+ }
}
//
Modified:
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 2008-02-16
06:20:27 UTC (rev 10000)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/PagePortletControllerContext.java 2008-02-16
19:09:16 UTC (rev 10001)
@@ -27,6 +27,8 @@
import org.jboss.portal.portlet.PortletInvoker;
import org.jboss.portal.portlet.info.PortletInfo;
import org.jboss.portal.portlet.controller.event.EventControllerContext;
+import org.jboss.portal.portlet.controller.state.StateControllerContext;
+import org.jboss.portal.portlet.controller.impl.state.StateControllerContextImpl;
import org.jboss.portal.portlet.invocation.PortletInvocation;
import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
import org.jboss.portal.portlet.test.controller.AbstractPortletControllerContext;
@@ -51,6 +53,9 @@
private final EventControllerContext eventControllerContext;
/** . */
+ private final StateControllerContext stateControllerContext;
+
+ /** . */
private final PortalPrepareResponse prepareResponse;
/** . */
@@ -67,7 +72,7 @@
PortalPrepareResponse prepareResponse)
throws IllegalRequestException, IOException, ServletException,
PortletInvokerException
{
- super(req, resp, servletContext);
+ super(req, resp);
//
Map<Key, Portlet> portlets = new HashMap<Key, Portlet>();
@@ -84,6 +89,7 @@
this.invoker = invoker;
this.portlets = portlets;
this.prepareResponse = prepareResponse;
+ this.stateControllerContext = new StateControllerContextImpl(this);
this.eventControllerContext = new PageEventControllerContext(this,
prepareResponse);
}
@@ -110,6 +116,11 @@
return eventControllerContext;
}
+ public StateControllerContext getStateControllerContext()
+ {
+ return stateControllerContext;
+ }
+
private static class Key
{
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/taglib/PortletURLTag.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/taglib/PortletURLTag.java 2008-02-16
06:20:27 UTC (rev 10000)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/taglib/PortletURLTag.java 2008-02-16
19:09:16 UTC (rev 10001)
@@ -94,7 +94,7 @@
}
PortletURLRenderer renderer = new PortletURLRenderer(
- (StateControllerContextImpl)context.getStateControllerContext(),
+ context.getStateControllerContext(),
renderResponse.getPageState(),
context.getClientRequest(),
context.getClientResponse());
Modified:
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/controller/StateControllerContextTestCase.java
===================================================================
---
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/controller/StateControllerContextTestCase.java 2008-02-16
06:20:27 UTC (rev 10000)
+++
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/controller/StateControllerContextTestCase.java 2008-02-16
19:09:16 UTC (rev 10001)
@@ -40,12 +40,10 @@
import org.jboss.portal.portlet.spi.PortletInvocationContext;
import org.jboss.portal.common.NotYetImplemented;
import org.jboss.portal.common.io.IOTools;
-import org.jboss.portal.common.io.SerializationFilter;
import org.jboss.portal.Mode;
import org.jboss.portal.WindowState;
import static org.jboss.unit.api.Assert.*;
-import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Cookie;
@@ -114,11 +112,6 @@
private static final PortletControllerContext dummyContext = new
PortletControllerContext()
{
- public ServletContext getServletContext()
- {
- throw new NotYetImplemented();
- }
-
public HttpServletRequest getClientRequest()
{
throw new NotYetImplemented();
@@ -129,7 +122,7 @@
throw new NotYetImplemented();
}
- public PortletInfo getPortletInfo(String windowId) throws PortletInvokerException
+ public PortletInfo getPortletInfo(String windowId)
{
throw new NotYetImplemented();
}
@@ -139,17 +132,17 @@
throw new NotYetImplemented();
}
- public PortletInvocationResponse invoke(String windowId, ActionInvocation
actionInvocation) throws PortletInvokerException
+ public PortletInvocationResponse invoke(ActionInvocation actionInvocation) throws
PortletInvokerException
{
throw new NotYetImplemented();
}
- public PortletInvocationResponse invoke(String windowId, List<Cookie>
requestCookies, EventInvocation eventInvocation) throws PortletInvokerException
+ public PortletInvocationResponse invoke(List<Cookie> requestCookies,
EventInvocation eventInvocation) throws PortletInvokerException
{
throw new NotYetImplemented();
}
- public PortletInvocationResponse invoke(String windowId, ResourceInvocation
resourceInvocation) throws PortletInvokerException
+ public PortletInvocationResponse invoke(ResourceInvocation resourceInvocation)
throws PortletInvokerException
{
throw new NotYetImplemented();
}