use of org.mvel2.integration.impl.ImmutableDefaultFactory 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.integration.impl.ImmutableDefaultFactory in project mvel by mvel.
the class MVELIncludeTest method testEvalFile1.
/**
* evalFile with sub template in utf-8 encoding
*
* @throws IOException
*/
public void testEvalFile1() throws IOException {
final CompiledTemplate template = TemplateCompiler.compileTemplate(file);
final String tr = (String) new TemplateRuntime(template.getTemplate(), null, template.getRoot(), "./samples/scripts/").execute(new StringAppender(), new HashMap<String, String>(), new ImmutableDefaultFactory());
assertEquals("Hello mister Gaël Périé", tr);
}
Aggregations