Author: simoneg
Date: Thu Jul 16 16:54:16 2009
New Revision: 794750

URL: http://svn.apache.org/viewvc?rev=794750&view=rev
Log:
LABS-373 : force absolute URLs when needed (like in RSS, some JSON etc..)

Modified:
    
labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/utils/URLRewritingStream.java

Modified: 
labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/utils/URLRewritingStream.java
URL: 
http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/utils/URLRewritingStream.java?rev=794750&r1=794749&r2=794750&view=diff
==============================================================================
--- 
labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/utils/URLRewritingStream.java
 (original)
+++ 
labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/utils/URLRewritingStream.java
 Thu Jul 16 16:54:16 2009
@@ -104,6 +104,11 @@
         * The local TODO ?? prefix for template resources, used when 
magma:template/ urls are found.
         */
        protected String templatePrefix;
+
+       /**
+        * If true, translate to absolute urls instead of server locals, which 
is the default. 
+        */
+       private boolean alwaysAbsolute = false;
        
        public URLRewritingStream(OutputStream out, String commonPrefix, String 
absolute) {
                super(out);
@@ -189,6 +194,9 @@
                        }
                        String accontent = new String(intbuff, chop ? 1 : 0, 
intbuffpos);
                        if (accontent.startsWith("magma:") || 
(!accontent.startsWith("/") && accontent.indexOf(':') == -1 && 
!accontent.startsWith("#"))) {
+                               if (this.alwaysAbsolute) {
+                                       send(this.absolute);
+                               }
                                if (accontent.startsWith("magma:")) {
                                        send(this.commonPrefix);
                                        stpos+=7;
@@ -332,7 +340,21 @@
                }
                this.setBaseUrl(pop);
        }
-       
+
+       /**
+        * Changes the keys and character this stream reacts to.
+        * 
+        * This is useful to adapt the URLRewritingStream to different formats, 
rewriting
+        * something different than HTML, without subclassing it.
+        * 
+        * NOTE : use this method only from inside Dispatch class or when using 
a stream
+        * externally, changing the state of the stream from a producer or 
while processing normal
+        * blocks will break the following parts of the page.
+        * 
+        * @param insider The insider character to use
+        * @param outsider The outsider characted to use
+        * @param key The new set of keys to trigger rewriting.
+        */
        public void changeKeys(char insider, char outsider, String... key) {
                this.insider = insider;
                this.outsider = outsider;
@@ -340,4 +362,20 @@
                this.keysMatch = new int[this.keys.length];
        }
 
+       
+       /**
+        * @return true if this URLRewritingStream always injects full absolute 
urls.
+        */
+       public boolean isAlwaysAbsolute() {
+               return alwaysAbsolute;
+       }
+
+       /**
+        * Forces this stream to produce always full absolute url.
+        * @param alwaysAbsolute if true, this stream will rewrite all urls as 
absolute urls, otherwise it will by default rewrite them to server relative.
+        */
+       public void setAlwaysAbsolute(boolean alwaysAbsolute) {
+               this.alwaysAbsolute = alwaysAbsolute;
+       }
+
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to