Skip to content

Instantly share code, notes, and snippets.

@kembuco
Created December 19, 2011 03:31
Show Gist options
  • Save kembuco/1495260 to your computer and use it in GitHub Desktop.
Save kembuco/1495260 to your computer and use it in GitHub Desktop.
Dust View
public class DustView extends AbstractTemplateView {
@Override
protected void renderMergedTemplateModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
try {
String basePath = getServletContext().getRealPath("");
Context cx = ContextFactory.getGlobal().enterContext();
cx.setOptimizationLevel(-1);
Global global = Main.getGlobal();
if (!global.isInitialized()) {
global.init(cx);
}
Scriptable scope = cx.initStandardObjects(global);
scope.put("basePath", scope, basePath);
scope.put("modelMap", scope, model);
scope.put("template", scope, FileUtils.readFileToString(new File(basePath + getUrl())));
Main.processFile(cx, scope, basePath + "/dust/dust-loader.js");
response.getOutputStream().write(scope.get("result", scope).toString().getBytes());
} finally {
Context.exit();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment