Author: julien(a)jboss.com
Date: 2008-02-04 06:10:11 -0500 (Mon, 04 Feb 2008)
New Revision: 9737
Removed:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/response/StateResponse.java
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/PortletRequestAttributes.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/MimeResponseImpl.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletRequestImpl.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/StateAwareResponseImpl.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/PortletInvocation.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/response/FragmentResponse.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/response/RedirectionResponse.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/response/UpdateNavigationalStateResponse.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PortletRequestHandler.java
Log:
- add notion of output request attributes in fragment and updatens responses
- remove the fact that a redirect can be followed by events (it wasnt make sense actally)
and remove the related StateResponse class that was carrying the events
- updated the controller accordingly
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/PortletRequestAttributes.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/PortletRequestAttributes.java 2008-02-04
10:57:05 UTC (rev 9736)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/PortletRequestAttributes.java 2008-02-04
11:10:11 UTC (rev 9737)
@@ -73,6 +73,19 @@
UserContext userContext,
HttpServletRequestWrapper wreq)
{
+ if (container == null)
+ {
+ throw new IllegalArgumentException("No null container allowed");
+ }
+ if (userContext == null)
+ {
+ throw new IllegalArgumentException("No null user context allowed");
+ }
+ if (wreq == null)
+ {
+ throw new IllegalArgumentException("No null wrapped request
allowed");
+ }
+
this.container = container;
this.userContext = userContext;
this.wreq = wreq;
@@ -193,4 +206,36 @@
}
setAttribute(name, null);
}
+
+ public void setAttributeMap(Map<String, Object> map)
+ {
+ for (Map.Entry<String, Object> attribute : map.entrySet())
+ {
+ setAttribute(attribute.getKey(), attribute.getValue());
+ }
+ }
+
+ public Map<String, Object> getAttributeMap()
+ {
+ Map<String, Object> map = Collections.emptyMap();
+
+ //
+ if (attributes != null)
+ {
+ for (Map.Entry<String, Object> attribute : attributes.entrySet())
+ {
+ if (attribute.getValue() != REMOVED_ATTRIBUTE)
+ {
+ if (map.size() == 0)
+ {
+ map = new HashMap<String, Object>(attributes.size());
+ }
+ map.put(attribute.getKey(), attribute.getValue());
+ }
+ }
+ }
+
+ //
+ return map;
+ }
}
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/MimeResponseImpl.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/MimeResponseImpl.java 2008-02-04
10:57:05 UTC (rev 9736)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/MimeResponseImpl.java 2008-02-04
11:10:11 UTC (rev 9737)
@@ -92,6 +92,7 @@
else
{
fragment.setProperties(getProperties(false));
+ fragment.setAttributes(preq.attributes.getAttributeMap());
//
return fragment;
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletRequestImpl.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletRequestImpl.java 2008-02-04
10:57:05 UTC (rev 9736)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletRequestImpl.java 2008-02-04
11:10:11 UTC (rev 9737)
@@ -148,8 +148,16 @@
ContainerPreferencesInfo containerPrefs = info.getPreferences();
ContainerNavigationInfo navigationInfo = info.getNavigation();
UserContext userContext = invocation.getUserContext();
+ HttpServletRequestWrapper realReq = new
HttpServletRequestWrapper(invocation.getDispatchedRequest());
//
+ PortletRequestAttributes attributes = new PortletRequestAttributes(container,
userContext, realReq);
+ if (invocation.getAttributes() != null)
+ {
+ attributes.setAttributeMap(invocation.getAttributes());
+ }
+
+ //
this.contextPath =
(String)invocation.getDispatchedRequest().getAttribute("javax.servlet.include.context_path");
this.invocation = invocation;
this.userContext = userContext;
@@ -158,9 +166,9 @@
this.clientContext = invocation.getClientContext();
this.windowContext = invocation.getWindowContext();
this.container = container;
- this.realReq = new HttpServletRequestWrapper(invocation.getDispatchedRequest());
+ this.realReq = realReq;
this.portalContext = new PortalContextImpl(invocation.getPortalContext());
- this.attributes = new PortletRequestAttributes(container, userContext, realReq);
+ this.attributes = attributes;
this.preferences = new PortletPreferencesImpl(prefs, containerPrefs, validator,
mode);
this.navigationInfo = navigationInfo;
this.requestParameterMap = PortletRequestParameterMap.create(navigationInfo,
invocation);
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/StateAwareResponseImpl.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/StateAwareResponseImpl.java 2008-02-04
10:57:05 UTC (rev 9736)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/StateAwareResponseImpl.java 2008-02-04
11:10:11 UTC (rev 9737)
@@ -35,7 +35,6 @@
import org.jboss.portal.portlet.invocation.PortletInvocation;
import org.jboss.portal.portlet.invocation.response.HTTPRedirectionResponse;
import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
-import org.jboss.portal.portlet.invocation.response.StateResponse;
import org.jboss.portal.portlet.invocation.response.UpdateNavigationalStateResponse;
import javax.portlet.PortletMode;
@@ -75,7 +74,7 @@
protected WantRedirect wantRedirect;
/** . */
- private List<StateResponse.Event> events;
+ private List<UpdateNavigationalStateResponse.Event> events;
public StateAwareResponseImpl(PortletInvocation invocation, PortletRequestImpl preq)
{
@@ -345,33 +344,16 @@
{
if (events == null)
{
- events = new LinkedList<StateResponse.Event>();
+ events = new LinkedList<UpdateNavigationalStateResponse.Event>();
}
- events.add(new StateResponse.Event(name, value));
+ events.add(new UpdateNavigationalStateResponse.Event(name, value));
}
private abstract class Decision
{
- protected StateResponse getResponse()
- {
- StateResponse response = createResponse();
+ protected abstract PortletInvocationResponse getResponse();
- //
- if (events != null)
- {
- for (StateResponse.Event event : events)
- {
- response.queueEvent(event);
- }
- }
-
- //
- return response;
- }
-
- protected abstract StateResponse createResponse();
-
}
protected class WantUpdate extends Decision
@@ -386,12 +368,13 @@
/** The new mode requested. */
protected Mode mode;
- protected StateResponse createResponse()
+ protected PortletInvocationResponse getResponse()
{
UpdateNavigationalStateResponse response = new
UpdateNavigationalStateResponse();
//
response.setProperties(getProperties(false));
+ response.setAttributes(preq.attributes.getAttributeMap());
//
response.setMode(mode);
@@ -400,6 +383,15 @@
response.setNavigationalState(ParametersStateString.create(navigationalState.getPrivateMapSnapshot()));
//
+ if (events != null)
+ {
+ for (UpdateNavigationalStateResponse.Event event : events)
+ {
+ response.queueEvent(event);
+ }
+ }
+
+ //
return response;
}
}
@@ -410,7 +402,7 @@
/** . */
protected String location;
- protected StateResponse createResponse()
+ protected PortletInvocationResponse getResponse()
{
return new HTTPRedirectionResponse(location);
}
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/PortletInvocation.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/PortletInvocation.java 2008-02-04
10:57:05 UTC (rev 9736)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/PortletInvocation.java 2008-02-04
11:10:11 UTC (rev 9737)
@@ -41,6 +41,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Set;
+import java.util.Map;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -80,6 +81,9 @@
/** The target portlet. */
protected PortletContext target;
+ /** . */
+ protected Map<String, Object> attributes;
+
/** The invocation context. */
protected PortletInvocationContext ctx;
@@ -291,4 +295,14 @@
{
this.windowContext = windowContext;
}
+
+ public Map<String, Object> getAttributes()
+ {
+ return attributes;
+ }
+
+ public void setAttributes(Map<String, Object> attributes)
+ {
+ this.attributes = attributes;
+ }
}
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/response/FragmentResponse.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/response/FragmentResponse.java 2008-02-04
10:57:05 UTC (rev 9736)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/response/FragmentResponse.java 2008-02-04
11:10:11 UTC (rev 9737)
@@ -31,6 +31,7 @@
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Set;
+import java.util.Map;
/**
* Data produced.
@@ -54,6 +55,9 @@
private ResponseProperties properties;
/** . */
+ private Map<String, Object> attributes;
+
+ /** . */
private ContentBuffer buffer;
/** The title if any. */
@@ -72,6 +76,7 @@
this.cacheControl = null;
this.properties = null;
this.nextModes = null;
+ this.attributes = null;
}
public ResponseProperties getProperties()
@@ -94,6 +99,16 @@
this.cacheControl = cacheControl;
}
+ public Map<String, Object> getAttributes()
+ {
+ return attributes;
+ }
+
+ public void setAttributes(Map<String, Object> attributes)
+ {
+ this.attributes = attributes;
+ }
+
public int getType()
{
return buffer.getType();
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/response/RedirectionResponse.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/response/RedirectionResponse.java 2008-02-04
10:57:05 UTC (rev 9736)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/response/RedirectionResponse.java 2008-02-04
11:10:11 UTC (rev 9737)
@@ -28,6 +28,6 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 5448 $
*/
-public abstract class RedirectionResponse extends StateResponse
+public abstract class RedirectionResponse extends PortletInvocationResponse
{
}
Deleted:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/response/StateResponse.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/response/StateResponse.java 2008-02-04
10:57:05 UTC (rev 9736)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/response/StateResponse.java 2008-02-04
11:10:11 UTC (rev 9737)
@@ -1,95 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, 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.invocation.response;
-
-import javax.xml.namespace.QName;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Collections;
-import java.io.Serializable;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-public class StateResponse extends PortletInvocationResponse
-{
-
- /** . */
- private List<Event> producedEvents = Collections.emptyList();
-
- public void queueEvent(Event event)
- {
- if (event == null)
- {
- throw new IllegalArgumentException("No null event accepted");
- }
-
- //
- if (producedEvents.size() == 0)
- {
- producedEvents = new ArrayList<Event>();
- }
-
- //
- producedEvents.add(event);
- }
-
- public List<Event> getEvents()
- {
- return producedEvents;
- }
-
- /**
- * An event produced by a state response.
- */
- public static class Event
- {
-
- /** The optional event. */
- private QName name;
-
- /** The optional event payload. */
- private Serializable payload;
-
- public Event(QName name, Serializable payload)
- {
- if (name == null)
- {
- throw new IllegalArgumentException();
- }
- this.name = name;
- this.payload = payload;
- }
-
- public QName getName()
- {
- return name;
- }
-
- public Serializable getPayload()
- {
- return payload;
- }
- }
-}
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/response/UpdateNavigationalStateResponse.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/response/UpdateNavigationalStateResponse.java 2008-02-04
10:57:05 UTC (rev 9736)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/response/UpdateNavigationalStateResponse.java 2008-02-04
11:10:11 UTC (rev 9737)
@@ -24,10 +24,14 @@
import org.jboss.portal.Mode;
import org.jboss.portal.WindowState;
-import org.jboss.portal.common.util.ParameterMap;
import org.jboss.portal.portlet.StateString;
+import javax.xml.namespace.QName;
import java.util.Map;
+import java.util.List;
+import java.util.Collections;
+import java.util.ArrayList;
+import java.io.Serializable;
/**
* Update the navigational state.
@@ -35,21 +39,27 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 5477 $
*/
-public class UpdateNavigationalStateResponse extends StateResponse
+public class UpdateNavigationalStateResponse extends PortletInvocationResponse
{
/** . */
private ResponseProperties properties;
/** The navigational state returned. */
- protected StateString navigationalState;
+ private StateString navigationalState;
/** The new window state requested. */
- protected WindowState windowState;
+ private WindowState windowState;
/** The new mode requested. */
- protected Mode mode;
+ private Mode mode;
+ /** The attributes snapshot after the request. */
+ private Map<String, Object> attributes;
+
+ /** . */
+ private List<Event> producedEvents;
+
/**
* The update to the public parameters. Each entry having a zero length value must be
interpeted as
* a public parameter removal otherwise it must be interpreted as a public parameter
values update.
@@ -62,6 +72,7 @@
windowState = null;
mode = null;
publicNavigationalStateUpdates = null;
+ producedEvents = Collections.emptyList();
}
public ResponseProperties getProperties()
@@ -74,6 +85,16 @@
this.properties = properties;
}
+ public Map<String, Object> getAttributes()
+ {
+ return attributes;
+ }
+
+ public void setAttributes(Map<String, Object> attributes)
+ {
+ this.attributes = attributes;
+ }
+
public Mode getMode()
{
return mode;
@@ -113,4 +134,59 @@
{
this.publicNavigationalStateUpdates = publicNavigationalStateUpdates;
}
+
+ public void queueEvent(UpdateNavigationalStateResponse.Event event)
+ {
+ if (event == null)
+ {
+ throw new IllegalArgumentException("No null event accepted");
+ }
+
+ //
+ if (producedEvents.size() == 0)
+ {
+ producedEvents = new ArrayList<Event>();
+ }
+
+ //
+ producedEvents.add(event);
+ }
+
+ public List<UpdateNavigationalStateResponse.Event> getEvents()
+ {
+ return producedEvents;
+ }
+
+ /**
+ * An event produced by a state response.
+ */
+ public static class Event
+ {
+
+ /** The optional event. */
+ private QName name;
+
+ /** The optional event payload. */
+ private Serializable payload;
+
+ public Event(QName name, Serializable payload)
+ {
+ if (name == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ this.name = name;
+ this.payload = payload;
+ }
+
+ public QName getName()
+ {
+ return name;
+ }
+
+ public Serializable getPayload()
+ {
+ return payload;
+ }
+ }
}
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-04
10:57:05 UTC (rev 9736)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PortletRequestHandler.java 2008-02-04
11:10:11 UTC (rev 9737)
@@ -25,9 +25,7 @@
import org.jboss.portal.portlet.invocation.response.HTTPRedirectionResponse;
import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
import org.jboss.portal.portlet.invocation.response.ResponseProperties;
-import org.jboss.portal.portlet.invocation.response.StateResponse;
import org.jboss.portal.portlet.invocation.response.UpdateNavigationalStateResponse;
-import org.jboss.portal.portlet.test.controller.PageNavigationalState;
import org.jboss.portal.portlet.test.PortletURLRenderer;
import org.jboss.portal.portlet.test.TestActionContext;
import org.jboss.portal.portlet.test.TestEventContext;
@@ -100,7 +98,7 @@
//
context.getClientResponse().sendError(404, error.getMessage());
}
- else if (response instanceof StateResponse)
+ else if (response instanceof UpdateNavigationalStateResponse)
{
// Update portlet NS
if (response instanceof UpdateNavigationalStateResponse)
@@ -118,11 +116,11 @@
//
EventControllerContext eventCC = context.getEventControllerContext();
- StateResponse stateResponse = (StateResponse)response;
+ UpdateNavigationalStateResponse stateResponse =
(UpdateNavigationalStateResponse)response;
// Create event list and feed it with the events that may have been produced
LinkedList<Event> eventQueue = new LinkedList<Event>();
- for (StateResponse.Event portletEvent : stateResponse.getEvents())
+ for (UpdateNavigationalStateResponse.Event portletEvent :
stateResponse.getEvents())
{
Event producedEvent = new Event(portletEvent.getName(),
portletEvent.getPayload(), portletContext);
List<Event> consumedEvents = eventCC.getConsumedEvents(producedEvent);
@@ -146,7 +144,7 @@
updateNavigationalState(context, event.getPortletContext().getId(),
update, pageState);
// Add events if any
- for (StateResponse.Event portletEvent : update.getEvents())
+ for (UpdateNavigationalStateResponse.Event portletEvent :
update.getEvents())
{
Event producedEvent = new Event(portletEvent.getName(),
portletEvent.getPayload(), portletContext);
List<Event> consumedEvents =
eventCC.getConsumedEvents(producedEvent);
@@ -169,14 +167,13 @@
// Do something here !!!!
}
}
-
- if (response instanceof HTTPRedirectionResponse)
- {
- HTTPRedirectionResponse redirection = (HTTPRedirectionResponse)response;
- context.getClientResponse().sendRedirect(redirection.getLocation());
- return;
- }
}
+ else if (response instanceof HTTPRedirectionResponse)
+ {
+ HTTPRedirectionResponse redirection = (HTTPRedirectionResponse)response;
+ context.getClientResponse().sendRedirect(redirection.getLocation());
+ return;
+ }
else
{
System.out.println("Not yet handled " + response);