[gatein-commits] gatein SVN: r4163 - in portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller: router and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Sep 13 02:48:22 EDT 2010


Author: julien_viet
Date: 2010-09-13 02:48:21 -0400 (Mon, 13 Sep 2010)
New Revision: 4163

Modified:
   portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouteDescriptor.java
   portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Route.java
   portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Router.java
Log:
- start to add query param 
- improves the route parameter map collecting process


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-13 03:21:15 UTC (rev 4162)
+++ portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/metadata/RouteDescriptor.java	2010-09-13 06:48:21 UTC (rev 4163)
@@ -40,12 +40,16 @@
    private final Map<QualifiedName, String> parameters;
 
    /** . */
+   private final Map<QualifiedName, String> queryParams;
+
+   /** . */
    private final List<RouteDescriptor> children;
 
    public RouteDescriptor(String path)
    {
       this.path = path;
       this.parameters = new HashMap<QualifiedName, String>();
+      this.queryParams = new HashMap<QualifiedName, String>();
       this.children = new ArrayList<RouteDescriptor>();
    }
 
@@ -70,6 +74,23 @@
       return parameters;
    }
 
+   public RouteDescriptor addQueryParam(QualifiedName name, String value)
+   {
+      queryParams.put(name, value);
+      return this;
+   }
+
+   public RouteDescriptor addQueryParam(String name, String value)
+   {
+      return addQueryParam(new QualifiedName(name), value);
+   }
+
+   public Map<QualifiedName, String> getQueryParams()
+   {
+      return queryParams;
+   }
+
+
    public RouteDescriptor addChild(RouteDescriptor child)
    {
       children.add(child);

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-13 03:21:15 UTC (rev 4162)
+++ portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Route.java	2010-09-13 06:48:21 UTC (rev 4163)
@@ -55,6 +55,9 @@
    /** . */
    private final Map<QualifiedName, String> routeParameters;
 
+   /** . */
+   private final Map<QualifiedName, String> queryParams;
+
    Route()
    {
       this.parent = null;
@@ -62,6 +65,7 @@
       this.segments = new LinkedHashMap<String, List<SegmentRoute>>();
       this.patterns = new ArrayList<PatternRoute>();
       this.routeParameters = new HashMap<QualifiedName, String>();
+      this.queryParams = new HashMap<QualifiedName, String>();
    }
 
    /**
@@ -190,29 +194,22 @@
    }
 
    /**
-    * Note : the parameters arguments is modified, I don't like it much but as this is only used
-    * by the framework, there is no side effects, but I should investigate about doing this in a
-    * better way.
-    *
     * @param path the path
-    * @param parameters the parameters
     * @return null or the parameters when it matches
     */
-   final Map<QualifiedName, String> route(String path, Map<QualifiedName, String> parameters)
+   final Map<QualifiedName, String> route(String path)
    {
       Map<QualifiedName, String> ret = null;
 
       // Anything that does not begin with '/' returns null
       if (path.length() > 0 && path.charAt(0) == '/')
       {
-
-
          // The '/' means the current controller if any, otherwise it may be processed by the pattern matching
          if (path.length() == 1)
          {
             if (terminal)
             {
-               ret = parameters;
+               ret = new HashMap<QualifiedName, String>();
             }
          }
          else
@@ -245,7 +242,7 @@
                for (SegmentRoute route : routes)
                {
                   // Delegate the process to the next route
-                  Map<QualifiedName, String> response = route.route(nextPath, parameters);
+                  Map<QualifiedName, String> response = route.route(nextPath);
 
                   // If we do have a response we return it
                   if (response != null)
@@ -267,13 +264,6 @@
                // We match
                if (matcher.find())
                {
-                  // Update parameters
-                  int group = 1;
-                  for (QualifiedName parameterName : route.parameterNames)
-                  {
-                     parameters.put(parameterName, matcher.group(group++));
-                  }
-
                   // Build next controller context
                   int nextPos = matcher.end() + 1;
                   String nextPath;
@@ -287,11 +277,19 @@
                   }
 
                   // Delegate to next route
-                  Map<QualifiedName, String> response = route.route(nextPath, parameters);
+                  Map<QualifiedName, String> response = route.route(nextPath);
 
                   // If we do have a response we return it
                   if (response != null)
                   {
+                     // Append parameters
+                     int group = 1;
+                     for (QualifiedName parameterName : route.parameterNames)
+                     {
+                        response.put(parameterName, matcher.group(group++));
+                     }
+
+                     //
                      ret = response;
                      break;
                   }

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-13 03:21:15 UTC (rev 4162)
+++ portal/branches/navcontroller/component/web/controller/src/main/java/org/exoplatform/web/controller/router/Router.java	2010-09-13 06:48:21 UTC (rev 4163)
@@ -60,6 +60,6 @@
 
    public Map<QualifiedName, String> process(String path) throws IOException
    {
-      return root.route(path, new HashMap<QualifiedName, String>());
+      return root.route(path);
    }
 }



More information about the gatein-commits mailing list