use of org.grails.gsp.GroovyPageTemplate in project grails-core by grails.
the class GroovyPageView method createGroovyPageException.
public static GroovyPagesException createGroovyPageException(Exception exception, GroovyPagesTemplateEngine engine, String pageUrl) {
GroovyPageTemplate t = (GroovyPageTemplate) engine.createTemplate(pageUrl);
StackTraceElement[] stackTrace = exception.getStackTrace();
String className = stackTrace[0].getClassName();
int lineNumber = stackTrace[0].getLineNumber();
if (className.contains("_gsp")) {
int[] lineNumbers = t.getMetaInfo().getLineNumbers();
if (lineNumber < lineNumbers.length) {
lineNumber = lineNumbers[lineNumber - 1];
}
}
Resource resource = pageUrl != null ? engine.getResourceForUri(pageUrl) : null;
String file;
try {
file = resource != null && resource.exists() ? resource.getFile().getAbsolutePath() : pageUrl;
} catch (IOException e) {
file = pageUrl;
}
return new GroovyPagesException("Error processing GroovyPageView: " + exception.getMessage(), exception, lineNumber, file);
}
use of org.grails.gsp.GroovyPageTemplate in project grails-core by grails.
the class GroovyPagesServlet method renderPageWithEngine.
/**
* Attempts to render the page with the given arguments
*
*
* @param engine The GroovyPagesTemplateEngine to use
* @param request The HttpServletRequest
* @param response The HttpServletResponse
* @param scriptSource The template
*
* @throws IOException Thrown when an I/O exception occurs rendering the page
*/
protected void renderPageWithEngine(GroovyPagesTemplateEngine engine, HttpServletRequest request, HttpServletResponse response, GroovyPageScriptSource scriptSource) throws Exception {
request.setAttribute(GrailsLayoutDecoratorMapper.RENDERING_VIEW, Boolean.TRUE);
GSPResponseWriter out = createResponseWriter(response);
try {
Template template = engine.createTemplate(scriptSource);
if (template instanceof GroovyPageTemplate) {
((GroovyPageTemplate) template).setAllowSettingContentType(true);
}
template.make().writeTo(out);
} catch (Exception e) {
out.setError();
throw e;
} finally {
if (out != null)
out.close();
}
}
Aggregations