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);
}
}
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;
}
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);
}
}
Aggregations