gatein SVN: r4161 - in portal/branches/navcontroller/component/web/controller/src: test/java/org/exoplatform/web/controller/router and 1 other directory.
by do-not-reply@jboss.org
Author: julien_viet
Date: 2010-09-12 19:55:04 -0400 (Sun, 12 Sep 2010)
New Revision: 4161
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/DescriptorBuilder.java
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouterDescriptor.java
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestDescriptorBuilder.java
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/router.xml
Log:
implement parsing of child routes
Modified: portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/DescriptorBuilder.java
===================================================================
--- portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/DescriptorBuilder.java 2010-09-12 23:07:32 UTC (rev 4160)
+++ portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/DescriptorBuilder.java 2010-09-12 23:55:04 UTC (rev 4161)
@@ -25,7 +25,9 @@
import org.exoplatform.web.controller.QualifiedName;
import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
+import java.util.List;
/**
* @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
@@ -50,23 +52,36 @@
SMInputCursor routeC = routerC.childElementCursor(routeQN);
while (routeC.getNext() != null)
{
- String path = routeC.getAttrValue("path");
- RouteDescriptor routeDesc = new RouteDescriptor(path);
+ build(routeC, routerDesc.getRoutes());
+ }
- //
- SMInputCursor parameterC = routeC.childElementCursor(parameterQN);
- while (parameterC.getNext() != null)
+ //
+ return routerDesc;
+ }
+
+ private void build(SMInputCursor routeC, List<RouteDescriptor> descriptors) throws XMLStreamException
+ {
+ String path = routeC.getAttrValue("path");
+ RouteDescriptor routeDesc = new RouteDescriptor(path);
+
+ //
+ SMInputCursor childC = routeC.childElementCursor();
+ while (childC.getNext() != null)
+ {
+ if (childC.getQName().equals(parameterQN))
{
- String name = parameterC.getAttrValue("name");
- String value = parameterC.getAttrValue("value");
+ String name = childC.getAttrValue("name");
+ String value = childC.getAttrValue("value");
routeDesc.addParameter(QualifiedName.parse(name), value);
}
-
- //
- routerDesc.addRoute(routeDesc);
+ else if (childC.getQName().equals(routeQN))
+ {
+ build(childC, routeDesc.getChildren());
+ }
}
//
- return routerDesc;
+ descriptors.add(routeDesc);
}
+
}
Modified: portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouterDescriptor.java
===================================================================
--- portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouterDescriptor.java 2010-09-12 23:07:32 UTC (rev 4160)
+++ portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouterDescriptor.java 2010-09-12 23:55:04 UTC (rev 4161)
@@ -51,7 +51,7 @@
return this;
}
- public Iterable<RouteDescriptor> getRoutes()
+ public List<RouteDescriptor> getRoutes()
{
return routes;
}
Modified: portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestDescriptorBuilder.java
===================================================================
--- portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestDescriptorBuilder.java 2010-09-12 23:07:32 UTC (rev 4160)
+++ portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestDescriptorBuilder.java 2010-09-12 23:55:04 UTC (rev 4161)
@@ -21,6 +21,7 @@
import junit.framework.TestCase;
import org.exoplatform.web.WebAppController;
+import org.exoplatform.web.controller.QualifiedName;
import org.exoplatform.web.controller.metadata.DescriptorBuilder;
import org.exoplatform.web.controller.metadata.RouteDescriptor;
import org.exoplatform.web.controller.metadata.RouterDescriptor;
@@ -70,5 +71,15 @@
RouteDescriptor route4 = i.next();
assertEquals("/download", route4.getPath());
assertEquals(Collections.singletonMap(WebAppController.HANDLER_PARAM, "download"), route4.getParameters());
+
+ //
+ assertTrue(i.hasNext());
+ RouteDescriptor route5 = i.next();
+ assertEquals("/a", route5.getPath());
+ assertEquals(Collections.singletonMap(new QualifiedName("a"), "a_value"), route5.getParameters());
+ assertEquals(1, route5.getChildren().size());
+ RouteDescriptor route5_1 = route5.getChildren().get(0);
+ assertEquals("/b", route5_1.getPath());
+ assertEquals(Collections.singletonMap(new QualifiedName("b"), "b_value"), route5_1.getParameters());
}
}
Modified: portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/router.xml
===================================================================
--- portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/router.xml 2010-09-12 23:07:32 UTC (rev 4160)
+++ portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/router.xml 2010-09-12 23:55:04 UTC (rev 4161)
@@ -19,4 +19,11 @@
<parameter name="{gtn}handler" value="download"/>
</route>
+ <route path="/a">
+ <parameter name="a" value="a_value"/>
+ <route path="/b">
+ <parameter name="b" value="b_value"/>
+ </route>
+ </route>
+
</router>
\ No newline at end of file
14 years, 3 months
gatein SVN: r4160 - in portal/branches/navcontroller/component/web/controller/src: main/java/org/exoplatform/web/controller/router and 1 other directories.
by do-not-reply@jboss.org
Author: julien_viet
Date: 2010-09-12 19:07:32 -0400 (Sun, 12 Sep 2010)
New Revision: 4160
Added:
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestHierarchy.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/metadata/RouterDescriptor.java
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/Router.java
Log:
- rename SimpleRoute to SegmentRoute
- add nested route descriptor
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-12 22:55:24 UTC (rev 4159)
+++ portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouteDescriptor.java 2010-09-12 23:07:32 UTC (rev 4160)
@@ -21,7 +21,9 @@
import org.exoplatform.web.controller.QualifiedName;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
/**
@@ -37,10 +39,14 @@
/** . */
private final Map<QualifiedName, String> parameters;
+ /** . */
+ private final List<RouteDescriptor> children;
+
public RouteDescriptor(String path)
{
this.path = path;
this.parameters = new HashMap<QualifiedName, String>();
+ this.children = new ArrayList<RouteDescriptor>();
}
public String getPath()
@@ -63,4 +69,15 @@
{
return parameters;
}
+
+ public RouteDescriptor addChild(RouteDescriptor child)
+ {
+ children.add(child);
+ return this;
+ }
+
+ public List<RouteDescriptor> getChildren()
+ {
+ return children;
+ }
}
Modified: portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouterDescriptor.java
===================================================================
--- portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouterDescriptor.java 2010-09-12 22:55:24 UTC (rev 4159)
+++ portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouterDescriptor.java 2010-09-12 23:07:32 UTC (rev 4160)
@@ -37,7 +37,7 @@
this.routes = new ArrayList<RouteDescriptor>();
}
- public void addRoute(RouteDescriptor controller)
+ public RouterDescriptor addRoute(RouteDescriptor controller)
{
if (controller == null)
{
@@ -46,6 +46,9 @@
//
routes.add(controller);
+
+ //
+ return this;
}
public Iterable<RouteDescriptor> getRoutes()
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-12 22:55:24 UTC (rev 4159)
+++ portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Route.java 2010-09-12 23:07:32 UTC (rev 4160)
@@ -20,6 +20,7 @@
package org.exoplatform.web.controller.router;
import org.exoplatform.web.controller.QualifiedName;
+import org.exoplatform.web.controller.metadata.RouteDescriptor;
import java.util.ArrayList;
import java.util.HashMap;
@@ -321,18 +322,8 @@
/** . */
private static final Pattern PARAMETER_REGEX = Pattern.compile("^(?:\\{([^\\}]*)\\})?(.*)$");
- final Route append(
- String path,
- Map<QualifiedName, String> parameters)
+ final <R extends Route> R add(R route)
{
- Route route = append(path);
- route.terminal = true;
- route.routeParameters.putAll(parameters);
- return route;
- }
-
- <R extends Route> R add(R route)
- {
if (route.parent != null)
{
throw new IllegalArgumentException();
@@ -366,33 +357,61 @@
}
}
- Set<String> getSegmentNames()
+ final Set<String> getSegmentNames()
{
return segments.keySet();
}
- int getSegmentSize(String segmentName)
+ final int getSegmentSize(String segmentName)
{
List<SegmentRoute> routes = segments.get(segmentName);
return routes != null ? routes.size() : 0;
}
- SegmentRoute getSegment(String segmentName, int index)
+ final SegmentRoute getSegment(String segmentName, int index)
{
List<SegmentRoute> routes = segments.get(segmentName);
return routes != null ? routes.get(index) : null;
}
- int getPatternSize()
+ final int getPatternSize()
{
return patterns.size();
}
- PatternRoute getPattern(int index)
+ final PatternRoute getPattern(int index)
{
return patterns.get(index);
}
+ final Route append(RouteDescriptor descriptor)
+ {
+ Route route = append(descriptor.getPath());
+
+ //
+ route.terminal = true;
+ route.routeParameters.putAll(descriptor.getParameters());
+
+ //
+ for (RouteDescriptor childDescriptor : descriptor.getChildren())
+ {
+ route.append(childDescriptor);
+ }
+
+ //
+ return route;
+ }
+
+ final Route append(
+ String path,
+ Map<QualifiedName, String> parameters)
+ {
+ Route route = append(path);
+ route.terminal = true;
+ route.routeParameters.putAll(parameters);
+ return route;
+ }
+
/**
* Append a path, creates the necessary routes and returns the last route added.
*
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-12 22:55:24 UTC (rev 4159)
+++ portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Router.java 2010-09-12 23:07:32 UTC (rev 4160)
@@ -50,7 +50,7 @@
public void addRoute(RouteDescriptor routeMetaData)
{
- root.append(routeMetaData.getPath(), routeMetaData.getParameters());
+ root.append(routeMetaData);
}
public String render(Map<QualifiedName, String> parameters)
Added: 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 (rev 0)
+++ portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestHierarchy.java 2010-09-12 23:07:32 UTC (rev 4160)
@@ -0,0 +1,56 @@
+/*
+ * 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 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 TestHierarchy extends AbstractTestController
+{
+
+ public void testFoo() throws Exception
+ {
+
+ RouteDescriptor descriptor = new RouteDescriptor("/a").
+ addParameter("foo", "bar").
+ addChild(new RouteDescriptor("/b").addParameter("juu", "daa"));
+
+ //
+ Router router = new Router(new RouterDescriptor().addRoute(descriptor));
+
+ //
+ assertEquals(Collections.singletonMap(new QualifiedName("foo"), "bar"), router.process("/a"));
+
+ //
+ Map<QualifiedName, String> expected = new HashMap<QualifiedName, String>();
+ expected.put(new QualifiedName("foo"), "bar");
+ expected.put(new QualifiedName("juu"), "daa");
+ assertEquals(expected, router.process("/a/b"));
+ }
+}
14 years, 3 months
gatein SVN: r4159 - in portal/branches/navcontroller/component/web/controller/src: test/java/org/exoplatform/web/controller/router and 1 other directory.
by do-not-reply@jboss.org
Author: julien_viet
Date: 2010-09-12 18:55:24 -0400 (Sun, 12 Sep 2010)
New Revision: 4159
Added:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/SegmentRoute.java
Removed:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/SimpleRoute.java
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/TestBuildRoute.java
Log:
rename SimpleRoute -> SegmentRoute
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-12 22:54:07 UTC (rev 4158)
+++ portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Route.java 2010-09-12 22:55:24 UTC (rev 4159)
@@ -46,10 +46,10 @@
boolean terminal;
/** . */
- private final Map<String, List<SimpleRoute>> simpleRoutes;
+ private final Map<String, List<SegmentRoute>> segments;
/** Actually here we allow to store several times the same pattern and routing could be optimized instead. */
- private final List<PatternRoute> patternRoutes;
+ private final List<PatternRoute> patterns;
/** . */
private final Map<QualifiedName, String> routeParameters;
@@ -58,8 +58,8 @@
{
this.parent = null;
this.terminal = false;
- this.simpleRoutes = new LinkedHashMap<String, List<SimpleRoute>>();
- this.patternRoutes = new ArrayList<PatternRoute>();
+ this.segments = new LinkedHashMap<String, List<SegmentRoute>>();
+ this.patterns = new ArrayList<PatternRoute>();
this.routeParameters = new HashMap<QualifiedName, String>();
}
@@ -76,7 +76,7 @@
}
else
{
- if (r instanceof PatternRoute || r instanceof SimpleRoute)
+ if (r instanceof PatternRoute || r instanceof SegmentRoute)
{
StringBuilder sb = new StringBuilder();
r.render(blah, sb);
@@ -97,9 +97,9 @@
}
//
- if (this instanceof SimpleRoute)
+ if (this instanceof SegmentRoute)
{
- SimpleRoute sr = (SimpleRoute)this;
+ SegmentRoute sr = (SegmentRoute)this;
sb.append('/').append(sr.name);
}
else if (this instanceof PatternRoute)
@@ -164,9 +164,9 @@
}
//
- for (List<SimpleRoute> routes : simpleRoutes.values())
+ for (List<SegmentRoute> routes : segments.values())
{
- for (SimpleRoute route : routes)
+ for (SegmentRoute route : routes)
{
Route a = route.find(abc);
if (a != null)
@@ -175,7 +175,7 @@
}
}
}
- for (PatternRoute route : patternRoutes)
+ for (PatternRoute route : patterns)
{
Route a = route.find(abc);
if (a != null)
@@ -226,7 +226,7 @@
String segment = path.substring(1, pos);
// Try to find a route for the segment
- List<SimpleRoute> routes = simpleRoutes.get(segment);
+ List<SegmentRoute> routes = segments.get(segment);
if (routes != null)
{
// Determine next path
@@ -241,7 +241,7 @@
}
//
- for (SimpleRoute route : routes)
+ for (SegmentRoute route : routes)
{
// Delegate the process to the next route
Map<QualifiedName, String> response = route.route(nextPath, parameters);
@@ -259,7 +259,7 @@
// Try to find a pattern matching route otherwise
if (ret == null)
{
- for (PatternRoute route : patternRoutes)
+ for (PatternRoute route : patterns)
{
Matcher matcher = route.pattern.matcher(path.substring(1));
@@ -339,14 +339,14 @@
}
//
- if (route instanceof SimpleRoute)
+ if (route instanceof SegmentRoute)
{
- SimpleRoute segment = (SimpleRoute)route;
- List<SimpleRoute> routes = simpleRoutes.get(segment.name);
+ SegmentRoute segment = (SegmentRoute)route;
+ List<SegmentRoute> routes = segments.get(segment.name);
if (routes == null)
{
- routes = new ArrayList<SimpleRoute>();
- simpleRoutes.put(segment.name, routes);
+ routes = new ArrayList<SegmentRoute>();
+ segments.put(segment.name, routes);
}
routes.add(segment);
((Route)segment).parent = this;
@@ -356,7 +356,7 @@
{
PatternRoute pattern = (PatternRoute)route;
- patternRoutes.add(pattern);
+ patterns.add(pattern);
route.parent = this;
return (R)pattern;
}
@@ -368,29 +368,29 @@
Set<String> getSegmentNames()
{
- return simpleRoutes.keySet();
+ return segments.keySet();
}
int getSegmentSize(String segmentName)
{
- List<SimpleRoute> routes = simpleRoutes.get(segmentName);
+ List<SegmentRoute> routes = segments.get(segmentName);
return routes != null ? routes.size() : 0;
}
- SimpleRoute getSegment(String segmentName, int index)
+ SegmentRoute getSegment(String segmentName, int index)
{
- List<SimpleRoute> routes = simpleRoutes.get(segmentName);
+ List<SegmentRoute> routes = segments.get(segmentName);
return routes != null ? routes.get(index) : null;
}
int getPatternSize()
{
- return patternRoutes.size();
+ return patterns.size();
}
PatternRoute getPattern(int index)
{
- return patternRoutes.get(index);
+ return patterns.get(index);
}
/**
@@ -443,7 +443,7 @@
else
{
String segment = path.substring(0, pos);
- SimpleRoute route = new SimpleRoute(segment);
+ SegmentRoute route = new SegmentRoute(segment);
add(route);
next = route;
}
Copied: portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/SegmentRoute.java (from rev 4158, portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/SimpleRoute.java)
===================================================================
--- portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/SegmentRoute.java (rev 0)
+++ portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/SegmentRoute.java 2010-09-12 22:55:24 UTC (rev 4159)
@@ -0,0 +1,36 @@
+/*
+ * 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$
+ */
+class SegmentRoute extends Route
+{
+
+ /** . */
+ final String name;
+
+ SegmentRoute(String name)
+ {
+ this.name = name;
+ }
+}
Deleted: portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/SimpleRoute.java
===================================================================
--- portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/SimpleRoute.java 2010-09-12 22:54:07 UTC (rev 4158)
+++ portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/SimpleRoute.java 2010-09-12 22:55:24 UTC (rev 4159)
@@ -1,36 +0,0 @@
-/*
- * 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$
- */
-class SimpleRoute extends Route
-{
-
- /** . */
- final String name;
-
- SimpleRoute(String name)
- {
- this.name = name;
- }
-}
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-12 22:54:07 UTC (rev 4158)
+++ portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestBuildRoute.java 2010-09-12 22:55:24 UTC (rev 4159)
@@ -55,7 +55,7 @@
routerMD.addRoute(new RouteDescriptor(path));
Router router = new Router(routerMD);
Route expectedRoute = new Route();
- expectedRoute.add(new SimpleRoute("a"));
+ expectedRoute.add(new SegmentRoute("a"));
assertEquals(expectedRoute, router.root);
}
}
@@ -153,9 +153,9 @@
assertEquals(expectedRoute.getSegmentSize(segmentName), route.getSegmentSize(segmentName));
for (int segmentIndex = 0;segmentIndex < expectedRoute.getSegmentSize(segmentName);segmentIndex++)
{
- SimpleRoute expectedSimpleRoute = expectedRoute.getSegment(segmentName, segmentIndex);
- SimpleRoute simpleRoute = route.getSegment(segmentName, segmentIndex);
- assertEquals(expectedSimpleRoute, simpleRoute);
+ SegmentRoute expectedSegmentRoute = expectedRoute.getSegment(segmentName, segmentIndex);
+ SegmentRoute segmentRoute = route.getSegment(segmentName, segmentIndex);
+ assertEquals(expectedSegmentRoute, segmentRoute);
}
}
assertEquals(expectedRoute.getPatternSize(), route.getPatternSize());
@@ -168,9 +168,9 @@
assertEquals(((PatternRoute)expectedRoute).pattern.toString(), ((PatternRoute)route).pattern.toString());
assertEquals(((PatternRoute)expectedRoute).parameterNames, ((PatternRoute)route).parameterNames);
}
- else if (route instanceof SimpleRoute)
+ else if (route instanceof SegmentRoute)
{
- assertEquals(((SimpleRoute)expectedRoute).name, ((SimpleRoute)route).name);
+ assertEquals(((SegmentRoute)expectedRoute).name, ((SegmentRoute)route).name);
}
}
}
14 years, 3 months
gatein SVN: r4158 - in portal/branches/navcontroller/component/web/controller/src: test/java/org/exoplatform/web/controller/router and 1 other directory.
by do-not-reply@jboss.org
Author: julien_viet
Date: 2010-09-12 18:54:07 -0400 (Sun, 12 Sep 2010)
New Revision: 4158
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/PatternRoute.java
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/SimpleRoute.java
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestBuildRoute.java
Log:
improve encapsulation of internal route structure
Modified: portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/PatternRoute.java
===================================================================
--- portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/PatternRoute.java 2010-09-12 21:53:26 UTC (rev 4157)
+++ portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/PatternRoute.java 2010-09-12 22:54:07 UTC (rev 4158)
@@ -44,15 +44,11 @@
final List<String> chunks;
PatternRoute(
- Route parent,
Pattern pattern,
List<QualifiedName> parameterNames,
List<Pattern> parameterPatterns,
List<String> chunks)
{
- super(parent);
-
- //
if (chunks.size() != parameterNames.size() + 1)
{
throw new AssertionError("Was expecting chunk size " + chunks.size() + " to be equals to " + parameterNames.size() + 1);
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-12 21:53:26 UTC (rev 4157)
+++ portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Route.java 2010-09-12 22:54:07 UTC (rev 4158)
@@ -26,6 +26,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -39,35 +40,20 @@
{
/** . */
- final Route parent;
+ private Route parent;
/** . */
boolean terminal;
/** . */
- final Map<String, List<SimpleRoute>> simpleRoutes;
+ private final Map<String, List<SimpleRoute>> simpleRoutes;
/** Actually here we allow to store several times the same pattern and routing could be optimized instead. */
- final List<PatternRoute> patternRoutes;
+ private final List<PatternRoute> patternRoutes;
/** . */
- final Map<QualifiedName, String> routeParameters;
+ private final Map<QualifiedName, String> routeParameters;
- protected Route(Route parent)
- {
- if (parent == null)
- {
- throw new NullPointerException("No null parent");
- }
-
- //
- this.parent = parent;
- this.terminal = false;
- this.simpleRoutes = new LinkedHashMap<String, List<SimpleRoute>>();
- this.patternRoutes = new ArrayList<PatternRoute>();
- this.routeParameters = new HashMap<QualifiedName, String>();
- }
-
Route()
{
this.parent = null;
@@ -114,7 +100,7 @@
if (this instanceof SimpleRoute)
{
SimpleRoute sr = (SimpleRoute)this;
- sb.append('/').append(sr.value);
+ sb.append('/').append(sr.name);
}
else if (this instanceof PatternRoute)
{
@@ -345,6 +331,68 @@
return route;
}
+ <R extends Route> R add(R route)
+ {
+ if (route.parent != null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ if (route instanceof SimpleRoute)
+ {
+ SimpleRoute segment = (SimpleRoute)route;
+ List<SimpleRoute> routes = simpleRoutes.get(segment.name);
+ if (routes == null)
+ {
+ routes = new ArrayList<SimpleRoute>();
+ simpleRoutes.put(segment.name, routes);
+ }
+ routes.add(segment);
+ ((Route)segment).parent = this;
+ return (R)segment;
+ }
+ else if (route instanceof PatternRoute)
+ {
+ PatternRoute pattern = (PatternRoute)route;
+
+ patternRoutes.add(pattern);
+ route.parent = this;
+ return (R)pattern;
+ }
+ else
+ {
+ throw new IllegalArgumentException();
+ }
+ }
+
+ Set<String> getSegmentNames()
+ {
+ return simpleRoutes.keySet();
+ }
+
+ int getSegmentSize(String segmentName)
+ {
+ List<SimpleRoute> routes = simpleRoutes.get(segmentName);
+ return routes != null ? routes.size() : 0;
+ }
+
+ SimpleRoute getSegment(String segmentName, int index)
+ {
+ List<SimpleRoute> routes = simpleRoutes.get(segmentName);
+ return routes != null ? routes.get(index) : null;
+ }
+
+ int getPatternSize()
+ {
+ return patternRoutes.size();
+ }
+
+ PatternRoute getPattern(int index)
+ {
+ return patternRoutes.get(index);
+ }
+
/**
* Append a path, creates the necessary routes and returns the last route added.
*
@@ -395,14 +443,8 @@
else
{
String segment = path.substring(0, pos);
- List<SimpleRoute> routes = simpleRoutes.get(segment);
- if (routes == null)
- {
- routes = new ArrayList<SimpleRoute>();
- simpleRoutes.put(segment, routes);
- }
- SimpleRoute route = new SimpleRoute(this, segment);
- routes.add(route);
+ SimpleRoute route = new SimpleRoute(segment);
+ add(route);
next = route;
}
}
@@ -463,8 +505,12 @@
// Julien : should the pattern end with a $ ?????? I don't see that for now
// we need to figure out clearly
Pattern pattern = builder.build();
- PatternRoute route = new PatternRoute(this, pattern, parameterNames, parameterPatterns, chunks);
- patternRoutes.add(route);
+ PatternRoute route = new PatternRoute(pattern, parameterNames, parameterPatterns, chunks);
+
+ // Wire
+ add(route);
+
+ //
next = route;
}
else
Modified: portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/SimpleRoute.java
===================================================================
--- portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/SimpleRoute.java 2010-09-12 21:53:26 UTC (rev 4157)
+++ portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/SimpleRoute.java 2010-09-12 22:54:07 UTC (rev 4158)
@@ -27,13 +27,10 @@
{
/** . */
- final String value;
+ final String name;
- SimpleRoute(Route parent, String value)
+ SimpleRoute(String name)
{
- super(parent);
-
- //
- this.value = value;
+ this.name = name;
}
}
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-12 21:53:26 UTC (rev 4157)
+++ portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestBuildRoute.java 2010-09-12 22:54:07 UTC (rev 4158)
@@ -24,10 +24,7 @@
import org.exoplatform.web.controller.metadata.RouteDescriptor;
import org.exoplatform.web.controller.metadata.RouterDescriptor;
-import java.util.Arrays;
import java.util.Collections;
-import java.util.List;
-import java.util.Map;
/**
* @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
@@ -58,8 +55,7 @@
routerMD.addRoute(new RouteDescriptor(path));
Router router = new Router(routerMD);
Route expectedRoute = new Route();
- SimpleRoute a = new SimpleRoute(expectedRoute, "a");
- expectedRoute.simpleRoutes.put("a", Arrays.asList(a));
+ expectedRoute.add(new SimpleRoute("a"));
assertEquals(expectedRoute, router.root);
}
}
@@ -74,9 +70,9 @@
Router router = new Router(routerMD);
//
- assertEquals(0, router.root.simpleRoutes.size());
- assertEquals(1, router.root.patternRoutes.size());
- PatternRoute patternRoute = router.root.patternRoutes.get(0);
+ assertEquals(0, router.root.getSegmentNames().size());
+ assertEquals(1, router.root.getPatternSize());
+ PatternRoute patternRoute = router.root.getPattern(0);
assertEquals("^([^/]+)", patternRoute.pattern.toString());
assertEquals(Collections.singletonList(new QualifiedName("a")), patternRoute.parameterNames);
assertEquals(1, patternRoute.parameterPatterns.size());
@@ -97,9 +93,9 @@
Router router = new Router(routerMD);
//
- assertEquals(0, router.root.simpleRoutes.size());
- assertEquals(1, router.root.patternRoutes.size());
- PatternRoute patternRoute = router.root.patternRoutes.get(0);
+ assertEquals(0, router.root.getSegmentNames().size());
+ assertEquals(1, router.root.getPatternSize());
+ PatternRoute patternRoute = router.root.getPattern(0);
assertEquals("^([^/]+)", patternRoute.pattern.toString());
assertEquals(Collections.singletonList(new QualifiedName("q", "a")), patternRoute.parameterNames);
assertEquals(1, patternRoute.parameterPatterns.size());
@@ -120,9 +116,9 @@
Router router = new Router(routerMD);
//
- assertEquals(0, router.root.simpleRoutes.size());
- assertEquals(1, router.root.patternRoutes.size());
- PatternRoute patternRoute = router.root.patternRoutes.get(0);
+ assertEquals(0, router.root.getSegmentNames().size());
+ assertEquals(1, router.root.getPatternSize());
+ PatternRoute patternRoute = router.root.getPattern(0);
assertEquals("^(.*)", patternRoute.pattern.toString());
assertEquals(Collections.singletonList(new QualifiedName("a")), patternRoute.parameterNames);
assertEquals(1, patternRoute.parameterPatterns.size());
@@ -141,25 +137,31 @@
//
Router router = new Router(routerMD);
- assertEquals(2, router.root.simpleRoutes.get("public").size());
- Route publicRoute1 = router.root.simpleRoutes.get("public").get(0);
- assertEquals(1, publicRoute1.simpleRoutes.get("foo").size());
- Route publicRoute2 = router.root.simpleRoutes.get("public").get(1);
- assertEquals(1, publicRoute2.simpleRoutes.get("bar").size());
+ assertEquals(2, router.root.getSegmentSize("public"));
+ Route publicRoute1 = router.root.getSegment("public", 0);
+ assertEquals(1, publicRoute1.getSegmentSize("foo"));
+ Route publicRoute2 = router.root.getSegment("public", 1);
+ assertEquals(1, publicRoute2.getSegmentSize("bar"));
}
private void assertEquals(Route expectedRoute, Route route)
{
assertEquals(expectedRoute.getClass(), route.getClass());
- assertEquals(expectedRoute.simpleRoutes.keySet(), route.simpleRoutes.keySet());
- for (Map.Entry<String, List<SimpleRoute>> entry : expectedRoute.simpleRoutes.entrySet())
+ assertEquals(expectedRoute.getSegmentNames(), route.getSegmentNames());
+ for (String segmentName : expectedRoute.getSegmentNames())
{
- assertEquals(entry.getValue(), expectedRoute.simpleRoutes.get(entry.getKey()));
+ assertEquals(expectedRoute.getSegmentSize(segmentName), route.getSegmentSize(segmentName));
+ for (int segmentIndex = 0;segmentIndex < expectedRoute.getSegmentSize(segmentName);segmentIndex++)
+ {
+ SimpleRoute expectedSimpleRoute = expectedRoute.getSegment(segmentName, segmentIndex);
+ SimpleRoute simpleRoute = route.getSegment(segmentName, segmentIndex);
+ assertEquals(expectedSimpleRoute, simpleRoute);
+ }
}
- assertEquals(expectedRoute.patternRoutes.size(), route.patternRoutes.size());
- for (int i = 0;i < expectedRoute.patternRoutes.size();i++)
+ assertEquals(expectedRoute.getPatternSize(), route.getPatternSize());
+ for (int i = 0;i < expectedRoute.getPatternSize();i++)
{
- assertEquals(expectedRoute.patternRoutes.get(i), route.patternRoutes.get(i));
+ assertEquals(expectedRoute.getPattern(i), route.getPattern(i));
}
if (route instanceof PatternRoute)
{
@@ -168,7 +170,7 @@
}
else if (route instanceof SimpleRoute)
{
- assertEquals(((SimpleRoute)expectedRoute).value, ((SimpleRoute)route).value);
+ assertEquals(((SimpleRoute)expectedRoute).name, ((SimpleRoute)route).name);
}
}
}
14 years, 3 months
gatein SVN: r4157 - portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router.
by do-not-reply@jboss.org
Author: julien_viet
Date: 2010-09-12 17:53:26 -0400 (Sun, 12 Sep 2010)
New Revision: 4157
Modified:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Route.java
Log:
note to sefl
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-12 21:51:02 UTC (rev 4156)
+++ portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Route.java 2010-09-12 21:53:26 UTC (rev 4157)
@@ -47,7 +47,7 @@
/** . */
final Map<String, List<SimpleRoute>> simpleRoutes;
- /** . */
+ /** Actually here we allow to store several times the same pattern and routing could be optimized instead. */
final List<PatternRoute> patternRoutes;
/** . */
14 years, 3 months
gatein SVN: r4156 - in portal/branches/navcontroller/component/web/controller/src: test/java/org/exoplatform/web/controller/router and 1 other directory.
by do-not-reply@jboss.org
Author: julien_viet
Date: 2010-09-12 17:51:02 -0400 (Sun, 12 Sep 2010)
New Revision: 4156
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/TestBuildRoute.java
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestMatch.java
Log:
allow two scope different parameter set for a segment route
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-12 13:57:47 UTC (rev 4155)
+++ portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Route.java 2010-09-12 21:51:02 UTC (rev 4156)
@@ -45,7 +45,7 @@
boolean terminal;
/** . */
- final Map<String, SimpleRoute> simpleRoutes;
+ final Map<String, List<SimpleRoute>> simpleRoutes;
/** . */
final List<PatternRoute> patternRoutes;
@@ -63,7 +63,7 @@
//
this.parent = parent;
this.terminal = false;
- this.simpleRoutes = new LinkedHashMap<String, SimpleRoute>();
+ this.simpleRoutes = new LinkedHashMap<String, List<SimpleRoute>>();
this.patternRoutes = new ArrayList<PatternRoute>();
this.routeParameters = new HashMap<QualifiedName, String>();
}
@@ -72,7 +72,7 @@
{
this.parent = null;
this.terminal = false;
- this.simpleRoutes = new LinkedHashMap<String, SimpleRoute>();
+ this.simpleRoutes = new LinkedHashMap<String, List<SimpleRoute>>();
this.patternRoutes = new ArrayList<PatternRoute>();
this.routeParameters = new HashMap<QualifiedName, String>();
}
@@ -178,12 +178,15 @@
}
//
- for (SimpleRoute route : simpleRoutes.values())
+ for (List<SimpleRoute> routes : simpleRoutes.values())
{
- Route a = route.find(abc);
- if (a != null)
+ for (SimpleRoute route : routes)
{
- return a;
+ Route a = route.find(abc);
+ if (a != null)
+ {
+ return a;
+ }
}
}
for (PatternRoute route : patternRoutes)
@@ -237,8 +240,8 @@
String segment = path.substring(1, pos);
// Try to find a route for the segment
- Route route = simpleRoutes.get(segment);
- if (route != null)
+ List<SimpleRoute> routes = simpleRoutes.get(segment);
+ if (routes != null)
{
// Determine next path
String nextPath;
@@ -251,13 +254,18 @@
nextPath = path.substring(pos);
}
- // Delegate the process to the next route
- Map<QualifiedName, String> response = route.route(nextPath, parameters);
+ //
+ for (SimpleRoute route : routes)
+ {
+ // Delegate the process to the next route
+ Map<QualifiedName, String> response = route.route(nextPath, parameters);
- // If we do have a response we return it
- if (response != null)
- {
- ret = response;
+ // If we do have a response we return it
+ if (response != null)
+ {
+ ret = response;
+ break;
+ }
}
}
}
@@ -387,12 +395,14 @@
else
{
String segment = path.substring(0, pos);
- SimpleRoute route = simpleRoutes.get(segment);
- if (route == null)
+ List<SimpleRoute> routes = simpleRoutes.get(segment);
+ if (routes == null)
{
- route = new SimpleRoute(this, segment);
- simpleRoutes.put(route.value, route);
+ routes = new ArrayList<SimpleRoute>();
+ simpleRoutes.put(segment, routes);
}
+ SimpleRoute route = new SimpleRoute(this, segment);
+ routes.add(route);
next = route;
}
}
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-12 13:57:47 UTC (rev 4155)
+++ portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestBuildRoute.java 2010-09-12 21:51:02 UTC (rev 4156)
@@ -24,7 +24,9 @@
import org.exoplatform.web.controller.metadata.RouteDescriptor;
import org.exoplatform.web.controller.metadata.RouterDescriptor;
+import java.util.Arrays;
import java.util.Collections;
+import java.util.List;
import java.util.Map;
/**
@@ -57,7 +59,7 @@
Router router = new Router(routerMD);
Route expectedRoute = new Route();
SimpleRoute a = new SimpleRoute(expectedRoute, "a");
- expectedRoute.simpleRoutes.put("a", a);
+ expectedRoute.simpleRoutes.put("a", Arrays.asList(a));
assertEquals(expectedRoute, router.root);
}
}
@@ -139,16 +141,18 @@
//
Router router = new Router(routerMD);
- Route publicRoute = router.root.simpleRoutes.get("public");
- assertNotNull(publicRoute.simpleRoutes.get("foo"));
- assertNotNull(publicRoute.simpleRoutes.get("bar"));
+ assertEquals(2, router.root.simpleRoutes.get("public").size());
+ Route publicRoute1 = router.root.simpleRoutes.get("public").get(0);
+ assertEquals(1, publicRoute1.simpleRoutes.get("foo").size());
+ Route publicRoute2 = router.root.simpleRoutes.get("public").get(1);
+ assertEquals(1, publicRoute2.simpleRoutes.get("bar").size());
}
private void assertEquals(Route expectedRoute, Route route)
{
assertEquals(expectedRoute.getClass(), route.getClass());
assertEquals(expectedRoute.simpleRoutes.keySet(), route.simpleRoutes.keySet());
- for (Map.Entry<String, SimpleRoute> entry : expectedRoute.simpleRoutes.entrySet())
+ for (Map.Entry<String, List<SimpleRoute>> entry : expectedRoute.simpleRoutes.entrySet())
{
assertEquals(entry.getValue(), expectedRoute.simpleRoutes.get(entry.getKey()));
}
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-12 13:57:47 UTC (rev 4155)
+++ portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestMatch.java 2010-09-12 21:51:02 UTC (rev 4156)
@@ -24,6 +24,8 @@
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>
@@ -193,4 +195,31 @@
//
assertEquals(Collections.singletonMap(new QualifiedName("p"), "a"), router.process("/a/b"));
}
+
+ public void testTwoRules1() throws Exception
+ {
+ RouterDescriptor routerMD = new RouterDescriptor();
+ routerMD.addRoute(new RouteDescriptor("/a").addParameter("b", "b"));
+ routerMD.addRoute(new RouteDescriptor("/a/b"));
+ Router router = new Router(routerMD);
+
+ //
+ assertEquals(Collections.singletonMap(new QualifiedName("b"), "b"), router.process("/a"));
+ assertEquals(Collections.<QualifiedName, String>emptyMap(), router.process("/a/b"));
+ }
+
+ public void testTwoRules2() throws Exception
+ {
+ RouterDescriptor routerMD = new RouterDescriptor();
+ routerMD.addRoute(new RouteDescriptor("/{a}").addParameter("b", "b"));
+ routerMD.addRoute(new RouteDescriptor("/{a}/b"));
+ Router router = new Router(routerMD);
+
+ //
+ Map<QualifiedName, String> expectedParameters = new HashMap<QualifiedName, String>();
+ expectedParameters.put(new QualifiedName("a"), "a");
+ expectedParameters.put(new QualifiedName("b"), "b");
+ assertEquals(expectedParameters, router.process("/a"));
+ assertEquals(Collections.singletonMap(new QualifiedName("a"), "a"), router.process("/a/b"));
+ }
}
14 years, 3 months
gatein SVN: r4155 - portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata.
by do-not-reply@jboss.org
Author: julien_viet
Date: 2010-09-12 09:57:47 -0400 (Sun, 12 Sep 2010)
New Revision: 4155
Removed:
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/controller.xml
Log:
remove that old file
Deleted: portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/controller.xml
===================================================================
--- portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/controller.xml 2010-09-11 20:53:04 UTC (rev 4154)
+++ portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/controller.xml 2010-09-12 13:57:47 UTC (rev 4155)
@@ -1,35 +0,0 @@
-<router>
-
- <route match="/private/{gtn:sitename}">
- <parameter name="gtn:controller" value="site"/>
- <parameter name="gtn:sitetype" value="portal"/>
- </route>
-
- <route match="/groups/{gtn:sitename}">
- <parameter name="gtn:controller" value="site"/>
- <parameter name="gtn:sitetype" value="group"/>
- </route>
-
- <route match="/users/{gtn:sitename}">
- <parameter name="gtn:controller" value="site"/>
- <parameter name="gtn:sitetype" value="user"/>
- </route>
-
- <route match="/toto">
- <route match="/titi"/>
- </route>
-
- <route match="/" to="foo"/>
-
- <route match="/public" to="foo"/>
-
- <route match="/download">
- <parameter name="gtn:controller" value="download"/>
- </route>
-
- <route match="/upload">
- <parameter name="gtn:controller" value="upload"/>
- </route>
-
-</router>
-
14 years, 3 months
gatein SVN: r4154 - portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application.
by do-not-reply@jboss.org
Author: julien_viet
Date: 2010-09-11 16:53:04 -0400 (Sat, 11 Sep 2010)
New Revision: 4154
Modified:
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java
Log:
better generate the portal URI
Modified: portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java
===================================================================
--- portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java 2010-09-11 20:27:14 UTC (rev 4153)
+++ portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java 2010-09-11 20:53:04 UTC (rev 4154)
@@ -231,7 +231,7 @@
Map<QualifiedName, String> tmp = new HashMap<QualifiedName, String>();
tmp.put(WebAppController.HANDLER_PARAM, "portal");
tmp.put(PortalRequestHandler.REQUEST_SITE_NAME, requestSiteName);
- tmp.put(PortalRequestHandler.REQUEST_PATH, "");
+ tmp.put(PortalRequestHandler.REQUEST_PATH, "/");
portalURI = controllerContext.renderURL(tmp);
//
14 years, 3 months
gatein SVN: r4153 - in portal/branches/navcontroller: component/web/controller/src/main/java and 11 other directories.
by do-not-reply@jboss.org
Author: julien_viet
Date: 2010-09-11 16:27:14 -0400 (Sat, 11 Sep 2010)
New Revision: 4153
Added:
portal/branches/navcontroller/component/web/controller/src/main/java/gatein_router_1_0.xsd
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/DescriptorBuilder.java
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/RouterDescriptor.java
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestDescriptorBuilder.java
portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/router.xml
portal/branches/navcontroller/web/portal/src/main/webapp/WEB-INF/conf/router.xml
Removed:
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
Modified:
portal/branches/navcontroller/component/web/controller/pom.xml
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/WebRequestHandler.java
portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/QualifiedName.java
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/Router.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
portal/branches/navcontroller/component/web/server/src/main/java/org/exoplatform/web/handler/DownloadHandler.java
portal/branches/navcontroller/component/web/server/src/main/java/org/exoplatform/web/handler/UploadHandler.java
portal/branches/navcontroller/packaging/module/src/main/javascript/portal.packaging.module.js
portal/branches/navcontroller/web/portal/src/main/webapp/WEB-INF/web.xml
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/url/PortalURL.java
Log:
- integrated the router framework with the portal url framework
- restrited how the portal servlet is mapped by using the "/" default mapping
- now routes are declared in a router.xml configuration
Modified: portal/branches/navcontroller/component/web/controller/pom.xml
===================================================================
--- portal/branches/navcontroller/component/web/controller/pom.xml 2010-09-11 12:12:12 UTC (rev 4152)
+++ portal/branches/navcontroller/component/web/controller/pom.xml 2010-09-11 20:27:14 UTC (rev 4153)
@@ -40,5 +40,10 @@
<groupId>org.exoplatform.portal</groupId>
<artifactId>exo.portal.component.web.resources</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.codehaus.staxmate</groupId>
+ <artifactId>staxmate</artifactId>
+ <version>2.0.0</version>
+ </dependency>
</dependencies>
</project>
Added: portal/branches/navcontroller/component/web/controller/src/main/java/gatein_router_1_0.xsd
===================================================================
--- portal/branches/navcontroller/component/web/controller/src/main/java/gatein_router_1_0.xsd (rev 0)
+++ portal/branches/navcontroller/component/web/controller/src/main/java/gatein_router_1_0.xsd 2010-09-11 20:27:14 UTC (rev 4153)
@@ -0,0 +1,52 @@
+<?xml version="1.0"?>
+<!--
+
+ Copyright (C) 2009 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.
+
+-->
+
+<xs:schema
+ targetNamespace="http://www.gatein.org/xml/ns/gatein_router_1_0"
+ xmlns="http://www.gatein.org/xml/ns/gatein_router_1_0"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ elementFormDefault="qualified"
+ attributeFormDefault="unqualified"
+ version="1.0">
+
+ <xs:element name="router" type="routerType" />
+
+ <xs:complexType name="routerType">
+ <xs:sequence>
+ <xs:element name="route" type="routeType" minOccurs="0" maxOccurs="unbounded"/>
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:complexType name="routeType">
+ <xs:sequence>
+ <xs:element name="parameter" type="parameterType" minOccurs="0" maxOccurs="unbounded"/>
+ <xs:element name="route" type="routeType" minOccurs="0" maxOccurs="unbounded"/>
+ </xs:sequence>
+ <xs:attribute name="path" type="xs:string" use="required"/>
+ </xs:complexType>
+
+ <xs:complexType name="parameterType">
+ <xs:attribute name="name" type="xs:string" use="required"/>
+ <xs:attribute name="value" type="xs:string" use="required"/>
+ </xs:complexType>
+
+</xs:schema>
\ No newline at end of file
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-11 12:12:12 UTC (rev 4152)
+++ portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/WebAppController.java 2010-09-11 20:27:14 UTC (rev 4153)
@@ -22,14 +22,16 @@
import org.exoplatform.container.ExoContainer;
import org.exoplatform.container.ExoContainerContext;
import org.exoplatform.container.component.RequestLifeCycle;
+import org.exoplatform.container.configuration.ConfigurationManager;
import org.exoplatform.web.application.Application;
import org.exoplatform.web.controller.QualifiedName;
-import org.exoplatform.web.controller.metadata.RouteMetaData;
-import org.exoplatform.web.controller.metadata.RouterMetaData;
+import org.exoplatform.web.controller.metadata.DescriptorBuilder;
+import org.exoplatform.web.controller.metadata.RouterDescriptor;
import org.exoplatform.web.controller.router.Router;
import org.gatein.common.logging.Logger;
import org.gatein.common.logging.LoggerFactory;
+import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -37,6 +39,8 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
/**
* Created by The eXo Platform SAS
@@ -75,12 +79,21 @@
*
* @throws Exception
*/
- public WebAppController() throws Exception
+ public WebAppController(ConfigurationManager configurationManager) throws Exception
{
- applications_ = new HashMap<String, Application>();
- attributes_ = new HashMap<String, Object>();
+ // Read configuration (a bit hardcoded for now)
+ URL routerURL = configurationManager.getResource("war:/conf/router.xml");
+ XMLStreamReader routerReader = XMLInputFactory.newInstance().createXMLStreamReader(routerURL.openStream());
+ RouterDescriptor routerDesc = new DescriptorBuilder().build(routerReader);
+
+ // Build router from configuration
+ Router router = new Router(routerDesc);
+
+ //
+ this.applications_ = new HashMap<String, Application>();
+ this.attributes_ = new HashMap<String, Object>();
this.handlers = new HashMap<String, WebRequestHandler>();
- this.router = new Router(new RouterMetaData());
+ this.router = router;
}
public Object getAttribute(String name, Object value)
@@ -117,22 +130,7 @@
public void register(WebRequestHandler handler) throws Exception
{
- for (String path : handler.getPath())
- {
- RouteMetaData routeMetaData = new RouteMetaData(path);
-
- //
- String handlerKey = handler.getClass().getSimpleName();
-
- //
- routeMetaData.addParameter(HANDLER_PARAM, handlerKey);
-
- //
- handlers.put(handlerKey, handler);
-
- //
- router.addRoute(routeMetaData);
- }
+ handlers.put(handler.getHandlerName(), handler);
}
/**
Modified: portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/WebRequestHandler.java
===================================================================
--- portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/WebRequestHandler.java 2010-09-11 12:12:12 UTC (rev 4152)
+++ portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/WebRequestHandler.java 2010-09-11 20:27:14 UTC (rev 4153)
@@ -40,7 +40,7 @@
}
- abstract public String[] getPath();
+ public abstract String getHandlerName();
abstract public void execute(ControllerContext context) throws Exception;
Modified: portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/QualifiedName.java
===================================================================
--- portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/QualifiedName.java 2010-09-11 12:12:12 UTC (rev 4152)
+++ portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/QualifiedName.java 2010-09-11 20:27:14 UTC (rev 4153)
@@ -28,6 +28,22 @@
public class QualifiedName
{
+ public static QualifiedName parse(String qname)
+ {
+ if (qname.length() > 0)
+ {
+ if (qname.charAt(0) == '{')
+ {
+ int index = qname.indexOf('}', 1);
+ if (index != -1)
+ {
+ return new QualifiedName(qname.substring(1, index), qname.substring(index + 1));
+ }
+ }
+ }
+ return new QualifiedName(qname);
+ }
+
/** . */
private final String qualifier;
Added: portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/DescriptorBuilder.java
===================================================================
--- portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/DescriptorBuilder.java (rev 0)
+++ portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/DescriptorBuilder.java 2010-09-11 20:27:14 UTC (rev 4153)
@@ -0,0 +1,72 @@
+/*
+ * 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.metadata;
+
+import org.codehaus.staxmate.SMInputFactory;
+import org.codehaus.staxmate.in.SMHierarchicCursor;
+import org.codehaus.staxmate.in.SMInputCursor;
+import org.exoplatform.web.controller.QualifiedName;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamReader;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class DescriptorBuilder
+{
+
+ /** . */
+ private static final QName routeQN = new QName("http://www.gatein.org/xml/ns/gatein_router_1_0", "route");
+
+ /** . */
+ private static final QName parameterQN = new QName("http://www.gatein.org/xml/ns/gatein_router_1_0", "parameter");
+
+ public RouterDescriptor build(XMLStreamReader reader) throws Exception
+ {
+ RouterDescriptor routerDesc = new RouterDescriptor();
+ SMHierarchicCursor routerC = SMInputFactory.rootElementCursor(reader);
+ routerC.getNext();
+
+ //
+ SMInputCursor routeC = routerC.childElementCursor(routeQN);
+ while (routeC.getNext() != null)
+ {
+ String path = routeC.getAttrValue("path");
+ RouteDescriptor routeDesc = new RouteDescriptor(path);
+
+ //
+ SMInputCursor parameterC = routeC.childElementCursor(parameterQN);
+ while (parameterC.getNext() != null)
+ {
+ String name = parameterC.getAttrValue("name");
+ String value = parameterC.getAttrValue("value");
+ routeDesc.addParameter(QualifiedName.parse(name), value);
+ }
+
+ //
+ routerDesc.addRoute(routeDesc);
+ }
+
+ //
+ return routerDesc;
+ }
+}
Copied: portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouteDescriptor.java (from rev 4147, 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/RouteDescriptor.java (rev 0)
+++ portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouteDescriptor.java 2010-09-11 20:27:14 UTC (rev 4153)
@@ -0,0 +1,66 @@
+/*
+ * 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.metadata;
+
+import org.exoplatform.web.controller.QualifiedName;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class RouteDescriptor
+{
+
+ /** . */
+ private final String path;
+
+ /** . */
+ private final Map<QualifiedName, String> parameters;
+
+ public RouteDescriptor(String path)
+ {
+ this.path = path;
+ this.parameters = new HashMap<QualifiedName, String>();
+ }
+
+ public String getPath()
+ {
+ return path;
+ }
+
+ public RouteDescriptor addParameter(QualifiedName name, String value)
+ {
+ parameters.put(name, value);
+ return this;
+ }
+
+ public RouteDescriptor addParameter(String name, String value)
+ {
+ return addParameter(new QualifiedName(name), value);
+ }
+
+ public Map<QualifiedName, String> getParameters()
+ {
+ return parameters;
+ }
+}
Deleted: 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-11 12:12:12 UTC (rev 4152)
+++ portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouteMetaData.java 2010-09-11 20:27:14 UTC (rev 4153)
@@ -1,66 +0,0 @@
-/*
- * 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.metadata;
-
-import org.exoplatform.web.controller.QualifiedName;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
- * @version $Revision$
- */
-public class RouteMetaData
-{
-
- /** . */
- private final String path;
-
- /** . */
- private final Map<QualifiedName, String> parameters;
-
- 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);
- return this;
- }
-
- public RouteMetaData addParameter(String name, String value)
- {
- return addParameter(new QualifiedName(name), value);
- }
-
- public Map<QualifiedName, String> getParameters()
- {
- return parameters;
- }
-}
Copied: portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouterDescriptor.java (from rev 4147, 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/RouterDescriptor.java (rev 0)
+++ portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouterDescriptor.java 2010-09-11 20:27:14 UTC (rev 4153)
@@ -0,0 +1,55 @@
+/*
+ * 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.metadata;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class RouterDescriptor
+{
+
+ /** . */
+ private final List<RouteDescriptor> routes;
+
+ public RouterDescriptor()
+ {
+ this.routes = new ArrayList<RouteDescriptor>();
+ }
+
+ public void addRoute(RouteDescriptor controller)
+ {
+ if (controller == null)
+ {
+ throw new NullPointerException();
+ }
+
+ //
+ routes.add(controller);
+ }
+
+ public Iterable<RouteDescriptor> getRoutes()
+ {
+ return routes;
+ }
+}
Deleted: 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-11 12:12:12 UTC (rev 4152)
+++ portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouterMetaData.java 2010-09-11 20:27:14 UTC (rev 4153)
@@ -1,55 +0,0 @@
-/*
- * 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.metadata;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
- * @version $Revision$
- */
-public class RouterMetaData
-{
-
- /** . */
- private final Map<String, RouteMetaData> routes;
-
- public RouterMetaData()
- {
- this.routes = new HashMap<String, RouteMetaData>();
- }
-
- public void addRoute(RouteMetaData controller)
- {
- if (controller == null)
- {
- throw new NullPointerException();
- }
-
- //
- routes.put(controller.getPath(), controller);
- }
-
- public Iterable<RouteMetaData> getRoutes()
- {
- return routes.values();
- }
-}
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-11 12:12:12 UTC (rev 4152)
+++ portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Route.java 2010-09-11 20:27:14 UTC (rev 4153)
@@ -386,8 +386,13 @@
}
else
{
- SimpleRoute route = new SimpleRoute(this, path.substring(0, pos));
- simpleRoutes.put(route.value, route);
+ String segment = path.substring(0, pos);
+ SimpleRoute route = simpleRoutes.get(segment);
+ if (route == null)
+ {
+ route = new SimpleRoute(this, segment);
+ simpleRoutes.put(route.value, route);
+ }
next = route;
}
}
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-11 12:12:12 UTC (rev 4152)
+++ portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Router.java 2010-09-11 20:27:14 UTC (rev 4153)
@@ -20,8 +20,8 @@
package org.exoplatform.web.controller.router;
import org.exoplatform.web.controller.QualifiedName;
-import org.exoplatform.web.controller.metadata.RouteMetaData;
-import org.exoplatform.web.controller.metadata.RouterMetaData;
+import org.exoplatform.web.controller.metadata.RouteDescriptor;
+import org.exoplatform.web.controller.metadata.RouterDescriptor;
import java.io.IOException;
import java.util.HashMap;
@@ -37,18 +37,18 @@
/** . */
final Route root;
- public Router(RouterMetaData metaData)
+ public Router(RouterDescriptor metaData)
{
this.root = new Route();
//
- for (RouteMetaData routeMetaData : metaData.getRoutes())
+ for (RouteDescriptor routeMetaData : metaData.getRoutes())
{
addRoute(routeMetaData);
}
}
- public void addRoute(RouteMetaData routeMetaData)
+ public void addRoute(RouteDescriptor routeMetaData)
{
root.append(routeMetaData.getPath(), routeMetaData.getParameters());
}
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-11 12:12:12 UTC (rev 4152)
+++ portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestBuildRoute.java 2010-09-11 20:27:14 UTC (rev 4153)
@@ -21,8 +21,8 @@
import junit.framework.TestCase;
import org.exoplatform.web.controller.QualifiedName;
-import org.exoplatform.web.controller.metadata.RouteMetaData;
-import org.exoplatform.web.controller.metadata.RouterMetaData;
+import org.exoplatform.web.controller.metadata.RouteDescriptor;
+import org.exoplatform.web.controller.metadata.RouterDescriptor;
import java.util.Collections;
import java.util.Map;
@@ -39,8 +39,8 @@
String[] paths = {"/",""};
for (String path : paths)
{
- RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute(new RouteMetaData(path));
+ RouterDescriptor routerMD = new RouterDescriptor();
+ routerMD.addRoute(new RouteDescriptor(path));
Router router = new Router(routerMD);
Route expectedRoute = new Route();
assertEquals(expectedRoute, router.root);
@@ -52,8 +52,8 @@
String[] paths = {"/a","a"};
for (String path : paths)
{
- RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute(new RouteMetaData(path));
+ RouterDescriptor routerMD = new RouterDescriptor();
+ routerMD.addRoute(new RouteDescriptor(path));
Router router = new Router(routerMD);
Route expectedRoute = new Route();
SimpleRoute a = new SimpleRoute(expectedRoute, "a");
@@ -67,8 +67,8 @@
String[] paths = {"/{a}","{a}"};
for (String path : paths)
{
- RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute(new RouteMetaData(path));
+ RouterDescriptor routerMD = new RouterDescriptor();
+ routerMD.addRoute(new RouteDescriptor(path));
Router router = new Router(routerMD);
//
@@ -90,8 +90,8 @@
String[] paths = {"/{{q}a}","{{q}a}"};
for (String path : paths)
{
- RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute(new RouteMetaData(path));
+ RouterDescriptor routerMD = new RouterDescriptor();
+ routerMD.addRoute(new RouteDescriptor(path));
Router router = new Router(routerMD);
//
@@ -113,8 +113,8 @@
String[] paths = {"/{a:.*}","{a:.*}"};
for (String path : paths)
{
- RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute(new RouteMetaData(path));
+ RouterDescriptor routerMD = new RouterDescriptor();
+ routerMD.addRoute(new RouteDescriptor(path));
Router router = new Router(routerMD);
//
@@ -131,6 +131,19 @@
}
}
+ public void testSamePrefix()
+ {
+ RouterDescriptor routerMD = new RouterDescriptor();
+ routerMD.addRoute(new RouteDescriptor("/public/foo"));
+ routerMD.addRoute(new RouteDescriptor("/public/bar"));
+
+ //
+ Router router = new Router(routerMD);
+ Route publicRoute = router.root.simpleRoutes.get("public");
+ assertNotNull(publicRoute.simpleRoutes.get("foo"));
+ assertNotNull(publicRoute.simpleRoutes.get("bar"));
+ }
+
private void assertEquals(Route expectedRoute, Route route)
{
assertEquals(expectedRoute.getClass(), route.getClass());
Added: portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestDescriptorBuilder.java
===================================================================
--- portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestDescriptorBuilder.java (rev 0)
+++ portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestDescriptorBuilder.java 2010-09-11 20:27:14 UTC (rev 4153)
@@ -0,0 +1,74 @@
+/*
+ * 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.WebAppController;
+import org.exoplatform.web.controller.metadata.DescriptorBuilder;
+import org.exoplatform.web.controller.metadata.RouteDescriptor;
+import org.exoplatform.web.controller.metadata.RouterDescriptor;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+import java.net.URL;
+import java.util.Collections;
+import java.util.Iterator;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class TestDescriptorBuilder extends TestCase
+{
+
+ public void testFoo() throws Exception
+ {
+
+ URL routerURL = TestDescriptorBuilder.class.getResource("router.xml");
+ XMLStreamReader routerReader = XMLInputFactory.newInstance().createXMLStreamReader(routerURL.openStream());
+ RouterDescriptor routerDesc = new DescriptorBuilder().build(routerReader);
+
+ Iterator<RouteDescriptor> i = routerDesc.getRoutes().iterator();
+
+ //
+ assertTrue(i.hasNext());
+ RouteDescriptor route1 = i.next();
+ assertEquals("/public/{{gtn}sitename}{{gtn}path:.*}", route1.getPath());
+ assertEquals(Collections.singletonMap(WebAppController.HANDLER_PARAM, "portal"), route1.getParameters());
+
+ //
+ assertTrue(i.hasNext());
+ RouteDescriptor route2 = i.next();
+ assertEquals("/private/{{gtn}sitename}{{gtn}path:.*}", route2.getPath());
+ assertEquals(Collections.singletonMap(WebAppController.HANDLER_PARAM, "portal"), route2.getParameters());
+
+ //
+ assertTrue(i.hasNext());
+ RouteDescriptor route3 = i.next();
+ assertEquals("/upload", route3.getPath());
+ assertEquals(Collections.singletonMap(WebAppController.HANDLER_PARAM, "upload"), route3.getParameters());
+
+ //
+ assertTrue(i.hasNext());
+ RouteDescriptor route4 = i.next();
+ assertEquals("/download", route4.getPath());
+ assertEquals(Collections.singletonMap(WebAppController.HANDLER_PARAM, "download"), route4.getParameters());
+ }
+}
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-11 12:12:12 UTC (rev 4152)
+++ portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestMatch.java 2010-09-11 20:27:14 UTC (rev 4153)
@@ -20,8 +20,8 @@
package org.exoplatform.web.controller.router;
import org.exoplatform.web.controller.QualifiedName;
-import org.exoplatform.web.controller.metadata.RouteMetaData;
-import org.exoplatform.web.controller.metadata.RouterMetaData;
+import org.exoplatform.web.controller.metadata.RouteDescriptor;
+import org.exoplatform.web.controller.metadata.RouterDescriptor;
import java.util.Collections;
@@ -34,8 +34,8 @@
public void testRoot() throws Exception
{
- RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute(new RouteMetaData("/"));
+ RouterDescriptor routerMD = new RouterDescriptor();
+ routerMD.addRoute(new RouteDescriptor("/"));
Router router = new Router(routerMD);
//
@@ -53,8 +53,8 @@
public void testA() throws Exception
{
- RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute(new RouteMetaData("/a"));
+ RouterDescriptor routerMD = new RouterDescriptor();
+ routerMD.addRoute(new RouteDescriptor("/a"));
Router router = new Router(routerMD);
//
@@ -87,8 +87,8 @@
public void testAB() throws Exception
{
- RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute(new RouteMetaData("/a/b"));
+ RouterDescriptor routerMD = new RouterDescriptor();
+ routerMD.addRoute(new RouteDescriptor("/a/b"));
Router router = new Router( routerMD);
//
@@ -121,25 +121,25 @@
public void testParameter() throws Exception
{
- RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute(new RouteMetaData("/{p}"));
+ RouterDescriptor routerMD = new RouterDescriptor();
+ routerMD.addRoute(new RouteDescriptor("/{p}"));
Router router = new Router(routerMD);
assertEquals(Collections.singletonMap(new QualifiedName("p"), "a"), router.process(("/a")));
}
public void testParameterPropagationToDescendants() throws Exception
{
- RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute(new RouteMetaData("/").addParameter("p", "a"));
- routerMD.addRoute(new RouteMetaData("/a"));
+ RouterDescriptor routerMD = new RouterDescriptor();
+ routerMD.addRoute(new RouteDescriptor("/").addParameter("p", "a"));
+ routerMD.addRoute(new RouteDescriptor("/a"));
Router router = new Router(routerMD);
assertEquals(Collections.singletonMap(new QualifiedName("p"), "a"), router.process(("/a")));
}
public void testWildcardPattern() throws Exception
{
- RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute(new RouteMetaData("/{p:.*}"));
+ RouterDescriptor routerMD = new RouterDescriptor();
+ routerMD.addRoute(new RouteDescriptor("/{p:.*}"));
Router router = new Router(routerMD);
//
@@ -157,8 +157,8 @@
public void testSimplePattern() throws Exception
{
- RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute(new RouteMetaData("/{p:a}"));
+ RouterDescriptor routerMD = new RouterDescriptor();
+ routerMD.addRoute(new RouteDescriptor("/{p:a}"));
Router router = new Router(routerMD);
//
@@ -176,9 +176,9 @@
public void testPrecedence() throws Exception
{
- RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute(new RouteMetaData("/a"));
- routerMD.addRoute(new RouteMetaData("/{p:a}/b"));
+ RouterDescriptor routerMD = new RouterDescriptor();
+ routerMD.addRoute(new RouteDescriptor("/a"));
+ routerMD.addRoute(new RouteDescriptor("/{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-11 12:12:12 UTC (rev 4152)
+++ portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestPortalConfiguration.java 2010-09-11 20:27:14 UTC (rev 4153)
@@ -20,8 +20,8 @@
package org.exoplatform.web.controller.router;
import org.exoplatform.web.controller.QualifiedName;
-import org.exoplatform.web.controller.metadata.RouteMetaData;
-import org.exoplatform.web.controller.metadata.RouterMetaData;
+import org.exoplatform.web.controller.metadata.RouteDescriptor;
+import org.exoplatform.web.controller.metadata.RouterDescriptor;
import java.util.HashMap;
import java.util.Map;
@@ -39,22 +39,22 @@
@Override
protected void setUp() throws Exception
{
- RouterMetaData routerMD = new RouterMetaData();
+ RouterDescriptor routerMD = new RouterDescriptor();
//
- RouteMetaData portalRouteMD = new RouteMetaData("/private/{{gtn}sitename}{{gtn}path:.*}");
+ RouteDescriptor portalRouteMD = new RouteDescriptor("/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:.*}");
+ RouteDescriptor groupRouteMD = new RouteDescriptor("/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:.*}");
+ RouteDescriptor userRouteMD = new RouteDescriptor("/users/{{gtn}sitename}{{gtn}path:.*}");
portalRouteMD.addParameter(new QualifiedName("gtn", "controller"), "site");
userRouteMD.addParameter(new QualifiedName("gtn", "sitetype"), "user");
routerMD.addRoute(userRouteMD);
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-11 12:12:12 UTC (rev 4152)
+++ portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/TestRender.java 2010-09-11 20:27:14 UTC (rev 4153)
@@ -20,8 +20,8 @@
package org.exoplatform.web.controller.router;
import org.exoplatform.web.controller.QualifiedName;
-import org.exoplatform.web.controller.metadata.RouteMetaData;
-import org.exoplatform.web.controller.metadata.RouterMetaData;
+import org.exoplatform.web.controller.metadata.RouteDescriptor;
+import org.exoplatform.web.controller.metadata.RouterDescriptor;
import java.util.Collections;
@@ -34,8 +34,8 @@
public void testRoot() throws Exception
{
- RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute(new RouteMetaData("/"));
+ RouterDescriptor routerMD = new RouterDescriptor();
+ routerMD.addRoute(new RouteDescriptor("/"));
Router router = new Router(routerMD);
//
@@ -44,8 +44,8 @@
public void testA() throws Exception
{
- RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute(new RouteMetaData("/a"));
+ RouterDescriptor routerMD = new RouterDescriptor();
+ routerMD.addRoute(new RouteDescriptor("/a"));
Router router = new Router(routerMD);
//
@@ -54,8 +54,8 @@
public void testAB() throws Exception
{
- RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute(new RouteMetaData("/a/b"));
+ RouterDescriptor routerMD = new RouterDescriptor();
+ routerMD.addRoute(new RouteDescriptor("/a/b"));
Router router = new Router( routerMD);
//
@@ -64,8 +64,8 @@
public void testParameter() throws Exception
{
- RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute(new RouteMetaData("/{p}"));
+ RouterDescriptor routerMD = new RouterDescriptor();
+ routerMD.addRoute(new RouteDescriptor("/{p}"));
Router router = new Router(routerMD);
//
@@ -75,8 +75,8 @@
public void testWildcardPattern() throws Exception
{
- RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute(new RouteMetaData("/{p:.*}"));
+ RouterDescriptor routerMD = new RouterDescriptor();
+ routerMD.addRoute(new RouteDescriptor("/{p:.*}"));
Router router = new Router(routerMD);
//
@@ -91,8 +91,8 @@
public void testSimplePattern() throws Exception
{
- RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute(new RouteMetaData("/{p:a}"));
+ RouterDescriptor routerMD = new RouterDescriptor();
+ routerMD.addRoute(new RouteDescriptor("/{p:a}"));
Router router = new Router(routerMD);
//
@@ -104,9 +104,9 @@
public void testPrecedence() throws Exception
{
- RouterMetaData routerMD = new RouterMetaData();
- routerMD.addRoute(new RouteMetaData("/a"));
- routerMD.addRoute(new RouteMetaData("/{p:a}/b"));
+ RouterDescriptor routerMD = new RouterDescriptor();
+ routerMD.addRoute(new RouteDescriptor("/a"));
+ routerMD.addRoute(new RouteDescriptor("/{p:a}/b"));
Router router = new Router(routerMD);
//
Added: portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/router.xml
===================================================================
--- portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/router.xml (rev 0)
+++ portal/branches/navcontroller/component/web/controller/src/test/java/org/exoplatform/web/controller/router/router.xml 2010-09-11 20:27:14 UTC (rev 4153)
@@ -0,0 +1,22 @@
+<router
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ 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:.*}">
+ <parameter name="{gtn}handler" value="portal"/>
+ </route>
+
+ <route path="/private/{{gtn}sitename}{{gtn}path:.*}">
+ <parameter name="{gtn}handler" value="portal"/>
+ </route>
+
+ <route path="/upload">
+ <parameter name="{gtn}handler" value="upload"/>
+ </route>
+
+ <route path="/download">
+ <parameter name="{gtn}handler" value="download"/>
+ </route>
+
+</router>
\ No newline at end of file
Modified: portal/branches/navcontroller/component/web/server/src/main/java/org/exoplatform/web/handler/DownloadHandler.java
===================================================================
--- portal/branches/navcontroller/component/web/server/src/main/java/org/exoplatform/web/handler/DownloadHandler.java 2010-09-11 12:12:12 UTC (rev 4152)
+++ portal/branches/navcontroller/component/web/server/src/main/java/org/exoplatform/web/handler/DownloadHandler.java 2010-09-11 20:27:14 UTC (rev 4153)
@@ -26,12 +26,10 @@
import org.exoplatform.web.ControllerContext;
import org.exoplatform.web.WebAppController;
import org.exoplatform.web.WebRequestHandler;
-import org.exoplatform.web.controller.QualifiedName;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URLEncoder;
-import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -45,10 +43,9 @@
public class DownloadHandler extends WebRequestHandler
{
- @Override
- public String[] getPath()
+ public String getHandlerName()
{
- return new String[]{"/download"};
+ return "download";
}
@Override
Modified: portal/branches/navcontroller/component/web/server/src/main/java/org/exoplatform/web/handler/UploadHandler.java
===================================================================
--- portal/branches/navcontroller/component/web/server/src/main/java/org/exoplatform/web/handler/UploadHandler.java 2010-09-11 12:12:12 UTC (rev 4152)
+++ portal/branches/navcontroller/component/web/server/src/main/java/org/exoplatform/web/handler/UploadHandler.java 2010-09-11 20:27:14 UTC (rev 4153)
@@ -27,11 +27,9 @@
import org.exoplatform.web.ControllerContext;
import org.exoplatform.web.WebAppController;
import org.exoplatform.web.WebRequestHandler;
-import org.exoplatform.web.controller.QualifiedName;
import java.io.Writer;
import java.net.URLEncoder;
-import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -49,10 +47,9 @@
PROGRESS, UPLOAD, DELETE, ABORT
}
- @Override
- public String[] getPath()
+ public String getHandlerName()
{
- return new String[]{"/upload"};
+ return "upload";
}
@Override
Modified: portal/branches/navcontroller/packaging/module/src/main/javascript/portal.packaging.module.js
===================================================================
--- portal/branches/navcontroller/packaging/module/src/main/javascript/portal.packaging.module.js 2010-09-11 12:12:12 UTC (rev 4152)
+++ portal/branches/navcontroller/packaging/module/src/main/javascript/portal.packaging.module.js 2010-09-11 20:27:14 UTC (rev 4153)
@@ -100,6 +100,8 @@
module.component.web = {}
module.component.web.controller =
new Project("org.exoplatform.portal", "exo.portal.component.web.controller", "jar", module.version).
+ addDependency(new Project("org.codehaus.staxmate", "staxmate", "jar", "2.0.0")).
+ addDependency(new Project("org.codehaus.woodstox", "stax2-api", "jar", "3.0.2")).
addDependency(module.component.common);
module.component.web.security =
Added: 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 (rev 0)
+++ portal/branches/navcontroller/web/portal/src/main/webapp/WEB-INF/conf/router.xml 2010-09-11 20:27:14 UTC (rev 4153)
@@ -0,0 +1,29 @@
+<router
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ 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:.*}">
+ <parameter name="{gtn}handler" value="portal"/>
+ </route>
+
+ <route path="/private/{{gtn}sitename}{{gtn}path:.*}">
+ <parameter name="{gtn}handler" value="portal"/>
+ </route>
+
+ <route path="/upload">
+ <parameter name="{gtn}handler" value="upload"/>
+ </route>
+
+ <route path="/download">
+ <parameter name="{gtn}handler" value="download"/>
+ </route>
+
+ <!-- Map the sitemap navigation on the /foo path -->
+ <route path="/foo">
+ <parameter name="{gtn}sitename" value="classic"/>
+ <parameter name="{gtn}path" value="/sitemap"/>
+ <parameter name="{gtn}handler" value="portal"/>
+ </route>
+
+</router>
\ No newline at end of file
Modified: portal/branches/navcontroller/web/portal/src/main/webapp/WEB-INF/web.xml
===================================================================
--- portal/branches/navcontroller/web/portal/src/main/webapp/WEB-INF/web.xml 2010-09-11 12:12:12 UTC (rev 4152)
+++ portal/branches/navcontroller/web/portal/src/main/webapp/WEB-INF/web.xml 2010-09-11 20:27:14 UTC (rev 4153)
@@ -97,7 +97,7 @@
<filter-mapping>
<filter-name>RememberMeFilter</filter-name>
- <url-pattern>/public/*</url-pattern>
+ <servlet-name>portal</servlet-name>
</filter-mapping>
<filter-mapping>
@@ -261,30 +261,7 @@
<servlet-name>javascript</servlet-name>
<url-pattern>/javascript/*</url-pattern>
</servlet-mapping>
- <servlet-mapping>
- <servlet-name>portal</servlet-name>
- <url-pattern>/private/*</url-pattern>
- </servlet-mapping>
- <servlet-mapping>
- <servlet-name>portal</servlet-name>
- <url-pattern>/public/*</url-pattern>
- </servlet-mapping>
- <servlet-mapping>
- <servlet-name>portal</servlet-name>
- <url-pattern>/admin/*</url-pattern>
- </servlet-mapping>
- <servlet-mapping>
- <servlet-name>portal</servlet-name>
- <url-pattern>/service</url-pattern>
- </servlet-mapping>
- <servlet-mapping>
- <servlet-name>portal</servlet-name>
- <url-pattern>/upload/*</url-pattern>
- </servlet-mapping>
- <servlet-mapping>
- <servlet-name>portal</servlet-name>
- <url-pattern>/download/*</url-pattern>
- </servlet-mapping>
+
<servlet-mapping>
<servlet-name>RestServer</servlet-name>
<url-pattern>/rest/*</url-pattern>
@@ -296,6 +273,11 @@
</servlet-mapping>
<servlet-mapping>
+ <servlet-name>portal</servlet-name>
+ <url-pattern>/</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
<servlet-name>GateInServlet</servlet-name>
<url-pattern>/gateinservlet</url-pattern>
</servlet-mapping>
Modified: portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java
===================================================================
--- portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java 2010-09-11 12:12:12 UTC (rev 4152)
+++ portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java 2010-09-11 20:27:14 UTC (rev 4153)
@@ -36,8 +36,10 @@
import org.exoplatform.services.log.Log;
import org.exoplatform.services.resources.Orientation;
import org.exoplatform.web.ControllerContext;
+import org.exoplatform.web.WebAppController;
import org.exoplatform.web.application.JavascriptManager;
import org.exoplatform.web.application.URLBuilder;
+import org.exoplatform.web.controller.QualifiedName;
import org.exoplatform.web.url.LocatorProvider;
import org.exoplatform.web.url.ResourceLocator;
import org.exoplatform.web.url.ResourceType;
@@ -225,8 +227,14 @@
portalOwner_ = requestSiteName;
nodePath_ = requestPath;
- portalURI = requestURI_.substring(0, requestURI_.lastIndexOf(nodePath_)) + "/";
+// portalURI = requestURI_.substring(0, requestURI_.lastIndexOf(nodePath_)) + "/";
+ Map<QualifiedName, String> tmp = new HashMap<QualifiedName, String>();
+ tmp.put(WebAppController.HANDLER_PARAM, "portal");
+ tmp.put(PortalRequestHandler.REQUEST_SITE_NAME, requestSiteName);
+ tmp.put(PortalRequestHandler.REQUEST_PATH, "");
+ portalURI = controllerContext.renderURL(tmp);
+ //
if (requestURI_.indexOf("/public/") >= 0)
{
accessPath = PUBLIC_ACCESS;
Modified: portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java
===================================================================
--- portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java 2010-09-11 12:12:12 UTC (rev 4152)
+++ portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java 2010-09-11 20:27:14 UTC (rev 4153)
@@ -57,12 +57,9 @@
/** . */
public static final QualifiedName REQUEST_SITE_NAME = new QualifiedName("gtn", "sitename");
- /** . */
- private String[] PATHS = {"/public/{{gtn}sitename}{{gtn}path:.*}", "/private/{{gtn}sitename}{{gtn}path:.*}"};
-
- public String[] getPath()
+ public String getHandlerName()
{
- return PATHS;
+ return "portal";
}
/**
Modified: portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/url/PortalURL.java
===================================================================
--- portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/url/PortalURL.java 2010-09-11 12:12:12 UTC (rev 4152)
+++ portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/url/PortalURL.java 2010-09-11 20:27:14 UTC (rev 4153)
@@ -89,7 +89,7 @@
Map<QualifiedName, String> parameters = new HashMap<QualifiedName, String>();
parameters.put(PortalRequestHandler.REQUEST_PATH, builder.toString());
parameters.put(PortalRequestHandler.REQUEST_SITE_NAME, "classic");
- parameters.put(WebAppController.HANDLER_PARAM, PortalRequestHandler.class.getSimpleName());
+ parameters.put(WebAppController.HANDLER_PARAM, "portal");
//
ControllerContext controllerContext = requestContext.getControllerContext();
14 years, 3 months
gatein SVN: r4152 - in portal/branches/branch-r4047: component/scripting/src/main/java/org/exoplatform/groovyscript/text and 2 other directories.
by do-not-reply@jboss.org
Author: phuong_vu
Date: 2010-09-11 08:12:12 -0400 (Sat, 11 Sep 2010)
New Revision: 4152
Modified:
portal/branches/branch-r4047/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyPrinter.java
portal/branches/branch-r4047/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyScript.java
portal/branches/branch-r4047/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyTemplate.java
portal/branches/branch-r4047/component/scripting/src/main/java/org/exoplatform/groovyscript/text/TemplateService.java
portal/branches/branch-r4047/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateRendering.java
portal/branches/branch-r4047/webui/framework/src/main/java/org/exoplatform/webui/core/lifecycle/Lifecycle.java
Log:
GTNPORTAL-1377 Locale encoding in Groovy templates
Modified: portal/branches/branch-r4047/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyPrinter.java
===================================================================
--- portal/branches/branch-r4047/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyPrinter.java 2010-09-11 08:17:14 UTC (rev 4151)
+++ portal/branches/branch-r4047/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyPrinter.java 2010-09-11 12:12:12 UTC (rev 4152)
@@ -18,12 +18,16 @@
*/
package org.exoplatform.groovyscript;
+import groovy.lang.GString;
import groovy.lang.GroovyInterceptable;
import groovy.lang.GroovyObjectSupport;
import org.exoplatform.commons.utils.Text;
import java.io.IOException;
import java.io.Writer;
+import java.text.DateFormat;
+import java.util.Date;
+import java.util.Locale;
/**
* @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
@@ -32,6 +36,19 @@
abstract class GroovyPrinter extends GroovyObjectSupport implements GroovyInterceptable
{
+ /** An optional locale. */
+ private Locale locale;
+
+ public Locale getLocale()
+ {
+ return locale;
+ }
+
+ public void setLocale(Locale locale)
+ {
+ this.locale = locale;
+ }
+
/**
* Optimize the call to the various print methods.
*
@@ -82,21 +99,65 @@
}
}
+ /**
+ * We handle in this method a conversion of an object to another one for formatting purposes.
+ *
+ * @param o the object to format
+ * @return the formatted object
+ */
+ private Object format(Object o)
+ {
+ if (o instanceof Date)
+ {
+ if (locale != null)
+ {
+ DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.FULL, locale);
+ o = dateFormat.format((Date)o);
+ }
+ }
+
+ //
+ return o;
+ }
+
+ private String toString(Object o)
+ {
+ Object f = format(o);
+ if (f == null)
+ {
+ return "null";
+ }
+ else if (f instanceof String)
+ {
+ return (String)f;
+ }
+ else
+ {
+ return o.toString();
+ }
+ }
+
public final void print(Object o)
{
try
{
- if (o == null)
+ if (o instanceof Text)
{
- write("null");
+ write((Text)o);
}
- else if (o instanceof Text)
+ else if (o instanceof GString)
{
- write((Text)o);
+ GString gs = (GString)o;
+ Object[] values = gs.getValues();
+ for (int i = 0;i < values.length;i++)
+ {
+ values[i] = format(values[i]);
+ }
+ write(o.toString());
}
else
{
- write(o.toString());
+ write(toString(o));
}
}
catch (IOException ignore)
Modified: portal/branches/branch-r4047/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyScript.java
===================================================================
--- portal/branches/branch-r4047/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyScript.java 2010-09-11 08:17:14 UTC (rev 4151)
+++ portal/branches/branch-r4047/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyScript.java 2010-09-11 12:12:12 UTC (rev 4152)
@@ -24,6 +24,7 @@
import java.io.IOException;
import java.io.Writer;
+import java.util.Locale;
import java.util.Map;
/**
@@ -70,7 +71,19 @@
return scriptClass;
}
- public void render(Map context, Writer writer) throws IOException, TemplateRuntimeException
+ /**
+ * Renders the script with the provided context and locale to the specified writer.
+ *
+ * @param context the context
+ * @param writer the writer
+ * @param locale the locale
+ * @throws IOException
+ * @throws TemplateRuntimeException
+ */
+ public void render(
+ Map context,
+ Writer writer,
+ Locale locale) throws IOException, TemplateRuntimeException
{
Binding binding = context != null ? new Binding(context) : new Binding();
@@ -86,6 +99,9 @@
}
//
+ printer.setLocale(locale);
+
+ //
BaseScript script = (BaseScript)InvokerHelper.createScript(scriptClass, binding);
script.printer = printer;
Modified: portal/branches/branch-r4047/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyTemplate.java
===================================================================
--- portal/branches/branch-r4047/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyTemplate.java 2010-09-11 08:17:14 UTC (rev 4151)
+++ portal/branches/branch-r4047/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyTemplate.java 2010-09-11 12:12:12 UTC (rev 4152)
@@ -22,6 +22,7 @@
import java.io.Reader;
import java.io.StringWriter;
import java.io.Writer;
+import java.util.Locale;
import java.util.Map;
/**
@@ -104,12 +105,22 @@
public void render(Writer writer) throws IOException, TemplateRuntimeException
{
- render(writer, null);
+ render(writer, (Map)null);
}
+ public void render(Writer writer, Locale locale) throws IOException, TemplateRuntimeException
+ {
+ render(writer, null, locale);
+ }
+
+ public void render(Writer writer, Map binding, Locale locale) throws IOException, TemplateRuntimeException
+ {
+ script.render(binding, writer, locale);
+ }
+
public void render(Writer writer, Map binding) throws IOException, TemplateRuntimeException
{
- script.render(binding, writer);
+ script.render(binding, writer, null);
}
public String render() throws IOException, TemplateRuntimeException
@@ -117,10 +128,20 @@
return render((Map)null);
}
+ public String render(Locale locale) throws IOException, TemplateRuntimeException
+ {
+ return render((Map)null, locale);
+ }
+
public String render(Map binding) throws IOException, TemplateRuntimeException
{
+ return render(binding, null);
+ }
+
+ public String render(Map binding, Locale locale) throws IOException, TemplateRuntimeException
+ {
StringWriter buffer = new StringWriter();
- render(buffer, binding);
+ render(buffer, binding, locale);
buffer.close();
return buffer.toString();
}
Modified: portal/branches/branch-r4047/component/scripting/src/main/java/org/exoplatform/groovyscript/text/TemplateService.java
===================================================================
--- portal/branches/branch-r4047/component/scripting/src/main/java/org/exoplatform/groovyscript/text/TemplateService.java 2010-09-11 08:17:14 UTC (rev 4151)
+++ portal/branches/branch-r4047/component/scripting/src/main/java/org/exoplatform/groovyscript/text/TemplateService.java 2010-09-11 12:12:12 UTC (rev 4152)
@@ -44,6 +44,7 @@
import java.io.InputStream;
import java.util.ArrayList;
+import java.util.Locale;
/**
* Created by The eXo Platform SAS Dec 26, 2005
@@ -113,8 +114,7 @@
GroovyTemplate template = getTemplate(name, context.getResourceResolver());
context.put("_ctx", context);
context.setGroovyTemplateService(this);
- template.render(context.getWriter(), context);
-
+ template.render(context.getWriter(), context, (Locale)context.get("locale"));
long endTime = System.currentTimeMillis();
TemplateStatistic templateStatistic = statisticService.getTemplateStatistic(name);
@@ -137,7 +137,7 @@
throw new Exception("Binding cannot be null");
context.put("_ctx", context);
GroovyTemplate template = getTemplate(name, context.getResourceResolver());
- template.render(context.getWriter(), context);
+ template.render(context.getWriter(), context, (Locale)context.get("locale"));
}
final public GroovyTemplate getTemplate(String name, ResourceResolver resolver) throws Exception
Modified: portal/branches/branch-r4047/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateRendering.java
===================================================================
--- portal/branches/branch-r4047/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateRendering.java 2010-09-11 08:17:14 UTC (rev 4151)
+++ portal/branches/branch-r4047/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateRendering.java 2010-09-11 12:12:12 UTC (rev 4152)
@@ -26,6 +26,7 @@
import java.io.*;
import java.util.EmptyStackException;
import java.util.HashMap;
+import java.util.Locale;
import java.util.Map;
/**
@@ -45,6 +46,32 @@
assertEquals("abcde", baos.toString("UTF-8"));
}
+ public void testDate1() throws Exception
+ {
+ GroovyTemplate template = new GroovyTemplate("<% print(new Date(0)); %>");
+ assertEquals("jeudi 1 janvier 1970", template.render(Locale.FRENCH));
+ assertEquals("Thursday, January 1, 1970", template.render(Locale.ENGLISH));
+ assertEquals("Thu Jan 01 07:00:00 ICT 1970", template.render());
+ }
+
+ public void testDate2() throws Exception
+ {
+ GroovyTemplate template = new GroovyTemplate("<% def date = new Date(0) %>$date");
+ System.out.println("template.getGroovy() = " + template.getGroovy());
+ assertEquals("jeudi 1 janvier 1970", template.render(Locale.FRENCH));
+ assertEquals("Thursday, January 1, 1970", template.render(Locale.ENGLISH));
+ assertEquals("Thu Jan 01 07:00:00 ICT 1970", template.render());
+ }
+
+ public void testDate3() throws Exception
+ {
+ GroovyTemplate template = new GroovyTemplate("<%= new Date(0) %>");
+ System.out.println("template.getGroovy() = " + template.getGroovy());
+ assertEquals("jeudi 1 janvier 1970", template.render(Locale.FRENCH));
+ assertEquals("Thursday, January 1, 1970", template.render(Locale.ENGLISH));
+ assertEquals("Thu Jan 01 07:00:00 ICT 1970", template.render());
+ }
+
public void testFoo() throws Exception
{
GroovyTemplate template = new GroovyTemplate("a");
Modified: portal/branches/branch-r4047/webui/framework/src/main/java/org/exoplatform/webui/core/lifecycle/Lifecycle.java
===================================================================
--- portal/branches/branch-r4047/webui/framework/src/main/java/org/exoplatform/webui/core/lifecycle/Lifecycle.java 2010-09-11 08:17:14 UTC (rev 4151)
+++ portal/branches/branch-r4047/webui/framework/src/main/java/org/exoplatform/webui/core/lifecycle/Lifecycle.java 2010-09-11 12:12:12 UTC (rev 4152)
@@ -101,9 +101,10 @@
*
*/
protected void renderTemplate(String template, WebuiBindingContext bcontext) throws Exception
- {
+ {
+ WebuiRequestContext context = bcontext.getRequestContext();
bcontext.put("decorator", decorator_);
- WebuiRequestContext context = bcontext.getRequestContext();
+ bcontext.put("locale", context.getLocale());
ExoContainer pcontainer = context.getApplication().getApplicationServiceContainer();
TemplateService service = (TemplateService)pcontainer.getComponentInstanceOfType(TemplateService.class);
ResourceResolver resolver = bcontext.getResourceResolver();
14 years, 3 months