|
|
CommonTemplate API 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 = ...
Writer out = ...
// setting context
Context context = factory.createContext(out);
context.defineAllVariables(model);
context.defineVariable("name", "value");
...
// run
Template template = factory.getTemplate("mytemplate.mtl");
template.render(context);
// clean (try finally)
context.clear();
out.flush();
out.close();
|
|
|