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:38:22 UTC

svn commit: r695917 - in /labs/magma/trunk/website-velocity: ./ 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/website/ve...

Author: simoneg
Date: Tue Sep 16 07:38:21 2008
New Revision: 695917

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

Added:
    labs/magma/trunk/website-velocity/pom.xml
    labs/magma/trunk/website-velocity/src/
    labs/magma/trunk/website-velocity/src/main/
    labs/magma/trunk/website-velocity/src/main/java/
    labs/magma/trunk/website-velocity/src/main/java/org/
    labs/magma/trunk/website-velocity/src/main/java/org/apache/
    labs/magma/trunk/website-velocity/src/main/java/org/apache/magma/
    labs/magma/trunk/website-velocity/src/main/java/org/apache/magma/website/
    labs/magma/trunk/website-velocity/src/main/java/org/apache/magma/website/velocity/
    labs/magma/trunk/website-velocity/src/main/java/org/apache/magma/website/velocity/VelocityHtmlProducer.java
    labs/magma/trunk/website-velocity/src/main/resources/
    labs/magma/trunk/website-velocity/src/main/resources/META-INF/
    labs/magma/trunk/website-velocity/src/main/resources/META-INF/magma.default.properties
    labs/magma/trunk/website-velocity/src/main/resources/META-INF/magma.devel.default.properties

Added: labs/magma/trunk/website-velocity/pom.xml
URL: http://svn.apache.org/viewvc/labs/magma/trunk/website-velocity/pom.xml?rev=695917&view=auto
==============================================================================
--- labs/magma/trunk/website-velocity/pom.xml (added)
+++ labs/magma/trunk/website-velocity/pom.xml Tue Sep 16 07:38:21 2008
@@ -0,0 +1,61 @@
+<?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 xmlns="http://maven.apache.org/POM/4.0.0"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+	<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>website-velocity</artifactId>
+	<name>Magma Website Velocity based templating</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>org.apache.magma</groupId>
+			<artifactId>foundation-website</artifactId>
+			<version>0.0.1-SNAPSHOT</version>
+		</dependency>
+		<dependency>
+			<groupId>javax.servlet</groupId>
+			<artifactId>servlet-api</artifactId>
+			<version>2.5</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.velocity</groupId>
+			<artifactId>velocity</artifactId>
+			<version>1.5</version>
+		</dependency>
+	</dependencies>
+</project>

Added: labs/magma/trunk/website-velocity/src/main/java/org/apache/magma/website/velocity/VelocityHtmlProducer.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/website-velocity/src/main/java/org/apache/magma/website/velocity/VelocityHtmlProducer.java?rev=695917&view=auto
==============================================================================
--- labs/magma/trunk/website-velocity/src/main/java/org/apache/magma/website/velocity/VelocityHtmlProducer.java (added)
+++ labs/magma/trunk/website-velocity/src/main/java/org/apache/magma/website/velocity/VelocityHtmlProducer.java Tue Sep 16 07:38:21 2008
@@ -0,0 +1,141 @@
+/*
+ * 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.velocity;
+
+import org.apache.magma.basics.MagmaException;
+import org.apache.magma.settings.Settings;
+import org.apache.magma.website.producers.ParametrizableHtmlProducerBase;
+
+import java.beans.Introspector;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.net.URL;
+import java.nio.charset.Charset;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.Velocity;
+
+public class VelocityHtmlProducer extends ParametrizableHtmlProducerBase {
+
+	{
+		try {
+			Properties prp = new Properties();
+			prp.putAll(Settings.getAll());
+			Velocity.init(prp);
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+	}
+	
+	public VelocityHtmlProducer(Object... params) {
+		for (Object object : params) {
+			addParameter(object);
+		}
+	}
+	
+	public VelocityHtmlProducer(String template) {
+		this.template = template;
+	}
+	
+	private String template;
+
+	public void produce(OutputStream stream) {
+		String tplname = this.template;
+		if (tplname == null && this.parameters != null) {
+			tplname = parameters.getTemplateName();
+		}
+		if (tplname == null) throw new MagmaException("Cannot find any template");
+		
+		if (!tplname.endsWith(".vm")) tplname += ".vm";
+		
+		
+		sendTemplate(stream, tplname);
+	}
+
+	private boolean sendTemplateIfExisting(OutputStream stream, String tplname) {
+		if (parameters != null && getCreatingHandler() != null) {
+			URL resource = getCreatingHandler().getClass().getResource(tplname);
+			if (resource != null) {
+				sendTemplate(stream, tplname);
+				return true;
+			}
+		}
+		if (Velocity.resourceExists(tplname)) {
+			sendTemplate(stream, tplname);
+			return true;
+		}
+		return false;
+	}
+	
+	private void sendTemplate(OutputStream stream, String tplname) {
+		VelocityContext ctx = new VelocityContext();
+		if (parameters != null) {
+			Map<String, Object> map = parameters.getParameters();
+			for (Map.Entry<String, Object> entry : map.entrySet()) {
+				ctx.put(entry.getKey(), entry.getValue());
+			}
+		}
+		
+		OutputStreamWriter writer = new OutputStreamWriter(stream, Charset.forName("UTF-8"));
+		
+		if (parameters != null && getCreatingHandler() != null) {
+			InputStream inputStream = getCreatingHandler().getClass().getResourceAsStream(tplname);
+			if (inputStream != null) {
+				InputStreamReader inreader = new InputStreamReader(inputStream, Charset.forName("UTF-8"));
+				try {
+					Velocity.evaluate(ctx, writer, tplname, inreader);
+					writer.flush();
+					return;
+				} catch (Throwable e) {
+					throw new MagmaException(e, "Error executing template {0} loaded from resource {1}", tplname, getCreatingHandler().getClass().getResource(tplname));
+				}
+			}
+		}
+		
+		try {
+			Velocity.mergeTemplate(tplname, "UTF-8", ctx, writer);
+			writer.flush();
+		} catch (Exception e) {
+			throw new MagmaException(e, "Error executing velocity template {0} loaded by default velocity loader", tplname);
+		}
+	}
+
+	public void head(OutputStream stream) {
+		String tplname = this.template;
+		if (tplname == null && this.parameters != null) {
+			tplname = parameters.getTemplateName();
+		}
+		
+		sendTemplateIfExisting(stream, "head.vm");
+		if (this.getCreatingHandler() != null) {
+			String handlername = Introspector.decapitalize(this.getCreatingHandler().getClass().getSimpleName());
+			sendTemplateIfExisting(stream, handlername + "-head.vm");
+		}
+		if (tplname != null) {
+			if (tplname.endsWith(".vm")) {
+				tplname = tplname.substring(0,tplname.length() - 3);
+			}
+			tplname += "-head.vm";
+			sendTemplateIfExisting(stream, tplname);
+		}
+	}
+
+}

Added: labs/magma/trunk/website-velocity/src/main/resources/META-INF/magma.default.properties
URL: http://svn.apache.org/viewvc/labs/magma/trunk/website-velocity/src/main/resources/META-INF/magma.default.properties?rev=695917&view=auto
==============================================================================
--- labs/magma/trunk/website-velocity/src/main/resources/META-INF/magma.default.properties (added)
+++ labs/magma/trunk/website-velocity/src/main/resources/META-INF/magma.default.properties Tue Sep 16 07:38:21 2008
@@ -0,0 +1,16 @@
+#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.
+input.encoding = UTF-8
+output.encoding = UTF-8

Added: labs/magma/trunk/website-velocity/src/main/resources/META-INF/magma.devel.default.properties
URL: http://svn.apache.org/viewvc/labs/magma/trunk/website-velocity/src/main/resources/META-INF/magma.devel.default.properties?rev=695917&view=auto
==============================================================================
--- labs/magma/trunk/website-velocity/src/main/resources/META-INF/magma.devel.default.properties (added)
+++ labs/magma/trunk/website-velocity/src/main/resources/META-INF/magma.devel.default.properties Tue Sep 16 07:38:21 2008
@@ -0,0 +1,17 @@
+#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.
+velocimacro.library.autoreload = true
+velocimacro.permissions.allow.inline.local.scope = true
+resource.manager.defaultcache.size = 0



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