/** * Builds the Freemarker template creating the output string. * * @param template the template, not null * @param data the root data to merge, not null * @return the template, not null */ @SuppressWarnings("unchecked") public String build(final Template template, final Object data) { if (data instanceof FlexiBean) { ((FlexiBean) data).put("freemarkerTemplateName", template.getName()); ((FlexiBean) data).put("freemarkerLocale", template.getLocale()); ((FlexiBean) data).put("freemarkerVersion", Configuration.getVersionNumber()); } if (data instanceof Map<?, ?>) { ((Map<String, Object>) data).put("freemarkerTemplateName", template.getName()); ((Map<String, Object>) data).put("freemarkerLocale", template.getLocale()); ((Map<String, Object>) data).put("freemarkerVersion", Configuration.getVersionNumber()); } try { StringWriter out = new StringWriter(1024 * 4); template.process(data, out); out.close(); return out.toString(); } catch (Exception ex) { return handleException(ex); } }
public ProcessadorFreemarkerSimples() { super(); cfg = new Configuration(); String s = cfg.getVersionNumber(); // Specify the data source where the template files come from. cfg.setTemplateLoader(this); // Specify how templates will see the data-model. cfg.setObjectWrapper(new DefaultObjectWrapper()); cfg.setWhitespaceStripping(true); cfg.setTagSyntax(Configuration.SQUARE_BRACKET_TAG_SYNTAX); cfg.setLocalizedLookup(false); }
// ------------------------------------------------------------------------- @Override public String toString() { return "FreemarkerOutputter[" + Configuration.getVersionNumber() + "]"; }