Search in sources :

Example 41 with TemplateException

use of freemarker.template.TemplateException in project stanbol by apache.

the class LdRenderer method render.

/**
	 * Renders a GraphNode with a template located in the templates
	 * folder of any active bundle
	 * 
	 * @param node the GraphNode to be rendered
	 * @param templatePath the freemarker path to the template
	 * @param out where the result is written to
	 */
public void render(GraphNode node, final String templatePath, Writer out) {
    //A GraphNode backend could be graph unspecific, so the same engine could be
    //reused, possibly being signifantly more performant (caching, etc.)
    RDFBackend<RDFTerm> backend = new ClerezzaBackend(node.getGraph());
    RDFTerm context = node.getNode();
    TemplateEngine<RDFTerm> engine = new TemplateEngine<RDFTerm>(backend);
    engine.setTemplateLoader(templateLoader);
    try {
        engine.processFileTemplate(context, templatePath, null, out);
        out.flush();
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (TemplateException e) {
        throw new RuntimeException(e);
    }
}
Also used : TemplateEngine(org.apache.marmotta.ldpath.template.engine.TemplateEngine) TemplateException(freemarker.template.TemplateException) ClerezzaBackend(org.apache.stanbol.commons.ldpath.clerezza.ClerezzaBackend) RDFTerm(org.apache.clerezza.commons.rdf.RDFTerm) IOException(java.io.IOException)

Example 42 with TemplateException

use of freemarker.template.TemplateException in project leopard by tanhaichao.

the class FreeMarkerUtil method getFreeMarkerConfigurer.

protected static FreeMarkerConfigurer getFreeMarkerConfigurer(ApplicationContext applicationContext, String templateLoaderPath) {
    Map<String, Object> freemarkerVariables = new HashMap<String, Object>();
    freemarkerVariables.put("xml_escape", "fmXmlEscape");
    freemarkerVariables.put("replaceParam", new ReplaceParamTemplateMethod());
    freemarkerVariables.put("timeAgo", new TimeAgoTemplateMethod());
    freemarkerVariables.putAll(listTemplateMethod(applicationContext));
    Properties freemarkerSettings = new Properties();
    freemarkerSettings.put("template_update_delay", "1");
    freemarkerSettings.put("defaultEncoding", "UTF-8");
    FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
    configurer.setTemplateLoaderPath(templateLoaderPath);
    configurer.setFreemarkerVariables(freemarkerVariables);
    configurer.setFreemarkerSettings(freemarkerSettings);
    try {
        configurer.afterPropertiesSet();
    } catch (IOException e) {
        throw new RuntimeException(e.getMessage(), e);
    } catch (TemplateException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
    return configurer;
}
Also used : HashMap(java.util.HashMap) TemplateException(freemarker.template.TemplateException) IOException(java.io.IOException) TimeAgoTemplateMethod(io.leopard.web.freemarker.template.TimeAgoTemplateMethod) Properties(java.util.Properties) ReplaceParamTemplateMethod(io.leopard.web.freemarker.template.ReplaceParamTemplateMethod) FreeMarkerConfigurer(org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer)

Example 43 with TemplateException

use of freemarker.template.TemplateException in project hub-alert by blackducksoftware.

the class HipChatChannel method createHtmlMessage.

private String createHtmlMessage(final ProjectData projectData) {
    try {
        final String templatesDirectory = System.getenv("ALERT_TEMPLATES_DIR");
        String templateDirectoryPath;
        if (StringUtils.isNotBlank(templatesDirectory)) {
            templateDirectoryPath = templatesDirectory + "/hipchat";
        } else {
            templateDirectoryPath = System.getProperties().getProperty("user.dir") + "/src/main/resources/hipchat/templates";
        }
        final ChannelFreemarkerTemplatingService freemarkerTemplatingService = new ChannelFreemarkerTemplatingService(templateDirectoryPath);
        final HashMap<String, Object> model = new HashMap<>();
        model.put("projectName", projectData.getProjectName());
        model.put("projectVersion", projectData.getProjectVersion());
        model.put("categoryMap", projectData.getCategoryMap());
        return freemarkerTemplatingService.getResolvedTemplate(model, "notification.ftl");
    } catch (final IOException | TemplateException e) {
        throw new RuntimeException(e);
    }
}
Also used : HashMap(java.util.HashMap) TemplateException(freemarker.template.TemplateException) ChannelFreemarkerTemplatingService(com.blackducksoftware.integration.hub.alert.channel.ChannelFreemarkerTemplatingService) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException)

Aggregations

TemplateException (freemarker.template.TemplateException)43 IOException (java.io.IOException)38 Template (freemarker.template.Template)21 HashMap (java.util.HashMap)19 Writer (java.io.Writer)15 StringWriter (java.io.StringWriter)13 Configuration (freemarker.template.Configuration)8 Map (java.util.Map)8 WriterRepresentation (org.restlet.representation.WriterRepresentation)6 File (java.io.File)5 OutputStreamWriter (java.io.OutputStreamWriter)4 MediaType (org.restlet.data.MediaType)4 Representation (org.restlet.representation.Representation)4 DefaultObjectWrapper (freemarker.template.DefaultObjectWrapper)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 FileWriter (java.io.FileWriter)3 StringRepresentation (org.restlet.representation.StringRepresentation)3 ParseException (freemarker.core.ParseException)2 SimpleHash (freemarker.template.SimpleHash)2 BufferedWriter (java.io.BufferedWriter)2