labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simo...@apache.org
Subject svn commit: r745493 - in /labs/magma/trunk/foundation-website/src: main/java/org/apache/magma/website/context/ main/java/org/apache/magma/website/templating/ main/java/org/apache/magma/website/utils/ test/java/org/apache/magma/website/ test/java/org/ap...
Date Wed, 18 Feb 2009 12:19:05 GMT
Author: simoneg
Date: Wed Feb 18 12:19:04 2009
New Revision: 745493

URL: http://svn.apache.org/viewvc?rev=745493&view=rev
Log:
LABS-292 : URLRewritingStream configured via aspects, and relative fixes and tests

Added:
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/utils/MakeURLRewritingContextBased.aj
    labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/teststuff/HtmlWithLinkProducer.java
Modified:
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/context/ContextWebMethods.aj
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/templating/Template.java
    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/WebHandlerCycleTest.java
    labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/teststuff/AuxiliaryWebHandler.java
    labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/teststuff/ConvertedSessionHandler.java

Modified: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/context/ContextWebMethods.aj
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/context/ContextWebMethods.aj?rev=745493&r1=745492&r2=745493&view=diff
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/context/ContextWebMethods.aj
(original)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/context/ContextWebMethods.aj
Wed Feb 18 12:19:04 2009
@@ -5,6 +5,7 @@
 import java.util.List;
 
 import org.apache.magma.basics.context.SubRunningContext;
+import org.apache.magma.website.RootWebHandler;
 import org.apache.magma.website.WebHandler;
 
 public aspect ContextWebMethods {
@@ -20,6 +21,11 @@
 		WebHandler prevh = null;
 		String prevseg = null;
 		for (WebMethodContextElement ctxele : methods) {
+			if (ctxele.getHandlerInstance() instanceof RootWebHandler) {
+				ret = new StringBuilder();
+				prevh = null;
+				prevseg = null;
+			}
 			if (ctxele.getHandlerInstance() != prevh) {
 				if (prevseg != null) {
 					ret.append('/');
@@ -29,9 +35,11 @@
 			prevh = ctxele.getHandlerInstance();
 			prevseg = ctxele.getURLSegment();
 		}
-		
+
 		ret.append('/');
-		ret.append(prevseg);							
+		if (prevseg != null) {
+			ret.append(prevseg);
+		}
 		return ret.toString();		
 	}
 	

Modified: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/templating/Template.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/templating/Template.java?rev=745493&r1=745492&r2=745493&view=diff
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/templating/Template.java
(original)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/templating/Template.java
Wed Feb 18 12:19:04 2009
@@ -144,6 +144,7 @@
 		
 		currentZone = "Main";
 		layoutMain();
+		current.clearDone();
 		
 		for (String acZone : data.zones) {
 			List<ZonePlaceholder> list = holders.get(acZone);
@@ -171,7 +172,6 @@
 					for (List<HtmlProducer> producers : zones.values()) {
 						for (HtmlProducer producer : producers) {
 							if (producer != null) {
-								rewrite.setBaseUrl(producer.getBasePath());
 								producer.head(head);
 								rewrite.flush();
 							}
@@ -185,7 +185,6 @@
 							if (producer != null) {
 								if (!zone.equals("ExtraContent")) openWrapper(zone, producer, osw);
 								osw.flush();
-								rewrite.setBaseUrl(producer.getBasePath());
 								producer.produce(rewrite);
 								rewrite.flush();
 								if (!zone.equals("ExtraContent")) closeWrapper(zone, producer, osw);

Added: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/utils/MakeURLRewritingContextBased.aj
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/utils/MakeURLRewritingContextBased.aj?rev=745493&view=auto
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/utils/MakeURLRewritingContextBased.aj
(added)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/utils/MakeURLRewritingContextBased.aj
Wed Feb 18 12:19:04 2009
@@ -0,0 +1,37 @@
+package org.apache.magma.website.utils;
+
+import org.apache.magma.website.Producer;
+import org.apache.magma.website.HtmlProducer;
+import java.io.OutputStream;
+import org.apache.magma.website.Head;
+
+public aspect MakeURLRewritingContextBased {
+
+	pointcut producing(URLRewritingStream stream, Producer prod) : execution(* Producer.produce(OutputStream))
&& this(prod) && args(stream);
+	
+	before(URLRewritingStream stream, Producer prod) : producing(stream, prod) {
+		stream.pushBaseUrl(prod.getBasePath());
+	}
+	
+	after(URLRewritingStream stream, Producer prod) : producing(stream, prod) {
+		stream.popBaseUrl();
+	}
+	
+	pointcut heading(Head head, HtmlProducer prod) : execution(* HtmlProducer.head(Head)) &&
this(prod) && args(head);
+	
+	before(Head head, HtmlProducer prod) : heading(head, prod) {
+		OutputStream stream = head.getStream();
+		if (!(stream instanceof URLRewritingStream)) return;
+		((URLRewritingStream)stream).pushBaseUrl(prod.getBasePath());		
+	}
+	
+	after(Head head, HtmlProducer prod) : heading(head, prod) {
+		OutputStream stream = head.getStream();
+		if (!(stream instanceof URLRewritingStream)) return;
+		((URLRewritingStream)stream).popBaseUrl();		
+	}
+	
+	
+	
+	
+}

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=745493&r1=745492&r2=745493&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
Wed Feb 18 12:19:04 2009
@@ -19,6 +19,7 @@
 import java.io.FilterOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.Stack;
 
 public class URLRewritingStream extends FilterOutputStream {
 
@@ -34,6 +35,7 @@
 	protected int intbuffpos = 0;
 	protected String commonPrefix;
 	protected String baseurl;
+	protected Stack<String> baseurlStack = new Stack<String>();
 	private boolean injecting = false;
 	protected String templatePrefix;
 	
@@ -208,5 +210,15 @@
 	public OutputStream getNonRewritingStream() {
 		return super.out;
 	}
+	
+	public void pushBaseUrl(String baseurl) {
+		this.baseurlStack.push(baseurl);
+		this.setBaseUrl(baseurl);
+	}
+	
+	public void popBaseUrl() {
+		String pop = this.baseurlStack.pop();
+		this.setBaseUrl(pop);
+	}
 
 }

Modified: labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/WebHandlerCycleTest.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/WebHandlerCycleTest.java?rev=745493&r1=745492&r2=745493&view=diff
==============================================================================
--- labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/WebHandlerCycleTest.java
(original)
+++ labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/WebHandlerCycleTest.java
Wed Feb 18 12:19:04 2009
@@ -285,6 +285,30 @@
 		assertStructure(def.out.toString(), "comp-head", "comp-bef", "comp-content", "comp-aft",
"comp-sidea", "comp-foot");
 	}	
 
+	@Test
+	public void links() throws Exception {
+		DefaultExpectations def = new DefaultExpectations() {};
+		UnitTestDispatch disp = new UnitTestDispatch();
+		disp.setTemplate(new SimpleTemplate());
+		def.disp = disp;
+		def.setupMinimal("/aux/checkLinks");
+		def.start();		
+		assertStructure(def.out.toString(), "<head>", "<link", "\"/aux/relative.css",
"</head","<body", "<a href", "\"/aux/inside", "<a href", "\"/base", "<a href",
"\"http://absolute");
+	}	
+
+	@Test
+	public void resendLinks() throws Exception {
+		DefaultExpectations def = new DefaultExpectations() {{
+			one(session).setAttribute("user", "Massimo");
+			one(session).getAttribute("user"); will(returnValue("Massimo"));						
+		}};
+		UnitTestDispatch disp = new UnitTestDispatch();
+		disp.setTemplate(new SimpleTemplate());
+		def.disp = disp;
+		def.setupMinimal("/testSession/resendLink");
+		def.start();		
+		assertStructure(def.out.toString(), "<head>", "<link", "\"/aux/relative.css",
"</head","<body", "<a href", "\"/aux/inside", "<a href", "\"/base", "<a href",
"\"http://absolute");
+	}	
 	
 	
 }

Modified: labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/teststuff/AuxiliaryWebHandler.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/teststuff/AuxiliaryWebHandler.java?rev=745493&r1=745492&r2=745493&view=diff
==============================================================================
--- labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/teststuff/AuxiliaryWebHandler.java
(original)
+++ labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/teststuff/AuxiliaryWebHandler.java
Wed Feb 18 12:19:04 2009
@@ -33,4 +33,8 @@
 		return new FakeHtmlProducer();		
 	}
 	
+	public HtmlProducer doCheckLinks() {
+		return new HtmlWithLinkProducer();
+	}
+	
 }

Modified: labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/teststuff/ConvertedSessionHandler.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/teststuff/ConvertedSessionHandler.java?rev=745493&r1=745492&r2=745493&view=diff
==============================================================================
--- labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/teststuff/ConvertedSessionHandler.java
(original)
+++ labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/teststuff/ConvertedSessionHandler.java
Wed Feb 18 12:19:04 2009
@@ -36,4 +36,8 @@
 		return ret;
 	}
 	
+	public HtmlProducer doResendLink() {
+		return root().handleAux().doCheckLinks();
+	}
+	
 }

Added: labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/teststuff/HtmlWithLinkProducer.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/teststuff/HtmlWithLinkProducer.java?rev=745493&view=auto
==============================================================================
--- labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/teststuff/HtmlWithLinkProducer.java
(added)
+++ labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/teststuff/HtmlWithLinkProducer.java
Wed Feb 18 12:19:04 2009
@@ -0,0 +1,32 @@
+package org.apache.magma.website.teststuff;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.List;
+
+import org.apache.magma.basics.MagmaException;
+import org.apache.magma.i18n.I18nRenderingHelper;
+import org.apache.magma.website.CompoundType;
+import org.apache.magma.website.CompoundableProducer;
+import org.apache.magma.website.Head;
+import org.apache.magma.website.HtmlProducer;
+import org.apache.magma.website.Producer;
+
+public class HtmlWithLinkProducer extends HtmlProducer {
+
+	@Override
+	public void head(Head head) {
+		head.addCss("relative.css");
+	}
+
+	@Override
+	public void produce(OutputStream stream) {
+		try {
+			String str = "<a href=\"inside\"/><a href=\"magma:/base\"/><a href=\"http://absolute.com/\"/>";
+			stream.write(str.getBytes());
+		} catch (IOException e) {
+			throw new MagmaException(e, "Error writing output");
+		}
+	}
+
+}



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


Mime
View raw message