Documentation of 'org.freehep.util.template.TemplateEngine' Java class
TemplateEngine
org.freehep.util.template

Class TemplateEngine



  • public class TemplateEngine
    extends java.lang.Object
    A very simple template engine. The template engine takes input and transforms it by looking for tags in the document, and replacing them with values provided by a set of ValueProviders.

    Example of HTML template:

    <html>
    <head>
    <title>{v:title}</title>
    </head>
    <body>
    Welcome {v:name} to Simple Template Example
    <table>
    <tr bgcolor="d0d0d0"><th>Author</th><th>Title</th><th>Year</th></tr>
    <t:book>
    <tr>
    <td><a href="#">{v:author}</a></td>
    <td><a href="#">{v:title}</a></td>
    <td><a href="#">{v:year}</a></td>
    </tr>
    </t:book>
    </table>
    </body>
    </html>

    The design (although not the code) was inspired by the JByte template engine

    • Constructor Detail

      • TemplateEngine

        public TemplateEngine()
    • Method Detail

      • filter

        public java.io.Reader filter(java.io.Reader in)
        Apply the template to a document.
        Parameters:
        in - The Reader from which the document will be read.
        Returns:
        A Reader from which the filtered document can be read.
      • addValueProvider

        public void addValueProvider(ValueProvider p)
        Add a value provider to the set of value providers
        Parameters:
        p - The ValueProvider to add
      • removeValueProvider

        public void removeValueProvider(ValueProvider p)
        Remove a value provider from the list of value providers.
        Parameters:
        p - The value provider to remove.

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.