Browse files

release

  • Loading branch information...
1 parent 4b1dd29 commit 8c33c5352731df35b5084292f973a2cecca970d6 @naltatis naltatis committed May 2, 2012
View
4 .gitignore
@@ -0,0 +1,4 @@
+target/
+.classpath
+.project
+.settings
View
1 README
@@ -1 +0,0 @@
-.. coming very very soon.
View
69 README.md
@@ -0,0 +1,69 @@
+[![Build Status](https://secure.travis-ci.org/neuland/spring-jade4j.png?branch=master)](http://travis-ci.org/neuland/spring-jade4j)
+
+# A Spring Integration for Jade4J
+
+See [neuland/jade4j](https://github.com/neuland/jade4j) for more information.
+
+## Bean Declarations
+
+applicationContext.xml
+
+```xml
+<bean id="templateLoader" class="de.neuland.jade4j.spring.template.SpringTemplateLoader">
+ <property name="basePath" value="classpath:/WEB-INF/pages/" />
+</bean>
+
+<bean id="jadeConfiguration" class="de.neuland.jade4j.JadeConfiguration">
+ <property name="prettyPrint" value="false" />
+ <property name="templateLoader" ref="templateLoader" />
+</bean>
+
+<bean id="viewResolver" class="de.neuland.jade4j.spring.view.JadeViewResolver">
+ <property name="configuration" ref="jadeConfiguration" />
+ <!-- rendering nice html formatted error pages for development -->
+ <property name="renderExceptions" value="true" />
+</bean>
+```
+
+
+## Usage
+
+### via Maven
+
+We are using Github for Maven hosting. Just add this repository ...
+
+```xml
+<repositories>
+ <repository>
+ <id>spring-jade4j-releases</id>
+ <url>https://github.com/neuland/spring-jade4j/raw/master/releases</url>
+ </repository>
+</repositories>
+```
+
+... and dependency definitions to your `pom.xml`.
+
+```xml
+<dependency>
+ <groupId>de.neuland</groupId>
+ <artifactId>spring-jade4j</artifactId>
+ <version>0.2.0</version>
+</dependency>
+```
+
+## Author
+
+- Stefan Kuper / [planetk](https://github.com/planetk)
+- Michael Geers / [naltatis](https://github.com/naltatis)
+
+## License
+
+The MIT License
+
+Copyright (C) 2012 [neuland Büro für Informatik](http://www.neuland-bfi.de/), Bremen, Germany
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
2 mvn-release.sh
@@ -0,0 +1,2 @@
+#!/bin/bash
+mvn -DaltDeploymentRepository=snapshot-repo::default::file:releases clean deploy
View
2 mvn-snapshot.sh
@@ -0,0 +1,2 @@
+#!/bin/bash
+mvn -DaltDeploymentRepository=snapshot-repo::default::file:snapshots clean deploy
View
93 pom.xml
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>de.neuland</groupId>
+ <artifactId>spring-jade4j</artifactId>
+ <version>0.2.0</version>
+ <name>Spring interface to the Jade compiler</name>
+ <properties>
+ <org.springframework.version>3.0.5.RELEASE</org.springframework.version>
+ <servlet-api-version>2.5</servlet-api-version>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <repositories>
+ <repository>
+ <id>jade4j-releases</id>
+ <url>https://github.com/neuland/jade4j/raw/master/releases</url>
+ </repository>
+ </repositories>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>${servlet-api-version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>de.neuland</groupId>
+ <artifactId>jade4j</artifactId>
+ <version>0.2.3</version>
+ </dependency>
+
+ <!-- Spring framework -->
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-core</artifactId>
+ <version>${org.springframework.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ <version>${org.springframework.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-webmvc</artifactId>
+ <version>${org.springframework.version}</version>
+ </dependency>
+
+ <!-- Other dependencies -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.6.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.6.0</version>
+ </dependency>
+
+ <!-- Test -->
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <version>${org.springframework.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.10</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
View
73 src/main/java/de/neuland/jade4j/spring/template/SpringTemplateLoader.java
@@ -0,0 +1,73 @@
+package de.neuland.jade4j.spring.template;
+
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+
+import org.springframework.core.io.DefaultResourceLoader;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.ResourceLoader;
+
+import de.neuland.jade4j.template.TemplateLoader;
+
+public class SpringTemplateLoader implements TemplateLoader {
+
+ private final ResourceLoader resourceLoader;
+
+ private String encoding = "UTF-8";
+ private String suffix = ".jade";
+ private String basePath = "";
+
+ public SpringTemplateLoader() {
+ this.resourceLoader = new DefaultResourceLoader();
+ }
+
+ @Override
+ public long getLastModified(String name) {
+ Resource resource = getResource(name);
+ try {
+ return resource.lastModified();
+ } catch (IOException ex) {
+ return -1;
+ }
+ }
+
+ @Override
+ public Reader getReader(String name) throws IOException {
+ Resource resource = getResource(name);
+ return new InputStreamReader(resource.getInputStream(), encoding);
+ }
+
+ private Resource getResource(String name) {
+ String resourceName = basePath + name;
+ if (!resourceName.endsWith(suffix)) {
+ resourceName += suffix;
+ }
+ return this.resourceLoader.getResource(resourceName);
+ }
+
+ public String getEncoding() {
+ return encoding;
+ }
+
+ public void setEncoding(String encoding) {
+ this.encoding = encoding;
+ }
+
+ public String getSuffix() {
+ return suffix;
+ }
+
+ public void setSuffix(String suffix) {
+ this.suffix = suffix;
+ }
+
+ public String getBasePath() {
+ return basePath;
+ }
+
+ public void setBasePath(String basePath) {
+ this.basePath = basePath;
+ }
+
+}
View
93 src/main/java/de/neuland/jade4j/spring/view/JadeView.java
@@ -0,0 +1,93 @@
+package de.neuland.jade4j.spring.view;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.springframework.web.servlet.view.AbstractUrlBasedView;
+
+import de.neuland.jade4j.JadeConfiguration;
+import de.neuland.jade4j.exceptions.JadeCompilerException;
+import de.neuland.jade4j.exceptions.JadeException;
+import de.neuland.jade4j.template.JadeTemplate;
+
+public class JadeView extends AbstractUrlBasedView {
+
+ private String encoding;
+ private JadeConfiguration configuration;
+ private boolean renderExceptions = false;
+
+ @Override
+ protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response)
+ throws Exception {
+ logger.trace("Rendering Jade template [" + getUrl() + "] in JadeView '" + getBeanName() + "'");
+
+ PrintWriter responseWriter = response.getWriter();
+
+ if (renderExceptions) {
+ Writer writer = new StringWriter();
+ try {
+ configuration.renderTemplate(getTemplate(), model, writer);
+ responseWriter.write(writer.toString());
+ } catch (JadeException e) {
+ String htmlString = e.toHtmlString();
+ responseWriter.write(htmlString);
+ } catch (IOException e) {
+ responseWriter.write("<pre>could not find template: " + getUrl() + "\n");
+ e.printStackTrace(responseWriter);
+ responseWriter.write("</pre>");
+ }
+ } else {
+ try {
+ configuration.renderTemplate(getTemplate(), model, responseWriter);
+ } catch (Throwable e) {
+ logger.error("could not render template [" + getUrl() + "]\n", e);
+ }
+ }
+ }
+
+ protected JadeTemplate getTemplate() throws IOException, JadeException {
+ return configuration.getTemplate(getUrl());
+ }
+
+ @Override
+ public boolean checkResource(Locale locale) throws Exception {
+ return configuration.templateExists(getUrl());
+ }
+
+ protected void processTemplate(JadeTemplate template, Map<String, Object> model, HttpServletResponse response) throws IOException {
+ try {
+ configuration.renderTemplate(template, model, response.getWriter());
+ } catch (JadeCompilerException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /* Configuration Handling */
+ public JadeConfiguration getConfiguration() {
+ return configuration;
+ }
+
+ public void setConfiguration(JadeConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
+ public String getEncoding() {
+ return encoding;
+ }
+
+ public void setEncoding(String encoding) {
+ this.encoding = encoding;
+ }
+
+ public void setRenderExceptions(boolean renderExceptions) {
+ this.renderExceptions = renderExceptions;
+ }
+
+}
View
39 src/main/java/de/neuland/jade4j/spring/view/JadeViewResolver.java
@@ -0,0 +1,39 @@
+package de.neuland.jade4j.spring.view;
+
+import org.springframework.web.servlet.view.AbstractUrlBasedView;
+import org.springframework.web.servlet.view.UrlBasedViewResolver;
+
+import de.neuland.jade4j.JadeConfiguration;
+
+public class JadeViewResolver extends UrlBasedViewResolver {
+
+ private JadeConfiguration configuration;
+ private boolean renderExceptions = false;
+
+ public JadeViewResolver() {
+ setViewClass(requiredViewClass());
+ }
+
+ @Override
+ @SuppressWarnings("rawtypes")
+ protected Class requiredViewClass() {
+ return JadeView.class;
+ }
+
+ @Override
+ protected AbstractUrlBasedView buildView(String viewName) throws Exception {
+ JadeView view = (JadeView) super.buildView(viewName);
+ view.setConfiguration(this.configuration);
+ view.setRenderExceptions(renderExceptions);
+ return view;
+ }
+
+ public void setConfiguration(JadeConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
+ public void setRenderExceptions(boolean renderExceptions) {
+ this.renderExceptions = renderExceptions;
+ }
+
+}
View
161 src/main/resources/log4j.dtd
@@ -0,0 +1,161 @@
+<!-- Authors: Chris Taylor, Ceki Gulcu. -->
+
+<!-- Version: 1.2 -->
+
+<!-- A configuration element consists of optional renderer
+elements,appender elements, categories and an optional root
+element. -->
+
+<!ELEMENT log4j:configuration (renderer*, appender*,(category|logger)*,root?,
+ categoryFactory?)>
+
+<!-- The "threshold" attribute takes a level value such that all -->
+<!-- logging statements with a level equal or below this value are -->
+<!-- disabled. -->
+
+<!-- Setting the "debug" or "configDebug" attributes enable the printing -->
+<!-- of internal log4j logging statements. -->
+
+<!-- By default, debug attribute is "null", meaning that we not touch -->
+<!-- internal log4j logging settings. -->
+
+
+<!ATTLIST log4j:configuration
+ xmlns:log4j CDATA #FIXED "http://jakarta.apache.org/log4j/"
+ threshold (all|debug|info|warn|error|fatal|off|null) "null"
+ debug (true|false|null) "null"
+>
+
+<!-- renderer elements allow the user to customize the conversion of -->
+<!-- message objects to String. -->
+
+<!ELEMENT renderer EMPTY>
+<!ATTLIST renderer
+ renderedClass CDATA #REQUIRED
+ renderingClass CDATA #REQUIRED
+>
+
+<!-- Appenders must have a name and a class. -->
+<!-- Appenders may contain an error handler, a layout, optional parameters -->
+<!-- and filters. They may also reference (or include) other appenders. -->
+<!ELEMENT appender (errorHandler?, param*, layout?, filter*, appender-ref*)>
+<!ATTLIST appender
+ name ID #REQUIRED
+ class CDATA #REQUIRED
+>
+
+<!ELEMENT layout (param*)>
+<!ATTLIST layout
+ class CDATA #REQUIRED
+>
+
+<!ELEMENT filter (param*)>
+<!ATTLIST filter
+ class CDATA #REQUIRED
+>
+
+<!-- ErrorHandlers can be of any class. They can admit any number of -->
+<!-- parameters. -->
+
+<!ELEMENT errorHandler (param*, root-ref?, logger-ref*, appender-ref?)>
+<!ATTLIST errorHandler
+ class CDATA #REQUIRED
+>
+
+<!ELEMENT root-ref EMPTY>
+
+<!ELEMENT logger-ref EMPTY>
+<!ATTLIST logger-ref
+ ref IDREF #REQUIRED
+>
+
+<!ELEMENT param EMPTY>
+<!ATTLIST param
+ name CDATA #REQUIRED
+ value CDATA #REQUIRED
+>
+
+
+<!-- The priority class is org.apache.log4j.Level by default -->
+<!ELEMENT priority (param*)>
+<!ATTLIST priority
+ class CDATA #IMPLIED
+ value CDATA #REQUIRED
+>
+
+<!-- The level class is org.apache.log4j.Level by default -->
+<!ELEMENT level (param*)>
+<!ATTLIST level
+ class CDATA #IMPLIED
+ value CDATA #REQUIRED
+>
+
+
+<!-- If no level element is specified, then the configurator MUST not -->
+<!-- touch the level of the named category. -->
+<!ELEMENT category (param*,(priority|level)?,appender-ref*)>
+<!ATTLIST category
+ class CDATA #IMPLIED
+ name CDATA #REQUIRED
+ additivity (true|false) "true"
+>
+
+<!-- If no level element is specified, then the configurator MUST not -->
+<!-- touch the level of the named logger. -->
+<!ELEMENT logger (level?,appender-ref*)>
+<!ATTLIST logger
+ name ID #REQUIRED
+ additivity (true|false) "true"
+>
+
+
+<!ELEMENT categoryFactory (param*)>
+<!ATTLIST categoryFactory
+ class CDATA #REQUIRED>
+
+<!ELEMENT appender-ref EMPTY>
+<!ATTLIST appender-ref
+ ref IDREF #REQUIRED
+>
+
+<!-- If no priority element is specified, then the configurator MUST not -->
+<!-- touch the priority of root. -->
+<!-- The root category always exists and cannot be subclassed. -->
+<!ELEMENT root (param*, (priority|level)?, appender-ref*)>
+
+
+<!-- ==================================================================== -->
+<!-- A logging event -->
+<!-- ==================================================================== -->
+<!ELEMENT log4j:eventSet (log4j:event*)>
+<!ATTLIST log4j:eventSet
+ xmlns:log4j CDATA #FIXED "http://jakarta.apache.org/log4j/"
+ version (1.1|1.2) "1.2"
+ includesLocationInfo (true|false) "true"
+>
+
+
+
+<!ELEMENT log4j:event (log4j:message, log4j:NDC?, log4j:throwable?,
+ log4j:locationInfo?) >
+
+<!-- The timestamp format is application dependent. -->
+<!ATTLIST log4j:event
+ logger CDATA #REQUIRED
+ level CDATA #REQUIRED
+ thread CDATA #REQUIRED
+ timestamp CDATA #REQUIRED
+>
+
+<!ELEMENT log4j:message (#PCDATA)>
+<!ELEMENT log4j:NDC (#PCDATA)>
+
+<!ELEMENT log4j:throwable (#PCDATA)>
+
+<!ELEMENT log4j:locationInfo EMPTY>
+<!ATTLIST log4j:locationInfo
+ class CDATA #REQUIRED
+ method CDATA #REQUIRED
+ file CDATA #REQUIRED
+ line CDATA #REQUIRED
+>
View
26 src/main/resources/log4j.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
+ <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="[%d] %-5p - %C{1}.%M(%L) | %m%n" />
+ </layout>
+ </appender>
+
+ <logger name="de.neuland.springjade">
+ <level value="TRACE" />
+ </logger>
+
+ <!-- Log JDBC bind parameter runtime arguments -->
+ <!--
+ <logger name="org.hibernate.type">
+ <level value="TRACE" />
+ </logger>
+ -->
+
+ <root>
+ <level value="TRACE" />
+ <appender-ref ref="CONSOLE" />
+ </root>
+</log4j:configuration>

0 comments on commit 8c33c53

Please sign in to comment.