This project has retired. For details please refer to its Attic page.
Apache Marmotta - LDPath - Template

LDPath Template

LDPath implements an extension of the FreeMarker template engine that allows constructing templates with LDPath statements for inserting and iterating over values.

Template example

<@namespace rdfs="http://www.w3.org/2000/01/rdf-schema#" />
<html>
    <head>
        <title><@ldpath path="rdfs:label[@en]"/></title>
    </head>

    <body>
        <h1><@ldpath path="rdfs:label[@en]"/></h1>

        <p>
            <@ldpath path="rdfs:comment[@en]"/>
        </p>

        <ul>
            <@ldpath path="fn:sort(rdf:type)">
                <#if evalLDPath("rdfs:label[@en] :: xsd:string")??>
                    <li><@ldpath path="rdfs:label[@en] :: xsd:string"/></li>
                </#if>
            </@ldpath>
        </ul>
    </body>

</html>

Usage

To use this templating mechanism you would need to include the following artifact in your Maven build file:

<dependency>
    <groupId>org.apache.marmotta</groupId>
    <artifactId>ldpath-template</artifactId>
    <version>3.3.0</version>
</dependency>

This is the basic Java code for rendering LDPath templates:

final RepositoryConnection conn = ...getConnection();
try {
    conn.begin();
    final URI subject = conn.getValueFactory().createURI(uri);

    final SesameConnectionBackend backend = SesameConnectionBackend.withConnection(conn);
    final TemplateEngine<Value> engine = new TemplateEngine<Value>(backend); 
    engine.setDirectoryForTemplateLoading(new File("/path/to/templates"));

    OutputStreamWriter writer = new OutputStreamWriter(System.out, Charset.forName("utf-8"));
    engine.processFileTemplate(subject, "example.ftl", writer);
} finally {
    conn.commit();
    conn.close();
}