use of freemarker.template.Version in project spring-framework by spring-projects.
the class FreeMarkerView method getObjectWrapper.
/**
* Return the configured FreeMarker {@link ObjectWrapper}, or the
* {@link ObjectWrapper#DEFAULT_WRAPPER default wrapper} if none specified.
* @see freemarker.template.Configuration#getObjectWrapper()
*/
protected ObjectWrapper getObjectWrapper() {
ObjectWrapper ow = getConfiguration().getObjectWrapper();
Version version = Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS;
return (ow != null ? ow : new DefaultObjectWrapperBuilder(version).build());
}
use of freemarker.template.Version in project deeplearning4j by deeplearning4j.
the class StaticPageUtil method renderHTMLContent.
public static String renderHTMLContent(Component... components) throws Exception {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
mapper.enable(SerializationFeature.INDENT_OUTPUT);
Configuration cfg = new Configuration(new Version(2, 3, 23));
// Where do we load the templates from:
cfg.setClassForTemplateLoading(StaticPageUtil.class, "");
// Some other recommended settings:
cfg.setIncompatibleImprovements(new Version(2, 3, 23));
cfg.setDefaultEncoding("UTF-8");
cfg.setLocale(Locale.US);
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
ClassPathResource cpr = new ClassPathResource("assets/dl4j-ui.js");
String scriptContents = IOUtils.toString(cpr.getInputStream(), "UTF-8");
Map<String, Object> pageElements = new HashMap<>();
List<ComponentObject> list = new ArrayList<>();
int i = 0;
for (Component c : components) {
list.add(new ComponentObject(String.valueOf(i), mapper.writeValueAsString(c)));
i++;
}
pageElements.put("components", list);
pageElements.put("scriptcontent", scriptContents);
Template template = cfg.getTemplate("staticpage.ftl");
Writer stringWriter = new StringWriter();
template.process(pageElements, stringWriter);
return stringWriter.toString();
}
use of freemarker.template.Version in project pcgen by PCGen.
the class ExportHandler method exportCharacterUsingFreemarker.
/**
* Produce an output file for a character using a FreeMarker template.
*
* @param aPC The character being output.
* @param outputWriter The destination for the output.
* @throws ExportException If the export fails.
*/
private void exportCharacterUsingFreemarker(PlayerCharacter aPC, BufferedWriter outputWriter) throws ExportException {
try {
// Set Directory for templates
Configuration cfg = new Configuration();
cfg.setDirectoryForTemplateLoading(templateFile.getParentFile());
cfg.setIncompatibleImprovements(new Version("2.3.20"));
// load template
Template template = cfg.getTemplate(templateFile.getName());
// Configure our custom directives and functions.
cfg.setSharedVariable("pcstring", new PCStringDirective(aPC, this));
cfg.setSharedVariable("pcvar", new PCVarFunction(aPC));
cfg.setSharedVariable("pcboolean", new PCBooleanFunction(aPC, this));
cfg.setSharedVariable("pchasvar", new PCHasVarFunction(aPC, this));
cfg.setSharedVariable("loop", new LoopDirective());
cfg.setSharedVariable("equipsetloop", new EquipSetLoopDirective(aPC));
GameMode gamemode = SettingsHandler.getGame();
// data-model
Map<String, Object> pc = OutputDB.buildDataModel(aPC.getCharID());
Map<String, Object> mode = OutputDB.buildModeDataModel(gamemode);
Map<String, Object> input = new HashMap<>();
input.put("pcgen", OutputDB.getGlobal());
input.put("pc", ObjectWrapper.DEFAULT_WRAPPER.wrap(pc));
input.put("gamemode", mode);
input.put("gamemodename", gamemode.getName());
// Process the template
template.process(input, outputWriter);
} catch (IOException | TemplateException exc) {
String message = "Error exporting character using template " + templateFile;
Logging.errorPrint(message, exc);
throw new ExportException(message + " : " + exc.getLocalizedMessage(), exc);
} finally {
if (outputWriter != null) {
try {
outputWriter.flush();
} catch (Exception ignored) {
}
}
}
}
Aggregations