Author: julien_viet
Date: 2010-11-29 10:22:49 -0500 (Mon, 29 Nov 2010)
New Revision: 5353
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/TestBuildRoute.java
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestLegacyPortal.java
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestPathParamEncoding.java
Log:
now use the correct form decoding in the router
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-11-29
14:52:18 UTC (rev 5352)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Route.java 2010-11-29
15:22:49 UTC (rev 5353)
@@ -24,6 +24,9 @@
import org.exoplatform.web.controller.metadata.RequestParamDescriptor;
import org.exoplatform.web.controller.metadata.RouteDescriptor;
import org.exoplatform.web.controller.metadata.RouteParamDescriptor;
+import org.exoplatform.web.controller.regexp.RENode;
+import org.exoplatform.web.controller.regexp.RegExpParser;
+import org.exoplatform.web.controller.regexp.SyntaxException;
import java.util.ArrayList;
import java.util.Collections;
@@ -640,25 +643,49 @@
//
if (regex == null)
{
- regex = "[^/]+";
+ if (encodingMode == EncodingMode.FORM)
+ {
+ regex = ".+";
+ }
+ else
+ {
+ regex = "[^/]+";
+ }
}
// Now analyse the regexp
- String regex2;
try
{
+ RegExpParser parser = new RegExpParser(regex);
+ RENode.Disjunction disjunction = parser.parseDisjunction();
+
+ // Process for form
+ if (encodingMode == EncodingMode.FORM)
+ {
+ RouteEscaper escaper = new RouteEscaper('/', '_');
+ escaper.visit(disjunction);
+ }
+
+ //
RegExpAnalyser analyser = new RegExpAnalyser();
- analyser.process(regex);
- regex2 = analyser.getPattern();
- System.out.println("" + regex + " -> " +
regex2);
+ analyser.process(disjunction);
+
+ //
+ String tmp = analyser.getPattern();
+ System.out.println("" + regex + " -> " + tmp);
+ regex = tmp;
}
+ catch (SyntaxException e)
+ {
+ throw new RuntimeException(e);
+ }
catch (MalformedRegExpException e)
{
throw new RuntimeException(e);
}
//
- builder.expr("(").expr(regex2).expr(")");
+ builder.expr("(").expr(regex).expr(")");
//
parameterPatterns.add(new PathParam(
Modified:
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestBuildRoute.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestBuildRoute.java 2010-11-29
14:52:18 UTC (rev 5352)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestBuildRoute.java 2010-11-29
15:22:49 UTC (rev 5353)
@@ -119,10 +119,10 @@
assertEquals(0, router.root.getSegmentNames().size());
assertEquals(1, router.root.getPatternSize());
PatternRoute patternRoute = router.root.getPattern(0);
- assertEquals("^/(.*)", patternRoute.pattern.toString());
+ assertEquals("^/([^/]*)", patternRoute.pattern.toString());
assertEquals(1, patternRoute.params.size());
assertEquals(QualifiedName.create("a"),
patternRoute.params.get(0).name);
- assertEquals("^.*$", patternRoute.params.get(0).pattern.toString());
+ assertEquals("^[^/]*$",
patternRoute.params.get(0).pattern.toString());
assertEquals(EncodingMode.FORM, patternRoute.params.get(0).encodingMode);
assertEquals(2, patternRoute.chunks.size());
assertEquals("", patternRoute.chunks.get(0));
Modified:
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestLegacyPortal.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestLegacyPortal.java 2010-11-29
14:52:18 UTC (rev 5352)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestLegacyPortal.java 2010-11-29
15:22:49 UTC (rev 5353)
@@ -48,10 +48,14 @@
addRequestParam(QualifiedName.parse("gtn:componentid"),
"portal:componentId", null, false).
addRequestParam(QualifiedName.parse("gtn:action"),
"portal:action", null, false).
addRequestParam(QualifiedName.parse("gtn:objectid"),
"portal:objectId", null, false).
- addRoute(new RouteDescriptor("/public/{gtn:sitename}{gtn:path}").
- addRouteParam(QualifiedName.parse("gtn:access"),
"public")).addPathParam(QualifiedName.parse("gtn:path"),
".*", EncodingMode.PRESERVE_PATH).
- addRoute(new
RouteDescriptor("/private/{gtn:sitename}{gtn:path}").addPathParam(QualifiedName.parse("gtn:path"),
".*", EncodingMode.PRESERVE_PATH).
- addRouteParam(QualifiedName.parse("gtn:access"),
"private"));
+ addRoute(
+ new RouteDescriptor("/public/{gtn:sitename}{gtn:path}").
+ addRouteParam(QualifiedName.parse("gtn:access"),
"public")).
+ addPathParam(QualifiedName.parse("gtn:path"), ".*",
EncodingMode.PRESERVE_PATH).
+ addRoute(
+ new RouteDescriptor("/private/{gtn:sitename}{gtn:path}").
+ addPathParam(QualifiedName.parse("gtn:path"), ".*",
EncodingMode.PRESERVE_PATH).
+ addRouteParam(QualifiedName.parse("gtn:access"),
"private"));
//
routerMD.addRoute(portal);
Modified:
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestPathParamEncoding.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestPathParamEncoding.java 2010-11-29
14:52:18 UTC (rev 5352)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestPathParamEncoding.java 2010-11-29
15:22:49 UTC (rev 5353)
@@ -35,7 +35,7 @@
public void testDefaultForm() throws Exception
{
RouterDescriptor routerMD = new RouterDescriptor();
- routerMD.addRoute(new
RouteDescriptor("/{p}").addPathParam(QualifiedName.parse("p"),
"[^/]+", EncodingMode.FORM));
+ routerMD.addRoute(new
RouteDescriptor("/{p}").addPathParam(QualifiedName.parse("p"),
".+", EncodingMode.FORM));
Router router = new Router(routerMD);
// Route
@@ -59,6 +59,22 @@
assertEquals(null,
router.render(Collections.singletonMap(QualifiedName.create("p"),
"/")));
}
+ public void testD() throws Exception
+ {
+ RouterDescriptor routerMD = new RouterDescriptor();
+ routerMD.addRoute(new RouteDescriptor("/{p}").
+ addPathParam(QualifiedName.parse("p"), "/[a-z]+/[a-z]+/?",
EncodingMode.FORM));
+ Router router = new Router(routerMD);
+
+ // Route
+ assertEquals(Collections.singletonMap(QualifiedName.create("p"),
"/platform/administrator"),
router.route("/_platform_administrator"));
+ assertEquals(Collections.singletonMap(QualifiedName.create("p"),
"/platform/administrator"),
router.route("/_platform_administrator/"));
+ assertEquals(Collections.singletonMap(QualifiedName.create("p"),
"/platform/administrator/"),
router.route("/_platform_administrator_"));
+ assertEquals(Collections.singletonMap(QualifiedName.create("p"),
"/platform/administrator/"),
router.route("/_platform_administrator_/"));
+
+ // todo : render
+ }
+
public void testWildcardPathParamWithPreservePath() throws Exception
{
RouterDescriptor routerMD = new RouterDescriptor();