use of freemarker.cache.FileNameGlobMatcher in project freemarker by apache.
the class DateFormatTest method testAlieses.
@Test
public void testAlieses() throws Exception {
Configuration cfg = getConfiguration();
cfg.setCustomDateFormats(ImmutableMap.of("d", new AliasTemplateDateFormatFactory("yyyy-MMM-dd"), "m", new AliasTemplateDateFormatFactory("yyyy-MMM"), "epoch", EpochMillisTemplateDateFormatFactory.INSTANCE));
TemplateConfiguration tc = new TemplateConfiguration();
tc.setCustomDateFormats(ImmutableMap.of("m", new AliasTemplateDateFormatFactory("yyyy-MMMM"), "i", new AliasTemplateDateFormatFactory("@epoch")));
cfg.setTemplateConfigurations(new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*2*"), tc));
addToDataModel("d", TM);
String commonFtl = "${d?string.@d} ${d?string.@m} " + "<#setting locale='fr_FR'>${d?string.@m} " + "<#attempt>${d?string.@i}<#recover>E</#attempt>";
addTemplate("t1.ftl", commonFtl);
addTemplate("t2.ftl", commonFtl);
// 2015-09-06T12:00:00Z
assertOutputForNamed("t1.ftl", "2015-Sep-06 2015-Sep 2015-sept. E");
assertOutputForNamed("t2.ftl", "2015-Sep-06 2015-September 2015-septembre " + T);
}
use of freemarker.cache.FileNameGlobMatcher in project freemarker by apache.
the class TemplateConfigurationExamples method example2.
@Test
public void example2() throws Exception {
Configuration cfg = getConfiguration();
addTemplate("t.subject.ftl", "");
addTemplate("mail/t.subject.ftl", "");
addTemplate("mail/t.body.ftl", "");
TemplateConfiguration tcSubject = new TemplateConfiguration();
tcSubject.setOutputFormat(PlainTextOutputFormat.INSTANCE);
TemplateConfiguration tcBody = new TemplateConfiguration();
tcBody.setOutputFormat(HTMLOutputFormat.INSTANCE);
cfg.setTemplateConfigurations(new ConditionalTemplateConfigurationFactory(new PathGlobMatcher("mail/**"), new FirstMatchTemplateConfigurationFactory(new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*.subject.*"), tcSubject), new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*.body.*"), tcBody)).noMatchErrorDetails("Mail template names must contain \".subject.\" or \".body.\"!")));
assertEquals(UndefinedOutputFormat.INSTANCE, cfg.getTemplate("t.subject.ftl").getOutputFormat());
assertEquals(PlainTextOutputFormat.INSTANCE, cfg.getTemplate("mail/t.subject.ftl").getOutputFormat());
assertEquals(HTMLOutputFormat.INSTANCE, cfg.getTemplate("mail/t.body.ftl").getOutputFormat());
// From properties:
cfg.setTemplateConfigurations(null);
cfg.setSettings(loadPropertiesFile("TemplateConfigurationExamples2.properties"));
assertEquals(UndefinedOutputFormat.INSTANCE, cfg.getTemplate("t.subject.ftl").getOutputFormat());
assertEquals(PlainTextOutputFormat.INSTANCE, cfg.getTemplate("mail/t.subject.ftl").getOutputFormat());
assertEquals(HTMLOutputFormat.INSTANCE, cfg.getTemplate("mail/t.body.ftl").getOutputFormat());
}
Aggregations