org.freehep.util.template
Class TemplateEngine
- java.lang.Object
-
- org.freehep.util.template.TemplateEngine
-
public class TemplateEngine extends java.lang.ObjectA 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 Summary
Constructors Constructor and Description TemplateEngine()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidaddValueProvider(ValueProvider p)Add a value provider to the set of value providersjava.io.Readerfilter(java.io.Reader in)Apply the template to a document.voidremoveValueProvider(ValueProvider p)Remove a value provider from the list of value providers.
-
-
-
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