Author: julien_viet
Date: 2010-09-14 17:08:10 -0400 (Tue, 14 Sep 2010)
New Revision: 4195
Added:
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestLegacyPortal.java
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouteDescriptor.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/TestHierarchy.java
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRequestParam.java
portal/branches/navcontroller/web/portal/src/main/webapp/WEB-INF/conf/router.xml
Log:
- fix a bug in router
- rewrote the router table to be more concise
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouteDescriptor.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouteDescriptor.java 2010-09-14
18:44:36 UTC (rev 4194)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouteDescriptor.java 2010-09-14
21:08:10 UTC (rev 4195)
@@ -90,7 +90,7 @@
return requestParams;
}
- public RouteDescriptor addChild(RouteDescriptor child)
+ public RouteDescriptor addRoute(RouteDescriptor child)
{
children.add(child);
return this;
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-14
18:44:36 UTC (rev 4194)
+++
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Route.java 2010-09-14
21:08:10 UTC (rev 4195)
@@ -70,7 +70,7 @@
this.requestParamDefs = new HashMap<String, RequestParamDef>();
}
- /**
+ /*
* Ok, so this is not the fastest way to do it, but for now it's OK, it's what
is needed, we'll find
* a way to optimize it later with some precompilation.
*/
@@ -79,15 +79,15 @@
Route r = find(blah);
if (r != null)
{
- r._render(blah, renderContext);
+ r._render(blah, renderContext, false);
}
}
- private void _render(Map<QualifiedName, String> blah, RenderContext
renderContext)
+ private void _render(Map<QualifiedName, String> blah, RenderContext
renderContext, boolean hasChildren)
{
- if (parent != null && parent.parent != null)
+ if (parent != null)
{
- parent._render(blah, renderContext);
+ parent._render(blah, renderContext, true);
}
//
@@ -126,7 +126,10 @@
}
else
{
- renderContext.appendPath("/");
+ if (!hasChildren)
+ {
+ renderContext.appendPath("/");
+ }
}
}
Modified:
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestHierarchy.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestHierarchy.java 2010-09-14
18:44:36 UTC (rev 4194)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestHierarchy.java 2010-09-14
21:08:10 UTC (rev 4195)
@@ -39,7 +39,7 @@
RouteDescriptor descriptor = new RouteDescriptor("/a").
addParam("foo", "bar").
- addChild(new RouteDescriptor("/b").addParam("juu",
"daa"));
+ addRoute(new RouteDescriptor("/b").addParam("juu",
"daa"));
//
Router router = new Router(new RouterDescriptor().addRoute(descriptor));
Added:
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
(rev 0)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestLegacyPortal.java 2010-09-14
21:08:10 UTC (rev 4195)
@@ -0,0 +1,143 @@
+/*
+ * 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;
+
+import junit.framework.TestCase;
+import org.exoplatform.web.controller.QualifiedName;
+import org.exoplatform.web.controller.metadata.RouteDescriptor;
+import org.exoplatform.web.controller.metadata.RouterDescriptor;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class TestLegacyPortal extends TestCase
+{
+
+ /** . */
+ private Router router;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ RouterDescriptor routerMD = new RouterDescriptor();
+
+ RouteDescriptor portal = new RouteDescriptor("/").
+ addParam(QualifiedName.parse("{gtn}handler"), "portal").
+ 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:.*}").
+ addParam(QualifiedName.parse("{gtn}access"), "public")).
+ addRoute(new
RouteDescriptor("/private/{{gtn}sitename}{{gtn}path:.*}").
+ addParam(QualifiedName.parse("{gtn}access"),
"private"));
+
+ //
+ routerMD.addRoute(portal);
+
+ //
+ this.router = new Router(routerMD);
+ }
+
+ public void testPrivateClassicComponent() throws Exception
+ {
+ Map<QualifiedName, String> expectedParameters = new HashMap<QualifiedName,
String>();
+ expectedParameters.put(new QualifiedName("gtn", "handler"),
"portal");
+ expectedParameters.put(new QualifiedName("gtn", "sitename"),
"classic");
+ expectedParameters.put(new QualifiedName("gtn", "access"),
"private");
+ expectedParameters.put(new QualifiedName("gtn", "path"),
"");
+ expectedParameters.put(new QualifiedName("gtn", "componentid"),
"foo");
+
+ //
+ assertEquals(expectedParameters, router.route("/private/classic",
Collections.singletonMap("portal:componentId", new
String[]{"foo"})));
+ assertEquals("/private/classic", router.render(expectedParameters));
+ }
+
+ public void testPrivateClassic() throws Exception
+ {
+ Map<QualifiedName, String> expectedParameters = new HashMap<QualifiedName,
String>();
+ expectedParameters.put(new QualifiedName("gtn", "handler"),
"portal");
+ expectedParameters.put(new QualifiedName("gtn", "sitename"),
"classic");
+ expectedParameters.put(new QualifiedName("gtn", "access"),
"private");
+ expectedParameters.put(new QualifiedName("gtn", "path"),
"");
+
+ //
+ assertEquals(expectedParameters, router.route("/private/classic"));
+ assertEquals("/private/classic", router.render(expectedParameters));
+ }
+
+ public void testPrivateClassicSlash() throws Exception
+ {
+ Map<QualifiedName, String> expectedParameters = new HashMap<QualifiedName,
String>();
+ expectedParameters.put(new QualifiedName("gtn", "handler"),
"portal");
+ expectedParameters.put(new QualifiedName("gtn", "sitename"),
"classic");
+ expectedParameters.put(new QualifiedName("gtn", "access"),
"private");
+ expectedParameters.put(new QualifiedName("gtn", "path"),
"/");
+
+ //
+ assertEquals(expectedParameters, router.route("/private/classic/"));
+ assertEquals("/private/classic/", router.render(expectedParameters));
+ }
+
+ public void testPrivateClassicSlashComponent() throws Exception
+ {
+ Map<QualifiedName, String> expectedParameters = new HashMap<QualifiedName,
String>();
+ expectedParameters.put(new QualifiedName("gtn", "handler"),
"portal");
+ expectedParameters.put(new QualifiedName("gtn", "sitename"),
"classic");
+ expectedParameters.put(new QualifiedName("gtn", "access"),
"private");
+ expectedParameters.put(new QualifiedName("gtn", "path"),
"/");
+ expectedParameters.put(new QualifiedName("gtn", "componentid"),
"foo");
+
+ //
+ assertEquals(expectedParameters, router.route("/private/classic/",
Collections.singletonMap("portal:componentId", new
String[]{"foo"})));
+ assertEquals("/private/classic/", router.render(expectedParameters));
+ }
+
+ public void testPrivateClassicHome() throws Exception
+ {
+ Map<QualifiedName, String> expectedParameters = new HashMap<QualifiedName,
String>();
+ expectedParameters.put(new QualifiedName("gtn", "handler"),
"portal");
+ expectedParameters.put(new QualifiedName("gtn", "sitename"),
"classic");
+ expectedParameters.put(new QualifiedName("gtn", "access"),
"private");
+ expectedParameters.put(new QualifiedName("gtn", "path"),
"/home");
+
+ //
+ assertEquals(expectedParameters, router.route("/private/classic/home"));
+ assertEquals("/private/classic/home",
router.render(expectedParameters));
+ }
+
+ public void testPrivateClassicHomeComponent() throws Exception
+ {
+ Map<QualifiedName, String> expectedParameters = new HashMap<QualifiedName,
String>();
+ expectedParameters.put(new QualifiedName("gtn", "handler"),
"portal");
+ expectedParameters.put(new QualifiedName("gtn", "sitename"),
"classic");
+ expectedParameters.put(new QualifiedName("gtn", "access"),
"private");
+ expectedParameters.put(new QualifiedName("gtn", "path"),
"/home");
+ expectedParameters.put(new QualifiedName("gtn", "componentid"),
"foo");
+
+ //
+ assertEquals(expectedParameters, router.route("/private/classic/home",
Collections.singletonMap("portal:componentId", new
String[]{"foo"})));
+ assertEquals("/private/classic/home",
router.render(expectedParameters));
+ }
+}
Modified:
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRequestParam.java
===================================================================
---
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRequestParam.java 2010-09-14
18:44:36 UTC (rev 4194)
+++
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRequestParam.java 2010-09-14
21:08:10 UTC (rev 4195)
@@ -117,7 +117,7 @@
public void testInheritance() throws Exception
{
RouterDescriptor descriptor = new RouterDescriptor();
- descriptor.addRoute(new
RouteDescriptor("/a").addRequestParam(QualifiedName.parse("foo"),
"a", "a", true).addChild(new
RouteDescriptor("/b").addRequestParam(QualifiedName.parse("bar"),
"b", "b", true)));
+ descriptor.addRoute(new
RouteDescriptor("/a").addRequestParam(QualifiedName.parse("foo"),
"a", "a", true).addRoute(new
RouteDescriptor("/b").addRequestParam(QualifiedName.parse("bar"),
"b", "b", true)));
Router router = new Router(descriptor);
//
@@ -168,4 +168,28 @@
assertEquals(Collections.singletonMap("a", "a"),
renderContext2.getQueryParams());
}
+ public void testMatchDescendantOfRootParameters() throws Exception
+ {
+ RouterDescriptor descriptor = new RouterDescriptor();
+ descriptor.
+ addRoute(new RouteDescriptor("/").
+ addRequestParam(QualifiedName.parse("foo"), "a",
"a", false).
+ addRoute(new RouteDescriptor("/a").
+ addRequestParam(QualifiedName.parse("bar"), "b",
"b", false))
+ );
+ Router router = new Router(descriptor);
+
+ //
+ SimpleRenderContext renderContext = new SimpleRenderContext();
+ Map<QualifiedName, String> parameters = new HashMap<QualifiedName,
String>();
+ parameters.put(QualifiedName.parse("foo"), "a");
+ parameters.put(QualifiedName.parse("bar"), "b");
+ router.render(parameters, renderContext);
+ assertEquals("/a", renderContext.getPath());
+ Map<String, String> expectedRequestParameters = new HashMap<String,
String>();
+ expectedRequestParameters.put("a", "a");
+ expectedRequestParameters.put("b", "b");
+ assertEquals(expectedRequestParameters, renderContext.getQueryParams());
+ }
+
}
Modified:
portal/branches/navcontroller/web/portal/src/main/webapp/WEB-INF/conf/router.xml
===================================================================
---
portal/branches/navcontroller/web/portal/src/main/webapp/WEB-INF/conf/router.xml 2010-09-14
18:44:36 UTC (rev 4194)
+++
portal/branches/navcontroller/web/portal/src/main/webapp/WEB-INF/conf/router.xml 2010-09-14
21:08:10 UTC (rev 4195)
@@ -3,22 +3,19 @@
xsi:schemaLocation="http://www.gatein.org/xml/ns/gatein_router_1_0
http://www.gatein.org/xml/ns/gatein_router_1_0"
xmlns="http://www.gatein.org/xml/ns/gatein_router_1_0">
- <route path="/public/{{gtn}sitename}{{gtn}path:.*}">
+ <route path="/">
<param name="{gtn}handler" value="portal"/>
- <param name="{gtn}access" value="public"/>
<request-param name="{gtn}componentid"
matchName="portal:componentId" required="false"/>
<request-param name="{gtn}action" matchName="portal:action"
required="false"/>
<request-param name="{gtn}objectid" matchName="objectId"
required="false"/>
+ <route path="/public/{{gtn}sitename}{{gtn}path:.*}">
+ <param name="{gtn}access" value="public"/>
+ </route>
+ <route path="/private/{{gtn}sitename}{{gtn}path:.*}">
+ <param name="{gtn}access" value="private"/>
+ </route>
</route>
- <route path="/private/{{gtn}sitename}{{gtn}path:.*}">
- <param name="{gtn}handler" value="portal"/>
- <param name="{gtn}access" value="private"/>
- <request-param name="{gtn}componentid"
matchName="portal:componentId" required="false"/>
- <request-param name="{gtn}action" matchName="portal:action"
required="false"/>
- <request-param name="{gtn}objectid" matchName="objectId"
required="false"/>
- </route>
-
<route path="/upload">
<param name="{gtn}handler" value="upload"/>
</route>