@Override
public String render(String uriOrContent, Map<String, Object> root) throws OperationException, IOException {
CompiledTemplate compiled;
String content;
if (uriOrContent.startsWith(Renderer.TEMPLATE_PREFIX)) {
String name = uriOrContent.substring(Renderer.TEMPLATE_PREFIX.length());
compiled = cache.get(name);
if (compiled == null) {
URL url = Framework.getService(ResourceService.class).getResource(name);
if (url == null) {
throw new OperationException("Rendering resource not found: " + name);
}
try (InputStream in = url.openStream()) {
content = IOUtils.toString(in, UTF_8);
}
compiled = TemplateCompiler.compileTemplate(content);
cache.put(name, compiled);
}
} else {
content = uriOrContent;
compiled = TemplateCompiler.compileTemplate(content);
}
Object obj = TemplateRuntime.execute(compiled, root);
return obj == null ? "" : obj.toString();
}