r9934 - apps/gobi/trunk/code/Redirect

[email protected] Sat, 19 Sep 2009 21:28:33 +0200 (CEST)
Newsgroups gmane.comp.java.helma.cvs
Message-ID <20090919192833.3603C3D0E3@mia>
Author: hannes
Date: 2009-09-19 21:28:32 +0200 (Sat, 19 Sep 2009)
New Revision: 9934

Modified:
   apps/gobi/trunk/code/Redirect/Redirect.js
Log:
Refinement

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

Modified: apps/gobi/trunk/code/Redirect/Redirect.js
===================================================================
--- apps/gobi/trunk/code/Redirect/Redirect.js	2009-09-19 12:28:17 UTC (rev 9933)
+++ apps/gobi/trunk/code/Redirect/Redirect.js	2009-09-19 19:28:32 UTC (rev 9934)
@@ -4,18 +4,34 @@
         res.data.body = this.renderSkinAsString("body");
         this.renderSkin("page");
     } else {
-        if (this.body.indexOf('://') == -1
-                || this.body.indexOf(app.props.baseUri) > -1) {
+        if (this.body.indexOf('://') == -1) {
+            // local redirect, set message
             res.message = "(Redirected from " + this.getHtmlLink() + ")";
         }
-        res.redirect(this.body);
+        res.redirect(this.getUrl());
     }
+
 }
 
 function url_macro() {
-    return "<a href='" + this.body + "'>" + this.body + "</a>";
+    return "<a href='" + this.getUrl() + "'>" + this.body + "</a>";
 }
 
+function getUrl() {
+    var url = this.body.trim();
+    if (url.indexOf('://') == -1) {
+        // local redirect url
+        if (url.indexOf("/") == 0) {
+            // local redirect with absolute path
+            url = root.href() + url.substring(1);
+        } else {
+            // local redirect with relative path
+            url = this.getParent().href() + url;
+        }
+    }
+    return url;
+}
+
 function redirectingHref(action) {
     return Page.prototype.href.apply(this, [action]);
 }