Search in sources :

Example 1 with GroovyPageTemplate

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);
}
Also used : GroovyPageTemplate(org.grails.gsp.GroovyPageTemplate) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException) GroovyPagesException(org.grails.gsp.GroovyPagesException)

Example 2 with GroovyPageTemplate

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();
    }
}
Also used : GroovyPageTemplate(org.grails.gsp.GroovyPageTemplate) ServletException(javax.servlet.ServletException) BeansException(org.springframework.beans.BeansException) IOException(java.io.IOException) GroovyPageTemplate(org.grails.gsp.GroovyPageTemplate) Template(groovy.text.Template)

Aggregations

IOException (java.io.IOException)2 GroovyPageTemplate (org.grails.gsp.GroovyPageTemplate)2 Template (groovy.text.Template)1 ServletException (javax.servlet.ServletException)1 GroovyPagesException (org.grails.gsp.GroovyPagesException)1 BeansException (org.springframework.beans.BeansException)1 Resource (org.springframework.core.io.Resource)1