this.tableColumns = tableColumns;
encoding = "UTF8";
// validations
if(outputFile == null) {
throw new DataUtilException("The outputFile field can not be a null value");
}
if(pageTitle == null) {
pageTitle = "";
}
if(tableColumns < 1) {
throw new DataUtilException("You must have at least one column. Invalid column value: " + tableColumns);
}
try {
// our output HTML file
writer = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(outputFile.getAbsoluteFile(), false), Charset.forName(encoding)));
// setup freemarker
cfg = new Configuration();
cfg.setClassForTemplateLoading(this.getClass(), "/templates");
cfg.setObjectWrapper(new DefaultObjectWrapper());
cfg.setDefaultEncoding(encoding);
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
cfg.setIncompatibleImprovements(new Version(2, 3, 20)); // FreeMarker 2.3.20
// render header
Map<String,Object> root = new HashMap<String,Object>();
root.put("pageTitle", pageTitle);
Template template = cfg.getTemplate("html-table-header.ftl");
template.process(root, writer);
} catch (FileNotFoundException e) {
throw new DataUtilException("Failed to open an HTML table file", e);
} catch (IOException e) {
throw new DataUtilException("Failed to open an HTML table file", e);
} catch (TemplateException e) {
throw new DataUtilException("Failed to write the HTML table file header", e);
}
}