Search in sources :

Example 1 with ByteArrayTemplateLoader

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;
}
Also used : MultiTemplateLoader(freemarker.cache.MultiTemplateLoader) StringTemplateLoader(freemarker.cache.StringTemplateLoader) Configuration(freemarker.template.Configuration) TemplateLoader(freemarker.cache.TemplateLoader) ByteArrayTemplateLoader(freemarker.cache.ByteArrayTemplateLoader) StringTemplateLoader(freemarker.cache.StringTemplateLoader) MultiTemplateLoader(freemarker.cache.MultiTemplateLoader)

Example 2 with ByteArrayTemplateLoader

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")));
}
Also used : Configuration(freemarker.template.Configuration) ByteArrayTemplateLoader(freemarker.cache.ByteArrayTemplateLoader) Test(org.junit.Test)

Example 3 with ByteArrayTemplateLoader

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;
}
Also used : Configuration(freemarker.template.Configuration) ByteArrayTemplateLoader(freemarker.cache.ByteArrayTemplateLoader) FileNameGlobMatcher(freemarker.cache.FileNameGlobMatcher) FirstMatchTemplateConfigurationFactory(freemarker.cache.FirstMatchTemplateConfigurationFactory) ConditionalTemplateConfigurationFactory(freemarker.cache.ConditionalTemplateConfigurationFactory)

Aggregations

ByteArrayTemplateLoader (freemarker.cache.ByteArrayTemplateLoader)3 Configuration (freemarker.template.Configuration)3 ConditionalTemplateConfigurationFactory (freemarker.cache.ConditionalTemplateConfigurationFactory)1 FileNameGlobMatcher (freemarker.cache.FileNameGlobMatcher)1 FirstMatchTemplateConfigurationFactory (freemarker.cache.FirstMatchTemplateConfigurationFactory)1 MultiTemplateLoader (freemarker.cache.MultiTemplateLoader)1 StringTemplateLoader (freemarker.cache.StringTemplateLoader)1 TemplateLoader (freemarker.cache.TemplateLoader)1 Test (org.junit.Test)1