Author: julien_viet
Date: 2010-09-02 09:32:01 -0400 (Thu, 02 Sep 2010)
New Revision: 4032
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/WebAppController.java
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouteMetaData.java
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouterMetaData.java
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Router.java
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/AbstractTestController.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/TestMatch.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:
improve a bit metadata configuration side
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/WebAppController.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/WebAppController.java 2010-09-02
13:22:37 UTC (rev 4031)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/WebAppController.java 2010-09-02
13:32:01 UTC (rev 4032)
@@ -25,6 +25,7 @@
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.exoplatform.web.application.Application;
+import org.exoplatform.web.controller.router.Router;
import java.util.ArrayList;
import java.util.HashMap;
@@ -53,6 +54,8 @@
private HashMap<String, WebRequestHandler> handlers_;
+ private Router router;
+
/**
* The WebAppControler along with the PortalRequestHandler defined in the init()
method of the
* PortalController servlet (controller.register(new PortalRequestHandler())) also add
the
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouteMetaData.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouteMetaData.java 2010-09-02
13:22:37 UTC (rev 4031)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouteMetaData.java 2010-09-02
13:32:01 UTC (rev 4032)
@@ -32,13 +32,22 @@
{
/** . */
+ private final String path;
+
+ /** . */
private final Map<QualifiedName, String> parameters;
- public RouteMetaData()
+ public RouteMetaData(String path)
{
+ this.path = path;
this.parameters = new HashMap<QualifiedName, String>();
}
+ public String getPath()
+ {
+ return path;
+ }
+
public RouteMetaData addParameter(QualifiedName name, String value)
{
parameters.put(name, value);
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouterMetaData.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouterMetaData.java 2010-09-02
13:22:37 UTC (rev 4031)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouterMetaData.java 2010-09-02
13:32:01 UTC (rev 4032)
@@ -37,23 +37,19 @@
this.routes = new HashMap<String, RouteMetaData>();
}
- public void addRoute(String pathTemplate, RouteMetaData controller)
+ public void addRoute(RouteMetaData controller)
{
- if (pathTemplate == null)
- {
- throw new NullPointerException();
- }
if (controller == null)
{
throw new NullPointerException();
}
//
- routes.put(pathTemplate, controller);
+ routes.put(controller.getPath(), controller);
}
- public Map<String, RouteMetaData> getRoutes()
+ public Iterable<RouteMetaData> getRoutes()
{
- return routes;
+ return routes.values();
}
}
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Router.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Router.java 2010-09-02
13:22:37 UTC (rev 4031)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Router.java 2010-09-02
13:32:01 UTC (rev 4032)
@@ -39,17 +39,18 @@
public Router(RouterMetaData metaData)
{
- Route root = new Route();
+ this.root = new Route();
//
- for (Map.Entry<String, RouteMetaData> routeMetaData :
metaData.getRoutes().entrySet())
+ for (RouteMetaData routeMetaData : metaData.getRoutes())
{
- String path = routeMetaData.getKey();
- root.append(path, routeMetaData.getValue().getParameters());
+ addRoute(routeMetaData);
}
+ }
- //
- this.root = root;
+ public void addRoute(RouteMetaData routeMetaData)
+ {
+ root.append(routeMetaData.getPath(), routeMetaData.getParameters());
}
public String render(Map<QualifiedName, String> parameters)
Modified:
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/AbstractTestController.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/AbstractTestController.java 2010-09-02
13:22:37 UTC (rev 4031)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/AbstractTestController.java 2010-09-02
13:32:01 UTC (rev 4032)
@@ -35,6 +35,7 @@
{
public void assertEquals(Map<QualifiedName, String> expectedParameters,
Map<QualifiedName, String> parameters)
{
+ assertNotNull(parameters);
Assert.assertEquals(expectedParameters.keySet(), parameters.keySet());
for (Map.Entry<QualifiedName, String> expectedEntry :
expectedParameters.entrySet())
{
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-09-02
13:22:37 UTC (rev 4031)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestBuildRoute.java 2010-09-02
13:32:01 UTC (rev 4032)
@@ -34,15 +34,13 @@
public class TestBuildRoute extends TestCase
{
- private RouteMetaData ref1 = new RouteMetaData();
-
public void testRoot()
{
String[] paths = {"/",""};
for (String path : paths)
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute(path, ref1);
+ routerMD.addRoute(new RouteMetaData(path));
Router router = new Router(routerMD);
Route expectedRoute = new Route();
assertEquals(expectedRoute, router.root);
@@ -55,7 +53,7 @@
for (String path : paths)
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute(path, ref1);
+ routerMD.addRoute(new RouteMetaData(path));
Router router = new Router(routerMD);
Route expectedRoute = new Route();
SimpleRoute a = new SimpleRoute(expectedRoute, "a");
@@ -70,7 +68,7 @@
for (String path : paths)
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute(path, ref1);
+ routerMD.addRoute(new RouteMetaData(path));
Router router = new Router(routerMD);
//
@@ -93,7 +91,7 @@
for (String path : paths)
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute(path, ref1);
+ routerMD.addRoute(new RouteMetaData(path));
Router router = new Router(routerMD);
//
@@ -116,7 +114,7 @@
for (String path : paths)
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute(path, ref1);
+ routerMD.addRoute(new RouteMetaData(path));
Router router = new Router(routerMD);
//
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-09-02
13:22:37 UTC (rev 4031)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestMatch.java 2010-09-02
13:32:01 UTC (rev 4032)
@@ -35,7 +35,7 @@
public void testRoot() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/", new RouteMetaData());
+ routerMD.addRoute(new RouteMetaData("/"));
Router router = new Router(routerMD);
//
@@ -54,7 +54,7 @@
public void testA() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/a", new RouteMetaData());
+ routerMD.addRoute(new RouteMetaData("/a"));
Router router = new Router(routerMD);
//
@@ -88,7 +88,7 @@
public void testAB() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/a/b", new RouteMetaData());
+ routerMD.addRoute(new RouteMetaData("/a/b"));
Router router = new Router( routerMD);
//
@@ -122,7 +122,7 @@
public void testParameter() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/{p}", new RouteMetaData());
+ routerMD.addRoute(new RouteMetaData("/{p}"));
Router router = new Router(routerMD);
assertEquals(Collections.singletonMap(new QualifiedName("p"),
"a"), router.process(("/a")));
}
@@ -130,8 +130,8 @@
public void testParameterPropagationToDescendants() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/", new RouteMetaData().addParameter("p",
"a"));
- routerMD.addRoute("/a", new RouteMetaData());
+ routerMD.addRoute(new RouteMetaData("/").addParameter("p",
"a"));
+ routerMD.addRoute(new RouteMetaData("/a"));
Router router = new Router(routerMD);
assertEquals(Collections.singletonMap(new QualifiedName("p"),
"a"), router.process(("/a")));
}
@@ -139,7 +139,7 @@
public void testWildcardPattern() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/{p:.*}", new RouteMetaData());
+ routerMD.addRoute(new RouteMetaData("/{p:.*}"));
Router router = new Router(routerMD);
//
@@ -158,7 +158,7 @@
public void testSimplePattern() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/{p:a}", new RouteMetaData());
+ routerMD.addRoute(new RouteMetaData("/{p:a}"));
Router router = new Router(routerMD);
//
@@ -177,8 +177,8 @@
public void testPrecedence() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/a", new RouteMetaData());
- routerMD.addRoute("/{p:a}/b", new RouteMetaData());
+ routerMD.addRoute(new RouteMetaData("/a"));
+ routerMD.addRoute(new RouteMetaData("/{p:a}/b"));
Router router = new Router(routerMD);
//
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-02
13:22:37 UTC (rev 4031)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestPortalConfiguration.java 2010-09-02
13:32:01 UTC (rev 4032)
@@ -40,20 +40,26 @@
protected void setUp() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- RouteMetaData portalControllerRef = new RouteMetaData();
- portalControllerRef.addParameter(new QualifiedName("gtn",
"controller"), "site");
- portalControllerRef.addParameter(new QualifiedName("gtn",
"sitetype"), "portal");
- routerMD.addRoute("/private/{{gtn}sitename}{{gtn}path:.*}",
portalControllerRef);
- RouteMetaData groupControllerRef = new RouteMetaData();
- portalControllerRef.addParameter(new QualifiedName("gtn",
"controller"), "site");
- groupControllerRef.addParameter(new QualifiedName("gtn",
"sitetype"), "group");
- routerMD.addRoute("/groups/{{gtn}sitename}{{gtn}path:.*}",
groupControllerRef);
- RouteMetaData userControllerRef = new RouteMetaData();
- portalControllerRef.addParameter(new QualifiedName("gtn",
"controller"), "site");
- userControllerRef.addParameter(new QualifiedName("gtn",
"sitetype"), "user");
- routerMD.addRoute("/users/{{gtn}sitename}{{gtn}path:.*}",
userControllerRef);
//
+ RouteMetaData portalRouteMD = new
RouteMetaData("/private/{{gtn}sitename}{{gtn}path:.*}");
+ portalRouteMD.addParameter(new QualifiedName("gtn",
"controller"), "site");
+ portalRouteMD.addParameter(new QualifiedName("gtn",
"sitetype"), "portal");
+ routerMD.addRoute(portalRouteMD);
+
+ //
+ RouteMetaData groupRouteMD = new
RouteMetaData("/groups/{{gtn}sitename}{{gtn}path:.*}");
+ portalRouteMD.addParameter(new QualifiedName("gtn",
"controller"), "site");
+ groupRouteMD.addParameter(new QualifiedName("gtn", "sitetype"),
"group");
+ routerMD.addRoute(groupRouteMD);
+
+ //
+ RouteMetaData userRouteMD = new
RouteMetaData("/users/{{gtn}sitename}{{gtn}path:.*}");
+ portalRouteMD.addParameter(new QualifiedName("gtn",
"controller"), "site");
+ userRouteMD.addParameter(new QualifiedName("gtn", "sitetype"),
"user");
+ routerMD.addRoute(userRouteMD);
+
+ //
this.router = new Router(routerMD);
}
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-02
13:22:37 UTC (rev 4031)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRender.java 2010-09-02
13:32:01 UTC (rev 4032)
@@ -35,7 +35,7 @@
public void testRoot() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/", new RouteMetaData());
+ routerMD.addRoute(new RouteMetaData("/"));
Router router = new Router(routerMD);
//
@@ -45,7 +45,7 @@
public void testA() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/a", new RouteMetaData());
+ routerMD.addRoute(new RouteMetaData("/a"));
Router router = new Router(routerMD);
//
@@ -55,7 +55,7 @@
public void testAB() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/a/b", new RouteMetaData());
+ routerMD.addRoute(new RouteMetaData("/a/b"));
Router router = new Router( routerMD);
//
@@ -65,7 +65,7 @@
public void testParameter() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/{p}", new RouteMetaData());
+ routerMD.addRoute(new RouteMetaData("/{p}"));
Router router = new Router(routerMD);
//
@@ -76,7 +76,7 @@
public void testWildcardPattern() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/{p:.*}", new RouteMetaData());
+ routerMD.addRoute(new RouteMetaData("/{p:.*}"));
Router router = new Router(routerMD);
//
@@ -92,7 +92,7 @@
public void testSimplePattern() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/{p:a}", new RouteMetaData());
+ routerMD.addRoute(new RouteMetaData("/{p:a}"));
Router router = new Router(routerMD);
//
@@ -105,8 +105,8 @@
public void testPrecedence() throws Exception
{
RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute("/a", new RouteMetaData());
- routerMD.addRoute("/{p:a}/b", new RouteMetaData());
+ routerMD.addRoute(new RouteMetaData("/a"));
+ routerMD.addRoute(new RouteMetaData("/{p:a}/b"));
Router router = new Router(routerMD);
//