You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by si...@apache.org on 2009/06/08 18:03:13 UTC

svn commit: r782689 - in /labs/magma/trunk/foundation-website/src: main/java/org/apache/magma/website/utils/URLRewritingStream.java test/java/org/apache/magma/website/utils/URLRewritingStreamTest.java

Author: simoneg
Date: Mon Jun  8 16:03:13 2009
New Revision: 782689

URL: http://svn.apache.org/viewvc?rev=782689&view=rev
Log:
LABS-376 : extra "/" on lcoal urls when empty context caused dojo CSS to have "//dojo" invalid urls

Modified:
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/utils/URLRewritingStream.java
    labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/utils/URLRewritingStreamTest.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=782689&r1=782688&r2=782689&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 Mon Jun  8 16:03:13 2009
@@ -21,23 +21,66 @@
 import java.io.OutputStream;
 import java.util.Stack;
 
+/**
+ * Filter stream that finds and replaces URLs depending on the context of the writer.
+ * 
+ *
+ * @author Simone Gianni <si...@apache.org>
+ */
 public class URLRewritingStream extends FilterOutputStream {
 
 
+	/**
+	 * Keys used to identify an URL
+	 */
 	protected String[] keys = { "href=", "src=", "action=", "data=" };
-	protected char insider = '<', outsider = '>';
 	
+	/**
+	 * Chars that enables or disables parsing
+	 */
+	protected char insider = '<', outsider = '>';
 	
+	/**
+	 * True when we are inside a part that must be parsed
+	 */
 	protected boolean inside = false;
+	
+	/**
+	 * True if we are buffering content to produce correct urls
+	 */
 	protected boolean buffering = false;
+	/**
+	 * True if we are currently injecting a rewritten url
+	 */
+	private boolean injecting = false;
+	
 	protected int matched = -1;
 	protected int[] intbuff = new int[30];
 	protected int intbuffpos = 0;
+	
+	/**
+	 * The absolute part of the URL, like "http://hostname:port/" TODO ??
+	 */
 	protected String absolute;
+	
+	/**
+	 * The common prefix for server urls, usually the context and Magma servlet path, like "/ctx/magma/"; always ends with "/".
+	 */
 	protected String commonPrefix;
+	
+	/**
+	 * The current local base url, that is the url of the current context, like "forum/show"; never starts with "/".
+	 */
 	protected String baseurl;
+	
+	/**
+	 * A stack of base urls, so that it does not have to be recalculated when restoring contexts.
+	 */
 	protected Stack<String> baseurlStack = new Stack<String>();
-	private boolean injecting = false;
+	
+	/**
+	 * The local TODO ?? prefix for template resources, used when magma:template/ urls are found.
+	 */
 	protected String templatePrefix;
 	
 	public URLRewritingStream(OutputStream out, String commonPrefix, String absolute) {
@@ -142,6 +185,7 @@
 				accontent = accontent.substring(8);
 				return this.templatePrefix + accontent;
 			} else {
+				while (accontent.startsWith("/")) accontent = accontent.substring(1);
 				return accontent;
 			}
 		} else {

Modified: labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/utils/URLRewritingStreamTest.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/utils/URLRewritingStreamTest.java?rev=782689&r1=782688&r2=782689&view=diff
==============================================================================
--- labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/utils/URLRewritingStreamTest.java (original)
+++ labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/utils/URLRewritingStreamTest.java Mon Jun  8 16:03:13 2009
@@ -90,6 +90,27 @@
 		assertEquals("dothis/dothat/test", urs.localUrl("test"));
 		assertEquals("/ctx/dothis/dothat/test", urs.serverUrl("test"));
 		assertEquals("http://localhost/ctx/dothis/dothat/test", urs.absoluteUrl("test"));
+		
+		assertEquals("test", urs.localUrl("magma:/test"));
+		assertEquals("/ctx/test", urs.serverUrl("magma:/test"));
+		assertEquals("http://localhost/ctx/test", urs.absoluteUrl("magma:/test"));
+		
+	}
+	
+	@Test
+	public void rootContext() throws Exception {
+		ByteArrayOutputStream baos = new ByteArrayOutputStream();
+		URLRewritingStream urs = new URLRewritingStream(baos, "", "http://localhost");
+		urs.setBaseUrl("dothis/dothat/");
+		
+		assertEquals("dothis/dothat/test", urs.localUrl("test"));
+		assertEquals("/dothis/dothat/test", urs.serverUrl("test"));
+	 	assertEquals("http://localhost/dothis/dothat/test", urs.absoluteUrl("test"));
+	 	
+		assertEquals("test", urs.localUrl("magma:/test"));
+		assertEquals("/test", urs.serverUrl("magma:/test"));
+		assertEquals("http://localhost/test", urs.absoluteUrl("magma:/test"));		
+	 	
 	}
 	
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org