Search in sources :

Example 6 with ClassTemplateLoader

use of freemarker.cache.ClassTemplateLoader 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;
}
Also used : MultiTemplateLoader(freemarker.cache.MultiTemplateLoader) UnexpectedServerException(com.pratilipi.common.exception.UnexpectedServerException) Configuration(freemarker.template.Configuration) ClassTemplateLoader(freemarker.cache.ClassTemplateLoader) IOException(java.io.IOException) FileTemplateLoader(freemarker.cache.FileTemplateLoader) File(java.io.File)

Aggregations

ClassTemplateLoader (freemarker.cache.ClassTemplateLoader)6 Configuration (freemarker.template.Configuration)4 UnexpectedServerException (com.pratilipi.common.exception.UnexpectedServerException)1 FileTemplateLoader (freemarker.cache.FileTemplateLoader)1 MultiTemplateLoader (freemarker.cache.MultiTemplateLoader)1 DefaultObjectWrapper (freemarker.template.DefaultObjectWrapper)1 Template (freemarker.template.Template)1 File (java.io.File)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 Resource (org.springframework.core.io.Resource)1