Author: julien_viet
Date: 2010-12-01 12:40:53 -0500 (Wed, 01 Dec 2010)
New Revision: 5428
Modified:
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
Log:
allow to match empty 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-12-01
17:13:39 UTC (rev 5427)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Route.java 2010-12-01
17:40:53 UTC (rev 5428)
@@ -520,12 +520,14 @@
{
nextPath = "/";
}
- else if (nextPos == 1)
- {
- nextPath = path;
- }
else
{
+ if (nextPos > 0 && path.charAt(nextPos - 1) ==
'/')
+ {
+ nextPos--;
+ }
+
+ //
nextPath = path.substring(nextPos);
}
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-12-01
17:13:39 UTC (rev 5427)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestMatch.java 2010-12-01
17:40:53 UTC (rev 5428)
@@ -157,6 +157,28 @@
assertEquals(Collections.singletonMap(QualifiedName.create("a"),
""), router.route("/b"));
}
+ public void testOptionalParameter() throws Exception
+ {
+ Router router = router().
+ add(route("/{a}/b").
+ with(
+ pathParam("a").matchedBy("a?").preservingPath(),
+ routeParam("b").withValue("b"))
+ ).build();
+
+ //
+ Map<QualifiedName, String> expectedParameters = new HashMap<QualifiedName,
String>();
+ expectedParameters.put(QualifiedName.create("a"), "a");
+ expectedParameters.put(QualifiedName.create("b"), "b");
+ assertEquals(expectedParameters, router.route("/a/b"));
+ assertEquals("/a/b", router.render(expectedParameters));
+
+ //
+ expectedParameters.put(QualifiedName.create("a"), "");
+ assertEquals(expectedParameters, router.route("/b"));
+ assertEquals("/b", router.render(expectedParameters));
+ }
+
public void testZeroOrOneFollowedBySubRoute() throws Exception
{
Router router = router().
Show replies by date