FreeHEP API
Version current

org.freehep.util.template
Class TemplateEngine

java.lang.Object
  extended byorg.freehep.util.template.TemplateEngine

public class TemplateEngine
extends 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

Version:
$Id: TemplateEngine.java,v 1.4 2003/05/03 00:39:37 duns Exp $
Author:
tonyj
Source Code:
TemplateEngine.java

Constructor Summary
TemplateEngine()
           
 
Method Summary
 void addValueProvider(ValueProvider p)
          Add a value provider to the set of value providers
 Reader filter(Reader in)
          Apply the template to a document.
 void removeValueProvider(ValueProvider p)
          Remove a value provider from the list of value providers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TemplateEngine

public TemplateEngine()
Method Detail

filter

public Reader filter(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.

FreeHEP API
Version current

Copyright © 2000-2004 FreeHEP, All Rights Reserved.