import freemarker.template.*;
import java.util.*;
import java.io.*;
public class Test {
public static void main(String[] args) throws Exception {
/* Adjust the configuration */
Configuration cfg = Configuration.getDefaultConfiguration();
cfg.setDirectoryForTemplateLoading(
new File("/where/you/store/templates"));
/* Create a template */
Template temp = cfg.getTemplate("test.ftl");
/* Create a data model */
Map root = new HashMap();
root.put("user", "Big Joe");
Map latest = new HashMap();
root.put("latestProduct", latest);
latest.put("url", "products/greenmouse.html");
latest.put("name", "green mouse");
/* Merge data model with template */
Writer out = new OutputStreamWriter(System.out);
temp.process(root, out);
out.flush();
}
} |