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
Show replies by date