Author: julien_viet
Date: 2010-11-27 16:29:45 -0500 (Sat, 27 Nov 2010)
New Revision: 5310
Added:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/MalformedRegExpException.java
Modified:
portal/branches/navcontroller/component/web/controller/pom.xml
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/regexp/Parser.java
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/SyntaxException.java
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/RegExpAnalyser.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/regexp/TestParser.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/TestPortal.java
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRegExpAnalyser.java
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRender.java
Log:
- use checked exceptions
- fix wrong parsing of alternatives (|)
- use regex analyzer in router
Modified: portal/branches/navcontroller/component/web/controller/pom.xml
===================================================================
--- portal/branches/navcontroller/component/web/controller/pom.xml 2010-11-27 13:17:30 UTC
(rev 5309)
+++ portal/branches/navcontroller/component/web/controller/pom.xml 2010-11-27 21:29:45 UTC
(rev 5310)
@@ -40,5 +40,10 @@
<groupId>org.exoplatform.portal</groupId>
<artifactId>exo.portal.component.web.resources</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.exoplatform.portal</groupId>
+ <artifactId>exo.portal.component.test.core</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/regexp/Parser.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/regexp/Parser.java 2010-11-27
13:17:30 UTC (rev 5309)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/regexp/Parser.java 2010-11-27
21:29:45 UTC (rev 5310)
@@ -83,9 +83,16 @@
return to;
}
- protected final int lastIndexOf(char c)
+ /**
+ * Finds the first index of the occurence of the specified char from a specified
index.
+ *
+ * @param c the char to match
+ * @param start the start index
+ * @return the matched char index or -1
+ */
+ protected final int indexOf(char c, int start)
{
- for (int i = to - 1;i >= from;i--)
+ for (int i = start;i < to;i++)
{
if (s.charAt(i) == c)
{
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-27
13:17:30 UTC (rev 5309)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/regexp/RegExpParser.java 2010-11-27
21:29:45 UTC (rev 5310)
@@ -73,10 +73,11 @@
* disjunction -> alternative | alternative '|' disjunction
*
* @return the disjunction
+ * @throws SyntaxException any syntax exception
*/
- public RENode.Disjunction parseDisjunction()
+ public RENode.Disjunction parseDisjunction() throws SyntaxException
{
- int pipe = lastIndexOf('|');
+ int pipe = indexOf('|', from);
if (pipe == -1)
{
return new RENode.Disjunction(parseAlternative());
@@ -96,8 +97,9 @@
* alternative -> expression | expression '|' alternative
*
* @return the alternative
+ * @throws SyntaxException any syntax exception
*/
- public RENode.Alternative parseAlternative()
+ public RENode.Alternative parseAlternative() throws SyntaxException
{
if (index < to)
{
@@ -119,7 +121,8 @@
}
/**
- * expression -> assertion | '(' disjunction ')' | character
| expression quantifier
+ * expression -> assertion | group | character | expression quantifier
+ * group -> '(' disjunction ')' | '('
'?' ':' disjunction ')'
* assertion -> '^' | '$'
* character -> '.' | escaped | character_class | literal
* escaped -> '\' any char
@@ -127,8 +130,9 @@
* quantifier_prefix -> '*' | '+' | '?' | '{' count
'}' | '{' count ',' '}' | '{' count ','
count '}'
*
* @return the expression
+ * @throws SyntaxException any syntax exception
*/
- public RENode.Exp parseExpression()
+ public RENode.Exp parseExpression() throws SyntaxException
{
if (index == to)
{
@@ -230,13 +234,13 @@
}
//
- exp.quantifier = parseQuantifierSymbol();
+ exp.quantifier = parseQuantifier();
//
return exp;
}
- Quantifier parseQuantifierSymbol()
+ Quantifier parseQuantifier() throws SyntaxException
{
if (index < to)
{
@@ -320,8 +324,9 @@
* @param begin the begin
* @param end the end
* @return a character class expression
+ * @throws SyntaxException any syntax exception
*/
- private RENode.CharacterClassExpr parseCharacterClass(int begin, int end)
+ private RENode.CharacterClassExpr parseCharacterClass(int begin, int end) throws
SyntaxException
{
if (begin == end)
{
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/regexp/SyntaxException.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/regexp/SyntaxException.java 2010-11-27
13:17:30 UTC (rev 5309)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/regexp/SyntaxException.java 2010-11-27
21:29:45 UTC (rev 5310)
@@ -23,7 +23,7 @@
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
* @version $Revision$
*/
-public class SyntaxException extends RuntimeException
+public class SyntaxException extends Exception
{
public SyntaxException()
{
Added:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/MalformedRegExpException.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/MalformedRegExpException.java
(rev 0)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/MalformedRegExpException.java 2010-11-27
21:29:45 UTC (rev 5310)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.exoplatform.web.controller.router;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class MalformedRegExpException extends Exception
+{
+ public MalformedRegExpException()
+ {
+ }
+
+ public MalformedRegExpException(String s)
+ {
+ super(s);
+ }
+
+ public MalformedRegExpException(String s, Throwable throwable)
+ {
+ super(s, throwable);
+ }
+
+ public MalformedRegExpException(Throwable throwable)
+ {
+ super(throwable);
+ }
+}
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/RegExpAnalyser.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/RegExpAnalyser.java 2010-11-27
13:17:30 UTC (rev 5309)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/RegExpAnalyser.java 2010-11-27
21:29:45 UTC (rev 5310)
@@ -22,6 +22,7 @@
import org.exoplatform.web.controller.regexp.Quantifier;
import org.exoplatform.web.controller.regexp.RENode;
import org.exoplatform.web.controller.regexp.RegExpParser;
+import org.exoplatform.web.controller.regexp.SyntaxException;
/**
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
@@ -31,47 +32,44 @@
{
/** . */
- private StringBuilder sb;
+ private StringBuilder pattern;
/** . */
- private boolean groupContainer;
-
- /** . */
private boolean needReset;
public RegExpAnalyser()
{
- this.sb = new StringBuilder();
- this.groupContainer = false;
+ this.pattern = new StringBuilder();
this.needReset = false;
}
- public boolean isGroupContainer()
- {
- return groupContainer;
- }
-
public String getPattern()
{
- return sb.toString();
+ return pattern.toString();
}
public RegExpAnalyser reset()
{
- sb.setLength(0);
- groupContainer = false;
+ pattern.setLength(0);
needReset = false;
return this;
}
- public void process(CharSequence pattern)
+ public void process(CharSequence pattern) throws MalformedRegExpException
{
- RegExpParser parser = new RegExpParser(pattern);
- RENode.Disjunction disjunction = parser.parseDisjunction();
- process(disjunction);
+ try
+ {
+ RegExpParser parser = new RegExpParser(pattern);
+ RENode.Disjunction disjunction = parser.parseDisjunction();
+ process(disjunction);
+ }
+ catch (SyntaxException e)
+ {
+ throw new MalformedRegExpException(e);
+ }
}
- public void process(RENode.Disjunction disjunction)
+ public void process(RENode.Disjunction disjunction) throws MalformedRegExpException
{
if (needReset)
{
@@ -83,18 +81,18 @@
visit(disjunction);
}
- private void visit(RENode.Disjunction disjunction)
+ private void visit(RENode.Disjunction disjunction) throws MalformedRegExpException
{
visit(disjunction.getAlternative());
RENode.Disjunction next = disjunction.getNext();
if (next != null)
{
- sb.append('|');
+ pattern.append('|');
visit(next);
}
}
- private void visit(RENode.Alternative alternative)
+ private void visit(RENode.Alternative alternative) throws MalformedRegExpException
{
visit(alternative.getExp());
RENode.Alternative next = alternative.getNext();
@@ -104,78 +102,84 @@
}
}
- private void visit(RENode.Exp expression)
+ private void visit(RENode.Exp expression) throws MalformedRegExpException
{
Quantifier quantifier = null;
if (expression instanceof RENode.Dot)
{
- sb.append('.');
+ pattern.append('.');
quantifier = expression.getQuantifier();
}
else if (expression instanceof RENode.Group)
{
RENode.Group group = (RENode.Group)expression;
- sb.append(groupContainer ? "(?:" : "(");
- groupContainer = true;
+ pattern.append("(?:");
visit(group.getDisjunction());
- sb.append(")");
+ pattern.append(")");
quantifier = expression.getQuantifier();
}
else if (expression instanceof RENode.Character)
{
RENode.Character character = (RENode.Character)expression;
- sb.append(character.getValue());
+ pattern.append(character.getValue());
quantifier = expression.getQuantifier();
}
else if (expression instanceof RENode.CharacterClass)
{
RENode.CharacterClass characterClass = (RENode.CharacterClass)expression;
- sb.append("[");
- visit(characterClass.getExpr());
- sb.append("]");
+ pattern.append("[");
+ visit(characterClass.getExpr(), true);
+ pattern.append("]");
quantifier = expression.getQuantifier();
}
//
if (quantifier != null)
{
- sb.append(quantifier);
+ pattern.append(quantifier);
}
}
- private void visit(RENode.CharacterClassExpr expr)
+ private void visit(RENode.CharacterClassExpr expr, boolean braced)
{
if (expr instanceof RENode.CharacterClassExpr.Simple)
{
RENode.CharacterClass.CharacterClassExpr.Simple simple =
(RENode.CharacterClass.CharacterClassExpr.Simple)expr;
- sb.append(simple.getValue());
+ pattern.append(simple.getValue());
}
else if (expr instanceof RENode.CharacterClass.CharacterClassExpr.Range)
{
RENode.CharacterClass.CharacterClassExpr.Range range =
(RENode.CharacterClass.CharacterClassExpr.Range)expr;
- sb.append(range.getFrom());
- sb.append('-');
- sb.append(range.getTo());
+ pattern.append(range.getFrom());
+ pattern.append('-');
+ pattern.append(range.getTo());
}
else if (expr instanceof RENode.CharacterClass.CharacterClassExpr.And)
{
RENode.CharacterClass.CharacterClassExpr.And and =
(RENode.CharacterClass.CharacterClassExpr.And)expr;
- visit(and.getLeft());
- sb.append("&&");
- visit(and.getRight());
+ visit(and.getLeft(), false);
+ pattern.append("&&");
+ visit(and.getRight(), false);
}
else if (expr instanceof RENode.CharacterClass.CharacterClassExpr.Or)
{
RENode.CharacterClass.CharacterClassExpr.Or or =
(RENode.CharacterClass.CharacterClassExpr.Or)expr;
- visit(or.getLeft());
- visit(or.getRight());
+ visit(or.getLeft(), false);
+ visit(or.getRight(), false);
}
else if (expr instanceof RENode.CharacterClass.CharacterClassExpr.Not)
{
RENode.CharacterClass.CharacterClassExpr.Not not =
(RENode.CharacterClass.CharacterClassExpr.Not)expr;
- sb.append("[^");
- visit(not.getNegated());
- sb.append(']');
+ if (!braced)
+ {
+ pattern.append("[");
+ }
+ pattern.append("^");
+ visit(not.getNegated(), false);
+ if (!braced)
+ {
+ pattern.append(']');
+ }
}
}
}
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-27
13:17:30 UTC (rev 5309)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Route.java 2010-11-27
21:29:45 UTC (rev 5310)
@@ -396,12 +396,26 @@
for (int i = 0;i < route.params.size();i++)
{
PathParam param = route.params.get(i);
- String value = matcher.group(group++);
- if (param.encodingMode == EncodingMode.DEFAULT_FORM)
+
+ //
+ String value = matcher.group(group);
+
+ //
+ if (value != null)
{
- value = value.replace(slashEscape, '/');
+ if (param.encodingMode == EncodingMode.DEFAULT_FORM)
+ {
+ value = value.replace(slashEscape, '/');
+ }
+ response.put(param.name, value);
}
- response.put(param.name, value);
+ else
+ {
+ // We have an optional match
+ }
+
+ //
+ group++;
}
//
@@ -630,20 +644,27 @@
}
// Now analyse the regexp
-// RegExpAnalyser analyser = new RegExpAnalyser();
-// analyser.process(regex);
-// String regex2 = analyser.getPattern();
-// System.out.println("" + regex + " -> " +
regex2);
+ String regex2;
+ try
+ {
+ RegExpAnalyser analyser = new RegExpAnalyser();
+ analyser.process(regex);
+ regex2 = analyser.getPattern();
+ System.out.println("" + regex + " -> " +
regex2);
+ }
+ catch (MalformedRegExpException e)
+ {
+ throw new RuntimeException(e);
+ }
//
- builder.expr("(").expr(regex).expr(")");
+ builder.expr("(").expr(regex2).expr(")");
//
parameterPatterns.add(new PathParam(
parameterQName,
encodingMode,
- Pattern.compile("^" + regex + "$")
- ));
+ Pattern.compile("^" + regex + "$")));
previous = end.get(i) + 1;
}
@@ -653,6 +674,7 @@
// Julien : should the pattern end with a $ ?????? I don't see that for
now
// we need to figure out clearly
Pattern pattern = builder.build();
+ System.out.println("pattern = " + pattern);
PatternRoute route = new PatternRoute(pattern, parameterPatterns, chunks);
// Wire
Modified:
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/regexp/TestParser.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/regexp/TestParser.java 2010-11-27
13:17:30 UTC (rev 5309)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/regexp/TestParser.java 2010-11-27
21:29:45 UTC (rev 5310)
@@ -19,7 +19,9 @@
package org.exoplatform.web.controller.regexp;
+import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
+import org.exoplatform.component.test.BaseGateInTest;
import java.util.regex.Pattern;
@@ -27,7 +29,7 @@
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
* @version $Revision$
*/
-public class TestParser extends TestCase
+public class TestParser extends BaseGateInTest
{
@@ -52,18 +54,32 @@
}
ParserTester assertParseCharacterClass(String expectedValue)
{
- RENode node = parser.parseExpression();
- assertTrue(node instanceof RENode.CharacterClass);
- assertEquals(expectedValue, node.toString());
- return this;
+ try
+ {
+ RENode node = parser.parseExpression();
+ assertTrue(node instanceof RENode.CharacterClass);
+ assertEquals(expectedValue, node.toString());
+ return this;
+ }
+ catch (SyntaxException e)
+ {
+ return fail(e);
+ }
}
ParserTester assertParseDisjunction(String expectedValue)
{
- int expectedIndex = parser.getTo();
- RENode.Disjunction disjunction = parser.parseDisjunction();
- assertEquals(expectedValue, disjunction.toString());
- assertEquals(expectedIndex, parser.getIndex());
- return this;
+ try
+ {
+ int expectedIndex = parser.getTo();
+ RENode.Disjunction disjunction = parser.parseDisjunction();
+ assertEquals(expectedValue, disjunction.toString());
+ assertEquals(expectedIndex, parser.getIndex());
+ return this;
+ }
+ catch (SyntaxException e)
+ {
+ return fail(e);
+ }
}
ParserTester assertNotParseDisjunction()
{
@@ -81,10 +97,17 @@
}
ParserTester assertParseExpression(String expectedValue, int expectedIndex)
{
- RENode.Exp exp = parser.parseExpression();
- assertEquals(expectedValue, exp.toString());
- assertEquals(expectedIndex, parser.getIndex());
- return this;
+ try
+ {
+ RENode.Exp exp = parser.parseExpression();
+ assertEquals(expectedValue, exp.toString());
+ assertEquals(expectedIndex, parser.getIndex());
+ return this;
+ }
+ catch (SyntaxException e)
+ {
+ return fail(e);
+ }
}
ParserTester assertNotParseExpression()
{
@@ -103,14 +126,23 @@
ParserTester assertParseQuantifier(int expectedIndex, Quantifier
expectedQuantifier)
{
int index = parser.getIndex();
+ Quantifier quantifier;
+ try
+ {
+ quantifier = parser.parseQuantifier();
+ }
+ catch (SyntaxException e)
+ {
+ return fail(e);
+ }
if (expectedQuantifier != null)
{
- assertEquals(expectedQuantifier, parser.parseQuantifierSymbol());
+ assertEquals(expectedQuantifier, quantifier);
assertEquals(expectedIndex, parser.getIndex());
}
else
{
- assertNull(parser.parseQuantifierSymbol());
+ assertNull(quantifier);
assertEquals(expectedIndex, parser.getIndex());
}
return this;
@@ -128,6 +160,7 @@
new
ParserTester("^$").assertParseDisjunction("<^/><$/>");
new
ParserTester("a").assertParseDisjunction("<c>a</c>");
new
ParserTester("a|b").assertParseDisjunction("<c>a</c>|<c>b</c>");
+ new
ParserTester("a|b|c").assertParseDisjunction("<c>a</c>|<c>b</c>|<c>c</c>");
new
ParserTester("a+|b*").assertParseDisjunction("<+><c>a</c></+>|<*><c>b</c></*>");
}
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-11-27
13:17:30 UTC (rev 5309)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestMatch.java 2010-11-27
21:29:45 UTC (rev 5310)
@@ -195,7 +195,7 @@
public void testLang() throws Exception
{
RouterDescriptor routerMD = new RouterDescriptor();
- routerMD.addRoute(new
RouteDescriptor("/{a}b").addPathParam(QualifiedName.parse("a"),
"(?:[A-Za-z]{2}/)?", EncodingMode.PRESERVE_PATH));
+ routerMD.addRoute(new
RouteDescriptor("/{a}b").addPathParam(QualifiedName.parse("a"),
"(([A-Za-z]{2})/)?", EncodingMode.PRESERVE_PATH));
Router router = new Router(routerMD);
//
Modified:
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestPortal.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestPortal.java 2010-11-27
13:17:30 UTC (rev 5309)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestPortal.java 2010-11-27
21:29:45 UTC (rev 5310)
@@ -47,7 +47,7 @@
{
RouterDescriptor routerMD = new RouterDescriptor().addRoute(
new RouteDescriptor("/{gtn:lang}public").addPathParam(
- QualifiedName.parse("gtn:lang"), "([A-Za-z][A-Za-z]/)?",
EncodingMode.PRESERVE_PATH)
+ QualifiedName.parse("gtn:lang"), "([A-Za-z]{2}/)?",
EncodingMode.PRESERVE_PATH)
);
Router router = new Router(routerMD);
assertEquals(Collections.singletonMap(QualifiedName.parse("gtn:lang"),
""), router.route("/public"));
@@ -59,7 +59,7 @@
RouterDescriptor routerMD = new RouterDescriptor().
addRoute(new RouteDescriptor("/public")).
addRoute(new RouteDescriptor("/{gtn:lang}/public").
- addPathParam(QualifiedName.parse("gtn:lang"),
"([A-Za-z][A-Za-z])", EncodingMode.DEFAULT_FORM
+ addPathParam(QualifiedName.parse("gtn:lang"),
"([A-Za-z]{2})", EncodingMode.DEFAULT_FORM
)
);
Router router = new Router(routerMD);
Modified:
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRegExpAnalyser.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRegExpAnalyser.java 2010-11-27
13:17:30 UTC (rev 5309)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRegExpAnalyser.java 2010-11-27
21:29:45 UTC (rev 5310)
@@ -19,49 +19,72 @@
package org.exoplatform.web.controller.router;
-import junit.framework.TestCase;
+import org.exoplatform.component.test.BaseGateInTest;
/**
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
* @version $Revision$
*/
-public class TestRegExpAnalyser extends TestCase
+public class TestRegExpAnalyser extends BaseGateInTest
{
/** . */
private RegExpAnalyser analyser = new RegExpAnalyser();
- private void assertAnalyse(String expectedPattern, boolean expectedGroupContainer,
String pattern)
+ private void assertAnalyse(String expectedPattern, String pattern)
{
+ try
+ {
+ analyser.reset();
+ analyser.process(pattern);
+ assertEquals(expectedPattern, analyser.getPattern());
+ }
+ catch (MalformedRegExpException e)
+ {
+ fail(e);
+ }
+ }
+
+ private void assertAnalyseFails(String pattern)
+ {
analyser.reset();
- analyser.process(pattern);
- assertEquals(expectedPattern, analyser.getPattern());
- assertEquals(expectedGroupContainer, analyser.isGroupContainer());
+ try
+ {
+ analyser.process(pattern);
+ fail();
+ }
+ catch (MalformedRegExpException e)
+ {
+ }
}
public void testCharacterClass()
{
- assertAnalyse("[a]", false, "[a]");
- assertAnalyse("[ab]", false, "[ab]");
- assertAnalyse("[ab]", false, "[a[b]]");
- assertAnalyse("[abc]", false, "[abc]");
- assertAnalyse("[abc]", false, "[[a]bc]");
- assertAnalyse("[abc]", false, "[a[b]c]");
- assertAnalyse("[abc]", false, "[ab[c]]");
- assertAnalyse("[abc]", false, "[[ab]c]");
- assertAnalyse("[abc]", false, "[a[bc]]");
- assertAnalyse("[abc]", false, "[[abc]]");
+ assertAnalyse("[a]", "[a]");
+ assertAnalyse("[ab]", "[ab]");
+ assertAnalyse("[ab]", "[a[b]]");
+ assertAnalyse("[abc]", "[abc]");
+ assertAnalyse("[abc]", "[[a]bc]");
+ assertAnalyse("[abc]", "[a[b]c]");
+ assertAnalyse("[abc]", "[ab[c]]");
+ assertAnalyse("[abc]", "[[ab]c]");
+ assertAnalyse("[abc]", "[a[bc]]");
+ assertAnalyse("[abc]", "[[abc]]");
+ assertAnalyse("[^a]", "[^a]");
}
public void testGroupContainer()
{
- assertAnalyse("(abc)", true, "(abc)");
- assertAnalyse("(a(?:bc))", true, "(a(bc))");
- assertAnalyse("(a)(?:b)", true, "(a)(b)");
+ assertAnalyse("(?:a)", "(a)");
+ assertAnalyse("(?:a(?:b))", "(a(?:b))");
+ assertAnalyse("(?:a(?:b))", "(?:a(b))");
+ assertAnalyse("(?:a)(?:b)", "(a)(?:b)");
+ assertAnalyse("(?:a(?:b))", "(a(b))");
+ assertAnalyse("(?:a)(?:b)", "(a)(b)");
}
public void testBilto()
{
- assertAnalyse("[a]+", false, "[a]+");
+ assertAnalyse("[a]+", "[a]+");
}
}
Modified:
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRender.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRender.java 2010-11-27
13:17:30 UTC (rev 5309)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRender.java 2010-11-27
21:29:45 UTC (rev 5310)
@@ -153,7 +153,7 @@
public void testLang() throws Exception
{
RouterDescriptor routerMD = new RouterDescriptor();
- routerMD.addRoute(new
RouteDescriptor("/{a}b").addPathParam(QualifiedName.parse("a"),
"(?:[A-Za-z]{2}/)?", EncodingMode.PRESERVE_PATH));
+ routerMD.addRoute(new
RouteDescriptor("/{a}b").addPathParam(QualifiedName.parse("a"),
"(([A-Za-z]{2})/)?", EncodingMode.PRESERVE_PATH));
Router router = new Router(routerMD);
//