use of org.mvel2.templates.CompiledTemplate in project fabric8 by jboss-fuse.
the class Auditor method toJson.
protected String toJson(String eventType, MessageReference messageReference) {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(Auditor.class.getClassLoader());
CompiledTemplate template = getTemplate(eventType, messageReference);
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("event", eventType);
vars.put("host", System.getProperty("runtime.id"));
vars.put("timestamp", new Date());
vars.put("message", messageReference.getMessage());
vars.put("messageReference", messageReference);
return TemplateRuntime.execute(template, context, vars).toString();
} finally {
Thread.currentThread().setContextClassLoader(cl);
}
}
use of org.mvel2.templates.CompiledTemplate in project fabric8 by jboss-fuse.
the class Auditor method getTemplate.
private CompiledTemplate getTemplate(String event, MessageReference message) {
String source = getTemplateSource(event, message);
CompiledTemplate template = templates.get(source);
if (template == null) {
template = TemplateCompiler.compileTemplate(source, context);
templates.put(source, template);
}
return template;
}
use of org.mvel2.templates.CompiledTemplate in project grafikon by jub77.
the class TextTemplateMvel method initialize.
private void initialize() {
TemplateCompiler compiler = new TemplateCompiler(this.getTemplate());
compiledTemplate = compiler.compile();
}
use of org.mvel2.templates.CompiledTemplate in project vertx-web by vert-x3.
the class MVELTemplateEngineImpl method render.
@Override
public void render(RoutingContext context, String templateDirectory, String templateFileName, Handler<AsyncResult<Buffer>> handler) {
try {
templateFileName = templateDirectory + templateFileName;
CompiledTemplate template = isCachingEnabled() ? cache.get(templateFileName) : null;
if (template == null) {
// real compile
String loc = adjustLocation(templateFileName);
String templateText = Utils.readFileToString(context.vertx(), loc);
if (templateText == null) {
throw new IllegalArgumentException("Cannot find template " + loc);
}
template = TemplateCompiler.compileTemplate(templateText);
if (isCachingEnabled()) {
cache.put(templateFileName, template);
}
}
Map<String, RoutingContext> variables = new HashMap<>(1);
variables.put("context", context);
final VertxInternal vertxInternal = (VertxInternal) context.vertx();
String directoryName = vertxInternal.resolveFile(templateFileName).getParent();
handler.handle(Future.succeededFuture(Buffer.buffer((String) new TemplateRuntime(template.getTemplate(), null, template.getRoot(), directoryName).execute(new StringAppender(), variables, new ImmutableDefaultFactory()))));
} catch (Exception ex) {
handler.handle(Future.failedFuture(ex));
}
}
use of org.mvel2.templates.CompiledTemplate in project gfm_viewer by satyagraha.
the class TransformerDefault method transformMarkdownFile.
@Override
public void transformMarkdownFile(File mdFile, File htFile) throws IOException {
String mdText = FileUtils.readFileToString(mdFile, UTF_8);
String htText = transformMarkdownText(mdText);
CompiledTemplate htmlTemplate = TemplateCompiler.compileTemplate(config.getHtmlTemplate());
Map<String, Object> vars = new TreeMap<String, Object>();
vars.put("title", htFile.toString());
vars.put("content", htText);
vars.put("cssText", config.getCssText());
vars.put("cssUris", config.getCssUris());
vars.put("jsText", config.getJsText());
vars.put("jsUris", config.getJsUris());
// LOGGER.fine("template vars: " + vars);
String rendered = (String) TemplateRuntime.execute(htmlTemplate, vars);
FileUtils.writeStringToFile(htFile, rendered, UTF_8);
}
Aggregations