Search in sources :

Example 6 with WebappTemplateLoader

use of freemarker.cache.WebappTemplateLoader in project wombat by PLOS.

the class SiteTemplateLoader method buildLoaders.

private static ImmutableMap<String, TemplateLoader> buildLoaders(ServletContext servletContext, SiteSet siteSet) throws IOException {
    ImmutableMap.Builder<String, TemplateLoader> builder = ImmutableMap.builder();
    // Add the loader for the application root page
    builder.put("NULLSITE", new WebappTemplateLoader(servletContext, "/WEB-INF/themes/root/app/"));
    // Add loader for each site
    for (Site site : siteSet.getSites()) {
        Theme leaf = site.getTheme();
        List<TemplateLoader> loaders = Lists.newArrayList();
        for (Theme theme : leaf.getInheritanceChain()) {
            loaders.add(theme.getTemplateLoader());
        }
        MultiTemplateLoader multiLoader = new MultiTemplateLoader(loaders.toArray(new TemplateLoader[loaders.size()]));
        builder.put(site.getKey(), multiLoader);
    }
    return builder.build();
}
Also used : MultiTemplateLoader(freemarker.cache.MultiTemplateLoader) WebappTemplateLoader(freemarker.cache.WebappTemplateLoader) DelegatingTemplateLoader(org.ambraproject.wombat.config.DelegatingTemplateLoader) TemplateLoader(freemarker.cache.TemplateLoader) WebappTemplateLoader(freemarker.cache.WebappTemplateLoader) MultiTemplateLoader(freemarker.cache.MultiTemplateLoader) Theme(org.ambraproject.wombat.config.theme.Theme) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

WebappTemplateLoader (freemarker.cache.WebappTemplateLoader)6 MultiTemplateLoader (freemarker.cache.MultiTemplateLoader)5 TemplateLoader (freemarker.cache.TemplateLoader)5 ClassTemplateLoader (freemarker.cache.ClassTemplateLoader)4 FileTemplateLoader (freemarker.cache.FileTemplateLoader)4 File (java.io.File)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Configuration (freemarker.template.Configuration)2 Test (org.junit.Test)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 StringTemplateLoader (freemarker.cache.StringTemplateLoader)1 ParseException (java.text.ParseException)1 List (java.util.List)1 DelegatingTemplateLoader (org.ambraproject.wombat.config.DelegatingTemplateLoader)1 Theme (org.ambraproject.wombat.config.theme.Theme)1