Author: julien(a)jboss.com
Date: 2008-01-17 08:44:09 -0500 (Thu, 17 Jan 2008)
New Revision: 9527
Added:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/PortletParameter.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/PortletParameterMap.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/PortletRequestParameterMap.java
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/ParametersStateString.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/ActionResponseImpl.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/EventResponseImpl.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/test/java/org/jboss/portal/test/portlet/ParametersTestCase.java
Log:
added PortletParameterMap object that manages the different maps that a Portlet can create
at runtime to update the navigational states (private and public). The intent is to reuse
it then in the PortletURLImpl.
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/ParametersStateString.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/ParametersStateString.java 2008-01-17
10:29:15 UTC (rev 9526)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/ParametersStateString.java 2008-01-17
13:44:09 UTC (rev 9527)
@@ -84,6 +84,10 @@
*/
public static ParametersStateString create(StateString stateString) throws
IllegalArgumentException
{
+ if (stateString == null)
+ {
+ throw new IllegalArgumentException("No null state string accepted");
+ }
if (stateString instanceof ParametersStateString)
{
return (ParametersStateString)stateString;
Added:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/PortletParameter.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/PortletParameter.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/PortletParameter.java 2008-01-17
13:44:09 UTC (rev 9527)
@@ -0,0 +1,65 @@
+/******************************************************************************
+ * 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.impl.jsr168;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+class PortletParameter
+{
+
+ enum Scope
+ {
+
+ PUBLIC, PRIVATE
+
+ }
+
+ /** The entry scope. */
+ private final Scope scope;
+
+ /** The entry value. */
+ private String[] values;
+
+ PortletParameter(Scope scope, String[] values)
+ {
+ this.scope = scope;
+ this.values = values;
+ }
+
+ Scope getScope()
+ {
+ return scope;
+ }
+
+ String[] getValues()
+ {
+ return values;
+ }
+
+ void setValues(String[] values)
+ {
+ this.values = values;
+ }
+}
Added:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/PortletParameterMap.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/PortletParameterMap.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/PortletParameterMap.java 2008-01-17
13:44:09 UTC (rev 9527)
@@ -0,0 +1,284 @@
+/******************************************************************************
+ * 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.impl.jsr168;
+
+import org.jboss.portal.common.util.TypedMap;
+import org.jboss.portal.portlet.info.NavigationInfo;
+import org.jboss.portal.portlet.info.ParameterInfo;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Set;
+import java.util.HashSet;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class PortletParameterMap
+{
+
+ /** . */
+ private static final String[] EMPTY_STRINGS = new String[0];
+
+ /** . */
+ private NavigationInfo navigationInfo;
+
+ /** . */
+ private Map<String, PortletParameter> entries = new HashMap<String,
PortletParameter>();
+
+ /** . */
+ private Set<String> publicEntryRemovals = new HashSet<String>();
+
+ /** . */
+ private TypedMap<String, String[], String, PortletParameter> combinedMap = new
TypedMap<String, String[], String, PortletParameter>(entries, keyConverter,
valueConverter);
+
+ public PortletParameterMap(NavigationInfo navigationInfo)
+ {
+ this.navigationInfo = navigationInfo;
+ }
+
+ public String getParameterValue(String name)
+ {
+ String[] values = getParameterValues(name);
+
+ return (values != null && values.length > 0) ? values[0] : null;
+ }
+
+ public String[] getParameterValues(String name)
+ {
+ if (name == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ PortletParameter entry = entries.get(name);
+
+ //
+ return entry != null ? entry.getValues() : null;
+ }
+
+ public void setParameterValue(String name, String value)
+ {
+ if (name == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (value == null)
+ {
+ throw new IllegalArgumentException("No null string array accepted");
+ }
+
+ //
+ internalPut(name, new String[]{value}, false);
+ }
+
+ public void setParameterValues(String name, String[] value)
+ {
+ if (name == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (value == null)
+ {
+ throw new IllegalArgumentException("No null string array accepted");
+ }
+ if (value.length == 0)
+ {
+ throw new IllegalArgumentException("Render parameter value cannot be a zero
length array");
+ }
+ for (int i = 0;i < value.length;i++)
+ {
+ if (value[i] == null)
+ {
+ throw new IllegalArgumentException("String of parameter value at index
" + i + " must not be null");
+ }
+ }
+
+ //
+ internalPut(name, value, true);
+ }
+
+ private void internalPut(String name, String[] value, boolean cloneValue)
+ {
+ // Look if we have an entry already
+ PortletParameter entry = entries.get(name);
+
+ //
+ PortletParameter.Scope scope;
+ if (entry == null)
+ {
+ ParameterInfo parameterInfo = navigationInfo.getPublicParameter(name);
+ scope = parameterInfo == null ? PortletParameter.Scope.PRIVATE :
PortletParameter.Scope.PUBLIC;
+ }
+ else
+ {
+ scope = entry.getScope();
+ }
+
+ //
+ if (cloneValue)
+ {
+ value = value.clone();
+ }
+
+ //
+ if (entry == null)
+ {
+ publicEntryRemovals.remove(name);
+ entries.put(name, new PortletParameter(scope, value));
+ }
+ else
+ {
+ entry.setValues(value);
+ }
+ }
+
+ public void removePublicParameterValue(String name)
+ {
+ ParameterInfo parameterInfo = navigationInfo.getPublicParameter(name);
+
+ //
+ if (parameterInfo != null)
+ {
+ publicEntryRemovals.add(name);
+ entries.remove(name);
+ }
+ }
+
+ public Map<String, String[]> getMap()
+ {
+ return combinedMap;
+ }
+
+ public void setMap(Map<String, String[]> map)
+ {
+ if (map == null)
+ {
+ throw new IllegalArgumentException("No null map accepted");
+ }
+
+ // Make the check first to ensure atomicity of the update
+ for (Map.Entry<String, String[]> entry : map.entrySet())
+ {
+ // We need to check that for portlets not using generics
+ if (!(entry.getKey() instanceof String))
+ {
+ throw new IllegalArgumentException();
+ }
+ // We need to check that for portlets not using generics
+ if (!(entry.getValue() instanceof String[]))
+ {
+ throw new IllegalArgumentException();
+ }
+ String[] values = entry.getValue();
+ for (String value : values)
+ {
+ if (value == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ }
+ }
+
+ //
+ entries.clear();
+ for (Map.Entry<String, String[]> entry : map.entrySet())
+ {
+ internalPut(entry.getKey(), entry.getValue(), true);
+ }
+ }
+
+ public Map<String, String[]> getPrivateMapSnapshot()
+ {
+ Map<String, String[]> snapshot =
getMapSnapshot(PortletParameter.Scope.PRIVATE);
+ for (String removal : publicEntryRemovals)
+ {
+ snapshot.put(removal, EMPTY_STRINGS);
+ }
+ return snapshot;
+ }
+
+ public Map<String, String[]> getPublicMapSnapshot()
+ {
+ return getMapSnapshot(PortletParameter.Scope.PUBLIC);
+ }
+
+ private Map<String, String[]> getMapSnapshot(PortletParameter.Scope scope)
+ {
+ Map<String, String[]> snapshot = new HashMap<String, String[]>();
+
+ //
+ for (Map.Entry<String, PortletParameter> entry : entries.entrySet())
+ {
+ PortletParameter parameter = entry.getValue();
+
+ //
+ if (parameter.getScope() == scope)
+ {
+ snapshot.put(entry.getKey(), parameter.getValues().clone());
+ }
+ }
+
+ //
+ return snapshot;
+ }
+
+ private static TypedMap.Converter<String, String> keyConverter = new
TypedMap.Converter<String, String>()
+ {
+ protected String getInternal(String external) throws IllegalArgumentException,
ClassCastException
+ {
+ return external;
+ }
+
+ protected String getExternal(String internal)
+ {
+ return internal;
+ }
+
+ protected boolean equals(String left, String right)
+ {
+ return left.equals(right);
+ }
+ };
+
+ private static TypedMap.Converter<String[], PortletParameter> valueConverter =
new TypedMap.Converter<String[], PortletParameter>()
+ {
+ protected PortletParameter getInternal(String[] external) throws
IllegalArgumentException, ClassCastException
+ {
+ throw new UnsupportedOperationException("Cannot write");
+ }
+
+ protected String[] getExternal(PortletParameter internal)
+ {
+ // We clone the value as it may be accessed
+ return internal.getValues().clone();
+ }
+
+ protected boolean equals(PortletParameter left, PortletParameter right)
+ {
+ throw new UnsupportedOperationException();
+ }
+ };
+}
Copied:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/PortletRequestParameterMap.java
(from rev 9520,
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/RequestParameters.java)
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/PortletRequestParameterMap.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/PortletRequestParameterMap.java 2008-01-17
13:44:09 UTC (rev 9527)
@@ -0,0 +1,197 @@
+/******************************************************************************
+ * 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.impl.jsr168;
+
+import org.jboss.portal.common.util.ParameterMap;
+import org.jboss.portal.portlet.spi.PortletInvocationContext;
+import org.jboss.portal.portlet.spi.ActionContext;
+import org.jboss.portal.portlet.StateString;
+import org.jboss.portal.portlet.ParametersStateString;
+import org.jboss.portal.portlet.info.NavigationInfo;
+
+import java.util.Iterator;
+
+/**
+ * The main responsibility of this class is to combine the different parameter sources
(private navigational state,
+ * public navigational state, interaction state, form) into the private map, public map
and parameter map.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class PortletRequestParameterMap
+{
+
+ /** . */
+ protected final ParameterMap parameters;
+
+ /** . */
+ protected final ParameterMap privateParameters;
+
+ /** . */
+ protected final ParameterMap publicParameters;
+
+ public PortletRequestParameterMap(NavigationInfo navigationInfo,
PortletInvocationContext context)
+ {
+ // Get public nav state and filter it
+ ParameterMap publicParameters = null;
+ if (context.getPublicNavigationalState() != null)
+ {
+ publicParameters = new ParameterMap(context.getPublicNavigationalState());
+
+ // Remove any parameter that would have been sent by the producer by mistake
+ for (Iterator<String> i = publicParameters.keySet().iterator();
i.hasNext();)
+ {
+ String name = i.next();
+ if (navigationInfo.getPublicParameter(name) == null)
+ {
+ i.remove();
+ }
+ }
+ }
+
+ //
+ if (context instanceof ActionContext)
+ {
+ ActionContext actionContext = (ActionContext)context;
+
+ // The private parameters
+ ParameterMap privateParameters = null;
+
+ // Get the possibly null interaction state
+ StateString interactionState = actionContext.getInteractionState();
+ if (interactionState != null)
+ {
+ //
+ ParametersStateString parametersState =
ParametersStateString.create(interactionState);
+
+ //
+ privateParameters = parametersState.getParameters();
+ }
+
+ // Combine form if we have one
+ ParameterMap form = actionContext.getForm();
+ if (form != null)
+ {
+ if (privateParameters == null)
+ {
+ privateParameters = form;
+ }
+ else
+ {
+ privateParameters = ParameterMap.clone(privateParameters);
+ privateParameters.append(form);
+ }
+ }
+
+ //
+ ParameterMap parameters;
+ if (publicParameters != null)
+ {
+ if (privateParameters != null)
+ {
+ ParameterMap tmp = ParameterMap.clone(privateParameters);
+ tmp.append(publicParameters);
+ parameters = tmp;
+ }
+ else
+ {
+ parameters = publicParameters;
+ }
+ }
+ else
+ {
+ if (privateParameters != null)
+ {
+ parameters = privateParameters;
+ }
+ else
+ {
+ parameters = null;
+ }
+ }
+
+ //
+ this.privateParameters = privateParameters;
+ this.publicParameters = publicParameters;
+ this.parameters = parameters;
+ }
+ else
+ {
+ // Get the possibly null navigational state
+ StateString navigationalState = context.getNavigationalState();
+
+ //
+ ParameterMap privateParameters = null;
+ if (navigationalState != null)
+ {
+ privateParameters =
ParametersStateString.create(navigationalState).getParameters();
+ }
+
+ // Build combined map
+ ParameterMap parameters;
+ if (publicParameters != null)
+ {
+ if (privateParameters != null)
+ {
+ parameters = ParameterMap.clone(privateParameters);
+ parameters.putAll(publicParameters);
+ }
+ else
+ {
+ parameters = publicParameters;
+ }
+ }
+ else
+ {
+ if (privateParameters != null)
+ {
+ parameters = privateParameters;
+ }
+ else
+ {
+ parameters = null;
+ }
+ }
+
+ //
+ this.privateParameters = privateParameters;
+ this.publicParameters = publicParameters;
+ this.parameters = parameters;
+ }
+ }
+
+ public ParameterMap getParameters()
+ {
+ return parameters;
+ }
+
+ public ParameterMap getPrivateParameters()
+ {
+ return privateParameters;
+ }
+
+ public ParameterMap getPublicParameters()
+ {
+ return publicParameters;
+ }
+}
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/ActionResponseImpl.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/ActionResponseImpl.java 2008-01-17
10:29:15 UTC (rev 9526)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/ActionResponseImpl.java 2008-01-17
13:44:09 UTC (rev 9527)
@@ -60,34 +60,24 @@
public void sendRedirect(String location) throws IOException
{
+ checkRedirect("sendRedirect cannot be called after " +
+
"setPortletMode/setWindowState/setRenderParameter/setRenderParameters " +
+ "has been called previously");
+
+ //
if (location == null)
{
- // do something more clever than simply returning
+ // Do something more clever than simply returning
return;
}
+ //
if (location.startsWith("http://") ||
location.startsWith("https://") || location.startsWith("/"))
{
- //
- if (decision == null)
- {
- WantRedirect redirect = new WantRedirect();
- redirect.location = location;
+ WantRedirect redirect = requireRedirect();
- //
- decision = redirect;
- }
- else if (decision instanceof WantRedirect)
- {
- WantRedirect redirect = (WantRedirect)decision;
- redirect.location = location;
- }
- else
- {
- throw new IllegalStateException("sendRedirect cannot be called after
" +
- "setPortletMode/setWindowState/setRenderParameter/setRenderParameters
" +
- "has been called previously");
- }
+ //
+ redirect.location = location;
}
else
{
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/EventResponseImpl.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/EventResponseImpl.java 2008-01-17
10:29:15 UTC (rev 9526)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/EventResponseImpl.java 2008-01-17
13:44:09 UTC (rev 9527)
@@ -44,8 +44,10 @@
{
if (eventRequest == null)
{
- // Do something ???
+ return;
}
+
+ //
if (eventRequest != preq)
{
// Do something ???
@@ -55,10 +57,11 @@
PortletInvocationContext context = invocation.getPortletContext();
//
- WantUpdate update = (WantUpdate)decision;
+ WantUpdate update = wantUpdate();
update.mode = context.getMode();
update.windowState = context.getWindowState();
- update.navigationalState =
ParametersStateString.create(context.getNavigationalState()).getParameters();
- update.publicNavigationalState = context.getPublicNavigationalState();
+
+// update.navigationalState =
ParametersStateString.create(context.getNavigationalState()).getParameters();
+// update.publicNavigationalState = context.getPublicNavigationalState();
}
}
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-01-17
10:29:15 UTC (rev 9526)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/PortletRequestImpl.java 2008-01-17
13:44:09 UTC (rev 9527)
@@ -31,7 +31,7 @@
import org.jboss.portal.portlet.impl.jsr168.PortletContainerImpl;
import org.jboss.portal.portlet.impl.jsr168.PortletUtils;
import org.jboss.portal.portlet.impl.jsr168.PortletRequestAttributes;
-import org.jboss.portal.portlet.impl.jsr168.RequestParameters;
+import org.jboss.portal.portlet.impl.jsr168.PortletRequestParameterMap;
import org.jboss.portal.portlet.impl.info.ContainerSecurityInfo;
import org.jboss.portal.portlet.impl.info.ContainerPreferencesInfo;
import org.jboss.portal.portlet.impl.info.ContainerNavigationInfo;
@@ -93,7 +93,7 @@
protected final PortletRequestAttributes attributes;
/** . */
- protected final RequestParameters requestParameters;
+ protected final PortletRequestParameterMap requestParameterMap;
public PortletRequestImpl(PortletInvocation invocation)
{
@@ -106,7 +106,7 @@
//
this.invocation = invocation;
- this.requestParameters = new RequestParameters(invocation.getPortletContext());
+ this.requestParameterMap = new PortletRequestParameterMap(navigationInfo,
invocation.getPortletContext());
this.userContext = invocation.getUserContext();
this.securityContext = invocation.getSecurityContext();
this.requestContext = invocation.getRequestContext();
@@ -123,7 +123,7 @@
public String getParameter(String name)
{
- ParameterMap parameters = requestParameters.getParameters();
+ ParameterMap parameters = requestParameterMap.getParameters();
//
if (name == null)
@@ -142,7 +142,7 @@
public Enumeration<String> getParameterNames()
{
- ParameterMap parameters = requestParameters.getParameters();
+ ParameterMap parameters = requestParameterMap.getParameters();
//
if (parameters != null)
@@ -162,7 +162,7 @@
throw new IllegalArgumentException("name must not be null");
}
- ParameterMap parameters = requestParameters.getParameters();
+ ParameterMap parameters = requestParameterMap.getParameters();
//
if (parameters != null)
@@ -177,7 +177,7 @@
public Map<String, String[]> getParameterMap()
{
- ParameterMap parameters = requestParameters.getParameters();
+ ParameterMap parameters = requestParameterMap.getParameters();
//
if (parameters != null)
@@ -502,7 +502,7 @@
public Map<String, String[]> getPrivateParameterMap()
{
- ParameterMap parameters = requestParameters.getPrivateParameters();
+ ParameterMap parameters = requestParameterMap.getPrivateParameters();
//
if (parameters != null)
@@ -517,7 +517,7 @@
public Map<String, String[]> getPublicParameterMap()
{
- ParameterMap parameters = requestParameters.getPublicParameters();
+ ParameterMap parameters = requestParameterMap.getPublicParameters();
//
if (parameters != null)
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-01-17
10:29:15 UTC (rev 9526)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/StateAwareResponseImpl.java 2008-01-17
13:44:09 UTC (rev 9527)
@@ -27,17 +27,15 @@
import org.jboss.portal.portlet.invocation.response.StateResponse;
import org.jboss.portal.portlet.invocation.response.HTTPRedirectionResponse;
import org.jboss.portal.portlet.ParametersStateString;
-import org.jboss.portal.portlet.impl.jsr168.PortletUtils;
import org.jboss.portal.portlet.impl.jsr168.PortletApplicationImpl;
+import org.jboss.portal.portlet.impl.jsr168.PortletParameterMap;
import org.jboss.portal.portlet.impl.info.ContainerEventingInfo;
import org.jboss.portal.portlet.impl.info.ContainerPortletApplicationInfo;
import org.jboss.portal.portlet.impl.info.ContainerTypeInfo;
import org.jboss.portal.portlet.impl.info.ContainerEventInfo;
-import org.jboss.portal.portlet.impl.info.ContainerParameterInfo;
import org.jboss.portal.Mode;
import org.jboss.portal.common.NotYetImplemented;
import org.jboss.portal.common.util.Tools;
-import org.jboss.portal.common.util.ParameterMap;
import org.apache.log4j.Logger;
import javax.portlet.StateAwareResponse;
@@ -55,7 +53,6 @@
import java.util.UUID;
import java.util.List;
import java.util.LinkedList;
-import java.util.HashMap;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URI;
@@ -72,24 +69,30 @@
private static final Logger log = Logger.getLogger(ActionResponseImpl.class);
/** . */
- protected Decision decision;
+ protected WantUpdate wantUpdate;
/** . */
+ protected WantRedirect wantRedirect;
+
+ /** . */
private List<StateResponse.Event> events;
public StateAwareResponseImpl(PortletInvocation invocation, PortletRequestImpl preq)
{
super(invocation, preq);
-
- //
- this.decision = null;
}
public StateResponse getResponse()
{
- Decision decision = this.decision;
+ Decision decision = wantRedirect;
//
+ if (wantRedirect == null)
+ {
+ decision = wantUpdate;
+ }
+
+ //
if (decision == null)
{
decision = new WantUpdate();
@@ -99,25 +102,52 @@
return decision.getResponse();
}
- protected WantUpdate wantUpdate(String errorMsg)
+ protected WantUpdate requireUpdate(String errorMsg)
{
- if (decision instanceof WantUpdate)
+ if (wantRedirect != null)
{
- return (WantUpdate)decision;
+ throw new IllegalStateException(errorMsg);
}
- else if (decision == null)
+ else if (wantUpdate == null)
{
- return new WantUpdate();
+ wantUpdate = new WantUpdate();
}
- else
+ return wantUpdate;
+ }
+
+ protected void checkRedirect(String errorMsg)
+ {
+ if (wantUpdate != null)
{
throw new IllegalStateException(errorMsg);
}
}
+ protected WantRedirect requireRedirect()
+ {
+ if (wantUpdate != null)
+ {
+ throw new IllegalStateException();
+ }
+ else if (wantRedirect == null)
+ {
+ wantRedirect = new WantRedirect();
+ }
+ return wantRedirect;
+ }
+
+ protected WantUpdate wantUpdate()
+ {
+ if (wantUpdate == null)
+ {
+ wantUpdate = new WantUpdate();
+ }
+ return wantUpdate;
+ }
+
public void setWindowState(WindowState windowState) throws WindowStateException
{
- WantUpdate update = wantUpdate("Window state cannot be set after
redirect");
+ WantUpdate update = requireUpdate("Window state cannot be set after
redirect");
//
if (!preq.isWindowStateAllowed(windowState))
@@ -127,12 +157,11 @@
//
update.windowState = org.jboss.portal.WindowState.create(windowState.toString());
- decision = update;
}
public void setPortletMode(PortletMode portletMode) throws PortletModeException
{
- WantUpdate update = wantUpdate("Portlet mode cannot be set after
redirect");
+ WantUpdate update = requireUpdate("Portlet mode cannot be set after
redirect");
//
if (portletMode == null)
@@ -150,59 +179,47 @@
//
update.mode = Mode.create(portletMode.toString());
- decision = update;
}
}
public void setRenderParameters(Map<String, String[]> map)
{
- PortletUtils.checkPortletParameterMapValidity(map);
+ WantUpdate update = requireUpdate("setRenderParameters cannot be called after
redirect");
//
- WantUpdate update = wantUpdate("setRenderParameters cannot be called after
redirect");
-
- //
- update.navigationalState.replace(map);
- decision = update;
+ update.navigationalState.setMap(map);
}
public void setRenderParameter(String name, String value)
{
- PortletUtils.checkPortletParameterValidity(name, value);
+ WantUpdate update = requireUpdate("setRenderParameter cannot be called after
redirect");
//
- setRenderParameter(name, new String[]{value});
+ update.navigationalState.setParameterValue(name, value);
}
public void setRenderParameter(String name, String[] values)
{
- PortletUtils.checkPortletParameterValidity(name, values);
+ WantUpdate update = requireUpdate("setRenderParameter cannot be called after
redirect");
//
- WantUpdate update = wantUpdate("setRenderParameter cannot be called after
redirect");
+ update.navigationalState.setParameterValues(name, values);
+ }
- // Find out
- ContainerParameterInfo pi = preq.navigationInfo.getPublicParameter(name);
+ public Map<String, String[]> getRenderParameterMap()
+ {
+ WantUpdate update = wantUpdate();
//
- if (pi != null)
- {
- for (String value : values)
- {
- if (value == null)
- {
- throw new IllegalArgumentException();
- }
- }
- update.publicNavigationalState.put(name, values.clone());
- }
- else
- {
- update.navigationalState.setValues(name, values);
- }
+ return update.navigationalState.getMap();
+ }
+ public void removePublicRenderParameter(String name)
+ {
+ WantUpdate update = wantUpdate();
+
//
- decision = update;
+ update.navigationalState.removePublicParameterValue(name);
}
private static final Set<? extends Class<? extends Serializable>>
acceptedFinalClasses = Tools.toSet(
@@ -322,11 +339,6 @@
setEvent(name, value);
}
- public Map<String, String[]> getRenderParameterMap()
- {
- throw new NotYetImplemented();
- }
-
public PortletMode getPortletMode()
{
throw new NotYetImplemented();
@@ -337,11 +349,6 @@
throw new NotYetImplemented();
}
- public void removePublicRenderParameter(String s)
- {
- throw new NotYetImplemented();
- }
-
protected final void queueEvent(QName name, Serializable value)
{
if (events == null)
@@ -379,7 +386,7 @@
{
/** The navigational state returned. */
- protected ParameterMap navigationalState = new
ParameterMap(ParameterMap.AccessMode.get(true, false));
+ protected PortletParameterMap navigationalState = new
PortletParameterMap(preq.navigationInfo);
/** The new window state requested. */
protected org.jboss.portal.WindowState windowState;
@@ -387,9 +394,6 @@
/** The new mode requested. */
protected Mode mode;
- /** The update to the shared parameters. */
- protected Map<String,String[]> publicNavigationalState;
-
protected StateResponse createResponse()
{
UpdateNavigationalStateResponse response = new
UpdateNavigationalStateResponse();
@@ -397,8 +401,8 @@
//
response.setMode(mode);
response.setWindowState(windowState);
- response.setPublicNavigationalStateUpdates(publicNavigationalState);
- response.setNavigationalState(new ParametersStateString(navigationalState));
+
response.setPublicNavigationalStateUpdates(navigationalState.getPublicMapSnapshot());
+ response.setNavigationalState(new
ParametersStateString(navigationalState.getPrivateMapSnapshot()));
//
return response;
Modified:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/ParametersTestCase.java
===================================================================
---
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/ParametersTestCase.java 2008-01-17
10:29:15 UTC (rev 9526)
+++
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/ParametersTestCase.java 2008-01-17
13:44:09 UTC (rev 9527)
@@ -22,17 +22,22 @@
******************************************************************************/
package org.jboss.portal.test.portlet;
-import org.jboss.portal.common.util.ParameterMap;
+import org.jboss.portal.portlet.impl.jsr168.PortletParameterMap;
+import org.jboss.portal.portlet.support.info.NavigationInfoSupport;
+import org.jboss.portal.portlet.support.info.ParameterInfoSupport;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import static org.jboss.unit.api.Assert.*;
+import static org.jboss.unit.api.Assert.assertEquals;
import org.jboss.unit.api.pojo.annotations.Test;
import org.jboss.unit.api.pojo.annotations.Create;
import org.jboss.unit.api.pojo.annotations.Destroy;
+import javax.xml.namespace.QName;
+
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 6639 $
@@ -45,18 +50,21 @@
{
}
- private ParameterMap param;
+ private NavigationInfoSupport navigation;
+ private PortletParameterMap map;
@Create
public void setUp()
{
- param = new ParameterMap();
+ navigation = new NavigationInfoSupport();
+ map = new PortletParameterMap(navigation);
}
@Destroy
public void tearDown()
{
- param = null;
+ map = null;
+ navigation = null;
}
@Test
@@ -64,10 +72,10 @@
{
try
{
- param.getValue(null);
+ map.getParameterValue(null);
fail("Expected IllegalArgumentException");
}
- catch (NullPointerException e)
+ catch (IllegalArgumentException e)
{
}
}
@@ -75,8 +83,8 @@
@Test
public void testSet()
{
- param.setValue("a", "b");
- assertEquals(param.getValue("a"), "b");
+ map.setParameterValue("a", "b");
+ assertEquals(map.getParameterValue("a"), "b");
}
@Test
@@ -84,10 +92,10 @@
{
try
{
- param.setValue(null, "b");
+ map.setParameterValue(null, "b");
fail("Expected IllegalArgumentException");
}
- catch (NullPointerException e)
+ catch (IllegalArgumentException e)
{
}
}
@@ -97,7 +105,7 @@
{
try
{
- param.setValue("a", null);
+ map.setParameterValue("a", null);
fail("Expected IllegalArgumentException");
}
catch (IllegalArgumentException e)
@@ -105,34 +113,34 @@
}
}
- @Test
- public void testRemoveWithNullName()
- {
- try
- {
- param.remove(null);
- fail("Expected IllegalArgumentException");
- }
- catch (NullPointerException e)
- {
- }
- }
+// @Test
+// public void testRemoveWithNullName()
+// {
+// try
+// {
+// param.remove(null);
+// fail("Expected IllegalArgumentException");
+// }
+// catch (NullPointerException e)
+// {
+// }
+// }
- @Test
- public void testRemove()
- {
- param.setValue("a", "b");
- param.remove("a");
- assertEquals(param.getValue("a"), null);
- }
+// @Test
+// public void testRemove()
+// {
+// param.setValue("a", "b");
+// param.remove("a");
+// assertEquals(param.getValue("a"), null);
+// }
@Test
public void testSetValues()
{
- param.setValues("a", new String[]{"b", "c"});
- assertTrue(Arrays.equals(param.getValues("a"), new String[]{
+ map.setParameterValues("a", new String[]{"b", "c"});
+ assertTrue(Arrays.equals(map.getParameterValues("a"), new String[]{
"b", "c"}));
- assertEquals(param.getValue("a"), "b");
+ assertEquals(map.getParameterValue("a"), "b");
}
@Test
@@ -140,10 +148,10 @@
{
try
{
- param.setValues(null, new String[]{"a"});
+ map.setParameterValues(null, new String[]{"a"});
fail("Expected IllegalArgumentException");
}
- catch (NullPointerException e)
+ catch (IllegalArgumentException e)
{
}
}
@@ -153,10 +161,10 @@
{
try
{
- param.setValues("a", null);
+ map.setParameterValues("a", null);
fail("Expected IllegalArgumentException");
}
- catch (NullPointerException e)
+ catch (IllegalArgumentException e)
{
}
}
@@ -166,7 +174,7 @@
{
try
{
- param.setValues("a", new String[0]);
+ map.setParameterValues("a", new String[0]);
fail("Expected IllegalArgumentException");
}
catch (IllegalArgumentException e)
@@ -179,7 +187,7 @@
{
try
{
- param.setValues("a", new String[]{"a", null});
+ map.setParameterValues("a", new String[]{"a", null});
fail("Expected IllegalArgumentException");
}
catch (IllegalArgumentException e)
@@ -187,142 +195,142 @@
}
}
- @Test
- public void testReplaceWithParameters()
- {
- ParameterMap other = new ParameterMap();
- other.setValue("a", "b");
- other.setValues("c", new String[]{"d", "e"});
- param.replace(other);
- assertEquals("b", param.getValue("a"));
- assertTrue(Arrays.equals(param.getValues("c"), new
String[]{"d", "e"}));
- }
+// @Test
+// public void testReplaceWithParameters()
+// {
+// ParameterMap other = new ParameterMap();
+// other.setValue("a", "b");
+// other.setValues("c", new String[]{"d", "e"});
+// param.replace(other);
+// assertEquals("b", param.getValue("a"));
+// assertTrue(Arrays.equals(param.getValues("c"), new
String[]{"d", "e"}));
+// }
@Test
- public void testCopyConstructorWithNullParameters()
+ public void testBlah()
{
- try
- {
- ParameterMap.clone(null);
- fail("Expected IllegalArgumentException");
- }
- catch (IllegalArgumentException e)
- {
- }
- }
+ navigation.addPublicParameter(new ParameterInfoSupport("foo", new
QName("", "foo")));
+ navigation.addPublicParameter(new ParameterInfoSupport("abc", new
QName("", "abc")));
- @Test
- public void testCopyConstructorWithNullMap()
- {
- try
- {
- ParameterMap.clone(null);
- fail("Expected IllegalArgumentException");
- }
- catch (IllegalArgumentException e)
- {
- }
- }
+ map.setParameterValue("juu", "daa");
+ map.setParameterValue("foo", "bar");
+ map.removePublicParameterValue("abc");
- @Test
- public void testReplaceWithNullMap()
- {
- try
- {
- param.replace(null);
- fail("Expected NullPointerException");
- }
- catch (NullPointerException e)
- {
- }
- }
+ Map<String, String[]> privateMap = map.getPrivateMapSnapshot();
+ assertEquals(2, privateMap.size());
+ assertEquals(new String[]{"daa"}, privateMap.get("juu"));
+ assertEquals(new String[]{}, privateMap.get("abc"));
- @Test
- public void testReplaceWithInvalidMap()
- {
- Map[] maps = buildInvalidMaps();
- Class[] exceptionClasses = buildExceptionClasses();
- for (int i = 0; i < maps.length; i++)
- {
- try
- {
- Map map = maps[i];
- param.replace(map);
- fail("Expected IllegalArgumentException with map=" + map);
- }
- catch (Exception e)
- {
- assertTrue(exceptionClasses[i].isAssignableFrom(e.getClass()));
- }
- }
- }
+ Map<String, String[]> publicMap = map.getPublicMapSnapshot();
+ assertEquals(1, publicMap.size());
+ assertEquals(new String[]{"bar"}, publicMap.get("foo"));
- @Test
- public void testReplace()
- {
- param.setValue("a", "b");
- param.setValues("c", new String[]{"d", "e"});
- param.setValue("f", "g");
- Map map = new HashMap();
- map.put("a", new String[]{"_b"});
- map.put("c", new String[]{"_d", "_e"});
- map.put("h", new String[]{"_i"});
- param.replace(map);
- assertEquals(3, param.size());
- assertEquals(param.getValues("a"), new String[]{"_b"});
- assertEquals(param.getValues("c"), new String[]{"_d",
"_e"});
- assertEquals(param.getValues("h"), new String[]{"_i"});
- }
+ Map<String, String[]> combinedMap = map.getMap();
+ assertEquals(2, combinedMap.size());
+ assertEquals(new String[]{"bar"}, combinedMap.get("foo"));
+ assertEquals(new String[]{"daa"}, combinedMap.get("juu"));
- @Test
- public void testAppendWithInvalidMap()
- {
- Map[] maps = buildInvalidMaps();
- Class[] exceptionClasses = buildExceptionClasses();
- for (int i = 0; i < maps.length; i++)
- {
- try
- {
- Map map = maps[i];
- param.append(map);
- fail("Expected IllegalArgumentException with map=" + map);
- }
- catch (Exception e)
- {
- if (!exceptionClasses[i].isAssignableFrom(e.getClass()))
- {
- fail("Exception class " + exceptionClasses[i].getName() + "
(index=" + i + ") should be assignable from caught exception " +
e.getClass());
- }
- }
- }
}
- @Test
- public void testAppend()
- {
- param.setValue("a", "b");
- param.setValues("c", new String[]{"d", "e"});
- param.setValue("f", "g");
- Map map = new HashMap();
- map.put("a", new String[]{"_b"});
- map.put("c", new String[]{"_d", "_e"});
- map.put("h", new String[]{"_i"});
- param.append(map);
- assertEquals(4, param.size());
- assertEquals(param.getValues("a"), new String[]{"b",
"_b"});
- assertEquals(param.getValues("c"), new String[]{"d",
"e", "_d", "_e"});
- assertEquals(param.getValues("f"), new String[]{"g"});
- assertEquals(param.getValues("h"), new String[]{"_i"});
- }
+// @Test
+// public void testReplaceWithNullMap()
+// {
+// try
+// {
+// param.replace(null);
+// fail("Expected NullPointerException");
+// }
+// catch (NullPointerException e)
+// {
+// }
+// }
- @Test
- public void testClear()
- {
- param.setValue("a", "b");
- param.clear();
- assertNull(param.getValue("a"));
- }
+// @Test
+// public void testReplaceWithInvalidMap()
+// {
+// Map[] maps = buildInvalidMaps();
+// Class[] exceptionClasses = buildExceptionClasses();
+// for (int i = 0; i < maps.length; i++)
+// {
+// try
+// {
+// Map map = maps[i];
+// param.replace(map);
+// fail("Expected IllegalArgumentException with map=" + map);
+// }
+// catch (Exception e)
+// {
+// assertTrue(exceptionClasses[i].isAssignableFrom(e.getClass()));
+// }
+// }
+// }
+// @Test
+// public void testReplace()
+// {
+// param.setValue("a", "b");
+// param.setValues("c", new String[]{"d", "e"});
+// param.setValue("f", "g");
+// Map map = new HashMap();
+// map.put("a", new String[]{"_b"});
+// map.put("c", new String[]{"_d", "_e"});
+// map.put("h", new String[]{"_i"});
+// param.replace(map);
+// assertEquals(3, param.size());
+// assertEquals(param.getValues("a"), new String[]{"_b"});
+// assertEquals(param.getValues("c"), new String[]{"_d",
"_e"});
+// assertEquals(param.getValues("h"), new String[]{"_i"});
+// }
+
+// @Test
+// public void testAppendWithInvalidMap()
+// {
+// Map[] maps = buildInvalidMaps();
+// Class[] exceptionClasses = buildExceptionClasses();
+// for (int i = 0; i < maps.length; i++)
+// {
+// try
+// {
+// Map map = maps[i];
+// param.append(map);
+// fail("Expected IllegalArgumentException with map=" + map);
+// }
+// catch (Exception e)
+// {
+// if (!exceptionClasses[i].isAssignableFrom(e.getClass()))
+// {
+// fail("Exception class " + exceptionClasses[i].getName() +
" (index=" + i + ") should be assignable from caught exception " +
e.getClass());
+// }
+// }
+// }
+// }
+
+// @Test
+// public void testAppend()
+// {
+// param.setValue("a", "b");
+// param.setValues("c", new String[]{"d", "e"});
+// param.setValue("f", "g");
+// Map map = new HashMap();
+// map.put("a", new String[]{"_b"});
+// map.put("c", new String[]{"_d", "_e"});
+// map.put("h", new String[]{"_i"});
+// param.append(map);
+// assertEquals(4, param.size());
+// assertEquals(param.getValues("a"), new String[]{"b",
"_b"});
+// assertEquals(param.getValues("c"), new String[]{"d",
"e", "_d", "_e"});
+// assertEquals(param.getValues("f"), new String[]{"g"});
+// assertEquals(param.getValues("h"), new String[]{"_i"});
+// }
+
+// @Test
+// public void testClear()
+// {
+// param.setValue("a", "b");
+// param.clear();
+// assertNull(param.getValue("a"));
+// }
+
public Class[] buildExceptionClasses()
{
return new Class[]