You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stanbol.apache.org by Reto Bachmann-Gmür <re...@apache.org> on 2012/09/23 20:11:08 UTC

Introducing LDPath template rendering service and LdViewable

As LDPath has been quite widely endorsed within Stanbol and the existing
pre dominant way of applying freemarker templates is problematic I've added
support to render GraphNodes using the LDPath template language. This
extension to the freemarker template language is described here:
http://code.google.com/p/ldpath/

How to use it?

Independently of context (web or not) and target format you can use the the
service exposing org.apache.stanbol.commons.ldpathtemplate.LdRenderer to
render a GraphNode to a writer. The template is specified relative to a
folder named "templates" in the root of any bundle.

Thanks to the org.apache.stanbol.commons.ldviewable artifact jax-rs
resources can return an instance of
org.apache.stanbol.commons.ldviewable.LdViewable this class encapsulates a
GraphNode and a template path. Note that the root for the templates depends
on the media-type being produced. Currently only "text/html" is supported
and for this the template must be located under "templates/html" in any
bundle.

Examples:

    @GET
    @Path("foo2")
    public LdViewable foo2() {
        return new LdViewable("tests/test.ftl", foo());
    }

--> In the maven source structure the template is located in
./src/main/resources/templates/html/tests/test.ftl

    @GET
    @Path("foo3")
    public LdViewable foo4() {
        return new LdViewable("test.ftl", foo(), this.getClass());
    }

--> This adds the package name of the class to the template path, this is
good practice to avoid conflicts between templates. If this is an instance
of org.apache.stanbol.commons.usermanagement.Foo, the template is located
at
./src/main/resources/templates/html/org/apache/stanbol/commons/usermanagement/test.ftl


Cheers,
Reto