use of freemarker.cache.ByteArrayTemplateLoader in project freemarker by apache.
the class GetOptionalTemplateTest method createConfiguration.
@Override
protected Configuration createConfiguration() throws Exception {
Configuration cfg = super.createConfiguration();
cfg.setTemplateLoader(new MultiTemplateLoader(new TemplateLoader[] { new StringTemplateLoader(), byteArrayTemplateLoader }));
return cfg;
}
use of freemarker.cache.ByteArrayTemplateLoader in project freemarker by apache.
the class TemplateConfigurationWithTemplateCacheTest method testIncludeAndEncoding.
@Test
public void testIncludeAndEncoding() throws Exception {
Configuration cfg = createCommonEncodingTesterConfig();
ByteArrayTemplateLoader tl = (ByteArrayTemplateLoader) cfg.getTemplateLoader();
tl.putTemplate("main.ftl", ("<#include 'utf8.ftl'>" + "<#include 'utf16.ftl'>" + "<#include 'default.ftl'>" + "<#include 'utf8-latin2.ftl'>" + // With mostly ignored encoding params:
"<#include 'utf8.ftl' encoding='utf-16'>" + "<#include 'utf16.ftl' encoding='iso-8859-5'>" + "<#include 'default.ftl' encoding='iso-8859-5'>" + "<#include 'utf8-latin2.ftl' encoding='iso-8859-5'>").getBytes("iso-8859-1"));
assertEquals(TEXT_WITH_ACCENTS + TEXT_WITH_ACCENTS + TEXT_WITH_ACCENTS + TEXT_WITH_ACCENTS + TEXT_WITH_ACCENTS + TEXT_WITH_ACCENTS + new String(TEXT_WITH_ACCENTS.getBytes("iso-8859-1"), "iso-8859-5") + TEXT_WITH_ACCENTS, getTemplateOutput(cfg.getTemplate("main.ftl")));
}
use of freemarker.cache.ByteArrayTemplateLoader in project freemarker by apache.
the class TemplateConfigurationWithTemplateCacheTest method createCommonEncodingTesterConfig.
private Configuration createCommonEncodingTesterConfig() throws UnsupportedEncodingException {
Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
cfg.setDefaultEncoding("iso-8859-1");
cfg.setLocale(Locale.US);
ByteArrayTemplateLoader tl = new ByteArrayTemplateLoader();
tl.putTemplate("utf8.ftl", TEXT_WITH_ACCENTS.getBytes("utf-8"));
tl.putTemplate("utf16.ftl", TEXT_WITH_ACCENTS.getBytes("utf-16"));
tl.putTemplate("default.ftl", TEXT_WITH_ACCENTS.getBytes("iso-8859-2"));
tl.putTemplate("utf8-latin2.ftl", ("<#ftl encoding='iso-8859-2'>" + TEXT_WITH_ACCENTS).getBytes("iso-8859-2"));
tl.putTemplate("default-latin2.ftl", ("<#ftl encoding='iso-8859-2'>" + TEXT_WITH_ACCENTS).getBytes("iso-8859-2"));
cfg.setTemplateLoader(tl);
TemplateConfiguration tcUtf8 = new TemplateConfiguration();
tcUtf8.setEncoding("utf-8");
TemplateConfiguration tcUtf16 = new TemplateConfiguration();
tcUtf16.setEncoding("utf-16");
cfg.setTemplateConfigurations(new FirstMatchTemplateConfigurationFactory(new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*utf8*"), tcUtf8), new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*utf16*"), tcUtf16)).allowNoMatch(true));
return cfg;
}
Aggregations