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 2008/09/16 16:34:52 UTC

svn commit: r695910 [1/3] - in /labs/magma/trunk/foundation-website: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/magma/ src/main/java/org/apache/magma/website/ src/main/java/org/apache/magma/we...

Author: simoneg
Date: Tue Sep 16 07:34:49 2008
New Revision: 695910

URL: http://svn.apache.org/viewvc?rev=695910&view=rev
Log:
Initial import.

Added:
    labs/magma/trunk/foundation-website/pom.xml
    labs/magma/trunk/foundation-website/src/
    labs/magma/trunk/foundation-website/src/main/
    labs/magma/trunk/foundation-website/src/main/java/
    labs/magma/trunk/foundation-website/src/main/java/org/
    labs/magma/trunk/foundation-website/src/main/java/org/apache/
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/ComposedHtmlProducer.java
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/Dispatch.java
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/GenericWarnings.aj
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/HandlerSetup.aj
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/HtmlProducer.java
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/Producer.java
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/ResourceProducer.java
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/RootWebHandler.java
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/Templatable.java
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/WebHandler.java
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/CompoundHtmlProducer.java
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/DontBotherWithExceptions.aj
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/JSONProducer.java
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/MockProducer.java
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/MockizeProducer.aj
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/ParametrizableHtmlProducerBase.java
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/ParametrizableProducer.java
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/ParametrizableProducerBase.java
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/ParametrizeHtmlProducer.aj
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/ProducerParameters.java
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/StringHtmlProducer.java
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/XmlProducer.java
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/templating/
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/templating/DefaultTemplate.java
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/templating/InstallTemplateResourceHandler.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/templating/TemplateData.java
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/templating/TemplateResourceHandler.java
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/utils/
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/utils/Binder.java
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/utils/URLRewritingStream.java
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/welcome/
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/welcome/InstallWelcome.aj
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/welcome/WelcomeWebHandler.java
    labs/magma/trunk/foundation-website/src/main/resources/
    labs/magma/trunk/foundation-website/src/main/resources/org/
    labs/magma/trunk/foundation-website/src/main/resources/org/apache/
    labs/magma/trunk/foundation-website/src/main/resources/org/apache/magma/
    labs/magma/trunk/foundation-website/src/main/resources/org/apache/magma/website/
    labs/magma/trunk/foundation-website/src/main/resources/org/apache/magma/website/templating/
    labs/magma/trunk/foundation-website/src/main/resources/org/apache/magma/website/templating/defaultstyle.css
    labs/magma/trunk/foundation-website/src/main/resources/org/apache/magma/website/templating/template.html
    labs/magma/trunk/foundation-website/src/main/resources/org/apache/magma/website/teststuff/
    labs/magma/trunk/foundation-website/src/main/resources/org/apache/magma/website/teststuff/resource.txt
    labs/magma/trunk/foundation-website/src/test/
    labs/magma/trunk/foundation-website/src/test/java/
    labs/magma/trunk/foundation-website/src/test/java/org/
    labs/magma/trunk/foundation-website/src/test/java/org/apache/
    labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/
    labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/
    labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/AssertStringStructure.java
    labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/MockServletOutputStream.java
    labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/UnitTestDispatch.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/WebHandlerTest.java
    labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/producers/
    labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/producers/TestXmlProducer.java
    labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/templating/
    labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/templating/TemplateDataTest.java
    labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/templating/TemplatingTest.java
    labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/teststuff/
    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/FakeHtmlProducer.java
    labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/teststuff/InferPersonConverter.aj
    labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/teststuff/InferTestIntoRoot.aj
    labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/teststuff/Person.java
    labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/teststuff/PersonConverter.java
    labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/teststuff/SimpleTemplate.java
    labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/teststuff/SimpleWebHandler.java
    labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/utils/
    labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/utils/RewritingTests.java
    labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/utils/URLRewritingStreamPerformanceTests.java
    labs/magma/trunk/foundation-website/src/test/java/org/apache/magma/website/utils/URLRewritingStreamTest.java
    labs/magma/trunk/foundation-website/src/test/resources/
    labs/magma/trunk/foundation-website/src/test/resources/org/
    labs/magma/trunk/foundation-website/src/test/resources/org/apache/
    labs/magma/trunk/foundation-website/src/test/resources/org/apache/magma/
    labs/magma/trunk/foundation-website/src/test/resources/org/apache/magma/website/
    labs/magma/trunk/foundation-website/src/test/resources/org/apache/magma/website/teststuff/
    labs/magma/trunk/foundation-website/src/test/resources/org/apache/magma/website/teststuff/template.html

Added: labs/magma/trunk/foundation-website/pom.xml
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/pom.xml?rev=695910&view=auto
==============================================================================
--- labs/magma/trunk/foundation-website/pom.xml (added)
+++ labs/magma/trunk/foundation-website/pom.xml Tue Sep 16 07:34:49 2008
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+<project
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+		<groupId>org.apache.magma</groupId>
+		<artifactId>magma-parent</artifactId>
+		<version>1</version>
+	</parent>
+	<groupId>org.apache.magma</groupId>
+	<artifactId>foundation-website</artifactId>
+	<name>Magma Foundation WebSite</name>
+	<version>0.0.1-SNAPSHOT</version>
+	<description />
+	<packaging>magma</packaging>
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.magma.tools</groupId>
+				<artifactId>maven-magma-plugin</artifactId>
+				<extensions>true</extensions>
+			</plugin>
+		</plugins>
+	</build>
+	<dependencies>
+		<dependency>
+			<groupId>com.thoughtworks.xstream</groupId>
+			<artifactId>xstream</artifactId>
+			<version>1.2.2</version>
+		</dependency>
+
+		<dependency>
+			<groupId>javax.servlet</groupId>
+			<artifactId>servlet-api</artifactId>
+			<version>2.5</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.magma</groupId>
+			<artifactId>foundation-validation</artifactId>
+			<version>0.0.1-SNAPSHOT</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.magma</groupId>
+			<artifactId>foundation-conversion</artifactId>
+			<version>0.0.1-SNAPSHOT</version>
+		</dependency>
+		<dependency>
+			<groupId>org.jmock</groupId>
+			<artifactId>jmock-junit4</artifactId>
+			<version>2.4.0</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<version>4.4</version>
+			<scope>test</scope>
+		</dependency>
+		<!--dependency>
+			<groupId>aspectj</groupId>
+			<artifactId>aspectjrt</artifactId>
+			<version>1.5.4</version>
+			</dependency-->
+		<dependency>
+			<groupId>org.apache.magma</groupId>
+			<artifactId>foundation-database</artifactId>
+			<version>0.0.1-SNAPSHOT</version>
+		</dependency>
+	</dependencies>
+</project>

Added: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/ComposedHtmlProducer.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/ComposedHtmlProducer.java?rev=695910&view=auto
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/ComposedHtmlProducer.java (added)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/ComposedHtmlProducer.java Tue Sep 16 07:34:49 2008
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.magma.website;
+
+
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+public class ComposedHtmlProducer extends HtmlProducer {
+
+	private List<HtmlProducer> composition = new ArrayList<HtmlProducer>();
+	
+	public ComposedHtmlProducer(HtmlProducer base) {
+		add(base);
+	}
+	
+	public void add(HtmlProducer producer) {
+		this.composition.add(producer);
+	}
+	
+	public void add(int position, HtmlProducer producer) {
+		this.composition.add(position, producer);
+	}
+	
+	public void produce(OutputStream stream) {
+		for (HtmlProducer producer : composition) {
+			producer.produce(stream);
+		}
+	}
+
+	public void head(OutputStream stream) {
+		for (HtmlProducer producer : composition) {
+			producer.head(stream);
+		}
+	}
+
+}

Added: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/Dispatch.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/Dispatch.java?rev=695910&view=auto
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/Dispatch.java (added)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/Dispatch.java Tue Sep 16 07:34:49 2008
@@ -0,0 +1,163 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.magma.website;
+
+import org.apache.magma.basics.MagmaException;
+import org.apache.magma.website.templating.DefaultTemplate;
+import org.apache.magma.website.templating.Template;
+import org.apache.magma.website.utils.Binder;
+import org.apache.magma.website.utils.URLRewritingStream;
+
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.StringTokenizer;
+
+import javax.servlet.ServletException;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+public class Dispatch extends HttpServlet {
+
+	@Override
+	public void init() throws ServletException {
+		super.init();
+	}
+	
+	@Override
+	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+		handle(req, resp);
+	}
+
+	@Override
+	public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+		handle(req, resp);
+	}
+
+	protected void handle(HttpServletRequest req, HttpServletResponse resp) {
+		String pathInfo = req.getPathInfo();
+		req.setAttribute("__magma_url", pathInfo);
+		Producer producer = findProducer(pathInfo);
+		try {
+			if (producer != null) {
+				if (producer instanceof HtmlProducer) {
+					handleHtml((HtmlProducer) producer, req, resp);
+				} else {
+					handleResource(producer, resp);
+				} 
+			} else {
+				handleNotFound(resp);
+			}
+		} catch (Throwable t) {
+			handleException(t, resp);
+		}
+	}
+
+	protected void handleException(Throwable t, HttpServletResponse resp) {
+		ServletOutputStream out = null;
+		try {
+			out = resp.getOutputStream();
+			out.write("<pre>".getBytes());
+			t.printStackTrace(new PrintStream(out));
+			out.write("</pre>".getBytes());
+		} catch (IOException e) {
+			t.printStackTrace();
+			return;
+		}
+	}
+
+	protected void handleHtml(HtmlProducer producer, HttpServletRequest req, HttpServletResponse resp) {
+		String mybaseurl = "";
+		if (req.getContextPath().length() > 0) {
+			mybaseurl += req.getContextPath();
+		}
+		if (req.getServletPath().length() > 0) {
+			mybaseurl += "/" + req.getServletPath();
+		}
+		
+		Template t = getDefaultTemplate();
+		t.setCurrent(producer);
+		
+		HttpSession session = req.getSession();
+		String last = (String) session.getAttribute("__magma_lastmain");
+		if (last != null) {
+			try {
+				Producer prod = findProducer(last);
+				if (prod != null && prod instanceof HtmlProducer) {
+					t.setPrevious((HtmlProducer) prod);
+				}
+			} catch (Exception e) {
+				// TODO log the exception
+			}
+		}
+		
+		try {
+			t.produce(mybaseurl, resp.getOutputStream());
+		} catch (IOException e) {
+			throw new MagmaException(e, "Error getting servlet output stream");
+		}
+		System.out.println("Producer has a complete path of " + producer.getCompletePath());
+		if (t.wasMain() && producer.getCompletePath() != null) {
+			session.setAttribute("__magma_lastmain", producer.getCompletePath());			
+		}
+	}
+	
+	public Template getDefaultTemplate() {
+		return new DefaultTemplate();
+	}
+
+	protected void handleNotFound(HttpServletResponse resp) {
+		try {
+			resp.sendError(404);
+		} catch (IOException e) {
+			throw new MagmaException(e, "Error sending 404 not found error");
+		}
+	}
+
+	protected void handleResource(Producer producer, HttpServletResponse resp) {
+		try {
+			producer.produce(resp.getOutputStream());
+		} catch (IOException e) {
+			throw new MagmaException(e, "Error getting servlet output stream");
+		}
+	}
+
+	protected Producer findProducer(String pathInfo) {
+		String[] info = tokenizeRequest(pathInfo);
+		WebHandler root = RootWebHandler.getInstance();
+		Producer producer = root.find(info);
+		return producer;
+	}
+
+	protected String[] tokenizeRequest(String pathInfo) {
+		String[] info = null;
+		if (pathInfo == null) {
+			info = new String[] { "" };
+		} else {
+			StringTokenizer stok = new StringTokenizer(pathInfo, "/-");
+			info = new String[stok.countTokens()];
+			int pos = 0;
+			while (stok.hasMoreTokens()) {
+				info[pos++] = stok.nextToken();
+			}
+		}
+		return info;
+	}
+	
+}

Added: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/GenericWarnings.aj
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/GenericWarnings.aj?rev=695910&view=auto
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/GenericWarnings.aj (added)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/GenericWarnings.aj Tue Sep 16 07:34:49 2008
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.magma.website;
+
+import org.apache.magma.website.WebHandler;
+
+public aspect GenericWarnings {
+
+	/*
+	declare warning : execution(WebHandler+ WebHandler+.handle*(..)) 
+	                  && !execution(WebHandler WebHandler+.handle*(..)) :
+	                	  "Magma: a handle method should be declared as returning a WebHandler, and not a specific subclass, otherwise it will be difficult to extend it in the future!";
+	*/
+	// Avoid narrowing
+  	declare warning : execution(Producer+ WebHandler+.do*(..)) 
+				      && !execution(Producer WebHandler+.do*(..))
+				      && !execution(HtmlProducer WebHandler+.do*(..)) :
+				    	  "Magma: a do method should be declared as returning a Producer or an HtmlProducer, and not a specific subclass, otherwise it will be difficult to extend it in the future!";
+	// Encourage narrowing
+	declare warning : execution(WebHandler WebHandler+.handle*(..)) : "Magma: You should declare the correct handler instead of the generic WebHandler.";
+	
+	// Check that do and handle methods are correct
+	declare warning : execution((!WebHandler+) WebHandler+.handle*(..)) : "Magma: A handle method should return a WebHandler, this method will not work!";
+	declare warning : execution((!Producer+) WebHandler+.do*(..)) : "Magma: A do method should return a Producer, this method will not work!";
+	
+	declare warning : execution(WebHandler+ WebHandler+.handlea*(..)) : "Magma: A handle method be composed by handle+CAPITALIZED name, for example handleShow, and not handleshow, this method will not work!";
+	declare warning : execution(WebHandler+ WebHandler+.handleb*(..)) : "Magma: A handle method be composed by handle+CAPITALIZED name, for example handleShow, and not handleshow, this method will not work!";
+	declare warning : execution(WebHandler+ WebHandler+.handlec*(..)) : "Magma: A handle method be composed by handle+CAPITALIZED name, for example handleShow, and not handleshow, this method will not work!";
+	declare warning : execution(WebHandler+ WebHandler+.handled*(..)) : "Magma: A handle method be composed by handle+CAPITALIZED name, for example handleShow, and not handleshow, this method will not work!";
+	declare warning : execution(WebHandler+ WebHandler+.handlee*(..)) : "Magma: A handle method be composed by handle+CAPITALIZED name, for example handleShow, and not handleshow, this method will not work!";
+	declare warning : execution(WebHandler+ WebHandler+.handlef*(..)) : "Magma: A handle method be composed by handle+CAPITALIZED name, for example handleShow, and not handleshow, this method will not work!";
+	declare warning : execution(WebHandler+ WebHandler+.handleg*(..)) : "Magma: A handle method be composed by handle+CAPITALIZED name, for example handleShow, and not handleshow, this method will not work!";
+	declare warning : execution(WebHandler+ WebHandler+.handleh*(..)) : "Magma: A handle method be composed by handle+CAPITALIZED name, for example handleShow, and not handleshow, this method will not work!";
+	declare warning : execution(WebHandler+ WebHandler+.handlei*(..)) : "Magma: A handle method be composed by handle+CAPITALIZED name, for example handleShow, and not handleshow, this method will not work!";
+	declare warning : execution(WebHandler+ WebHandler+.handlej*(..)) : "Magma: A handle method be composed by handle+CAPITALIZED name, for example handleShow, and not handleshow, this method will not work!";
+	declare warning : execution(WebHandler+ WebHandler+.handlek*(..)) : "Magma: A handle method be composed by handle+CAPITALIZED name, for example handleShow, and not handleshow, this method will not work!";
+	declare warning : execution(WebHandler+ WebHandler+.handlel*(..)) : "Magma: A handle method be composed by handle+CAPITALIZED name, for example handleShow, and not handleshow, this method will not work!";
+	declare warning : execution(WebHandler+ WebHandler+.handlem*(..)) : "Magma: A handle method be composed by handle+CAPITALIZED name, for example handleShow, and not handleshow, this method will not work!";
+	declare warning : execution(WebHandler+ WebHandler+.handlen*(..)) : "Magma: A handle method be composed by handle+CAPITALIZED name, for example handleShow, and not handleshow, this method will not work!";
+	declare warning : execution(WebHandler+ WebHandler+.handleo*(..)) : "Magma: A handle method be composed by handle+CAPITALIZED name, for example handleShow, and not handleshow, this method will not work!";
+	declare warning : execution(WebHandler+ WebHandler+.handlep*(..)) : "Magma: A handle method be composed by handle+CAPITALIZED name, for example handleShow, and not handleshow, this method will not work!";
+	declare warning : execution(WebHandler+ WebHandler+.handleq*(..)) : "Magma: A handle method be composed by handle+CAPITALIZED name, for example handleShow, and not handleshow, this method will not work!";
+	declare warning : execution(WebHandler+ WebHandler+.handler*(..)) : "Magma: A handle method be composed by handle+CAPITALIZED name, for example handleShow, and not handleshow, this method will not work!";
+	declare warning : execution(WebHandler+ WebHandler+.handles*(..)) : "Magma: A handle method be composed by handle+CAPITALIZED name, for example handleShow, and not handleshow, this method will not work!";
+	declare warning : execution(WebHandler+ WebHandler+.handlet*(..)) : "Magma: A handle method be composed by handle+CAPITALIZED name, for example handleShow, and not handleshow, this method will not work!";
+	declare warning : execution(WebHandler+ WebHandler+.handleu*(..)) : "Magma: A handle method be composed by handle+CAPITALIZED name, for example handleShow, and not handleshow, this method will not work!";
+	declare warning : execution(WebHandler+ WebHandler+.handlev*(..)) : "Magma: A handle method be composed by handle+CAPITALIZED name, for example handleShow, and not handleshow, this method will not work!";
+	declare warning : execution(WebHandler+ WebHandler+.handlew*(..)) : "Magma: A handle method be composed by handle+CAPITALIZED name, for example handleShow, and not handleshow, this method will not work!";
+	declare warning : execution(WebHandler+ WebHandler+.handlex*(..)) : "Magma: A handle method be composed by handle+CAPITALIZED name, for example handleShow, and not handleshow, this method will not work!";
+	declare warning : execution(WebHandler+ WebHandler+.handley*(..)) : "Magma: A handle method be composed by handle+CAPITALIZED name, for example handleShow, and not handleshow, this method will not work!";
+	declare warning : execution(WebHandler+ WebHandler+.handlez*(..)) : "Magma: A handle method be composed by handle+CAPITALIZED name, for example handleShow, and not handleshow, this method will not work!";
+	
+	declare warning : execution(Producer+ WebHandler+.doa(..)) : "Magma: A do method be composed by do+CAPITALIZED name, for example doShow, and not doshow, this method will not work!";
+	declare warning : execution(Producer+ WebHandler+.dob(..)) : "Magma: A do method be composed by do+CAPITALIZED name, for example doShow, and not doshow, this method will not work!";
+	declare warning : execution(Producer+ WebHandler+.doc(..)) : "Magma: A do method be composed by do+CAPITALIZED name, for example doShow, and not doshow, this method will not work!";
+	declare warning : execution(Producer+ WebHandler+.dod(..)) : "Magma: A do method be composed by do+CAPITALIZED name, for example doShow, and not doshow, this method will not work!";
+	declare warning : execution(Producer+ WebHandler+.doe(..)) : "Magma: A do method be composed by do+CAPITALIZED name, for example doShow, and not doshow, this method will not work!";
+	declare warning : execution(Producer+ WebHandler+.dof(..)) : "Magma: A do method be composed by do+CAPITALIZED name, for example doShow, and not doshow, this method will not work!";
+	declare warning : execution(Producer+ WebHandler+.dog(..)) : "Magma: A do method be composed by do+CAPITALIZED name, for example doShow, and not doshow, this method will not work!";
+	declare warning : execution(Producer+ WebHandler+.doh(..)) : "Magma: A do method be composed by do+CAPITALIZED name, for example doShow, and not doshow, this method will not work!";
+	declare warning : execution(Producer+ WebHandler+.doi(..)) : "Magma: A do method be composed by do+CAPITALIZED name, for example doShow, and not doshow, this method will not work!";
+	declare warning : execution(Producer+ WebHandler+.doj(..)) : "Magma: A do method be composed by do+CAPITALIZED name, for example doShow, and not doshow, this method will not work!";
+	declare warning : execution(Producer+ WebHandler+.dok(..)) : "Magma: A do method be composed by do+CAPITALIZED name, for example doShow, and not doshow, this method will not work!";
+	declare warning : execution(Producer+ WebHandler+.dol(..)) : "Magma: A do method be composed by do+CAPITALIZED name, for example doShow, and not doshow, this method will not work!";
+	declare warning : execution(Producer+ WebHandler+.dom(..)) : "Magma: A do method be composed by do+CAPITALIZED name, for example doShow, and not doshow, this method will not work!";
+	declare warning : execution(Producer+ WebHandler+.don(..)) : "Magma: A do method be composed by do+CAPITALIZED name, for example doShow, and not doshow, this method will not work!";
+	declare warning : execution(Producer+ WebHandler+.doo(..)) : "Magma: A do method be composed by do+CAPITALIZED name, for example doShow, and not doshow, this method will not work!";
+	declare warning : execution(Producer+ WebHandler+.dop(..)) : "Magma: A do method be composed by do+CAPITALIZED name, for example doShow, and not doshow, this method will not work!";
+	declare warning : execution(Producer+ WebHandler+.doq(..)) : "Magma: A do method be composed by do+CAPITALIZED name, for example doShow, and not doshow, this method will not work!";
+	declare warning : execution(Producer+ WebHandler+.dor(..)) : "Magma: A do method be composed by do+CAPITALIZED name, for example doShow, and not doshow, this method will not work!";
+	declare warning : execution(Producer+ WebHandler+.dos(..)) : "Magma: A do method be composed by do+CAPITALIZED name, for example doShow, and not doshow, this method will not work!";
+	declare warning : execution(Producer+ WebHandler+.dot(..)) : "Magma: A do method be composed by do+CAPITALIZED name, for example doShow, and not doshow, this method will not work!";
+	declare warning : execution(Producer+ WebHandler+.dou(..)) : "Magma: A do method be composed by do+CAPITALIZED name, for example doShow, and not doshow, this method will not work!";
+	declare warning : execution(Producer+ WebHandler+.dov(..)) : "Magma: A do method be composed by do+CAPITALIZED name, for example doShow, and not doshow, this method will not work!";
+	declare warning : execution(Producer+ WebHandler+.dow(..)) : "Magma: A do method be composed by do+CAPITALIZED name, for example doShow, and not doshow, this method will not work!";
+	declare warning : execution(Producer+ WebHandler+.dox(..)) : "Magma: A do method be composed by do+CAPITALIZED name, for example doShow, and not doshow, this method will not work!";
+	declare warning : execution(Producer+ WebHandler+.doy(..)) : "Magma: A do method be composed by do+CAPITALIZED name, for example doShow, and not doshow, this method will not work!";
+	declare warning : execution(Producer+ WebHandler+.doz(..)) : "Magma: A do method be composed by do+CAPITALIZED name, for example doShow, and not doshow, this method will not work!";
+	
+}

Added: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/HandlerSetup.aj
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/HandlerSetup.aj?rev=695910&view=auto
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/HandlerSetup.aj (added)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/HandlerSetup.aj Tue Sep 16 07:34:49 2008
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.magma.website;
+
+import org.apache.magma.beans.MagmaBeanSupport;
+import org.apache.magma.conversion.Converter;
+import org.apache.magma.conversion.Converters;
+import org.apache.magma.website.utils.Binder;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.aspectj.lang.reflect.MethodSignature;
+
+
+public aspect HandlerSetup percflow(inRequest()) {
+
+	declare parents : (WebHandler) implements MagmaBeanSupport;
+
+	public pointcut inRequest() : execution(public void Dispatch+.doGet(..)) || execution(public void Dispatch+.doPost(..)); 
+	
+	private HttpServletRequest request = null;
+	private HttpServletResponse response = null;
+	
+	
+	before(HttpServletRequest req, HttpServletResponse resp) : 
+		inRequest() &&
+		args(req, resp) {
+		this.request = req;
+		this.response = resp;
+	}
+	
+	private boolean WebHandler.inited = false;
+	
+	public pointcut subHandle(WebHandler h) : execution(public WebHandler+ WebHandler+.handle*(..)) && this(h);
+	public pointcut doMethod(WebHandler h) : execution(public Producer+ WebHandler+.do*(..)) && this(h);
+	
+
+	
+	Object around (WebHandler h) : (doMethod(h) || subHandle(h)) {
+		Object retObj = null;
+		if (!h.inited) { 
+			try {
+				Binder.bind(h, request);
+				h.inited = true;
+			} catch (Throwable e) {
+				e.printStackTrace();
+			}
+			retObj = proceed(h);
+			try {
+				Binder.flush(h, request, response);
+				h.inited = false;
+			} catch (Throwable e) {
+				e.printStackTrace();
+			}
+		} else {
+			retObj = proceed(h);
+		}
+		if (retObj instanceof WebHandler) {
+			WebHandler ret = (WebHandler)retObj;
+			ret.setCreatingHandler(h);
+			String methname = ((MethodSignature)thisJoinPoint.getSignature()).getName();
+			boolean valid = true;
+			methname = methname.substring(6);
+			methname = Character.toLowerCase(methname.charAt(0)) + methname.substring(1);
+			String relpath = h.getRelativePath() + methname;
+			Object[] args = thisJoinPoint.getArgs();
+			if (args != null && args.length > 0) {
+				for (int i = 0; i < args.length; i++) {
+					relpath += "-";
+					if (args[i] == null) continue;
+					Converter conv = Converters.getConverterFor(args[i].getClass());
+					if (conv == null) {
+						valid = false;
+						break;
+					}
+					try {
+						relpath += conv.toString(args[i]);
+					} catch (Throwable e) {
+						valid = false;
+						break;
+					}
+				}
+			}
+			if (valid) {
+				relpath += "/";
+				ret.setRelativePath(relpath);
+			} else {
+				ret.setRelativePath(null);
+			}
+		}
+		return retObj;
+	}
+		
+}

Added: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/HtmlProducer.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/HtmlProducer.java?rev=695910&view=auto
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/HtmlProducer.java (added)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/HtmlProducer.java Tue Sep 16 07:34:49 2008
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.magma.website;
+
+import org.apache.magma.website.templating.Template;
+
+import java.io.OutputStream;
+
+
+public abstract class HtmlProducer extends Producer implements Templatable {
+
+	private Template template;
+
+	@Override
+	public String getMimeType() {
+		return "text/html";
+	}
+	
+	public abstract void head(OutputStream stream);
+	
+	public void setTemplate(Template t) {
+		this.template = t;
+	}
+	
+	public Template getTemplate() {
+		if (this.template != null) {
+			return this.template;
+		} else return this.getCreatingHandler().getTemplate();
+	}
+	
+}

Added: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/Producer.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/Producer.java?rev=695910&view=auto
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/Producer.java (added)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/Producer.java Tue Sep 16 07:34:49 2008
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.magma.website;
+
+
+import java.io.OutputStream;
+import java.lang.reflect.Method;
+
+public abstract class Producer {
+
+	private Method method;
+	private WebHandler handler;
+	private String basePath;
+	private String completePath;
+
+	public Method getCreatingMethod() {
+		return this.method;
+	}
+	
+	void setCreatingMethod(Method method) {
+		this.method = method;
+	}
+	
+	public WebHandler getCreatingHandler() {
+		return this.handler;
+	}
+	
+	public void setCreatingHandler(WebHandler handler) {
+		this.handler = handler;
+	}
+	
+	public abstract void produce(OutputStream stream);	
+	
+	public abstract String getMimeType();
+	
+	public boolean isFrom(Class<? extends WebHandler> handlerClass) {
+		WebHandler ach = this.getCreatingHandler();
+		while (ach != null) {
+			if (ach.getClass().equals(handlerClass)) return true;
+			ach = ach.getCreatingHandler();
+		}
+		return false;
+	}
+	
+	public boolean isFrom(Producer other) {
+		return isFrom(other.getCreatingHandler().getClass()) && other.getCreatingMethod().equals(this.getCreatingMethod());
+	}
+
+	public String getBasePath() {
+		return basePath;
+	}
+
+	public void setBasePath(String basePath) {
+		this.basePath = basePath;
+	}
+
+	/**
+	 * Finds this producer complete path inside the URI space.
+	 * <p>
+	 * This method will return the complete path of this producer watching in which doMethod
+	 * this producer was created, which parameters where passed to the doMethod, and which was the
+	 * complete path of the {@link WebHandler} using {@link WebHandler#getRelativePath()} .
+	 * </p>
+	 * <p>
+	 * Using this path again should produce another producer constructed by the same method, using same
+	 * parameters, on a handler obtained using same handleMethods with same parameter as the current one.
+	 * See also {@link WebHandler#getRelativePath()} to know limitations.
+	 * </p>
+	 * <p>
+	 * In case such a path does not exist, cause it was not possible to construct it converting parameters
+	 * or the originating method of this producer was not a doMethod inside a WebHandler, it will return null.
+	 * </p>
+	 * @return A path that, if reused, should return a producer equivalent to this one, or null is such a path could not be constructed.
+	 */
+	public String getCompletePath() {
+		return completePath;
+	}
+
+	public void setCompletePath(String completePath) {
+		this.completePath = completePath;
+	}
+
+}

Added: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/ResourceProducer.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/ResourceProducer.java?rev=695910&view=auto
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/ResourceProducer.java (added)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/ResourceProducer.java Tue Sep 16 07:34:49 2008
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.magma.website;
+
+import org.apache.magma.basics.MagmaException;
+import org.apache.magma.settings.Settings;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+public class ResourceProducer extends Producer {
+
+	private static Map<String, String> mimes = new HashMap<String, String>();
+	
+	static {
+		mimes.put("gif", "image/gif");
+		mimes.put("jpg", "image/jpeg");
+		mimes.put("jpeg", "image/jpeg");
+		mimes.put("jpe", "image/jpeg");
+		mimes.put("js", "application/javascript");
+		mimes.put("htm", "text/html");
+		mimes.put("html", "text/html");
+		mimes.put("txt", "text/plain");
+		mimes.put("html", "text/html");
+		mimes.put("css", "text/css");
+	}
+	
+	private String fileName;
+
+	public ResourceProducer(String fileName) {
+		this.fileName = fileName;
+	}
+	
+	@Override
+	public String getMimeType() {
+		int pp = fileName.lastIndexOf('.');
+		if (pp == -1) return "application/octet-stream";
+		String ext = fileName.substring(pp + 1);
+		ext = getMimeForExtension(ext.toLowerCase());
+		if (ext == null) return "application/octet-stream";
+		return ext;
+	}
+	
+	protected String getMimeForExtension(String ext) {
+		String mime = mimes.get(ext);
+		if (mime == null) {
+			mime = Settings.get("mimetype." + ext);
+		}
+		return mime;
+	}
+	
+	public boolean exists() {
+		return getCreatingHandler().getClass().getResource(fileName) != null; 
+	}
+
+	@Override
+	public void produce(OutputStream stream) {
+		InputStream inputStream = getCreatingHandler().getClass().getResourceAsStream(fileName);
+		if (inputStream == null) throw new MagmaException("Resource {0}/{1} not found", getCreatingHandler().getClass().getPackage().getName(), fileName);
+		byte[] buff = new byte[1024];
+		int len = 0;
+		try {
+			while ((len = inputStream.read(buff)) != -1) {
+				stream.write(buff, 0, len);
+			}
+		} catch (IOException e) {
+			throw new MagmaException(e, "Error copying resource to output stream");
+		} finally {
+			try {
+				inputStream.close();
+			} catch (IOException e) {
+			}
+		}
+	}
+
+}

Added: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/RootWebHandler.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/RootWebHandler.java?rev=695910&view=auto
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/RootWebHandler.java (added)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/RootWebHandler.java Tue Sep 16 07:34:49 2008
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.magma.website;
+
+public class RootWebHandler extends WebHandler {
+
+	@Override
+	public String getRelativePath() {
+		return "/";
+	}
+	
+	@Override
+	public void setRelativePath(String path) {
+	}
+	
+	public static RootWebHandler getInstance() {
+		return new RootWebHandler();
+	}
+	
+}

Added: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/Templatable.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/Templatable.java?rev=695910&view=auto
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/Templatable.java (added)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/Templatable.java Tue Sep 16 07:34:49 2008
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.magma.website;
+
+import org.apache.magma.website.templating.Template;
+
+public interface Templatable {
+
+	public void setTemplate(Template t);
+	
+}

Added: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/WebHandler.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/WebHandler.java?rev=695910&view=auto
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/WebHandler.java (added)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/WebHandler.java Tue Sep 16 07:34:49 2008
@@ -0,0 +1,228 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.magma.website;
+
+import org.apache.magma.basics.MagmaException;
+import org.apache.magma.conversion.Converter;
+import org.apache.magma.conversion.Converters;
+import org.apache.magma.website.templating.Template;
+
+import java.lang.reflect.Method;
+import java.util.Arrays;
+
+public class WebHandler implements Templatable {
+
+	public static final String defaultPostfix = "_default";
+	public static final String defaultMethod = "do_default";
+	
+	protected String relativePath = "";
+	protected WebHandler creatingHandler = null;
+	protected Template template;
+	
+	
+	/**
+	 * Finds this handler complete path inside the URI space.
+	 * <p>
+	 * This method will return the complete path of this handler watching in which handleMethod
+	 * this handler was created in, which parameters where passed to the handleMethod, and which was the
+	 * complete path of the parent WebHandler.
+	 * </p>
+	 * <p>
+	 * Using this path again should produce another handler constructed by the same method, using same
+	 * parameters, on a handler obtained using same handleMethods with same parameter as the current one.
+	 * </p>
+	 * <p>
+	 * Since handlers also interact with the request, the session, and other elements in the environment,
+	 * it is not always possible to effectively GRANT that reusing this path in another request will lead to 
+	 * something valid and not to an exception. 
+	 * </p>
+	 * <p>
+	 * In case such a path does not exist, cause it was not possible to construct it converting parameters
+	 * or the originating method of this producer was not a doMethod inside a WebHandler, it will return null.
+	 * </p>
+	 * @return A path that, if reused, should return a producer equivalent to this one, or null is such a path could not be constructed.
+	 */	
+	public String getRelativePath() {
+		return this.relativePath;
+	}
+	
+	public void setRelativePath(String path) {
+		this.relativePath = path;
+	}
+	
+	public void setTemplate(Template t) {
+		this.template = t;
+	}
+	
+	public Template getTemplate() {
+		return this.template;
+	}
+	
+	
+	public Producer doResource(String fileName) {
+		ResourceProducer rp = new ResourceProducer(fileName);
+		if (rp.exists()) return rp;
+		return null;		
+	}
+	
+	public Producer find(String[] info) {
+		if (info == null || info.length == 0 || (info.length == 1 && info[0].length() == 0)) {
+			info = new String[] { defaultPostfix };
+		}
+		String seg = getFirstSegment(info);
+		String subp = getJavaSegment(seg);
+		
+		Method rightMethod = findMethodFor(subp);
+		if (rightMethod == null) {
+			info[0] = seg;
+			rightMethod = findMethodFor("Resource");
+		}
+
+
+		Object[] params = bindParameters(rightMethod, info);
+		
+		try {
+			Object ret = rightMethod.invoke(this, params);
+			if (ret instanceof Producer) {
+				return (Producer) ret;
+			} else if (ret instanceof WebHandler) {
+				String[] subinfo = prepareSubinfo(info);
+				return ((WebHandler)ret).find(subinfo);
+			} else {
+				throw new MagmaException("Invalid return type " + ret);
+			}
+		} catch (Exception e) {
+			throw new MagmaException(e, "Error invoking ", rightMethod);
+		}
+	}
+
+	String getFirstSegment(String[] info) {
+		String ret = "";
+		if (info[0].length() != 0) {
+			ret = info[0];
+		}
+		info[0] = null;
+		return ret;
+	}
+	
+	String getJavaSegment(String seg) {
+		StringBuffer subp = new StringBuffer(seg);		
+		for (int i = 0; i < subp.length(); i++) {
+			if (!(Character.isLetterOrDigit(subp.charAt(i)))) {
+				subp.setCharAt(i, '_');
+			}
+		}
+		subp.setCharAt(0, Character.toUpperCase(subp.charAt(0)));
+		return subp.toString();
+	}
+
+	Object[] bindParameters(Method rightMethod, String[] info) {
+		Class<?>[] types = rightMethod.getParameterTypes();
+		if (types.length == 0) return null;
+		int consumed = getConsumed(info);
+		boolean isfinal = rightMethod.getName().startsWith("do");
+		Object[] vals = convertParameters(info, types, consumed, isfinal);
+		return vals;
+	}
+
+	Object[] convertParameters(String[] info, Class<?>[] types,
+			int consumed, boolean isfinal) {
+		Object[] vals = new Object[types.length];
+		for (int i = 0; i < types.length; i++) {
+			if (i + consumed >= info.length) break;
+			Class<?> clazz = types[i];
+			if (clazz.equals(String.class)) {
+				if (isfinal && i == (types.length - 1)) {
+					String full = ""; 
+					for (int j = i + consumed; j < info.length; j++) {
+						if (full.length() > 0) full += "/";
+						full += info[j];
+						info[j] = null;
+					}
+					vals[i] = full;
+				} else {
+					vals[i] = info[i + consumed];
+					info[i + consumed] = null;
+				}
+			} else {
+				Converter converter = Converters.getConverterFor(clazz);
+				if (converter == null) {
+					throw new MagmaException("There is no converter for {0}", clazz.getName());
+				}
+				vals[i] = converter.fromString(info[i + consumed]);
+				info[i + consumed] = null;
+			}			
+		}
+		return vals;
+	}
+
+	String[] prepareSubinfo(String[] info) {
+		int consumed = getConsumed(info);
+		String[] subinfo = null;
+		if (consumed < info.length) {
+			subinfo = Arrays.copyOfRange(info, consumed, info.length);
+		}
+		if (subinfo == null || subinfo.length == 0) subinfo = new String[] { "" };
+		return subinfo;
+	}
+
+	private int getConsumed(String[] info) {
+		int consumed = 0;
+		for (String seg : info) {
+			if (seg == null) consumed++;
+		}
+		return consumed;
+	}
+
+	Method findMethodFor(String segment) {
+		if (segment.length() == 0) segment=defaultPostfix;
+		Method[] methods = getClass().getMethods();
+		Method rightMethod = null;
+		for (Method method : methods) {
+			if (method.getName().equals("do" + segment)) {
+				if (Producer.class.isAssignableFrom(method.getReturnType())) {
+					rightMethod = method;
+					break;
+				}
+			} else if (method.getName().equals("handle" + segment)) {
+				if (WebHandler.class.isAssignableFrom(method.getReturnType())) {
+					rightMethod = method;
+					break;
+				}				
+			}
+		}
+		if (rightMethod == null) {
+			// TODO throw an error? go for a default one if provided?
+			return null;
+		}
+		return rightMethod;
+	}
+
+	public WebHandler getCreatingHandler() {
+		return creatingHandler;
+	}
+
+	public void setCreatingHandler(WebHandler creatingHandler) {
+		this.creatingHandler = creatingHandler;
+	}
+	
+	protected HtmlProducer unrepeatable(HtmlProducer producer) {
+		producer.setCompletePath(null);
+		return producer;
+	}
+	
+}

Added: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/CompoundHtmlProducer.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/CompoundHtmlProducer.java?rev=695910&view=auto
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/CompoundHtmlProducer.java (added)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/CompoundHtmlProducer.java Tue Sep 16 07:34:49 2008
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.magma.website.producers;
+
+import org.apache.magma.website.HtmlProducer;
+
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+public class CompoundHtmlProducer extends HtmlProducer {
+
+	private List<HtmlProducer> producers = null;
+	
+	public CompoundHtmlProducer(HtmlProducer... producers) {
+		for (HtmlProducer htmlProducer : producers) {
+			addProducer(htmlProducer);
+		}
+	}
+	
+	public void addProducer(HtmlProducer htmlProducer) {
+		if (htmlProducer == null) return;
+		if (producers == null) producers = new ArrayList<HtmlProducer>();
+		producers.add(htmlProducer);
+	}
+
+	@Override
+	public void head(OutputStream stream) {
+		for (HtmlProducer producer : this.producers) {
+			producer.head(stream);
+		}
+	}
+
+	@Override
+	public void produce(OutputStream stream) {
+		for (HtmlProducer producer : this.producers) {
+			producer.produce(stream);
+		}
+	}
+
+}

Added: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/DontBotherWithExceptions.aj
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/DontBotherWithExceptions.aj?rev=695910&view=auto
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/DontBotherWithExceptions.aj (added)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/DontBotherWithExceptions.aj Tue Sep 16 07:34:49 2008
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.magma.website.producers;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+
+import org.apache.magma.website.HtmlProducer;
+import org.apache.magma.website.Producer;
+
+public aspect DontBotherWithExceptions {
+
+	pointcut headmethod() : execution(void HtmlProducer+.head(..));
+	pointcut bodymethod() : execution(void Producer+.produce(..));
+	
+	declare soft : IOException : headmethod() || bodymethod(); 
+	declare soft : UnsupportedEncodingException : headmethod() || bodymethod();
+	
+}

Added: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/JSONProducer.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/JSONProducer.java?rev=695910&view=auto
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/JSONProducer.java (added)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/JSONProducer.java Tue Sep 16 07:34:49 2008
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.magma.website.producers;
+
+import com.thoughtworks.xstream.XStream;
+import com.thoughtworks.xstream.io.json.JsonHierarchicalStreamDriver;
+
+public class JSONProducer extends XmlProducer {
+
+	public JSONProducer(Object object) {
+		super(object);
+		this.xstream = new XStream(new JsonHierarchicalStreamDriver());
+	}
+}

Added: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/MockProducer.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/MockProducer.java?rev=695910&view=auto
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/MockProducer.java (added)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/MockProducer.java Tue Sep 16 07:34:49 2008
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.magma.website.producers;
+
+import org.apache.magma.website.HtmlProducer;
+
+import java.io.OutputStream;
+
+public class MockProducer extends HtmlProducer {
+
+	@Override
+	public String getMimeType() {
+		return null;
+	}
+
+	@Override
+	public void produce(OutputStream stream) {
+	}
+
+	@Override
+	public void head(OutputStream stream) {
+	}
+
+}

Added: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/MockizeProducer.aj
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/MockizeProducer.aj?rev=695910&view=auto
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/MockizeProducer.aj (added)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/MockizeProducer.aj Tue Sep 16 07:34:49 2008
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.magma.website.producers;
+
+import org.apache.magma.website.WebHandler;
+
+public aspect MockizeProducer {
+
+	declare precedence : *, MockizeProducer;
+	
+	pointcut inMainCheck() : execution(boolean Selector+.acceptAsMain(HtmlProducer));
+	
+	pointcut inSelectTemplate() : execution(Template+ Selector+.selectTemplate(HtmlProducer));
+	
+	pointcut mustMockize() : inMainCheck() || inSelectTemplate();
+	
+	pointcut mockizeCreation() : call(Producer+ WebHandler+.do*(..)) && cflow(mustMockize());
+	
+	Object around() : mockizeCreation() {
+		return new MockProducer();
+	}
+}

Added: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/ParametrizableHtmlProducerBase.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/ParametrizableHtmlProducerBase.java?rev=695910&view=auto
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/ParametrizableHtmlProducerBase.java (added)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/ParametrizableHtmlProducerBase.java Tue Sep 16 07:34:49 2008
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.magma.website.producers;
+
+import org.apache.magma.website.HtmlProducer;
+import org.apache.magma.website.WebHandler;
+
+import java.io.OutputStream;
+
+public abstract class ParametrizableHtmlProducerBase extends HtmlProducer implements
+		ParametrizableProducer {
+
+	protected ProducerParameters parameters = new ProducerParameters();
+	
+	public ParametrizableHtmlProducerBase addParameter(Object param) {
+		parameters.addParameter(param);
+		return this;
+	}
+
+	public ParametrizableHtmlProducerBase addParameter(String name, Object param) {
+		parameters.addParameter(name, param);
+		return this;
+	}
+
+	public void parametrizeByHandler() {
+		if (getCreatingHandler() != null) parameters.setHandler(getCreatingHandler());
+	}
+
+
+	public void setTemplateName(String name) {
+		parameters.setTemplateName(name);
+	}
+
+}

Added: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/ParametrizableProducer.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/ParametrizableProducer.java?rev=695910&view=auto
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/ParametrizableProducer.java (added)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/ParametrizableProducer.java Tue Sep 16 07:34:49 2008
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.magma.website.producers;
+
+import org.apache.magma.website.WebHandler;
+
+
+public interface ParametrizableProducer {
+
+	public ParametrizableProducer addParameter(Object param);
+	
+	public ParametrizableProducer addParameter(String name, Object param);
+		
+	public void setTemplateName(String name);
+	
+	public void parametrizeByHandler();
+	
+}

Added: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/ParametrizableProducerBase.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/ParametrizableProducerBase.java?rev=695910&view=auto
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/ParametrizableProducerBase.java (added)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/ParametrizableProducerBase.java Tue Sep 16 07:34:49 2008
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.magma.website.producers;
+
+import org.apache.magma.website.Producer;
+import org.apache.magma.website.WebHandler;
+
+public abstract class ParametrizableProducerBase extends Producer implements ParametrizableProducer {
+
+	protected ProducerParameters parameters = new ProducerParameters();
+	
+	public ParametrizableProducer addParameter(Object param) {
+		parameters.addParameter(param);
+		return this;		
+	}
+
+	public ParametrizableProducer addParameter(String name, Object param) {
+		parameters.addParameter(name, param);
+		return this;
+	}
+
+	public void parametrizeByHandler() {
+		if (getCreatingHandler() != null) parameters.setHandler(getCreatingHandler());
+	}
+
+	public void setTemplateName(String name) {
+		parameters.setTemplateName(name);
+	}
+
+}

Added: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/ParametrizeHtmlProducer.aj
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/ParametrizeHtmlProducer.aj?rev=695910&view=auto
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/ParametrizeHtmlProducer.aj (added)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/ParametrizeHtmlProducer.aj Tue Sep 16 07:34:49 2008
@@ -0,0 +1,189 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.magma.website.producers;
+
+import org.apache.magma.conversion.Converter;
+import org.apache.magma.conversion.Converters;
+import org.apache.magma.website.WebHandler;
+import org.apache.magma.website.Producer;
+import java.beans.Introspector;
+import org.aspectj.lang.reflect.MethodSignature;
+import java.util.Stack;
+import java.lang.reflect.Method;
+
+
+public privileged aspect ParametrizeHtmlProducer {
+
+	private ThreadLocal<Stack<Object[]>> params = new ThreadLocal<Stack<Object[]>>();
+	private ThreadLocal<Stack<WebHandler>> handlers = new ThreadLocal<Stack<WebHandler>>();
+	private ThreadLocal<Stack<Method>> methods = new ThreadLocal<Stack<Method>>();
+	
+	private boolean Producer.inited = false;
+	private boolean ParametrizableProducer.paramsinited = false;
+	 	
+	pointcut doMethod() : execution(Producer+ WebHandler+.do*(..)) || call(Producer+ WebHandler+.do*(..));
+
+	pointcut parametrizableProducerCreation(ParametrizableProducer p) : execution(ParametrizableProducer+.new(..)) && target(p);
+	
+	pointcut producerCreation(Producer p) : execution(Producer+.new(..)) && target(p);
+	
+	before() : doMethod() {
+		Stack<Object[]> stack = params.get();
+		if (stack == null) {
+			stack = new Stack<Object[]>();
+			params.set(stack);
+		}
+		stack.push(thisJoinPoint.getArgs());
+		
+		Stack<WebHandler> handler = handlers.get();
+		if (handler == null) {
+			handler = new Stack<WebHandler>();
+			handlers.set(handler);
+		}
+		Object trg = thisJoinPoint.getThis();
+		if (!(trg instanceof WebHandler)) {
+			trg = thisJoinPoint.getTarget();
+		}
+		if (!(trg instanceof WebHandler)) {
+			handler.push(null);
+		} else {
+			handler.push((WebHandler)trg);
+		}			
+		
+		Stack<Method> name = methods.get();
+		if (name == null) {
+			name = new Stack<Method>();
+			methods.set(name);
+		}
+		name.push(((MethodSignature)thisJoinPoint.getSignature()).getMethod());
+	}
+	
+	after() : doMethod() {
+		Stack<Object[]> stack = params.get();
+		if (stack != null && stack.size() != 0) {
+			stack.pop();
+		}
+		Stack<WebHandler> handler = handlers.get();
+		if (handler != null && handler.size() != 0) {
+			handler.pop();
+		}
+		Stack<Method> name = methods.get();
+		if (name != null && name.size() != 0) {
+			name.pop();
+		}
+	}
+	
+	after(Producer producer) : producerCreation(producer) {
+		if (producer.inited) return;
+		producer.inited = true;
+		Stack<WebHandler> handler = handlers.get();
+		if (handler != null && handler.size() != 0) {
+			WebHandler h = handler.peek();
+			producer.setCreatingHandler(h);
+			producer.setBasePath(h.getRelativePath());
+		} 
+		
+		
+		Method acmethod = null;
+		Stack<Method> method = methods.get();
+		if (method != null && method.size() != 0) {
+			acmethod = method.peek();
+		}
+		if (acmethod != null) {
+			producer.setCreatingMethod(acmethod);
+			String methodName = acmethod.getName();
+			boolean valid = true;
+			if (methodName.startsWith("do")) {
+				methodName = methodName.substring(2);
+				methodName = Introspector.decapitalize(methodName);
+				Stack<Object[]> stack = params.get();
+				if (stack != null && stack.size() != 0) {
+					Object[] params = stack.peek();
+					for (Object object : params) {
+						String rep = "";
+						if (object != null) {
+							Converter converter = Converters.getConverterFor(object.getClass());
+							if (converter != null) {
+								try {
+									rep = converter.toString(object);
+								} catch (Throwable e) {
+									valid = false;
+									break;
+								}
+							} else {
+								valid = false;
+								break;
+							}
+						}
+						methodName += "-" + rep; 
+					}
+				}
+				if (valid) {
+					String parentPath = producer.getBasePath();
+					if (parentPath == null) {
+						valid = false;
+					} else {
+						methodName = parentPath + methodName;
+					}
+				}
+				if (valid) {
+					producer.setCompletePath(methodName);
+				} else {
+					producer.setCompletePath(null);
+				}
+			}
+		}
+	}
+	
+	after(ParametrizableProducer producer) : parametrizableProducerCreation(producer) {
+		if (producer.paramsinited) return;
+		producer.paramsinited = true;
+		Stack<Object[]> stack = params.get();
+		if (stack != null && stack.size() != 0) {
+			Object[] params = stack.peek();
+			for (Object object : params) {
+				producer.addParameter(object);
+			}
+		}
+		
+		producer.parametrizeByHandler();
+		
+		/*
+		Stack<WebHandler> handler = handlers.get();
+		if (handler != null && handler.size() != 0) {
+			WebHandler h = handler.peek();
+			producer.setCreatingHandler(h);
+		} 
+		*/
+		
+		
+		Method acmethod = null;
+		Stack<Method> method = methods.get();
+		if (method != null && method.size() != 0) {
+			acmethod = method.peek();
+		}
+		if (acmethod != null) {
+			String methodName = acmethod.getName();
+			if (methodName.startsWith("do")) {
+				methodName = methodName.substring(2);
+				methodName = Introspector.decapitalize(methodName);
+			}
+			producer.setTemplateName(methodName);
+		}		
+	}
+}
+

Added: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/ProducerParameters.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/ProducerParameters.java?rev=695910&view=auto
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/ProducerParameters.java (added)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/ProducerParameters.java Tue Sep 16 07:34:49 2008
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.magma.website.producers;
+
+import org.apache.magma.beans.BeanData;
+import org.apache.magma.beans.BeanHandler;
+import org.apache.magma.beans.PropertyInfo;
+import org.apache.magma.website.WebHandler;
+
+import java.beans.Introspector;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+public class ProducerParameters {
+
+	private Map<String, Object> parameters = new HashMap<String, Object>();
+	private String templateName = null;
+	
+	public void addParameter(Object o) {
+		if (o == null) return;
+		String name = o.getClass().getSimpleName();
+		name = Introspector.decapitalize(name);
+		Object prev = parameters.get(name);
+		if (prev == null) {
+			parameters.put(name, o);
+		} else {
+			int i = 1;
+			while (prev != null) {
+				i++;
+				prev = parameters.get(name + i);
+			}
+			parameters.put(name + i, o);
+		}
+	}
+	
+	public void addParameter(String name, Object o) {
+		parameters.put(name, o);
+	}
+	
+	public void setHandler(WebHandler h) {
+		BeanHandler bh = h.handler();
+		BeanData bd = h.beanData();
+		
+		Set<String> names = bd.getPropertyNames();
+		for (String name : names) {
+			PropertyInfo pi = bd.getProperty(name);
+			if (pi.isReadable()) {
+				Object value = bh.getValue(name);
+				parameters.put(name, value);
+			}
+		}
+		
+	}	
+	
+	
+	public Map<String, Object> getParameters() {
+		return Collections.unmodifiableMap(parameters);
+	}
+
+	public String getTemplateName() {
+		return templateName;
+	}
+
+	public void setTemplateName(String templateName) {
+		this.templateName = templateName;
+	}
+
+}

Added: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/StringHtmlProducer.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/StringHtmlProducer.java?rev=695910&view=auto
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/StringHtmlProducer.java (added)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/StringHtmlProducer.java Tue Sep 16 07:34:49 2008
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.magma.website.producers;
+
+import org.apache.magma.website.HtmlProducer;
+
+import java.io.OutputStream;
+
+public class StringHtmlProducer extends HtmlProducer {
+
+	private String heads = null;
+	private String body = null;
+	
+	public StringHtmlProducer() {
+		
+	}
+	
+	public StringHtmlProducer(String body) {
+		this.body = body;
+	}
+	
+	public StringHtmlProducer(String head, String body) {
+		this.heads = head;
+		this.body = body;
+	}
+	
+	
+	@Override
+	public void head(OutputStream stream) {
+		if (heads != null) stream.write(heads.getBytes("UTF-8"));
+	}
+
+	@Override
+	public void produce(OutputStream stream) {
+		if (body != null) stream.write(body.getBytes("UTF-8"));
+	}
+
+	public String getHeads() {
+		return heads;
+	}
+
+	public void setHeads(String heads) {
+		this.heads = heads;
+	}
+
+	public String getBody() {
+		return body;
+	}
+
+	public void setBody(String body) {
+		this.body = body;
+	}
+
+}

Added: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/XmlProducer.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/XmlProducer.java?rev=695910&view=auto
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/XmlProducer.java (added)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/producers/XmlProducer.java Tue Sep 16 07:34:49 2008
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.magma.website.producers;
+
+import org.apache.magma.basics.MagmaException;
+import org.apache.magma.website.Producer;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.nio.charset.Charset;
+
+import com.thoughtworks.xstream.XStream;
+
+public class XmlProducer extends Producer {
+
+	private Object object;
+	protected XStream xstream;
+
+	public XmlProducer(Object object) {
+		this.object = object;
+		this.xstream = new XStream();
+	}
+
+	@Override
+	public String getMimeType() {
+		return "text/xml";
+	}
+
+	public void produce(OutputStream stream) {
+		if (this.object == null)
+			throw new MagmaException("Cannot find any object to serialize");
+
+		OutputStreamWriter writer = new OutputStreamWriter(stream, Charset
+				.forName("UTF-8"));
+
+		try {
+			this.xstream.toXML(this.object, writer);
+			writer.flush();
+		} catch (IOException e) {
+			throw new MagmaException(e, "Error rendering XML");
+		}
+	}
+
+	public void head(OutputStream stream) {
+	}
+
+}

Added: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/templating/DefaultTemplate.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/templating/DefaultTemplate.java?rev=695910&view=auto
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/templating/DefaultTemplate.java (added)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/templating/DefaultTemplate.java Tue Sep 16 07:34:49 2008
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.magma.website.templating;
+
+
+public class DefaultTemplate extends Template {
+
+	public DefaultTemplate() {
+	}
+	
+	public void layoutTop() {
+		
+	}
+	
+	public void layoutHeader() {
+		
+	}
+	
+	public void layoutLeft() {
+		
+	}
+	
+	public void layoutRight() {
+		
+	}
+	
+	public void layoutBottom() {
+		
+	}
+	
+	public void layoutFooter() {
+		
+	}
+	
+}



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