Author: julien_viet
Date: 2010-11-29 17:51:54 -0500 (Mon, 29 Nov 2010)
New Revision: 5362
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/regexp/RegExpParser.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/TestBuildRoute.java
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRouteEscaper.java
Log:
use correct regex for route rendering
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/regexp/RegExpParser.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/regexp/RegExpParser.java 2010-11-29
22:43:42 UTC (rev 5361)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/regexp/RegExpParser.java 2010-11-29
22:51:54 UTC (rev 5362)
@@ -51,6 +51,11 @@
this.index = from;
}
+ public void reset()
+ {
+ this.index = 0;
+ }
+
public int getIndex()
{
return index;
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
22:43:42 UTC (rev 5361)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Route.java 2010-11-29
22:51:54 UTC (rev 5362)
@@ -224,7 +224,6 @@
switch (param.encodingMode)
{
case FORM:
- s = s.replace('/', slashEscape);
matched = param.pattern.matcher(s).matches();
break;
case PRESERVE_PATH:
@@ -653,25 +652,30 @@
}
}
- // Now analyse the regexp
+ // Now work on the regex
+ String renderingRegex;
+ String routingRegex;
try
{
RegExpParser parser = new RegExpParser(regex);
- RENode.Disjunction disjunction = parser.parseDisjunction();
- // Process for form
+ //
+ RENode.Disjunction routingDisjunction = parser.parseDisjunction();
if (encodingMode == EncodingMode.FORM)
{
RouteEscaper escaper = new RouteEscaper('/', '_');
- escaper.visit(disjunction);
+ escaper.visit(routingDisjunction);
}
+ RegExpAnalyser routingAnalyser = new RegExpAnalyser();
+ routingAnalyser.process(routingDisjunction);
+ routingRegex = routingAnalyser.getPattern();
//
- RegExpAnalyser analyser = new RegExpAnalyser();
- analyser.process(disjunction);
-
- //
- regex = analyser.getPattern();
+ parser.reset();
+ RENode.Disjunction renderingDisjunction = parser.parseDisjunction();
+ RegExpAnalyser renderingAnalyser = new RegExpAnalyser();
+ renderingAnalyser.process(renderingDisjunction);
+ renderingRegex = renderingAnalyser.getPattern();
}
catch (SyntaxException e)
{
@@ -683,13 +687,13 @@
}
//
- builder.expr("(").expr(regex).expr(")");
+ builder.expr("(").expr(routingRegex).expr(")");
//
parameterPatterns.add(new PathParam(
parameterQName,
encodingMode,
- Pattern.compile("^" + regex + "$")));
+ Pattern.compile("^" + renderingRegex + "$")));
previous = end.get(i) + 1;
}
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
22:43:42 UTC (rev 5361)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestBuildRoute.java 2010-11-29
22:51:54 UTC (rev 5362)
@@ -67,7 +67,7 @@
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));
@@ -89,7 +89,7 @@
assertEquals("^/([^/]+)", patternRoute.pattern.toString());
assertEquals(1, patternRoute.params.size());
assertEquals(QualifiedName.create("q", "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));
@@ -111,7 +111,7 @@
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/TestRouteEscaper.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRouteEscaper.java 2010-11-29
22:43:42 UTC (rev 5361)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRouteEscaper.java 2010-11-29
22:51:54 UTC (rev 5362)
@@ -41,7 +41,6 @@
escaper.visit(re);
RegExpAnalyser analyser = new RegExpAnalyser();
analyser.process(re);
- System.out.println(pattern + " --> " + analyser.getPattern());
Pattern p = Pattern.compile(analyser.getPattern());
Matcher matcher = p.matcher(test);
assertTrue(matcher.find());