You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by re...@apache.org on 2012/09/23 19:36:01 UTC

svn commit: r1389101 - in /stanbol/trunk/commons: ./ ldtemplaterenderer/ ldtemplaterenderer/src/ ldtemplaterenderer/src/main/ ldtemplaterenderer/src/main/java/ ldtemplaterenderer/src/main/java/at/ ldtemplaterenderer/src/main/java/at/newmedialab/ ldtemp...

Author: reto
Date: Sun Sep 23 17:35:59 2012
New Revision: 1389101

URL: http://svn.apache.org/viewvc?rev=1389101&view=rev
Log:
STANBOL-749: added service to render GraphNodes using the LDPath Template language

Added:
    stanbol/trunk/commons/ldtemplaterenderer/   (with props)
    stanbol/trunk/commons/ldtemplaterenderer/README.md
    stanbol/trunk/commons/ldtemplaterenderer/pom.xml
    stanbol/trunk/commons/ldtemplaterenderer/src/
    stanbol/trunk/commons/ldtemplaterenderer/src/main/
    stanbol/trunk/commons/ldtemplaterenderer/src/main/java/
    stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/
    stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/
    stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/
    stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/
    stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/engine/
    stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/engine/LDPathDirective.java
    stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/engine/LDPathMethod.java
    stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/engine/NamespaceDirective.java
    stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/engine/TemplateEngine.java
    stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/
    stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/freemarker/
    stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/freemarker/TemplateNodeModel.java
    stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/freemarker/TemplateStackModel.java
    stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/freemarker/TemplateWrapperModel.java
    stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/transformers/
    stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/transformers/TemplateBooleanTransformer.java
    stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/transformers/TemplateDateTransformer.java
    stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/transformers/TemplateDoubleTransformer.java
    stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/transformers/TemplateFloatTransformer.java
    stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/transformers/TemplateIntegerTransformer.java
    stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/transformers/TemplateLongTransformer.java
    stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/transformers/TemplateScalarTransformer.java
    stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/util/
    stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/util/FormatUtil.java
    stanbol/trunk/commons/ldtemplaterenderer/src/main/java/org/
    stanbol/trunk/commons/ldtemplaterenderer/src/main/java/org/apache/
    stanbol/trunk/commons/ldtemplaterenderer/src/main/java/org/apache/stanbol/
    stanbol/trunk/commons/ldtemplaterenderer/src/main/java/org/apache/stanbol/commons/
    stanbol/trunk/commons/ldtemplaterenderer/src/main/java/org/apache/stanbol/commons/ldpathtemplate/
    stanbol/trunk/commons/ldtemplaterenderer/src/main/java/org/apache/stanbol/commons/ldpathtemplate/LdRenderer.java
Modified:
    stanbol/trunk/commons/pom.xml

Propchange: stanbol/trunk/commons/ldtemplaterenderer/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sun Sep 23 17:35:59 2012
@@ -0,0 +1,5 @@
+.project
+.gitignore
+.classpath
+target
+.settings

Added: stanbol/trunk/commons/ldtemplaterenderer/README.md
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/ldtemplaterenderer/README.md?rev=1389101&view=auto
==============================================================================
--- stanbol/trunk/commons/ldtemplaterenderer/README.md (added)
+++ stanbol/trunk/commons/ldtemplaterenderer/README.md Sun Sep 23 17:35:59 2012
@@ -0,0 +1,4 @@
+LDPath template rendering service
+===========
+
+Provides a service to render GraphNodes using an LDPath template

Added: stanbol/trunk/commons/ldtemplaterenderer/pom.xml
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/ldtemplaterenderer/pom.xml?rev=1389101&view=auto
==============================================================================
--- stanbol/trunk/commons/ldtemplaterenderer/pom.xml (added)
+++ stanbol/trunk/commons/ldtemplaterenderer/pom.xml Sun Sep 23 17:35:59 2012
@@ -0,0 +1,140 @@
+<?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.stanbol</groupId>
+    <artifactId>stanbol-parent</artifactId>
+    <version>2-incubating-SNAPSHOT</version>
+    <relativePath>../../parent</relativePath>
+  </parent>
+
+  <groupId>org.apache.stanbol</groupId>
+  <artifactId>org.apache.stanbol.commons.ldpathtemplate</artifactId>
+  <version>0.10.0-incubating-SNAPSHOT</version>
+  <packaging>bundle</packaging>
+
+  <name>Apache Stanbol LDPath template service</name>
+  <description>A service providing ldpath template redering</description>
+  <scm>
+    <connection>
+      scm:svn:http://svn.apache.org/repos/asf/stanbol/trunk/commons/ldpathtemplate
+    </connection>
+    <developerConnection>
+      scm:svn:https://svn.apache.org/repos/asf/stanbol/trunk/commons/ldpathtemplate
+    </developerConnection>
+    <url>http://incubator.apache.org/stanbol/</url>
+  </scm>
+
+  <build>
+    <!-- make it an OSGi bundle -->
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-scr-plugin</artifactId>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <extensions>true</extensions>
+      </plugin>
+    </plugins>
+  </build>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+    </dependency>
+    <dependency>
+		<groupId>org.apache.clerezza</groupId>
+		<artifactId>rdf.ontologies</artifactId>
+	</dependency>
+	<dependency>
+		<groupId>org.apache.clerezza</groupId>
+		<artifactId>rdf.utils</artifactId>
+	</dependency>
+    <dependency>
+      <groupId>org.apache.felix</groupId>
+      <artifactId>org.apache.felix.webconsole</artifactId>
+      <version>3.1.8</version>
+    </dependency>
+    <dependency>
+		<groupId>org.apache.clerezza</groupId>
+		<artifactId>platform.config</artifactId>
+		<version>0.3-incubating</version>
+	</dependency>
+    
+    <!-- Jersey, servlet and freemarker -->
+    <dependency>
+      <groupId>javax.servlet</groupId>
+      <artifactId>servlet-api</artifactId>
+    </dependency>
+
+    <!-- OSGi tax -->
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.core</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.felix</groupId>
+      <artifactId>org.apache.felix.scr.annotations</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>at.newmedialab.ldpath</groupId>
+      <artifactId>ldpath-core-bundle</artifactId>
+    </dependency>
+    <dependency>
+       <groupId>org.freemarker</groupId>
+       <artifactId>freemarker</artifactId>
+    </dependency>
+    <!-- integrated for now
+    <dependency>
+      <groupId>at.newmedialab.ldpath</groupId>
+      <artifactId>ldpath-template</artifactId>
+	  <version>0.9.3-SNAPSHOT</version>
+	</dependency>
+	-->
+	<dependency>
+      <groupId>org.apache.stanbol</groupId>
+      <artifactId>org.apache.stanbol.commons.ldpath.clerezza</artifactId>
+      <version>0.9.0-incubating</version>
+    </dependency>
+
+  </dependencies>
+
+<!-- 
+  <repositories>
+  	<repository>
+  		<name>ldpath template suff</name>
+  		<id>newmedialab</id>
+  		<snapshots></snapshots>
+  		<url>http://devel.kiwi-project.eu:8080/nexus/content/repositories/snapshots/</url>
+  	</repository>
+  </repositories>
+   -->
+
+</project>

Added: stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/engine/LDPathDirective.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/engine/LDPathDirective.java?rev=1389101&view=auto
==============================================================================
--- stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/engine/LDPathDirective.java (added)
+++ stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/engine/LDPathDirective.java Sun Sep 23 17:35:59 2012
@@ -0,0 +1,202 @@
+/*
+ * Copyright (c) 2011 Salzburg Research.
+ *
+ * Licensed 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 at.newmedialab.ldpath.template.engine;
+
+import at.newmedialab.ldpath.LDPath;
+import at.newmedialab.ldpath.api.backend.RDFBackend;
+import at.newmedialab.ldpath.exception.LDPathParseException;
+import at.newmedialab.ldpath.model.Constants;
+import at.newmedialab.ldpath.template.model.freemarker.TemplateNodeModel;
+import at.newmedialab.ldpath.template.model.freemarker.TemplateStackModel;
+import at.newmedialab.ldpath.template.model.freemarker.TemplateWrapperModel;
+import at.newmedialab.ldpath.template.model.transformers.*;
+import at.newmedialab.ldpath.template.*;
+import at.newmedialab.ldpath.template.util.FormatUtil;
+import freemarker.core.Environment;
+import freemarker.template.*;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * A directive for inserting values retrieved with LDPath. It can be used in several forms:
+ * <p/>
+ * <strong>Value Insertion (without body):</strong><br/>
+ * Allows inserting the value of a path expression. The path expression should specify an XML schema type for the
+ * type conversion. If no type is given, string conversion is assumed. If the expression would return several values,
+ * only the first result is taken.
+ * <p/>
+ * <code>
+ * &lt;@ldpath path="... :: xsd:type">
+ * </code>
+ * <p/>
+ * <strong>Value Iteration (with body):</strong>
+ * Allows iterating over result nodes of a path expression. Further path expressions can be used to select the
+ * values of each result node.
+ * <p/>
+ * <code>
+ * &lt;@ldpath path="..."><br/>
+ *    &nbsp;...<br/>
+ *    &nbsp;&lt;@ldpath path="..."><br/>
+ *    &nbsp;...<br/>
+ * &lt;/@ldpath>
+ * </code>
+ * <p/>
+ * If a loop variable is given, it will be bound to the context node. The context node is also implicitly available
+ * as the variable "context".
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class LDPathDirective<Node> implements TemplateDirectiveModel {
+
+
+    private LDPath<Node>     ldpath;
+    private RDFBackend<Node> backend;
+
+    public LDPathDirective(RDFBackend<Node> backend) {
+        this.ldpath  = new LDPath<Node>(backend);
+        this.backend = backend;
+
+        // register custom freemarker transformers for the parser so we get the results immediately in the freemarker model
+        ldpath.registerTransformer(Constants.NS_XSD + "string", new TemplateScalarTransformer<Node>());
+        ldpath.registerTransformer(Constants.NS_XSD + "decimal", new TemplateLongTransformer<Node>());
+        ldpath.registerTransformer(Constants.NS_XSD + "integer", new TemplateIntegerTransformer<Node>());
+        ldpath.registerTransformer(Constants.NS_XSD + "long", new TemplateLongTransformer<Node>());
+        ldpath.registerTransformer(Constants.NS_XSD + "short", new TemplateIntegerTransformer<Node>());
+        ldpath.registerTransformer(Constants.NS_XSD + "double", new TemplateDoubleTransformer<Node>());
+        ldpath.registerTransformer(Constants.NS_XSD + "float", new TemplateFloatTransformer<Node>());
+        ldpath.registerTransformer(Constants.NS_XSD + "dateTime", new TemplateDateTransformer<Node>(TemplateDateModel.DATETIME));
+        ldpath.registerTransformer(Constants.NS_XSD + "date", new TemplateDateTransformer<Node>(TemplateDateModel.DATE));
+        ldpath.registerTransformer(Constants.NS_XSD + "time", new TemplateDateTransformer<Node>(TemplateDateModel.TIME));
+        ldpath.registerTransformer(Constants.NS_XSD + "boolean", new TemplateBooleanTransformer<Node>());
+        ldpath.registerTransformer(Constants.NS_XSD + "anyURI", new TemplateScalarTransformer<Node>());
+
+    }
+
+    /**
+     * Executes this user-defined directive; called by FreeMarker when the user-defined
+     * directive is called in the template.
+     *
+     * @param env      the current processing environment. Note that you can access
+     *                 the output {@link java.io.Writer Writer} by {@link freemarker.core.Environment#getOut()}.
+     * @param params   the parameters (if any) passed to the directive as a
+     *                 map of key/value pairs where the keys are {@link String}-s and the
+     *                 values are {@link freemarker.template.TemplateModel} instances. This is never
+     *                 <code>null</code>. If you need to convert the template models to POJOs,
+     *                 you can use the utility methods in the {@link freemarker.template.utility.DeepUnwrap} class.
+     * @param loopVars an array that corresponds to the "loop variables", in
+     *                 the order as they appear in the directive call. ("Loop variables" are out-parameters
+     *                 that are available to the nested body of the directive; see in the Manual.)
+     *                 You set the loop variables by writing this array. The length of the array gives the
+     *                 number of loop-variables that the caller has specified.
+     *                 Never <code>null</code>, but can be a zero-length array.
+     * @param body     an object that can be used to render the nested content (body) of
+     *                 the directive call. If the directive call has no nested content (i.e., it is like
+     *                 [@myDirective /] or [@myDirective][/@myDirective]), then this will be
+     *                 <code>null</code>.
+     * @throws freemarker.template.TemplateException
+     *
+     * @throws java.io.IOException
+     */
+    @Override
+    public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
+        TemplateStackModel contextStack = (TemplateStackModel)env.getVariable("context");
+        if(contextStack == null || contextStack.empty()) {
+            throw new TemplateModelException("error; no context node available");
+        }
+        TemplateNodeModel<Node> context = (TemplateNodeModel<Node>)contextStack.peek();
+
+        SimpleScalar pathScalar = (SimpleScalar)params.get("path");
+        if(pathScalar == null) {
+            throw new TemplateException("the directive has been called without a path parameter",env);
+        }
+        String path = pathScalar.getAsString();
+
+        TemplateWrapperModel<Map<String,String>> namespacesWrapped = (TemplateWrapperModel<Map<String,String>>)env.getGlobalVariable("namespaces");
+
+        Map<String,String> namespaces;
+        if(namespacesWrapped == null) {
+            namespaces = new HashMap<String, String>();
+            namespacesWrapped = new TemplateWrapperModel<Map<String, String>>(new HashMap<String, String>());
+            env.setGlobalVariable("namespaces",namespacesWrapped);
+        } else {
+            namespaces = namespacesWrapped.getAdaptedObject(Map.class);
+        }
+
+
+        if(body == null) { // value insertion
+            if(!path.contains("::")) {
+                path = path + ":: xsd:string";
+            }
+            try {
+                Collection results = ldpath.pathTransform(context.getNode(),path,namespaces);
+
+                if(results.size() > 0) {
+                    Object result = results.iterator().next();
+
+                    if(result instanceof TemplateNumberModel) {
+                        env.getOut().write(FormatUtil.formatNumber( ((TemplateNumberModel)result).getAsNumber() ));
+                    } else if(result instanceof TemplateDateModel) {
+                        switch (((TemplateDateModel)result).getDateType()) {
+                            case TemplateDateModel.DATE:
+                                env.getOut().write(FormatUtil.formatDate(((TemplateDateModel)result).getAsDate()));
+                                break;
+                            case TemplateDateModel.TIME:
+                                env.getOut().write(FormatUtil.formatTime(((TemplateDateModel)result).getAsDate()));
+                                break;
+                            case TemplateDateModel.DATETIME:
+                                env.getOut().write(FormatUtil.formatDateTime(((TemplateDateModel)result).getAsDate()));
+                                break;
+                            default:
+                                env.getOut().write(FormatUtil.formatDateTime(((TemplateDateModel)result).getAsDate()));
+                        }
+                    } else if(result instanceof TemplateScalarModel) {
+                        env.getOut().write( ((TemplateScalarModel)result).getAsString() );
+                    } else if(result instanceof TemplateBooleanModel) {
+                        env.getOut().write( Boolean.toString(((TemplateBooleanModel)result).getAsBoolean()) );
+                    }
+
+                } // else write nothing
+
+
+            } catch (LDPathParseException e) {
+                throw new TemplateException("invalid path for ldpath directive: "+path,e,env);
+            }
+
+        } else {
+            try {
+                for(Node node : ldpath.pathQuery(context.getNode(),path,namespaces)) {
+                    contextStack.push(new TemplateNodeModel<Node>(node, backend));
+
+                    if(loopVars.length > 0) {
+                        loopVars[0] = new TemplateNodeModel<Node>(node,backend);
+                    }
+
+                    body.render(env.getOut());
+
+                    contextStack.pop();
+                }
+            } catch(LDPathParseException ex) {
+                throw new TemplateException("invalid path for ldpath directive: "+path,ex,env);
+            }
+
+        }
+
+    }
+}

Added: stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/engine/LDPathMethod.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/engine/LDPathMethod.java?rev=1389101&view=auto
==============================================================================
--- stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/engine/LDPathMethod.java (added)
+++ stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/engine/LDPathMethod.java Sun Sep 23 17:35:59 2012
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2011 Salzburg Research.
+ *
+ * Licensed 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 at.newmedialab.ldpath.template.engine;
+
+import at.newmedialab.ldpath.LDPath;
+import at.newmedialab.ldpath.api.backend.RDFBackend;
+import at.newmedialab.ldpath.exception.LDPathParseException;
+import at.newmedialab.ldpath.model.Constants;
+import at.newmedialab.ldpath.template.model.freemarker.TemplateNodeModel;
+import at.newmedialab.ldpath.template.model.freemarker.TemplateStackModel;
+import at.newmedialab.ldpath.template.model.freemarker.TemplateWrapperModel;
+import at.newmedialab.ldpath.template.model.transformers.*;
+import freemarker.core.Environment;
+import freemarker.template.TemplateDateModel;
+import freemarker.template.TemplateMethodModel;
+import freemarker.template.TemplateModelException;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Add file description here!
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class LDPathMethod<Node> implements TemplateMethodModel {
+
+
+    private LDPath<Node> ldpath;
+    private RDFBackend<Node> backend;
+
+    public LDPathMethod(RDFBackend<Node> backend) {
+        this.ldpath  = new LDPath<Node>(backend);
+        this.backend = backend;
+
+        // register custom freemarker transformers for the parser so we get the results immediately in the freemarker model
+        ldpath.registerTransformer(Constants.NS_XSD + "string", new TemplateScalarTransformer<Node>());
+        ldpath.registerTransformer(Constants.NS_XSD + "decimal", new TemplateLongTransformer<Node>());
+        ldpath.registerTransformer(Constants.NS_XSD + "integer", new TemplateIntegerTransformer<Node>());
+        ldpath.registerTransformer(Constants.NS_XSD + "long", new TemplateLongTransformer<Node>());
+        ldpath.registerTransformer(Constants.NS_XSD + "short", new TemplateIntegerTransformer<Node>());
+        ldpath.registerTransformer(Constants.NS_XSD + "double", new TemplateDoubleTransformer<Node>());
+        ldpath.registerTransformer(Constants.NS_XSD + "float", new TemplateFloatTransformer<Node>());
+        ldpath.registerTransformer(Constants.NS_XSD + "dateTime", new TemplateDateTransformer<Node>(TemplateDateModel.DATETIME));
+        ldpath.registerTransformer(Constants.NS_XSD + "date", new TemplateDateTransformer<Node>(TemplateDateModel.DATE));
+        ldpath.registerTransformer(Constants.NS_XSD + "time", new TemplateDateTransformer<Node>(TemplateDateModel.TIME));
+        ldpath.registerTransformer(Constants.NS_XSD + "boolean", new TemplateBooleanTransformer<Node>());
+        ldpath.registerTransformer(Constants.NS_XSD + "anyURI", new TemplateScalarTransformer<Node>());
+
+    }
+
+
+    /**
+     * Executes a method call. All arguments passed to the method call are
+     * coerced to strings before being passed, if the FreeMarker rules allow
+     * the coercion. If some of the passed arguments can not be coerced to a
+     * string, an exception will be raised in the engine and the method will
+     * not be called. If your method would like to act on actual data model
+     * objects instead of on their string representations, implement the
+     * {@link freemarker.template.TemplateMethodModelEx} instead.
+     *
+     * @param arguments a <tt>List</tt> of <tt>String</tt> objects
+     *                  containing the values of the arguments passed to the method.
+     * @return the return value of the method, or null. If the returned value
+     *         does not implement {@link freemarker.template.TemplateModel}, it will be automatically
+     *         wrapped using the {@link freemarker.core.Environment#getObjectWrapper() environment
+     *         object wrapper}.
+     */
+    @Override
+    public Object exec(List arguments) throws TemplateModelException {
+        Environment env = Environment.getCurrentEnvironment();
+
+
+        TemplateStackModel contextStack = (TemplateStackModel)env.getVariable("context");
+        if(contextStack == null || contextStack.empty()) {
+            throw new TemplateModelException("error; no context node available");
+        }
+        TemplateNodeModel<Node> context = (TemplateNodeModel<Node>)contextStack.peek();
+
+        String path;
+        if(arguments.size() != 1) {
+            throw new TemplateModelException("the directive has been called without a path parameter");
+        } else {
+            path = (String)arguments.get(0);
+            if(!path.contains("::")) {
+                path = path + " :: xsd:string";
+            }
+        }
+
+        TemplateWrapperModel<Map<String,String>> namespacesWrapped = (TemplateWrapperModel<Map<String,String>>)env.getGlobalVariable("namespaces");
+
+        Map<String,String> namespaces;
+        if(namespacesWrapped == null) {
+            namespaces = new HashMap<String, String>();
+            namespacesWrapped = new TemplateWrapperModel<Map<String, String>>(new HashMap<String, String>());
+            env.setGlobalVariable("namespaces",namespacesWrapped);
+        } else {
+            namespaces = namespacesWrapped.getAdaptedObject(Map.class);
+        }
+
+        if(arguments.size() != 1) {
+            throw new TemplateModelException("wrong number of arguments for method call");
+        }
+
+        try {
+            Collection result = ldpath.pathTransform(context.getNode(),path,namespaces);
+            if(result.size() > 0) {
+                return result;
+            } else {
+                return null;
+            }
+        } catch (LDPathParseException e) {
+            throw new TemplateModelException("could not parse path expression '"+path+"'",e);
+        }
+    }
+}

Added: stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/engine/NamespaceDirective.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/engine/NamespaceDirective.java?rev=1389101&view=auto
==============================================================================
--- stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/engine/NamespaceDirective.java (added)
+++ stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/engine/NamespaceDirective.java Sun Sep 23 17:35:59 2012
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2011 Salzburg Research.
+ *
+ * Licensed 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 at.newmedialab.ldpath.template.engine;
+
+import at.newmedialab.ldpath.template.model.freemarker.TemplateWrapperModel;
+import freemarker.core.Environment;
+import freemarker.template.*;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * Add file description here!
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class NamespaceDirective implements TemplateDirectiveModel {
+
+
+    public NamespaceDirective() {
+    }
+
+    /**
+     * Executes this user-defined directive; called by FreeMarker when the user-defined
+     * directive is called in the template.
+     *
+     * @param env      the current processing environment. Note that you can access
+     *                 the output {@link java.io.Writer Writer} by {@link freemarker.core.Environment#getOut()}.
+     * @param params   the parameters (if any) passed to the directive as a
+     *                 map of key/value pairs where the keys are {@link String}-s and the
+     *                 values are {@link freemarker.template.TemplateModel} instances. This is never
+     *                 <code>null</code>. If you need to convert the template models to POJOs,
+     *                 you can use the utility methods in the {@link freemarker.template.utility.DeepUnwrap} class.
+     * @param loopVars an array that corresponds to the "loop variables", in
+     *                 the order as they appear in the directive call. ("Loop variables" are out-parameters
+     *                 that are available to the nested body of the directive; see in the Manual.)
+     *                 You set the loop variables by writing this array. The length of the array gives the
+     *                 number of loop-variables that the caller has specified.
+     *                 Never <code>null</code>, but can be a zero-length array.
+     * @param body     an object that can be used to render the nested content (body) of
+     *                 the directive call. If the directive call has no nested content (i.e., it is like
+     *                 [@myDirective /] or [@myDirective][/@myDirective]), then this will be
+     *                 <code>null</code>.
+     * @throws freemarker.template.TemplateException
+     *
+     * @throws java.io.IOException
+     */
+    @Override
+    public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
+        TemplateWrapperModel<Map<String,String>> namespacesWrapped = (TemplateWrapperModel<Map<String,String>>)env.getGlobalVariable("namespaces");
+
+        Map<String,String> namespaces;
+        if(namespacesWrapped == null) {
+            namespaces = new HashMap<String, String>();
+            namespacesWrapped = new TemplateWrapperModel<Map<String, String>>(namespaces);
+            env.setGlobalVariable("namespaces",namespacesWrapped);
+        } else {
+            namespaces = namespacesWrapped.getAdaptedObject(Map.class);
+        }
+
+
+        Iterator paramIter = params.entrySet().iterator();
+        while (paramIter.hasNext()) {
+            Map.Entry ent = (Map.Entry) paramIter.next();
+
+            String paramName = (String) ent.getKey();
+            TemplateModel paramValue = (TemplateModel) ent.getValue();
+
+            if(paramValue instanceof TemplateScalarModel) {
+                String uri = ((TemplateScalarModel)paramValue).getAsString();
+
+                try {
+                    URI test = new URI(uri);
+                    namespaces.put(paramName,test.toString());
+                } catch (URISyntaxException e) {
+                    throw new TemplateModelException("invalid namespace URI '"+uri+"'",e);
+                }
+            }
+        }
+
+    }
+}

Added: stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/engine/TemplateEngine.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/engine/TemplateEngine.java?rev=1389101&view=auto
==============================================================================
--- stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/engine/TemplateEngine.java (added)
+++ stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/engine/TemplateEngine.java Sun Sep 23 17:35:59 2012
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2011 Salzburg Research.
+ *
+ * Licensed 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 at.newmedialab.ldpath.template.engine;
+
+import at.newmedialab.ldpath.api.backend.RDFBackend;
+import at.newmedialab.ldpath.template.model.freemarker.TemplateNodeModel;
+import at.newmedialab.ldpath.template.model.freemarker.TemplateStackModel;
+import freemarker.cache.TemplateLoader;
+import freemarker.template.Configuration;
+import freemarker.template.DefaultObjectWrapper;
+import freemarker.template.Template;
+import freemarker.template.TemplateException;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Add file description here!
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class TemplateEngine<Node> {
+
+    private Configuration freemarker;
+
+    private RDFBackend<Node> backend;
+
+    public TemplateEngine(RDFBackend<Node> backend) {
+
+        this.backend = backend;
+
+        freemarker = new Configuration();
+        freemarker.setObjectWrapper(new DefaultObjectWrapper());
+
+
+    }
+
+
+    /**
+     * Allow setting a different template loader. Custom template loaders can be implemented in addition to
+     * those provided by FreeMarker.
+     *
+     * @param loader
+     */
+    public void setTemplateLoader(TemplateLoader loader) {
+        freemarker.setTemplateLoader(loader);
+    }
+
+
+    public void setDirectoryForTemplateLoading(File dir) throws IOException {
+        freemarker.setDirectoryForTemplateLoading(dir);
+    }
+
+    public void setServletContextForTemplateLoading(Object sctxt, String path) {
+        freemarker.setServletContextForTemplateLoading(sctxt, path);
+    }
+
+    public void setClassForTemplateLoading(Class clazz, String pathPrefix) {
+        freemarker.setClassForTemplateLoading(clazz, pathPrefix);
+    }
+
+
+    /**
+     * Process the template with the given name forn the given context node and write the result to the given
+     * output writer. The way the template is retrieved depends on the template loader, which can be set using the
+     * setTemplateLoader() method.
+     *
+     * @param context the  initial context node to apply this template to
+     * @param templateName the name of the template
+     * @param out          where to write the results
+     * @throws IOException
+     * @throws TemplateException
+     */
+    public void processFileTemplate(Node context, String templateName, Writer out) throws IOException, TemplateException {
+        processTemplate(context,freemarker.getTemplate(templateName),null,out);
+    }
+
+    /**
+     * Process the template with the given name forn the given context node and write the result to the given
+     * output writer. The initial environment is passed over to the invocation of the template. The way the template
+     * is retrieved depends on the template loader, which can be set using the setTemplateLoader() method.
+     *
+     * @param context the  initial context node to apply this template to
+     * @param templateName the name of the template
+     * @param initialEnv   an initial root environment for processing the template
+     * @param out          where to write the results
+     * @throws IOException
+     * @throws TemplateException
+     */
+    public void processFileTemplate(Node context, String templateName, Map initialEnv,  Writer out) throws IOException, TemplateException {
+        processTemplate(context,freemarker.getTemplate(templateName),initialEnv,out);
+    }
+
+
+    public void processTemplate(Node context, Template template, Map initialEnv, Writer out) throws IOException, TemplateException {
+        Map root = new HashMap();
+
+        if(initialEnv != null) {
+            for(Map.Entry entry : (Set<Map.Entry>) initialEnv.entrySet()) {
+                root.put(entry.getKey(), entry.getValue());
+            }
+        }
+
+        root.put("namespace", new NamespaceDirective());
+        root.put("evalLDPath",new LDPathMethod(backend));
+        root.put("ldpath",new LDPathDirective(backend));
+
+        TemplateStackModel contexts = new TemplateStackModel();
+        contexts.push(new TemplateNodeModel(context,backend));
+        root.put("context",contexts);
+
+        template.process(root,out);
+    }
+}

Added: stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/freemarker/TemplateNodeModel.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/freemarker/TemplateNodeModel.java?rev=1389101&view=auto
==============================================================================
--- stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/freemarker/TemplateNodeModel.java (added)
+++ stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/freemarker/TemplateNodeModel.java Sun Sep 23 17:35:59 2012
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2011 Salzburg Research.
+ *
+ * Licensed 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 at.newmedialab.ldpath.template.model.freemarker;
+
+import at.newmedialab.ldpath.api.backend.RDFBackend;
+import freemarker.template.*;
+
+/**
+ * A custom freemarker model to represent RDF nodes (implementation independent, generic)
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class TemplateNodeModel<Node> implements TemplateModel, TemplateHashModel, AdapterTemplateModel {
+
+    private Node node;
+    private RDFBackend<Node> backend;
+
+    public TemplateNodeModel(Node node, RDFBackend<Node> backend) {
+        this.node    = node;
+        this.backend = backend;
+    }
+
+    public Node getNode() {
+        return node;
+    }
+
+    /**
+     * Gets a <tt>TemplateModel</tt> from the hash.
+     *
+     * @param key the name by which the <tt>TemplateModel</tt>
+     *            is identified in the template.
+     * @return the <tt>TemplateModel</tt> referred to by the key,
+     *         or null if not found.
+     */
+    @Override
+    public TemplateModel get(String key) throws TemplateModelException {
+        if( ("uri".equals(key) && backend.isURI(node)) || ("content".equals(key) && backend.isLiteral(node))) {
+            return new TemplateScalarModel() {
+                @Override
+                public String getAsString() throws TemplateModelException {
+                    return backend.stringValue(node);
+                }
+            };
+        } else if("language".equals(key) && backend.isLiteral(node)) {
+            return new TemplateScalarModel() {
+                @Override
+                public String getAsString() throws TemplateModelException {
+                    return backend.getLiteralLanguage(node).getLanguage();
+                }
+            };
+        } else if("type".equals(key) && backend.isLiteral(node)) {
+            return new TemplateScalarModel() {
+                @Override
+                public String getAsString() throws TemplateModelException {
+                    return backend.getLiteralType(node).toString();
+                }
+            };
+        } else if("id".equals(key) && backend.isBlank(node)) {
+            return new TemplateScalarModel() {
+                @Override
+                public String getAsString() throws TemplateModelException {
+                    return backend.stringValue(node);
+                }
+            };
+        }
+        return null;
+    }
+
+    @Override
+    public boolean isEmpty() throws TemplateModelException {
+        return false;
+    }
+
+    /**
+     * Retrieves the underlying object, or some other object semantically
+     * equivalent to its value narrowed by the class hint.
+     *
+     * @param hint the desired class of the returned value. An implementation
+     *             should make reasonable effort to retrieve an object of the requested
+     *             class, but if that is impossible, it must at least return the underlying
+     *             object as-is. As a minimal requirement, an implementation must always
+     *             return the exact underlying object when
+     *             <tt>hint.isInstance(underlyingObject) == true</tt> holds. When called
+     *             with <tt>java.lang.Object.class</tt>, it should return a generic Java
+     *             object (i.e. if the model is wrapping a scripting lanugage object that is
+     *             further wrapping a Java object, the deepest underlying Java object should
+     *             be returned).
+     * @return the underlying object, or its value accommodated for the hint
+     *         class.
+     */
+    @Override
+    public Object getAdaptedObject(Class hint) {
+        return node;
+    }
+}

Added: stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/freemarker/TemplateStackModel.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/freemarker/TemplateStackModel.java?rev=1389101&view=auto
==============================================================================
--- stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/freemarker/TemplateStackModel.java (added)
+++ stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/freemarker/TemplateStackModel.java Sun Sep 23 17:35:59 2012
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2011 Salzburg Research.
+ *
+ * Licensed 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 at.newmedialab.ldpath.template.model.freemarker;
+
+import freemarker.template.TemplateModel;
+
+import java.util.Stack;
+
+/**
+ * Add file description here!
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class TemplateStackModel implements TemplateModel {
+
+    private Stack<TemplateModel> stack;
+
+    public TemplateStackModel() {
+        stack = new Stack<TemplateModel>();
+    }
+
+
+    public TemplateModel push(TemplateModel item) {
+        return stack.push(item);
+    }
+
+    public TemplateModel pop() {
+        return stack.pop();
+    }
+
+    public TemplateModel peek() {
+        return stack.peek();
+    }
+
+    public boolean empty() {
+        return stack.empty();
+    }
+}

Added: stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/freemarker/TemplateWrapperModel.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/freemarker/TemplateWrapperModel.java?rev=1389101&view=auto
==============================================================================
--- stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/freemarker/TemplateWrapperModel.java (added)
+++ stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/freemarker/TemplateWrapperModel.java Sun Sep 23 17:35:59 2012
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2011 Salzburg Research.
+ *
+ * Licensed 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 at.newmedialab.ldpath.template.model.freemarker;
+
+import freemarker.template.AdapterTemplateModel;
+
+/**
+ * Add file description here!
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class TemplateWrapperModel<T> implements AdapterTemplateModel {
+
+    private T object;
+
+    public TemplateWrapperModel(T object) {
+        this.object = object;
+    }
+
+    /**
+     * Retrieves the underlying object, or some other object semantically
+     * equivalent to its value narrowed by the class hint.
+     *
+     * @param hint the desired class of the returned value. An implementation
+     *             should make reasonable effort to retrieve an object of the requested
+     *             class, but if that is impossible, it must at least return the underlying
+     *             object as-is. As a minimal requirement, an implementation must always
+     *             return the exact underlying object when
+     *             <tt>hint.isInstance(underlyingObject) == true</tt> holds. When called
+     *             with <tt>java.lang.Object.class</tt>, it should return a generic Java
+     *             object (i.e. if the model is wrapping a scripting lanugage object that is
+     *             further wrapping a Java object, the deepest underlying Java object should
+     *             be returned).
+     * @return the underlying object, or its value accommodated for the hint
+     *         class.
+     */
+    @Override
+    public T getAdaptedObject(Class hint) {
+        return object;
+    }
+}

Added: stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/transformers/TemplateBooleanTransformer.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/transformers/TemplateBooleanTransformer.java?rev=1389101&view=auto
==============================================================================
--- stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/transformers/TemplateBooleanTransformer.java (added)
+++ stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/transformers/TemplateBooleanTransformer.java Sun Sep 23 17:35:59 2012
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2011 Salzburg Research.
+ *
+ * Licensed 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 at.newmedialab.ldpath.template.model.transformers;
+
+import at.newmedialab.ldpath.api.backend.RDFBackend;
+import at.newmedialab.ldpath.api.transformers.NodeTransformer;
+import at.newmedialab.ldpath.model.transformers.BooleanTransformer;
+import freemarker.template.TemplateBooleanModel;
+import freemarker.template.TemplateModelException;
+
+/**
+ * Transform a node into the freemarker boolean type (TemplateBooleanModel).
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class TemplateBooleanTransformer<Node> implements NodeTransformer<TemplateBooleanModel,Node> {
+
+    private BooleanTransformer<Node> delegate;
+
+    public TemplateBooleanTransformer() {
+        delegate = new BooleanTransformer<Node>();
+    }
+
+    /**
+     * Transform the KiWiNode node into the datatype T. In case the node cannot be transformed to
+     * the respective datatype, throws an IllegalArgumentException that needs to be caught by the class
+     * carrying out the transformation.
+     *
+     * @param node
+     * @return
+     */
+    @Override
+    public TemplateBooleanModel transform(final RDFBackend<Node> nodeRDFBackend, final Node node) throws IllegalArgumentException {
+        return new TemplateBooleanModel() {
+            @Override
+            public boolean getAsBoolean() throws TemplateModelException {
+                return delegate.transform(nodeRDFBackend,node);
+            }
+        };
+    }
+}

Added: stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/transformers/TemplateDateTransformer.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/transformers/TemplateDateTransformer.java?rev=1389101&view=auto
==============================================================================
--- stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/transformers/TemplateDateTransformer.java (added)
+++ stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/transformers/TemplateDateTransformer.java Sun Sep 23 17:35:59 2012
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2011 Salzburg Research.
+ *
+ * Licensed 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 at.newmedialab.ldpath.template.model.transformers;
+
+import at.newmedialab.ldpath.api.backend.RDFBackend;
+import at.newmedialab.ldpath.api.transformers.NodeTransformer;
+import at.newmedialab.ldpath.model.transformers.DateTimeTransformer;
+import freemarker.template.TemplateDateModel;
+import freemarker.template.TemplateModelException;
+
+import java.util.Date;
+
+/**
+ * Transform a node into the freemarker date type ({@link freemarker.template.TemplateDateModel}).
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class TemplateDateTransformer<Node> implements NodeTransformer<TemplateDateModel,Node> {
+
+    private DateTimeTransformer<Node> delegate;
+
+    private int type = TemplateDateModel.UNKNOWN;
+
+    public TemplateDateTransformer() {
+        delegate = new DateTimeTransformer<Node>();
+    }
+
+    public TemplateDateTransformer(int type) {
+        this.type = type;
+    }
+
+    /**
+     * Transform the KiWiNode node into the datatype T. In case the node cannot be transformed to
+     * the respective datatype, throws an IllegalArgumentException that needs to be caught by the class
+     * carrying out the transformation.
+     *
+     * @param node
+     * @return
+     */
+    @Override
+    public TemplateDateModel transform(final RDFBackend<Node> nodeRDFBackend, final Node node) throws IllegalArgumentException {
+        return new TemplateDateModel() {
+            @Override
+            public Date getAsDate() throws TemplateModelException {
+                return delegate.transform(nodeRDFBackend, node);
+            }
+
+            @Override
+            public int getDateType() {
+                return type;
+            }
+        };
+    }
+}

Added: stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/transformers/TemplateDoubleTransformer.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/transformers/TemplateDoubleTransformer.java?rev=1389101&view=auto
==============================================================================
--- stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/transformers/TemplateDoubleTransformer.java (added)
+++ stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/transformers/TemplateDoubleTransformer.java Sun Sep 23 17:35:59 2012
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2011 Salzburg Research.
+ *
+ * Licensed 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 at.newmedialab.ldpath.template.model.transformers;
+
+import at.newmedialab.ldpath.api.backend.RDFBackend;
+import at.newmedialab.ldpath.api.transformers.NodeTransformer;
+import at.newmedialab.ldpath.model.transformers.DoubleTransformer;
+import freemarker.template.TemplateModelException;
+import freemarker.template.TemplateNumberModel;
+
+/**
+ * Transform a node into the freemarker double type (TemplateDoubleModel).
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class TemplateDoubleTransformer<Node> implements NodeTransformer<TemplateNumberModel,Node> {
+
+    private DoubleTransformer<Node> delegate;
+
+    public TemplateDoubleTransformer() {
+        delegate = new DoubleTransformer<Node>();
+    }
+
+    /**
+     * Transform the KiWiNode node into the datatype T. In case the node cannot be transformed to
+     * the respective datatype, throws an IllegalArgumentException that needs to be caught by the class
+     * carrying out the transformation.
+     *
+     * @param node
+     * @return
+     */
+    @Override
+    public TemplateNumberModel transform(final RDFBackend<Node> nodeRDFBackend, final Node node) throws IllegalArgumentException {
+        return new TemplateNumberModel() {
+            @Override
+            public Number getAsNumber() throws TemplateModelException {
+                return delegate.transform(nodeRDFBackend,node);
+            }
+        };
+    }
+}

Added: stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/transformers/TemplateFloatTransformer.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/transformers/TemplateFloatTransformer.java?rev=1389101&view=auto
==============================================================================
--- stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/transformers/TemplateFloatTransformer.java (added)
+++ stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/transformers/TemplateFloatTransformer.java Sun Sep 23 17:35:59 2012
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2011 Salzburg Research.
+ *
+ * Licensed 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 at.newmedialab.ldpath.template.model.transformers;
+
+import at.newmedialab.ldpath.api.backend.RDFBackend;
+import at.newmedialab.ldpath.api.transformers.NodeTransformer;
+import at.newmedialab.ldpath.model.transformers.FloatTransformer;
+import freemarker.template.TemplateModelException;
+import freemarker.template.TemplateNumberModel;
+
+/**
+ * Transform a node into the freemarker float type (TemplateFloatModel).
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class TemplateFloatTransformer<Node> implements NodeTransformer<TemplateNumberModel,Node> {
+
+    private FloatTransformer<Node> delegate;
+
+    public TemplateFloatTransformer() {
+        delegate = new FloatTransformer<Node>();
+    }
+
+    /**
+     * Transform the KiWiNode node into the datatype T. In case the node cannot be transformed to
+     * the respective datatype, throws an IllegalArgumentException that needs to be caught by the class
+     * carrying out the transformation.
+     *
+     * @param node
+     * @return
+     */
+    @Override
+    public TemplateNumberModel transform(final RDFBackend<Node> nodeRDFBackend, final Node node) throws IllegalArgumentException {
+        return new TemplateNumberModel() {
+            @Override
+            public Number getAsNumber() throws TemplateModelException {
+                return delegate.transform(nodeRDFBackend,node);
+            }
+        };
+    }
+}

Added: stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/transformers/TemplateIntegerTransformer.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/transformers/TemplateIntegerTransformer.java?rev=1389101&view=auto
==============================================================================
--- stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/transformers/TemplateIntegerTransformer.java (added)
+++ stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/transformers/TemplateIntegerTransformer.java Sun Sep 23 17:35:59 2012
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2011 Salzburg Research.
+ *
+ * Licensed 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 at.newmedialab.ldpath.template.model.transformers;
+
+import at.newmedialab.ldpath.api.backend.RDFBackend;
+import at.newmedialab.ldpath.api.transformers.NodeTransformer;
+import at.newmedialab.ldpath.model.transformers.IntTransformer;
+import freemarker.template.TemplateModelException;
+import freemarker.template.TemplateNumberModel;
+
+/**
+ * Transform a node into the freemarker integer type (TemplateNumberModel).
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class TemplateIntegerTransformer<Node> implements NodeTransformer<TemplateNumberModel,Node> {
+
+    private IntTransformer<Node> delegate;
+
+    public TemplateIntegerTransformer() {
+        delegate = new IntTransformer<Node>();
+    }
+
+    /**
+     * Transform the KiWiNode node into the datatype T. In case the node cannot be transformed to
+     * the respective datatype, throws an IllegalArgumentException that needs to be caught by the class
+     * carrying out the transformation.
+     *
+     * @param node
+     * @return
+     */
+    @Override
+    public TemplateNumberModel transform(final RDFBackend<Node> nodeRDFBackend, final Node node) throws IllegalArgumentException {
+        return new TemplateNumberModel() {
+            @Override
+            public Number getAsNumber() throws TemplateModelException {
+                return delegate.transform(nodeRDFBackend, node);
+            }
+        };
+    }
+}

Added: stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/transformers/TemplateLongTransformer.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/transformers/TemplateLongTransformer.java?rev=1389101&view=auto
==============================================================================
--- stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/transformers/TemplateLongTransformer.java (added)
+++ stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/transformers/TemplateLongTransformer.java Sun Sep 23 17:35:59 2012
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2011 Salzburg Research.
+ *
+ * Licensed 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 at.newmedialab.ldpath.template.model.transformers;
+
+import at.newmedialab.ldpath.api.backend.RDFBackend;
+import at.newmedialab.ldpath.api.transformers.NodeTransformer;
+import at.newmedialab.ldpath.model.transformers.LongTransformer;
+import freemarker.template.TemplateModelException;
+import freemarker.template.TemplateNumberModel;
+
+/**
+ * Transform a node into the freemarker long type (TemplateNumberModel).
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class TemplateLongTransformer<Node> implements NodeTransformer<TemplateNumberModel,Node> {
+
+    private LongTransformer delegate;
+
+    public TemplateLongTransformer() {
+        delegate = new LongTransformer();
+    }
+
+    /**
+     * Transform the KiWiNode node into the datatype T. In case the node cannot be transformed to
+     * the respective datatype, throws an IllegalArgumentException that needs to be caught by the class
+     * carrying out the transformation.
+     *
+     * @param node
+     * @return
+     */
+    @Override
+    public TemplateNumberModel transform(final RDFBackend<Node> nodeRDFBackend, final Node node) throws IllegalArgumentException {
+        return new TemplateNumberModel() {
+            @Override
+            public Number getAsNumber() throws TemplateModelException {
+                return delegate.transform(nodeRDFBackend, node);
+            }
+        };
+    }
+}

Added: stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/transformers/TemplateScalarTransformer.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/transformers/TemplateScalarTransformer.java?rev=1389101&view=auto
==============================================================================
--- stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/transformers/TemplateScalarTransformer.java (added)
+++ stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/model/transformers/TemplateScalarTransformer.java Sun Sep 23 17:35:59 2012
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2011 Salzburg Research.
+ *
+ * Licensed 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 at.newmedialab.ldpath.template.model.transformers;
+
+import at.newmedialab.ldpath.api.backend.RDFBackend;
+import at.newmedialab.ldpath.api.transformers.NodeTransformer;
+import at.newmedialab.ldpath.model.transformers.StringTransformer;
+import freemarker.template.TemplateModelException;
+import freemarker.template.TemplateScalarModel;
+
+/**
+ * Transform a node into the freemarker string (scalar) type (TemplateScalarModel).
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class TemplateScalarTransformer<Node> implements NodeTransformer<TemplateScalarModel,Node> {
+
+    private StringTransformer<Node> delegate;
+
+
+    public TemplateScalarTransformer() {
+        delegate = new StringTransformer<Node>();
+    }
+
+    /**
+     * Transform the KiWiNode node into the datatype T. In case the node cannot be transformed to
+     * the respective datatype, throws an IllegalArgumentException that needs to be caught by the class
+     * carrying out the transformation.
+     *
+     * @param node
+     * @return
+     */
+    @Override
+    public TemplateScalarModel transform(final RDFBackend<Node> nodeRDFBackend, final Node node) throws IllegalArgumentException {
+        return new TemplateScalarModel() {
+            @Override
+            public String getAsString() throws TemplateModelException {
+                return delegate.transform(nodeRDFBackend,node);
+            }
+        };
+    }
+}

Added: stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/util/FormatUtil.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/util/FormatUtil.java?rev=1389101&view=auto
==============================================================================
--- stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/util/FormatUtil.java (added)
+++ stanbol/trunk/commons/ldtemplaterenderer/src/main/java/at/newmedialab/ldpath/template/util/FormatUtil.java Sun Sep 23 17:35:59 2012
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2011 Salzburg Research.
+ *
+ * Licensed 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 at.newmedialab.ldpath.template.util;
+
+import java.text.DateFormat;
+import java.text.NumberFormat;
+import java.util.Date;
+import java.util.Locale;
+
+/**
+ * A utility class for formatting Java values when writing out the templating results. The methods are implemented
+ * to copy the formatting behaviour of FreeMarker
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class FormatUtil {
+
+
+    public static String formatNumber(Number number) {
+        NumberFormat format = NumberFormat.getNumberInstance(Locale.getDefault());
+        return format.format(number);
+    }
+
+
+    public static String formatDate(Date date) {
+        DateFormat format = DateFormat.getDateInstance(DateFormat.MEDIUM,Locale.getDefault());
+        return format.format(date);
+    }
+
+    public static String formatTime(Date date) {
+        DateFormat format = DateFormat.getTimeInstance(DateFormat.MEDIUM, Locale.getDefault());
+        return format.format(date);
+    }
+
+    public static String formatDateTime(Date date) {
+        DateFormat format = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.getDefault());
+        return format.format(date);
+    }
+
+}

Added: stanbol/trunk/commons/ldtemplaterenderer/src/main/java/org/apache/stanbol/commons/ldpathtemplate/LdRenderer.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/ldtemplaterenderer/src/main/java/org/apache/stanbol/commons/ldpathtemplate/LdRenderer.java?rev=1389101&view=auto
==============================================================================
--- stanbol/trunk/commons/ldtemplaterenderer/src/main/java/org/apache/stanbol/commons/ldpathtemplate/LdRenderer.java (added)
+++ stanbol/trunk/commons/ldtemplaterenderer/src/main/java/org/apache/stanbol/commons/ldpathtemplate/LdRenderer.java Sun Sep 23 17:35:59 2012
@@ -0,0 +1,137 @@
+package org.apache.stanbol.commons.ldpathtemplate;
+
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.Writer;
+import java.net.URL;
+import java.util.Collection;
+import java.util.HashSet;
+
+import org.apache.clerezza.rdf.core.Resource;
+import org.apache.clerezza.rdf.utils.GraphNode;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.stanbol.commons.ldpath.clerezza.ClerezzaBackend;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.BundleListener;
+import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.newmedialab.ldpath.api.backend.RDFBackend;
+import at.newmedialab.ldpath.template.engine.TemplateEngine;
+import freemarker.cache.TemplateLoader;
+import freemarker.template.TemplateException;
+
+/**
+ * This service renders a GraphNode to a Writer given the 
+ * path of an ldpath template
+ *
+ */
+@Component
+@Service(LdRenderer.class)
+public class LdRenderer {
+	
+	private static final String TEMPLATES_PATH_IN_BUNDLES = "templates/";
+
+	private static final Logger log = LoggerFactory.getLogger(LdRenderer.class);
+	
+	private final Collection<Bundle> bundles = new HashSet<Bundle>();
+	
+	private BundleListener bundleListener = new BundleListener() {
+		
+		@Override
+		public void bundleChanged(BundleEvent event) {
+			if ((event.getType() == BundleEvent.STARTED) && containsTemplates(event.getBundle())) {
+				bundles.add(event.getBundle());
+			} else {
+				bundles.remove(event.getBundle());
+			}
+		}
+	};
+	
+	private TemplateLoader templateLoader = new TemplateLoader() {
+		
+		@Override
+		public Reader getReader(Object templateSource, String encoding)
+				throws IOException {
+			URL templateUrl = (URL) templateSource;
+			return new InputStreamReader(templateUrl.openStream(), encoding);
+		}
+		
+		@Override
+		public long getLastModified(Object templateSource) {
+			// not known
+			return -1;
+		}
+		
+		@Override
+		public Object findTemplateSource(String name) throws IOException {
+			for (Bundle bundle : bundles) {
+				URL res = bundle.getResource(TEMPLATES_PATH_IN_BUNDLES+name);
+				if (res != null) {
+					return res;
+				}
+			}
+			log.warn("Template "+name+" not known");
+			return null;
+		}
+		
+		@Override
+		public void closeTemplateSource(Object templateSource) throws IOException {
+
+			
+		}
+	};
+	
+	@Activate
+	protected void activate(final ComponentContext context) {
+		final Bundle[] registeredBundles = context.getBundleContext().getBundles();
+		for (int i = 0; i < registeredBundles.length; i++) {
+			if ((registeredBundles[i].getState() == Bundle.ACTIVE) 
+					&& containsTemplates(registeredBundles[i])) {
+				bundles.add(registeredBundles[i]);
+			}
+		}	
+		context.getBundleContext().addBundleListener(bundleListener);
+	}
+
+	@Deactivate
+	protected void deactivate(final ComponentContext context) {
+		context.getBundleContext().removeBundleListener(bundleListener);
+	}
+	
+	private boolean containsTemplates(Bundle bundle) {
+		return bundle.getResource(TEMPLATES_PATH_IN_BUNDLES) != null;
+	}
+
+	/**
+	 * Renders a GraphNode with a template located in the templates
+	 * folder of any active bundle
+	 * 
+	 * @param node the GraphNode to be rendered
+	 * @param templatePath the freemarker path to the template
+	 * @param out where the result is written to
+	 */
+	public void render(GraphNode node, final String templatePath, Writer out) {	
+		//A GraphNode backend could be graph unspecific, so the same engine could be
+		//reused, possibly being signifantly more performant (caching, etc.)
+		RDFBackend<Resource> backend = new ClerezzaBackend(node.getGraph());
+		Resource context = node.getNode();
+		TemplateEngine<Resource> engine = new TemplateEngine<Resource>(backend);
+		engine.setTemplateLoader(templateLoader);
+		try {
+			engine.processFileTemplate(context, templatePath, null, out);
+			out.flush();
+			out.close();
+		} catch (IOException e) {
+			throw new RuntimeException(e);
+		} catch (TemplateException e) {
+			throw new RuntimeException(e);
+		}
+	}
+}

Modified: stanbol/trunk/commons/pom.xml
URL: http://svn.apache.org/viewvc/stanbol/trunk/commons/pom.xml?rev=1389101&r1=1389100&r2=1389101&view=diff
==============================================================================
--- stanbol/trunk/commons/pom.xml (original)
+++ stanbol/trunk/commons/pom.xml Sun Sep 23 17:35:59 2012
@@ -59,6 +59,7 @@
   
     <module>indexedgraph</module>
     <module>ldpath/clerezza</module>
+	<module>ldtemplaterenderer</module>
     <module>httpqueryheaders</module>
     <module>launchpad</module>
     <module>security</module>