use of freemarker.template.Configuration in project freemarker by apache.
the class TemplateConfigurationTest method testConfigureParserTooLowIcI.
@Test
public void testConfigureParserTooLowIcI() throws Exception {
Configuration cfgWithTooLowIcI = new Configuration(Configuration.VERSION_2_3_21);
for (PropertyDescriptor propDesc : getTemplateConfigurationSettingPropDescs(true, false)) {
TemplateConfiguration tc = new TemplateConfiguration();
String propName = propDesc.getName();
Object value = SETTING_ASSIGNMENTS.get(propName);
propDesc.getWriteMethod().invoke(tc, value);
boolean shouldFail;
if (CONFIGURABLE_PROP_NAMES.contains(propName)) {
shouldFail = true;
} else if (PARSER_PROP_NAMES.contains(propName)) {
shouldFail = false;
} else {
fail("Uncategorized property: " + propName);
return;
}
try {
tc.setParentConfiguration(cfgWithTooLowIcI);
if (shouldFail) {
fail("Should fail with property: " + propName);
}
} catch (IllegalStateException e) {
if (!shouldFail) {
throw e;
}
assertThat(e.getMessage(), containsString("2.3.22"));
}
}
}
use of freemarker.template.Configuration in project freemarker by apache.
the class TemplateConfigurationTest method testSetParentConfiguration.
@Test
public void testSetParentConfiguration() throws IOException {
TemplateConfiguration tc = new TemplateConfiguration();
Template t = new Template(null, "", DEFAULT_CFG);
try {
tc.apply(t);
fail();
} catch (IllegalStateException e) {
assertThat(e.getMessage(), containsString("Configuration"));
}
tc.setParent(DEFAULT_CFG);
try {
tc.setParentConfiguration(new Configuration());
fail();
} catch (IllegalStateException e) {
assertThat(e.getMessage(), containsString("Configuration"));
}
try {
// Same as setParentConfiguration
tc.setParent(new Configuration());
fail();
} catch (IllegalStateException e) {
assertThat(e.getMessage(), containsString("Configuration"));
}
try {
tc.setParentConfiguration(null);
fail();
} catch (NullArgumentException e) {
// exected
}
tc.setParent(DEFAULT_CFG);
tc.apply(t);
}
use of freemarker.template.Configuration in project freemarker by apache.
the class TemplateConfigurationWithTemplateCacheTest method testPlainText.
@Test
public void testPlainText() throws Exception {
Configuration cfg = createCommonEncodingTesterConfig();
cfg.setIncompatibleImprovements(Configuration.VERSION_2_3_22);
TemplateConfiguration tcDE = new TemplateConfiguration();
tcDE.setLocale(Locale.GERMANY);
TemplateConfiguration tcYN = new TemplateConfiguration();
tcYN.setBooleanFormat("Y,N");
cfg.setTemplateConfigurations(new MergingTemplateConfigurationFactory(cfg.getTemplateConfigurations(), new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("utf16.ftl"), tcDE), new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("utf16.ftl"), tcYN)));
{
Template t = cfg.getTemplate("utf8.ftl", null, null, false);
assertEquals("utf-8", t.getEncoding());
assertEquals(TEXT_WITH_ACCENTS, getTemplateOutput(t));
assertEquals(Locale.US, t.getLocale());
assertEquals("true,false", t.getBooleanFormat());
}
{
Template t = cfg.getTemplate("utf8.ftl", null, "iso-8859-1", false);
assertEquals("utf-8", t.getEncoding());
assertEquals(TEXT_WITH_ACCENTS, getTemplateOutput(t));
}
{
Template t = cfg.getTemplate("utf16.ftl", null, null, false);
assertEquals("utf-16", t.getEncoding());
assertEquals(TEXT_WITH_ACCENTS, getTemplateOutput(t));
assertEquals(Locale.GERMANY, t.getLocale());
assertEquals("Y,N", t.getBooleanFormat());
}
{
Template t = cfg.getTemplate("default.ftl", null, null, false);
assertEquals("iso-8859-1", t.getEncoding());
assertEquals(TEXT_WITH_ACCENTS, getTemplateOutput(t));
}
}
use of freemarker.template.Configuration in project freemarker by apache.
the class TemplateLevelSettings method renderWith.
private String renderWith(Version version, String mainBoolFmt, String incBoolFmt, String impBoolFtm) throws IOException, TemplateException {
Configuration cfg = new Configuration(version);
cfg.setTemplateLoader(TEMPLATES);
cfg.setCacheStorage(new StrongCacheStorage());
cfg.setBooleanFormat("C,c");
if (incBoolFmt != null) {
cfg.getTemplate(INCLUDED_FTL).setBooleanFormat(incBoolFmt);
}
if (impBoolFtm != null) {
cfg.getTemplate(IMPORTED_FTL).setBooleanFormat(impBoolFtm);
}
Template t = cfg.getTemplate(MAIN_FTL);
if (mainBoolFmt != null) {
t.setBooleanFormat(mainBoolFmt);
}
StringWriter sw = new StringWriter();
t.process(null, sw);
return sw.toString();
}
use of freemarker.template.Configuration in project freemarker by apache.
the class TemplateNameSpecialVariablesTest method setup.
@Before
public void setup() {
Configuration cfg = getConfiguration();
cfg.setWhitespaceStripping(false);
}
Aggregations