Author: chris.laprun(a)jboss.com
Date: 2010-10-14 21:53:39 -0400 (Thu, 14 Oct 2010)
New Revision: 4673
Modified:
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPRenderURL.java
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPTypeFactory.java
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPUtils.java
components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/WSRPRenderURLTestCase.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/InvocationDispatcher.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/InvocationHandler.java
components/wsrp/trunk/pom.xml
Log:
- GTNWSRP-97, GTNWSRP-99:
+ Significantly improved URL templates by providing values where none were previously
provided, including parameters that cannot be handled by
PortletInvocationContext.renderURL method.
+ Parameters that cannot be handled regularly are passed around using the Invocation
attribute mechanism. Note that this will require support from the portal side.
- Should now properly handle public navigational state provided via URL templates as well,
though this hasn't been tested yet.
- Adapted to changes in PC CacheLevel.
- Moved public NS encoding and decoding methods from WSRPRenderURL to WSRPUtils.
- Use PC 2.2.0-BETA06-SNAPSHOT.
Modified: components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPRenderURL.java
===================================================================
---
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPRenderURL.java 2010-10-14
21:44:04 UTC (rev 4672)
+++
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPRenderURL.java 2010-10-15
01:53:39 UTC (rev 4673)
@@ -23,17 +23,13 @@
package org.gatein.wsrp;
-import org.gatein.common.net.URLTools;
-import org.gatein.common.util.ParameterValidation;
import org.gatein.pc.api.Mode;
import org.gatein.pc.api.RenderURL;
import org.gatein.pc.api.StateString;
import org.gatein.pc.api.WindowState;
import org.gatein.wsrp.spec.v2.WSRP2RewritingConstants;
-import java.util.HashMap;
import java.util.Map;
-import java.util.Set;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -63,7 +59,7 @@
String paramValue = getRawParameterValueFor(params,
WSRP2RewritingConstants.NAVIGATIONAL_VALUES);
if (paramValue != null)
{
- publicNSChanges = decodePublicNS(paramValue);
+ publicNSChanges = WSRPUtils.decodePublicNS(paramValue);
params.remove(WSRP2RewritingConstants.NAVIGATIONAL_VALUES);
}
}
@@ -82,108 +78,7 @@
{
if (publicNSChanges != null)
{
- createURLParameter(sb, WSRP2RewritingConstants.NAVIGATIONAL_VALUES,
encodePublicNS(publicNSChanges));
+ createURLParameter(sb, WSRP2RewritingConstants.NAVIGATIONAL_VALUES,
WSRPUtils.encodePublicNS(publicNSChanges));
}
}
-
- /**
- * Encodes the public NS according to the rules found at <a
href='http://docs.oasis-open.org/wsrp/v2/wsrp-2.0-spec-os-01.html#_ws...
- *
http://docs.oasis-open.org/wsrp/v2/wsrp-2.0-spec-os-01.html#_wsrp-navigat...
- *
- * @param publicNSChanges
- * @return
- */
- protected static String encodePublicNS(Map<String, String[]> publicNSChanges)
- {
- if (ParameterValidation.existsAndIsNotEmpty(publicNSChanges))
- {
- StringBuilder sb = new StringBuilder(128);
-
- Set<Map.Entry<String, String[]>> entries =
publicNSChanges.entrySet();
- int entryNb = entries.size();
- int currentEntry = 0;
- for (Map.Entry<String, String[]> entry : entries)
- {
- String name = entry.getKey();
- String[] values = entry.getValue();
-
- if (ParameterValidation.existsAndIsNotEmpty(values))
- {
- int valueNb = values.length;
- int currentValueIndex = 0;
- for (String value : values)
- {
- sb.append(name).append("=").append(value);
- if (currentValueIndex++ != valueNb - 1)
- {
- sb.append("&");
- }
- }
- }
- else
- {
- sb.append(name);
- }
-
- if (currentEntry++ != entryNb - 1)
- {
- sb.append("&");
- }
- }
-
- return URLTools.encodeXWWWFormURL(sb.toString());
- }
- else
- {
- return null;
- }
- }
-
- protected static Map<String, String[]> decodePublicNS(String paramValue)
- {
- if (!ParameterValidation.isNullOrEmpty(paramValue))
- {
- String encodedURL = URLTools.decodeXWWWFormURL(paramValue);
- Map<String, String[]> publicNS = new HashMap<String, String[]>(7);
-
- boolean finished = false;
- while (encodedURL.length() > 0 && !finished)
- {
- int endParamIndex = encodedURL.indexOf(AMPERSAND);
- String param;
- if (endParamIndex < 0)
- {
- // no param left: try the remainder of the String
- param = encodedURL;
- finished = true;
- }
- else
- {
- param = encodedURL.substring(0, endParamIndex);
- }
-
- int equalsIndex = param.indexOf(EQUALS);
- if (equalsIndex < 0)
- {
- publicNS.put(param, null);
- }
- else
- {
- // extract param name
- String name = param.substring(0, equalsIndex);
- // extract param value
- String value = param.substring(equalsIndex + EQUALS.length(),
param.length());
-
- WSRPUtils.addMultiValuedValueTo(publicNS, name, value);
- }
- encodedURL = encodedURL.substring(endParamIndex + AMPERSAND.length());
- }
-
- return publicNS;
- }
- else
- {
- return null;
- }
- }
}
Modified: components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPTypeFactory.java
===================================================================
---
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPTypeFactory.java 2010-10-14
21:44:04 UTC (rev 4672)
+++
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPTypeFactory.java 2010-10-15
01:53:39 UTC (rev 4673)
@@ -40,6 +40,7 @@
import org.gatein.pc.api.spi.PortletInvocationContext;
import org.gatein.wsrp.payload.PayloadUtils;
import org.gatein.wsrp.spec.v2.ErrorCodes;
+import org.gatein.wsrp.spec.v2.WSRP2RewritingConstants;
import org.oasis.wsrp.v2.BlockingInteractionResponse;
import org.oasis.wsrp.v2.CacheControl;
import org.oasis.wsrp.v2.ClientData;
@@ -134,6 +135,7 @@
import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -150,7 +152,16 @@
*/
public class WSRPTypeFactory
{
- private static final String REQUIRE_REWRITE_URL_PARAM = "&" +
WSRPRewritingConstants.RESOURCE_REQUIRES_REWRITE + "=" +
WSRPRewritingConstants.WSRP_REQUIRES_REWRITE;
+ private static final String AMP = "&";
+ private static final String EQ = "=";
+ private static final String ADDITIONAL_RESOURCE_URL_PARAMS = AMP +
RESOURCE_REQUIRES_REWRITE + EQ
+ + WSRP_REQUIRES_REWRITE + AMP + WSRPRewritingConstants.RESOURCE_URL + EQ +
REWRITE_PARAMETER_OPEN
+ + WSRPRewritingConstants.RESOURCE_URL + REWRITE_PARAMETER_CLOSE + AMP
+ + WSRP2RewritingConstants.RESOURCE_PREFER_OPERATION + EQ + REWRITE_PARAMETER_OPEN
+ + WSRP2RewritingConstants.RESOURCE_PREFER_OPERATION + REWRITE_PARAMETER_CLOSE;
+ private static final OpaqueStateString WSRP_NAVIGATIONAL_STATE_TOKEN = new
OpaqueStateString(REWRITE_PARAMETER_OPEN + NAVIGATIONAL_STATE + REWRITE_PARAMETER_CLOSE);
+ private static final WindowState WSRP_WINDOW_STATE_TOKEN =
WindowState.create(REWRITE_PARAMETER_OPEN + WINDOW_STATE + REWRITE_PARAMETER_CLOSE,
true);
+ private static final Mode WSRP_MODE_TOKEN = Mode.create(REWRITE_PARAMETER_OPEN + MODE
+ REWRITE_PARAMETER_CLOSE, true);
private WSRPTypeFactory()
{
@@ -738,11 +749,12 @@
return property;
}
+ private static final OpaqueStateString WSRP_INTERACTION_STATE_TOKEN = new
OpaqueStateString(REWRITE_PARAMETER_OPEN + INTERACTION_STATE + REWRITE_PARAMETER_CLOSE);
private static final ActionURL ACTION_URL = new ActionURL()
{
public StateString getInteractionState()
{
- return new OpaqueStateString(REWRITE_PARAMETER_OPEN + INTERACTION_STATE +
REWRITE_PARAMETER_CLOSE);
+ return WSRP_INTERACTION_STATE_TOKEN;
}
public StateString getNavigationalState()
@@ -766,6 +778,14 @@
}
};
+ private static final HashMap<String, String[]> WSRP_PNS_MAP_TOKEN = new
HashMap<String, String[]>();
+
+ static
+ {
+ WSRP_PNS_MAP_TOKEN.put(WSRP2RewritingConstants.NAVIGATIONAL_VALUES,
+ new String[]{REWRITE_PARAMETER_OPEN +
WSRP2RewritingConstants.NAVIGATIONAL_VALUES + REWRITE_PARAMETER_CLOSE});
+ }
+
private static final RenderURL RENDER_URL = new RenderURL()
{
public StateString getNavigationalState()
@@ -775,8 +795,7 @@
public Map<String, String[]> getPublicNavigationalStateChanges()
{
- // todo: implement properly
- return null;
+ return WSRP_PNS_MAP_TOKEN;
}
public Mode getMode()
@@ -795,23 +814,22 @@
}
};
- private static ResourceURL RESOURCE_URL = new WSRPResourceURL()
+ private static final OpaqueStateString WSRP_RESOURCE_STATE_TOKEN = new
OpaqueStateString(REWRITE_PARAMETER_OPEN + WSRP2RewritingConstants.RESOURCE_STATE +
REWRITE_PARAMETER_CLOSE);
+ private static ResourceURL RESOURCE_URL = new ResourceURL()
{
public String getResourceId()
{
- return REWRITE_PARAMETER_OPEN + WSRPRewritingConstants.RESOURCE_URL +
REWRITE_PARAMETER_CLOSE;
+ return REWRITE_PARAMETER_OPEN + WSRP2RewritingConstants.RESOURCE_ID +
REWRITE_PARAMETER_CLOSE;
}
public StateString getResourceState()
{
- // todo: fix-me
- return null;
+ return WSRP_RESOURCE_STATE_TOKEN;
}
public CacheLevel getCacheability()
{
- // todo: fix-me
- return null;
+ return CacheLevel.create(REWRITE_PARAMETER_OPEN +
WSRP2RewritingConstants.RESOURCE_CACHEABILITY + REWRITE_PARAMETER_CLOSE);
}
public Mode getMode()
@@ -828,21 +846,26 @@
{
return getTemplateNS();
}
+
+ public Map<String, String> getProperties()
+ {
+ return Collections.emptyMap();
+ }
};
private static StateString getTemplateNS()
{
- return new OpaqueStateString(REWRITE_PARAMETER_OPEN + NAVIGATIONAL_STATE +
REWRITE_PARAMETER_CLOSE);
+ return WSRP_NAVIGATIONAL_STATE_TOKEN;
}
private static WindowState getTemplateWindowState()
{
- return WindowState.create(REWRITE_PARAMETER_OPEN + WINDOW_STATE +
REWRITE_PARAMETER_CLOSE, true);
+ return WSRP_WINDOW_STATE_TOKEN;
}
private static Mode getTemplateMode()
{
- return Mode.create(REWRITE_PARAMETER_OPEN + MODE + REWRITE_PARAMETER_CLOSE, true);
+ return WSRP_MODE_TOKEN;
}
@@ -862,8 +885,6 @@
templates.setRenderTemplate(createTemplate(context, RENDER_URL, Boolean.FALSE));
templates.setSecureBlockingActionTemplate(createTemplate(context, ACTION_URL,
Boolean.TRUE));
templates.setSecureRenderTemplate(createTemplate(context, RENDER_URL,
Boolean.TRUE));
-
- //fix-me: deal with resources properly, create fake ones for now
templates.setResourceTemplate(createTemplate(context, RESOURCE_URL, false));
templates.setSecureResourceTemplate(createTemplate(context, RESOURCE_URL, true));
@@ -894,7 +915,7 @@
// fix for GTNWSRP-22
if (RESOURCE_URL == url)
{
- template += REQUIRE_REWRITE_URL_PARAM;
+ template += ADDITIONAL_RESOURCE_URL_PARAMS;
}
return template;
Modified: components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPUtils.java
===================================================================
--- components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPUtils.java 2010-10-14
21:44:04 UTC (rev 4672)
+++ components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPUtils.java 2010-10-15
01:53:39 UTC (rev 4673)
@@ -300,7 +300,7 @@
{
return CacheLevel.PAGE;
}
- return CacheLevel.valueOf(resourceCacheability.toUpperCase(Locale.ENGLISH));
+ return CacheLevel.create(resourceCacheability.toUpperCase(Locale.ENGLISH));
}
@@ -569,6 +569,107 @@
}
/**
+ * Encodes the public NS according to the rules found at <a
href='http://docs.oasis-open.org/wsrp/v2/wsrp-2.0-spec-os-01.html#_ws...
+ *
http://docs.oasis-open.org/wsrp/v2/wsrp-2.0-spec-os-01.html#_wsrp-navigat...
+ *
+ * @param publicNSChanges
+ * @return
+ */
+ public static String encodePublicNS(Map<String, String[]> publicNSChanges)
+ {
+ if (ParameterValidation.existsAndIsNotEmpty(publicNSChanges))
+ {
+ StringBuilder sb = new StringBuilder(128);
+
+ Set<Map.Entry<String, String[]>> entries =
publicNSChanges.entrySet();
+ int entryNb = entries.size();
+ int currentEntry = 0;
+ for (Map.Entry<String, String[]> entry : entries)
+ {
+ String name = entry.getKey();
+ String[] values = entry.getValue();
+
+ if (ParameterValidation.existsAndIsNotEmpty(values))
+ {
+ int valueNb = values.length;
+ int currentValueIndex = 0;
+ for (String value : values)
+ {
+ sb.append(name).append("=").append(value);
+ if (currentValueIndex++ != valueNb - 1)
+ {
+ sb.append("&");
+ }
+ }
+ }
+ else
+ {
+ sb.append(name);
+ }
+
+ if (currentEntry++ != entryNb - 1)
+ {
+ sb.append("&");
+ }
+ }
+
+ return URLTools.encodeXWWWFormURL(sb.toString());
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public static Map<String, String[]> decodePublicNS(String paramValue)
+ {
+ if (!ParameterValidation.isNullOrEmpty(paramValue))
+ {
+ String encodedURL = URLTools.decodeXWWWFormURL(paramValue);
+ Map<String, String[]> publicNS = new HashMap<String, String[]>(7);
+
+ boolean finished = false;
+ while (encodedURL.length() > 0 && !finished)
+ {
+ int endParamIndex = encodedURL.indexOf(WSRPPortletURL.AMPERSAND);
+ String param;
+ if (endParamIndex < 0)
+ {
+ // no param left: try the remainder of the String
+ param = encodedURL;
+ finished = true;
+ }
+ else
+ {
+ param = encodedURL.substring(0, endParamIndex);
+ }
+
+ int equalsIndex = param.indexOf(WSRPPortletURL.EQUALS);
+ if (equalsIndex < 0)
+ {
+ publicNS.put(param, null);
+ }
+ else
+ {
+ // extract param name
+ String name = param.substring(0, equalsIndex);
+ // extract param value
+ String value = param.substring(equalsIndex +
WSRPPortletURL.EQUALS.length(), param.length());
+
+ addMultiValuedValueTo(publicNS, name, value);
+ }
+ encodedURL = encodedURL.substring(endParamIndex +
WSRPPortletURL.AMPERSAND.length());
+ }
+
+ return publicNS;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ /**
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
* @version $Revision$
*/
Modified:
components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/WSRPRenderURLTestCase.java
===================================================================
---
components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/WSRPRenderURLTestCase.java 2010-10-14
21:44:04 UTC (rev 4672)
+++
components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/WSRPRenderURLTestCase.java 2010-10-15
01:53:39 UTC (rev 4673)
@@ -56,13 +56,13 @@
publicNS.put("p1", new String[]{"value1",
"value2"});
publicNS.put("p2", null);
- String actual = WSRPRenderURL.encodePublicNS(publicNS);
+ String actual = WSRPUtils.encodePublicNS(publicNS);
assertEquals("p1%3Dvalue1%26p1%3Dvalue2%26p2", actual);
}
public void testPublicNavigationalStateDecoding()
{
- Map<String, String[]> publicNS =
WSRPRenderURL.decodePublicNS("p1%3Dvalue1%26p1%3Dvalue2%26p2");
+ Map<String, String[]> publicNS =
WSRPUtils.decodePublicNS("p1%3Dvalue1%26p1%3Dvalue2%26p2");
assertEquals(2, publicNS.size());
assertTrue(publicNS.containsKey("p2"));
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/InvocationDispatcher.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/InvocationDispatcher.java 2010-10-14
21:44:04 UTC (rev 4672)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/InvocationDispatcher.java 2010-10-15
01:53:39 UTC (rev 4673)
@@ -28,6 +28,7 @@
import org.gatein.common.net.media.MediaType;
import org.gatein.common.net.media.TypeDef;
import org.gatein.common.util.MultiValuedPropertyMap;
+import org.gatein.common.util.ParameterValidation;
import org.gatein.common.util.Tools;
import org.gatein.pc.api.PortletInvokerException;
import org.gatein.pc.api.invocation.ActionInvocation;
@@ -88,13 +89,27 @@
}
else if (invocation instanceof ResourceInvocation)
{
- String resourceInvocationId = ((ResourceInvocation)invocation).getResourceId();
+ ResourceInvocation resourceInvocation = (ResourceInvocation)invocation;
+ String resourceInvocationId = resourceInvocation.getResourceId();
+ String resourceId;
+ String resourceURL;
+ String preferOperationAsString;
- Map<String, String> resourceMap =
WSRPResourceURL.decodeResource(resourceInvocationId);
+ if (!ParameterValidation.isNullOrEmpty(resourceInvocationId))
+ {
+ Map<String, String> resourceMap =
WSRPResourceURL.decodeResource(resourceInvocationId);
+ resourceId = resourceMap.get(WSRP2RewritingConstants.RESOURCE_ID);
+ resourceURL = resourceMap.get(WSRPRewritingConstants.RESOURCE_URL);
+ preferOperationAsString =
resourceMap.get(WSRP2RewritingConstants.RESOURCE_PREFER_OPERATION);
+ }
+ else
+ {
+ // GateIn-specific: WSRP-specific URL parameters might also be put as
attributes by UIPortlet when the invocation is created
+ resourceId =
(String)resourceInvocation.getAttribute(WSRP2RewritingConstants.RESOURCE_ID);
+ resourceURL =
(String)resourceInvocation.getAttribute(WSRPRewritingConstants.RESOURCE_URL);
+ preferOperationAsString =
(String)resourceInvocation.getAttribute(WSRP2RewritingConstants.RESOURCE_PREFER_OPERATION);
+ }
- String resourceId = resourceMap.get(WSRP2RewritingConstants.RESOURCE_ID);
- String resourceURL = resourceMap.get(WSRPRewritingConstants.RESOURCE_URL);
- String preferOperationAsString =
resourceMap.get(WSRP2RewritingConstants.RESOURCE_PREFER_OPERATION);
boolean preferOperation = (preferOperationAsString != null &&
Boolean.parseBoolean(preferOperationAsString));
if (consumer.isUsingWSRP2() && (preferOperation || resourceURL == null
|| (resourceId != null && resourceId.length() > 0)))
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/InvocationHandler.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/InvocationHandler.java 2010-10-14
21:44:04 UTC (rev 4672)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/InvocationHandler.java 2010-10-15
01:53:39 UTC (rev 4673)
@@ -38,6 +38,7 @@
import org.gatein.wsrp.WSRPTypeFactory;
import org.gatein.wsrp.WSRPUtils;
import org.gatein.wsrp.consumer.WSRPConsumerImpl;
+import org.gatein.wsrp.spec.v2.WSRP2RewritingConstants;
import org.oasis.wsrp.v2.InvalidCookie;
import org.oasis.wsrp.v2.InvalidRegistration;
import org.oasis.wsrp.v2.InvalidSession;
@@ -390,6 +391,14 @@
// navigational state
StateString navigationalState = invocation.getNavigationalState();
Map<String, String[]> publicNavigationalState =
invocation.getPublicNavigationalState();
+
+ // it is possible to get additonal public navigational state from the invocation
attributes if the producer used templates:
+ String publicNS =
(String)invocation.getAttribute(WSRP2RewritingConstants.NAVIGATIONAL_VALUES);
+ if (!ParameterValidation.isNullOrEmpty(publicNS))
+ {
+ publicNavigationalState.putAll(WSRPUtils.decodePublicNS(publicNS));
+ }
+
NavigationalContext navigationalContext =
WSRPTypeFactory.createNavigationalContextOrNull(navigationalState,
publicNavigationalState);
getMarkupParams().setNavigationalContext(navigationalContext);
Modified: components/wsrp/trunk/pom.xml
===================================================================
--- components/wsrp/trunk/pom.xml 2010-10-14 21:44:04 UTC (rev 4672)
+++ components/wsrp/trunk/pom.xml 2010-10-15 01:53:39 UTC (rev 4673)
@@ -21,7 +21,8 @@
~ 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-->
-<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
@@ -46,7 +47,7 @@
</scm>
<properties>
- <version.gatein.pc>2.2.0-Beta05</version.gatein.pc>
+ <version.gatein.pc>2.2.0-Beta06-SNAPSHOT</version.gatein.pc>
<version.gatein.common>2.0.3-GA</version.gatein.common>
<version.gatein.wci>2.0.2-GA</version.gatein.wci>