Show HTMLReport.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.ext.beans.BeansWrapper;
import freemarker.template.SimpleHash;
import freemarker.template.TemplateException;
import net.time4tea.webstats.freemarker.StatisticWrapper;
import net.time4tea.webstats.statistic.Statistic;
import net.time4tea.webstats.statistic.StatisticMap;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
/**
* Originally richja May 1, 2006
*/
public class HTMLReport {
private Writer writer;
private List<Spec> specs = new ArrayList<Spec>();
private String templateName = "singlesource.ftl";
public HTMLReport(Writer writer) {
this.writer = writer;
}
public HTMLReport(String templateName,Writer writer) {
this.writer = writer;
this.templateName = templateName;
}
public void add(Spec spec) {
specs.add(spec);
}
public void doReport() throws IOException, TemplateException {
SimpleHash model = new SimpleHash();
BeansWrapper beansWrapper = new BeansWrapper();
List<Object> reports = new ArrayList<Object>();
for (Spec spec : specs) {
reports.add(beansWrapper.wrap(new StatisticWrapper(spec.statisticMap, spec.how, spec.top)));
}
model.put("reports", reports);
FreemarkerTemplate template = new FreemarkerTemplate(this, templateName);
template.process(model, writer);
}
public static class Spec {
public StatisticMap statisticMap;
public Comparator<Statistic> how;
public int top;
public Spec(StatisticMap statisticMap, Comparator<Statistic> how, int top) {
this.statisticMap = statisticMap;
this.how = how;
this.top = top;
}
}
}
See more files for this project here