Author: chris.laprun(a)jboss.com
Date: 2008-02-01 15:15:37 -0500 (Fri, 01 Feb 2008)
New Revision: 9704
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PortletController.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PortletRequestHandler.java
Log:
- Moved PortletController.deliverEvent to PortletRequestHandler as it's only used
there.
- Removed useless calls to downcastRequest in PortletRequestHandler.
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PortletController.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PortletController.java 2008-02-01
20:04:09 UTC (rev 9703)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PortletController.java 2008-02-01
20:15:37 UTC (rev 9704)
@@ -22,7 +22,6 @@
******************************************************************************/
package org.jboss.portal.portlet.test.controller;
-import org.apache.log4j.Logger;
import org.jboss.portal.Mode;
import org.jboss.portal.WindowState;
import org.jboss.portal.common.util.MarkupInfo;
@@ -40,30 +39,23 @@
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.NavigationInfo;
-import org.jboss.portal.portlet.info.ParameterInfo;
-import org.jboss.portal.portlet.invocation.EventInvocation;
import org.jboss.portal.portlet.invocation.RenderInvocation;
import org.jboss.portal.portlet.invocation.response.ErrorResponse;
import org.jboss.portal.portlet.invocation.response.FragmentResponse;
import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
import org.jboss.portal.portlet.invocation.response.ResponseProperties;
-import org.jboss.portal.portlet.invocation.response.UpdateNavigationalStateResponse;
import org.jboss.portal.portlet.spi.PortalContext;
import org.jboss.portal.portlet.test.PageNavigationalState;
import org.jboss.portal.portlet.test.PortletURLRenderer;
-import org.jboss.portal.portlet.test.TestEventContext;
import org.jboss.portal.portlet.test.TestInstanceContext;
import org.jboss.portal.portlet.test.TestRenderContext;
import org.jboss.portal.portlet.test.WindowNavigationalState;
-import org.jboss.portal.portlet.test.event.Event;
import org.jboss.portal.web.IllegalRequestException;
import org.w3c.dom.Element;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import javax.xml.namespace.QName;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
@@ -88,16 +80,10 @@
// private final boolean redirectAfterAction = true;
/** . */
- private final Logger log;
-
- /** . */
private final PortalContext portalContext;
public PortletController() throws IllegalRequestException,
UnsupportedEncodingException
{
- //
- this.log = Logger.getLogger(PortletController.class);
-
Map<String, String> portalProperties = new HashMap<String, String>();
portalProperties.put("javax.portlet.markup.head.element.support",
"true");
@@ -128,64 +114,6 @@
handler.handle(controllerRequest);
}
- PortletInvocationResponse deliverEvent(
- PortletControllerContext context,
- Event event,
- PageNavigationalState pageNS,
- List<Cookie> requestCookies) throws PortletInvokerException
- {
- Portlet portlet = context.getPortlet(event.getPortletContext().getId());
- HttpServletRequest req = context.getClientRequest();
- HttpServletResponse resp = context.getClientResponse();
- WindowNavigationalState windowNS =
pageNS.getWindowNavigationalState(portlet.getContext().getId());
- PortletURLRenderer renderer = new PortletURLRenderer(pageNS, windowNS, portlet,
req, resp);
-
- //
- if (windowNS == null)
- {
- windowNS = new WindowNavigationalState();
- }
-
- //
- ParameterMap publicNS = pageNS.getPublicNavigationalState(portlet);
-
- //
- TestInstanceContext instanceContext = new TestInstanceContext(req,
portlet.getContext(), true);
- TestEventContext actionContext = new TestEventContext(
- renderer,
- windowNS.getMode(),
- windowNS.getWindowState(),
- windowNS.getPortletNavigationalState(),
- publicNS,
- MARKUP_INFO,
- event.getName(),
- event.getPayload());
- EventInvocation eventInvocation = new EventInvocation(actionContext);
-
- //
- eventInvocation.setClientContext(new AbstractClientContext(req, requestCookies));
- eventInvocation.setServerContext(new AbstractServerContext(req, resp));
- eventInvocation.setInstanceContext(instanceContext);
- eventInvocation.setUserContext(new AbstractUserContext(req));
- eventInvocation.setWindowContext(new
AbstractWindowContext(portlet.getContext().getId()));
- eventInvocation.setPortalContext(getPortalContext());
- eventInvocation.setSecurityContext(new AbstractSecurityContext(req));
- eventInvocation.setTarget(instanceContext.getTarget());
-
- //
- try
- {
- return context.invoke(eventInvocation);
- }
- catch (PortletInvokerException e)
- {
- log.error("Error during event invocation", e);
-
- //
- return null;
- }
- }
-
/**
* @param context
* @param pageProperties properties that needs to be rendered on this page
@@ -382,71 +310,6 @@
}
}
- void updateNavigationalState(
- PortletControllerContext context,
- String portletId,
- UpdateNavigationalStateResponse update,
- PageNavigationalState pageState) throws PortletInvokerException
- {
- Portlet portlet = context.getPortlet(portletId);
-
- //
- WindowNavigationalState windowNS =
pageState.getWindowNavigationalState(portletId);
-
- //
- if (windowNS == null)
- {
- windowNS = new WindowNavigationalState();
- }
-
- //
- Mode mode = windowNS.getMode();
- if (update.getMode() != null)
- {
- mode = update.getMode();
- }
- WindowState windowState = windowNS.getWindowState();
- if (update.getWindowState() != null)
- {
- windowState = update.getWindowState();
- }
- StateString portletNS = windowNS.getPortletNavigationalState();
- if (update.getNavigationalState() != null)
- {
- portletNS = update.getNavigationalState();
- }
- windowNS = new WindowNavigationalState(portletNS, mode, windowState);
- pageState.setWindowNavigationalState(portletId, windowNS);
-
- // Now update shared state scoped at page
- Map<String, String[]> publicNS = update.getPublicNavigationalStateUpdates();
- if (publicNS != null)
- {
- NavigationInfo navigationInfo = portlet.getInfo().getNavigation();
- Map<QName, String[]> pageNS = pageState.getPageNavigationalState();
- for (Map.Entry<String, String[]> entry : publicNS.entrySet())
- {
- String id = entry.getKey();
- ParameterInfo parameterInfo = navigationInfo.getPublicParameter(id);
-
- //
- if (parameterInfo != null)
- {
- QName name = parameterInfo.getName();
- String[] value = entry.getValue();
- if (value.length > 0)
- {
- pageNS.put(name, value);
- }
- else
- {
- pageNS.remove(name);
- }
- }
- }
- }
- }
-
PortalContext getPortalContext()
{
return portalContext;
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PortletRequestHandler.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PortletRequestHandler.java 2008-02-01
20:04:09 UTC (rev 9703)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PortletRequestHandler.java 2008-02-01
20:15:37 UTC (rev 9704)
@@ -10,13 +10,17 @@
import org.jboss.portal.portlet.Portlet;
import org.jboss.portal.portlet.PortletContext;
import org.jboss.portal.portlet.PortletInvokerException;
+import org.jboss.portal.portlet.StateString;
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.NavigationInfo;
+import org.jboss.portal.portlet.info.ParameterInfo;
import org.jboss.portal.portlet.invocation.ActionInvocation;
+import org.jboss.portal.portlet.invocation.EventInvocation;
import org.jboss.portal.portlet.invocation.response.ErrorResponse;
import org.jboss.portal.portlet.invocation.response.HTTPRedirectionResponse;
import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
@@ -26,16 +30,21 @@
import org.jboss.portal.portlet.test.PageNavigationalState;
import org.jboss.portal.portlet.test.PortletURLRenderer;
import org.jboss.portal.portlet.test.TestActionContext;
+import org.jboss.portal.portlet.test.TestEventContext;
import org.jboss.portal.portlet.test.TestInstanceContext;
+import org.jboss.portal.portlet.test.WindowNavigationalState;
import static org.jboss.portal.portlet.test.controller.PortletController.*;
import org.jboss.portal.portlet.test.event.Event;
import org.jboss.portal.portlet.test.event.EventControllerContext;
+import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import javax.xml.namespace.QName;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
/**
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
@@ -58,10 +67,8 @@
return (PortletRequest)request;
}
- void processResponse(PortletRequest request, PortletInvocationResponse response)
throws IOException, PortletInvokerException
+ void processResponse(PortletRequest portletRequest, PortletInvocationResponse
response) throws IOException, PortletInvokerException
{
- PortletRequest portletRequest = downcastRequest(request);
-
PortletControllerContext context = portletRequest.controllerContext;
//
@@ -93,7 +100,7 @@
if (response instanceof UpdateNavigationalStateResponse)
{
UpdateNavigationalStateResponse updateResponse =
(UpdateNavigationalStateResponse)response;
- controller.updateNavigationalState(context, portletRequest.portletId,
updateResponse, portletRequest.pageState);
+ updateNavigationalState(context, portletRequest.portletId, updateResponse,
portletRequest.pageState);
//
ResponseProperties update = updateResponse.getProperties();
@@ -122,7 +129,7 @@
Event event = eventQueue.removeFirst();
//
- PortletInvocationResponse eventResponse = controller.deliverEvent(context,
event, portletRequest.pageState, requestProperties.getCookies());
+ PortletInvocationResponse eventResponse = deliverEvent(context, event,
portletRequest.pageState, requestProperties.getCookies());
//
if (eventResponse instanceof UpdateNavigationalStateResponse)
@@ -130,7 +137,7 @@
UpdateNavigationalStateResponse update =
(UpdateNavigationalStateResponse)eventResponse;
// Update ns
- controller.updateNavigationalState(context,
event.getPortletContext().getId(), update, portletRequest.pageState);
+ updateNavigationalState(context, event.getPortletContext().getId(),
update, portletRequest.pageState);
// Add events if any
for (StateResponse.Event portletEvent : update.getEvents())
@@ -197,10 +204,8 @@
controller.render(context, requestProperties, portletRequest.pageState);
}
- PortletInvocationResponse invoke(PortletRequest controllerRequest) throws
PortletInvokerException
+ PortletInvocationResponse invoke(PortletRequest portletRequest) throws
PortletInvokerException
{
- PortletRequest portletRequest = downcastRequest(controllerRequest);
-
PortletControllerContext context = portletRequest.controllerContext;
Portlet portlet = context.getPortlet(portletRequest.portletId);
HttpServletRequest req = context.getClientRequest();
@@ -284,4 +289,122 @@
}
}
+ private PortletInvocationResponse deliverEvent(PortletControllerContext context, Event
event,
+ PageNavigationalState pageNS,
List<Cookie> requestCookies)
+ throws PortletInvokerException
+ {
+ Portlet portlet = context.getPortlet(event.getPortletContext().getId());
+ HttpServletRequest req = context.getClientRequest();
+ HttpServletResponse resp = context.getClientResponse();
+ WindowNavigationalState windowNS =
pageNS.getWindowNavigationalState(portlet.getContext().getId());
+ PortletURLRenderer renderer = new PortletURLRenderer(pageNS, windowNS, portlet,
req, resp);
+
+ //
+ if (windowNS == null)
+ {
+ windowNS = new WindowNavigationalState();
+ }
+
+ //
+ ParameterMap publicNS = pageNS.getPublicNavigationalState(portlet);
+
+ //
+ TestInstanceContext instanceContext = new TestInstanceContext(req,
portlet.getContext(), true);
+ TestEventContext actionContext = new TestEventContext(
+ renderer,
+ windowNS.getMode(),
+ windowNS.getWindowState(),
+ windowNS.getPortletNavigationalState(),
+ publicNS,
+ MARKUP_INFO,
+ event.getName(),
+ event.getPayload());
+ EventInvocation eventInvocation = new EventInvocation(actionContext);
+
+ //
+ eventInvocation.setClientContext(new AbstractClientContext(req, requestCookies));
+ eventInvocation.setServerContext(new AbstractServerContext(req, resp));
+ eventInvocation.setInstanceContext(instanceContext);
+ eventInvocation.setUserContext(new AbstractUserContext(req));
+ eventInvocation.setWindowContext(new
AbstractWindowContext(portlet.getContext().getId()));
+ eventInvocation.setPortalContext(controller.getPortalContext());
+ eventInvocation.setSecurityContext(new AbstractSecurityContext(req));
+ eventInvocation.setTarget(instanceContext.getTarget());
+
+ //
+ try
+ {
+ return context.invoke(eventInvocation);
+ }
+ catch (PortletInvokerException e)
+ {
+ log.error("Error during event invocation", e);
+
+ //
+ return null;
+ }
+ }
+
+ private void updateNavigationalState(PortletControllerContext context, String
portletId,
+ UpdateNavigationalStateResponse update,
PageNavigationalState pageState)
+ throws PortletInvokerException
+ {
+ Portlet portlet = context.getPortlet(portletId);
+
+ //
+ WindowNavigationalState windowNS =
pageState.getWindowNavigationalState(portletId);
+
+ //
+ if (windowNS == null)
+ {
+ windowNS = new WindowNavigationalState();
+ }
+
+ //
+ Mode mode = windowNS.getMode();
+ if (update.getMode() != null)
+ {
+ mode = update.getMode();
+ }
+ WindowState windowState = windowNS.getWindowState();
+ if (update.getWindowState() != null)
+ {
+ windowState = update.getWindowState();
+ }
+ StateString portletNS = windowNS.getPortletNavigationalState();
+ if (update.getNavigationalState() != null)
+ {
+ portletNS = update.getNavigationalState();
+ }
+ windowNS = new WindowNavigationalState(portletNS, mode, windowState);
+ pageState.setWindowNavigationalState(portletId, windowNS);
+
+ // Now update shared state scoped at page
+ Map<String, String[]> publicNS = update.getPublicNavigationalStateUpdates();
+ if (publicNS != null)
+ {
+ NavigationInfo navigationInfo = portlet.getInfo().getNavigation();
+ Map<QName, String[]> pageNS = pageState.getPageNavigationalState();
+ for (Map.Entry<String, String[]> entry : publicNS.entrySet())
+ {
+ String id = entry.getKey();
+ ParameterInfo parameterInfo = navigationInfo.getPublicParameter(id);
+
+ //
+ if (parameterInfo != null)
+ {
+ QName name = parameterInfo.getName();
+ String[] value = entry.getValue();
+ if (value.length > 0)
+ {
+ pageNS.put(name, value);
+ }
+ else
+ {
+ pageNS.remove(name);
+ }
+ }
+ }
+ }
+ }
}