FreemarkerTemplate.java from Tea Stats at Krugle
Show FreemarkerTemplate.java syntax highlighted
/*
* This file is distributed under the GPL v2 as part of teastats site statistics package
* http://teastats.sourceforge.net
*/
package net.time4tea.webstats.report;
import freemarker.template.Configuration;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;
import net.time4tea.webstats.freemarker.ResourceTemplateLoader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.StringWriter;
import java.io.Writer;
/**
* $$Header$
* Initially by: james on 30-Jul-2006
*/
public class FreemarkerTemplate {
private String name;
public Configuration configuration;
public FreemarkerTemplate(Object owner, String name) {
configuration = new Configuration();
configuration.setTemplateLoader(new ResourceTemplateLoader(owner));
this.name = name;
}
public String process(TemplateModel model) throws IOException, TemplateException {
StringWriter writer = new StringWriter();
process(model, writer);
return writer.toString();
}
public void process(TemplateModel model, Writer writer) throws TemplateException, IOException {
configuration.getTemplate(name).process(model, writer);
}
public void process(TemplateModel templateModel, File file) throws IOException, TemplateException {
process(templateModel, new OutputStreamWriter(new FileOutputStream(file)));
}
}
See more files for this project here