Author: julien_viet
Date: 2010-09-01 14:21:04 -0400 (Wed, 01 Sep 2010)
New Revision: 4021
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/ControllerRefMetaData.java
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Route.java
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestMatch.java
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestPortalConfiguration.java
Log:
better impl of route parameters
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/ControllerRefMetaData.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/ControllerRefMetaData.java 2010-09-01
17:38:44 UTC (rev 4020)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/ControllerRefMetaData.java 2010-09-01
18:21:04 UTC (rev 4021)
@@ -58,11 +58,20 @@
this.ref = ref;
}
- public void setParameter(QualifiedName name, String... value)
+ public ControllerRefMetaData addParameter(QualifiedName name, String first, String...
rest)
{
+ String[] value = new String[1 + rest.length];
+ value[0] = first;
+ System.arraycopy(rest, 0, value, 1, rest.length);
parameters.put(name, value);
+ return this;
}
+ public ControllerRefMetaData addParameter(String name, String first, String... rest)
+ {
+ return addParameter(new QualifiedName(name), first, rest);
+ }
+
public Map<QualifiedName, String[]> getParameters()
{
return parameters;
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Route.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Route.java 2010-09-01
17:38:44 UTC (rev 4020)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Route.java 2010-09-01
18:21:04 UTC (rev 4021)
@@ -177,14 +177,6 @@
{
Map<QualifiedName, String[]> parameters = context.getParameters();
- // Update parameters
- if (route.routeParameters.size() > 0)
- {
- parameters = new HashMap<QualifiedName, String[]>(parameters);
- // julien : do a safe put all here on String[]
- parameters.putAll(route.routeParameters);
- }
-
// Determine next path
String nextPath;
if (pos == path.length())
@@ -220,8 +212,6 @@
{
// Update parameters
Map<QualifiedName, String[]> parameters = new
HashMap<QualifiedName, String[]>(context.getParameters());
- // julien : do a safe put all here on String[]
- parameters.putAll(route.routeParameters);
int group = 1;
for (QualifiedName parameterName : route.parameterNames)
{
@@ -254,6 +244,22 @@
}
}
}
+
+ // Update parameters if it is possible
+ if (ret != null)
+ {
+ if (routeParameters.size() > 0)
+ {
+ for (Map.Entry<QualifiedName, String[]> entry :
routeParameters.entrySet())
+ {
+ if (!ret.getParameters().containsKey(entry.getKey()))
+ {
+ // julien : should do a safe put all here on String[]
+ ret.getParameters().put(entry.getKey(), entry.getValue());
+ }
+ }
+ }
+ }
}
//
Modified:
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestMatch.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestMatch.java 2010-09-01
17:38:44 UTC (rev 4020)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestMatch.java 2010-09-01
18:21:04 UTC (rev 4021)
@@ -128,6 +128,15 @@
assertProcessResponse("ref1", Collections.singletonMap(new
QualifiedName("p"), new String[]{"a"}), router.process(new
ControllerContext("/a")));
}
+ public void testParameterPropagationToDescendants() throws Exception
+ {
+ RouterMetaData routerMD = new RouterMetaData();
+ routerMD.addRoute("/", new
ControllerRefMetaData("ref1").addParameter("p", "a"));
+ routerMD.addRoute("/a", new ControllerRefMetaData("ref2"));
+ Router router = new Router(routerMD);
+ assertProcessResponse("ref2", Collections.singletonMap(new
QualifiedName("p"), new String[]{"a"}), router.process(new
ControllerContext("/a")));
+ }
+
public void testWildcardPattern() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
Modified:
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestPortalConfiguration.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestPortalConfiguration.java 2010-09-01
17:38:44 UTC (rev 4020)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestPortalConfiguration.java 2010-09-01
18:21:04 UTC (rev 4021)
@@ -42,13 +42,13 @@
{
RouterMetaData routerMD = new RouterMetaData();
ControllerRefMetaData portalControllerRef = new
ControllerRefMetaData("site");
- portalControllerRef.setParameter(new QualifiedName("gtn",
"sitetype"), "portal");
+ portalControllerRef.addParameter(new QualifiedName("gtn",
"sitetype"), "portal");
routerMD.addRoute("/private/{{gtn}sitename}/{{gtn}path:.*}",
portalControllerRef);
ControllerRefMetaData groupControllerRef = new
ControllerRefMetaData("site");
- groupControllerRef.setParameter(new QualifiedName("gtn",
"sitetype"), "group");
+ groupControllerRef.addParameter(new QualifiedName("gtn",
"sitetype"), "group");
routerMD.addRoute("/groups/{{gtn}sitename}/{{gtn}path:.*}",
groupControllerRef);
ControllerRefMetaData userControllerRef = new
ControllerRefMetaData("site");
- userControllerRef.setParameter(new QualifiedName("gtn",
"sitetype"), "user");
+ userControllerRef.addParameter(new QualifiedName("gtn",
"sitetype"), "user");
routerMD.addRoute("/users/{{gtn}sitename}/{{gtn}path:.*}",
userControllerRef);
//