Created
December 19, 2011 03:31
-
-
Save kembuco/1495260 to your computer and use it in GitHub Desktop.
Dust View
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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