|
CommonTemplate Use Guide |
|
1. Using API JavaDoc>>
// import commontemplate module
import org.commontemplate.core.*;
import org.commontemplate.engine.*;
import org.commontemplate.standard.*;
import java.util.*;
// config and build factory
StandardConfiguration config = new StandardConfiguration();
config.loadStandardConfiguration();
config.set...
config.add...
...
Factory factory = new Engine(config);
// setting global context
GlobalContext globalContext = factory.getGlobalContext();
globalContext.defineVariable("name", "value");
...
// define data
Map model = ...
Appendable output = ...
Locale locale = ...
TimeZone timeZone = ...
// setting context
Context context = factory.createContext(output, locale, timeZone);
context.defineAllVariables(model);
context.defineVariable("name", "value");
...
// run
Template template = factory.getTemplate("mytemplate.mtl");
template.render(context);
// clean (try finally)
context.clear();
output.flush();
output.close();
|
|