Search in sources :

Example 1 with URLTemplateLoader

use of freemarker.cache.URLTemplateLoader in project camel by apache.

the class SpringBootStarterMojo method getTemplate.

private Template getTemplate(String name) throws IOException {
    Configuration cfg = new Configuration(Configuration.getVersion());
    cfg.setTemplateLoader(new URLTemplateLoader() {

        @Override
        protected URL getURL(String name) {
            return SpringBootStarterMojo.class.getResource("/" + name);
        }
    });
    cfg.setDefaultEncoding("UTF-8");
    Template template = cfg.getTemplate(name);
    return template;
}
Also used : URLTemplateLoader(freemarker.cache.URLTemplateLoader) Configuration(freemarker.template.Configuration) URL(java.net.URL) Template(freemarker.template.Template)

Example 2 with URLTemplateLoader

use of freemarker.cache.URLTemplateLoader in project camel by apache.

the class FreemarkerComponent method getConfiguration.

public synchronized Configuration getConfiguration() {
    if (configuration == null) {
        configuration = new Configuration();
        configuration.setTemplateLoader(new URLTemplateLoader() {

            @Override
            protected URL getURL(String name) {
                try {
                    return ResourceHelper.resolveMandatoryResourceAsUrl(getCamelContext().getClassResolver(), name);
                } catch (Exception e) {
                    // so we should return null to signal the resource could not be found
                    return null;
                }
            }
        });
    }
    return (Configuration) configuration.clone();
}
Also used : URLTemplateLoader(freemarker.cache.URLTemplateLoader) Configuration(freemarker.template.Configuration) URL(java.net.URL)

Aggregations

URLTemplateLoader (freemarker.cache.URLTemplateLoader)2 Configuration (freemarker.template.Configuration)2 URL (java.net.URL)2 Template (freemarker.template.Template)1