Author: julien_viet
Date: 2010-09-01 10:04:51 -0400 (Wed, 01 Sep 2010)
New Revision: 4012
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/TestPortalConfiguration.java
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRender.java
Log:
update controller uri rendering
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
13:54:55 UTC (rev 4011)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Route.java 2010-09-01
14:04:51 UTC (rev 4012)
@@ -63,6 +63,9 @@
this.routeParameters = new HashMap<QualifiedName, String[]>();
}
+ /**
+ * todo: a version that does not string concatenation but instead a buffer
+ */
String render(String controllerId, Map<QualifiedName, String[]> blah)
{
if (controllerRef != null && controllerRef.equals(controllerId))
@@ -75,7 +78,7 @@
return null;
}
}
- return "";
+ return "/";
}
else
{
@@ -84,13 +87,13 @@
String b = a.getValue().render(controllerId, blah);
if (b != null)
{
- if (b.length() > 0)
+ if (b.length() > 1)
{
- return a.getKey() + "/" + b;
+ return "/" + a.getKey() + b;
}
else
{
- return a.getKey();
+ return "/" + a.getKey();
}
}
}
@@ -128,13 +131,13 @@
String bilto = a.render(controllerId, blah);
if (bilto != null)
{
- if (bilto.length() > 0)
+ if (bilto.length() > 1)
{
- return sb + "/" + bilto;
+ return "/" + sb + bilto;
}
else
{
- return sb.toString();
+ return "/" + sb.toString();
}
}
}
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
13:54:55 UTC (rev 4011)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestPortalConfiguration.java 2010-09-01
14:04:51 UTC (rev 4012)
@@ -64,7 +64,7 @@
//
assertProcessResponse("site", expectedParameters, router.process(new
ControllerContext("/private/classic")));
- assertEquals("private/classic", router.render("site",
expectedParameters));
+ assertEquals("/private/classic", router.render("site",
expectedParameters));
}
public void testPrivateClassicSlash() throws Exception
@@ -77,7 +77,7 @@
//
assertProcessResponse("site", expectedParameters, router.process(new
ControllerContext("/private/classic/")));
- assertEquals("private/classic", router.render("site",
expectedParameters));
+ assertEquals("/private/classic", router.render("site",
expectedParameters));
}
public void testPrivateClassicHome() throws Exception
@@ -89,6 +89,6 @@
//
assertProcessResponse("site", expectedParameters, router.process(new
ControllerContext("/private/classic/home")));
- assertEquals("private/classic/home", router.render("site",
expectedParameters));
+ assertEquals("/private/classic/home", router.render("site",
expectedParameters));
}
}
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-09-01
13:54:55 UTC (rev 4011)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRender.java 2010-09-01
14:04:51 UTC (rev 4012)
@@ -39,7 +39,7 @@
Router router = new Router(routerMD);
//
- assertEquals("", router.render("ref1",
Collections.<QualifiedName, String[]>emptyMap()));
+ assertEquals("/", router.render("ref1",
Collections.<QualifiedName, String[]>emptyMap()));
}
public void testA() throws Exception
@@ -49,7 +49,7 @@
Router router = new Router(routerMD);
//
- assertEquals("a", router.render("ref1",
Collections.<QualifiedName, String[]>emptyMap()));
+ assertEquals("/a", router.render("ref1",
Collections.<QualifiedName, String[]>emptyMap()));
}
public void testAB() throws Exception
@@ -59,7 +59,7 @@
Router router = new Router( routerMD);
//
- assertEquals("a/b", router.render("ref1",
Collections.<QualifiedName, String[]>emptyMap()));
+ assertEquals("/a/b", router.render("ref1",
Collections.<QualifiedName, String[]>emptyMap()));
}
public void testParameter() throws Exception
@@ -69,7 +69,7 @@
Router router = new Router(routerMD);
//
- assertEquals("a", router.render("ref1",
Collections.singletonMap(new QualifiedName("p"), new
String[]{"a"})));
+ assertEquals("/a", router.render("ref1",
Collections.singletonMap(new QualifiedName("p"), new
String[]{"a"})));
}
public void testWildcardPattern() throws Exception
@@ -79,13 +79,13 @@
Router router = new Router(routerMD);
//
- assertEquals("", router.render("ref1",
Collections.singletonMap(new QualifiedName("p"), new String[]{""})));
+ assertEquals("/", router.render("ref1",
Collections.singletonMap(new QualifiedName("p"), new String[]{""})));
//
- assertEquals("a", router.render("ref1",
Collections.singletonMap(new QualifiedName("p"), new
String[]{"a"})));
+ assertEquals("/a", router.render("ref1",
Collections.singletonMap(new QualifiedName("p"), new
String[]{"a"})));
//
- assertEquals("a/b", router.render("ref1",
Collections.singletonMap(new QualifiedName("p"), new
String[]{"a/b"})));
+ assertEquals("/a/b", router.render("ref1",
Collections.singletonMap(new QualifiedName("p"), new
String[]{"a/b"})));
}
public void testSimplePattern() throws Exception
@@ -95,7 +95,7 @@
Router router = new Router(routerMD);
//
- assertEquals("a", router.render("ref1",
Collections.singletonMap(new QualifiedName("p"), new
String[]{"a"})));
+ assertEquals("/a", router.render("ref1",
Collections.singletonMap(new QualifiedName("p"), new
String[]{"a"})));
//
assertNull(router.render("ref1", Collections.singletonMap(new
QualifiedName("p"), new String[]{"ab"})));
@@ -109,9 +109,9 @@
Router router = new Router(routerMD);
//
- assertEquals("a", router.render("ref1",
Collections.<QualifiedName, String[]>emptyMap()));
+ assertEquals("/a", router.render("ref1",
Collections.<QualifiedName, String[]>emptyMap()));
//
- assertEquals("a/b", router.render("ref2",
Collections.singletonMap(new QualifiedName("p"), new
String[]{"a"})));
+ assertEquals("/a/b", router.render("ref2",
Collections.singletonMap(new QualifiedName("p"), new
String[]{"a"})));
}
}