r9757 - helma-ng/trunk/modules/helma

[email protected] Thu, 14 May 2009 17:27:28 +0200 (CEST)
Newsgroups gmane.comp.java.helma.cvs
Message-ID <20090514152728.A8DCB3D0D6@mia>
Author: hannes
Date: 2009-05-14 17:27:28 +0200 (Thu, 14 May 2009)
New Revision: 9757

Modified:
   helma-ng/trunk/modules/helma/webapp.js
Log:
Implement req.actionPath as the (canonical) part of the request path resolving to the current action.
This makes default actions explicit ("/" -> "/index") and is thus usable for composing paths containing extra arguments.

Details at http://dev.helma.org/trac/helma/changeset/9757

Modified: helma-ng/trunk/modules/helma/webapp.js
===================================================================
--- helma-ng/trunk/modules/helma/webapp.js	2009-05-14 13:45:22 UTC (rev 9756)
+++ helma-ng/trunk/modules/helma/webapp.js	2009-05-14 15:27:28 UTC (rev 9757)
@@ -42,6 +42,9 @@
         // strip leading slash
         path = path.slice(1);
     }
+    // used to compose req.actionPath, which is the part of the path
+    // that resolves to the action (req.path minus argument elements)
+    var actionPath = ["/"];
 
     function getPattern(spec) {
         var pattern = spec[0];
@@ -94,6 +97,10 @@
                     var action = getAction(module, pathArray[0]);
                     // log.debug("got action: " + action);
                     if (typeof action == "function" && pathArray.length <= action.length) {
+                        // set req.actionPath to the part of the path that resolves to the action
+                        actionPath.push(match[0], pathArray[0] || "index");
+                        req.actionPath =  actionPath.join("/").replace(/\/+/g, "/");
+                        print(req.actionPath);
                         // add remaining path elements as additional action arguments
                         var actionArgs = pathArray.slice(1);
                         var matchedArgs = match.slice(1);
@@ -111,7 +118,8 @@
                         return req.process();
                     } else if (module.urls instanceof Array) {
                         // nested app
-                        return resolveInConfig(module, path, match[0] + "/");
+                        actionPath.push(match[0]);
+                        return resolveInConfig(module, path, match[0]);
                     } else {
                         break;
                     }