use of freemarker.cache.MultiTemplateLoader in project pratilipi by Pratilipi.
the class FreeMarkerUtil method getConfiguration.
private static Configuration getConfiguration() throws UnexpectedServerException {
if (cfg == null) {
FileTemplateLoader ftl;
try {
ftl = new FileTemplateLoader(new File("."));
} catch (IOException e) {
logger.log(Level.SEVERE, "Failed to set template directory.", e);
throw new UnexpectedServerException();
}
ClassTemplateLoader ctl = new ClassTemplateLoader(FreeMarkerUtil.class.getClassLoader(), "");
MultiTemplateLoader mtl = new MultiTemplateLoader(new TemplateLoader[] { ftl, ctl });
cfg = new Configuration(Configuration.VERSION_2_3_22);
cfg.setTemplateLoader(mtl);
cfg.setDefaultEncoding("UTF-8");
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
}
return cfg;
}
use of freemarker.cache.MultiTemplateLoader in project drill by axbaretto.
the class DrillRestServer method getFreemarkerConfiguration.
/**
* Creates freemarker configuration settings,
* default output format to trigger auto-escaping policy
* and template loaders.
*
* @param servletContext servlet context
* @return freemarker configuration settings
*/
private Configuration getFreemarkerConfiguration(ServletContext servletContext) {
Configuration configuration = new Configuration(Configuration.VERSION_2_3_26);
configuration.setOutputFormat(HTMLOutputFormat.INSTANCE);
List<TemplateLoader> loaders = new ArrayList<>();
loaders.add(new WebappTemplateLoader(servletContext));
loaders.add(new ClassTemplateLoader(DrillRestServer.class, "/"));
try {
loaders.add(new FileTemplateLoader(new File("/")));
} catch (IOException e) {
logger.error("Could not set up file template loader.", e);
}
configuration.setTemplateLoader(new MultiTemplateLoader(loaders.toArray(new TemplateLoader[loaders.size()])));
return configuration;
}
use of freemarker.cache.MultiTemplateLoader 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("", 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();
}
use of freemarker.cache.MultiTemplateLoader in project revapi by revapi.
the class TextReporter method createFreeMarkerConfiguration.
/**
* Creates a new FreeMarker configuration.
* By default, it is configured as follows:
* <ul>
* <li>compatibility level is set to 2.3.23
* <li>the object wrapper is configured to expose fields
* <li>API builtins are enabled
* <li>there are 2 template loaders - 1 for loading templates from /META-INF using a classloader and a second
* one to load templates from files.
* </ul>
* @return
*/
protected Configuration createFreeMarkerConfiguration() {
DefaultObjectWrapperBuilder bld = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_23);
bld.setExposeFields(true);
Configuration freeMarker = new Configuration(Configuration.VERSION_2_3_23);
freeMarker.setObjectWrapper(bld.build());
freeMarker.setAPIBuiltinEnabled(true);
freeMarker.setTemplateLoader(new MultiTemplateLoader(new TemplateLoader[] { new ClassTemplateLoader(getClass(), "/META-INF"), new NaiveFileTemplateLoader() }));
return freeMarker;
}
use of freemarker.cache.MultiTemplateLoader in project drill by apache.
the class DrillRestServer method getFreemarkerConfiguration.
/**
* Creates freemarker configuration settings,
* default output format to trigger auto-escaping policy
* and template loaders.
*
* @param servletContext servlet context
* @return freemarker configuration settings
*/
private Configuration getFreemarkerConfiguration(ServletContext servletContext) {
Configuration configuration = new Configuration(Configuration.VERSION_2_3_26);
configuration.setOutputFormat(HTMLOutputFormat.INSTANCE);
List<TemplateLoader> loaders = new ArrayList<>();
loaders.add(new WebappTemplateLoader(servletContext));
loaders.add(new ClassTemplateLoader(DrillRestServer.class, "/"));
try {
loaders.add(new FileTemplateLoader(new File("/")));
} catch (IOException e) {
logger.error("Could not set up file template loader.", e);
}
configuration.setTemplateLoader(new MultiTemplateLoader(loaders.toArray(new TemplateLoader[loaders.size()])));
return configuration;
}
Aggregations