Java源码示例:no.api.freemarker.java8.Java8ObjectWrapper
示例1
@Test
public void testFull() throws IOException {
// Create FreeMarker configuration
Configuration cfg = new Configuration(FMV);
// Override the default ObjectWrapper with the one from freemarker-java-8
cfg.setObjectWrapper(new Java8ObjectWrapper(FMV, new KeepingZonedDateTimeStrategy()));
// Set class for template loading. In this case the test class itself
cfg.setClassForTemplateLoading(this.getClass(), "/templates");
cfg.setDefaultEncoding("UTF-8");
// Load or full FreeMarker template tester
Template template = cfg.getTemplate("full.ftl");
Map<String, Object> templateData = new HashMap<>();
templateData.put("clock", Clock.system(ZoneId.of("Europe/Oslo")));
try (StringWriter out = new StringWriter()) {
template.process(templateData, out);
System.out.println(out.getBuffer().toString());
out.flush();
} catch (TemplateException e) {
e.printStackTrace();
}
}
示例2
public TemplateEngine() {
this.configuration.setClassForTemplateLoading(this.getClass(), Default.TEMPLATES_FOLDER.toString());
this.configuration.setDefaultEncoding(StandardCharsets.UTF_8.name());
this.configuration.setOutputEncoding(StandardCharsets.UTF_8.name());
this.configuration.setLocalizedLookup(false);
this.configuration.setNumberFormat(Default.NUMBER_FORMAT.toString());
this.configuration.setAPIBuiltinEnabled(true);
this.configuration.setObjectWrapper(new Java8ObjectWrapper(VERSION));
this.configuration.setOutputFormat(HTMLOutputFormat.INSTANCE);
this.configuration.setRecognizeStandardFileExtensions(false);
if (Application.inDevMode()) {
this.configuration.setTemplateUpdateDelayMilliseconds(ONE_SECOND_MS);
} else {
this.configuration.setTemplateUpdateDelayMilliseconds(Integer.MAX_VALUE);
this.configuration.setCacheStorage(new MruCacheStorage(STRONG_SIZE_LIMIT, Integer.MAX_VALUE));
}
}
示例3
public DateTimeStepdefs() {
this.configuration = new Configuration(Configuration.VERSION_2_3_23);
this.objectWrapper = new Java8ObjectWrapper(VERSION_2_3_23, new KeepingZonedDateTimeStrategy());
this.configuration.setObjectWrapper(objectWrapper);
}
示例4
private void setStrategy(ZonedDateTimeStrategy strategy) {
this.objectWrapper = new Java8ObjectWrapper(VERSION_2_3_23, strategy);
this.configuration.setObjectWrapper(objectWrapper);
}