Search in sources :

Example 1 with GroovyPagesException

use of org.grails.gsp.GroovyPagesException 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)

Aggregations

IOException (java.io.IOException)1 GroovyPageTemplate (org.grails.gsp.GroovyPageTemplate)1 GroovyPagesException (org.grails.gsp.GroovyPagesException)1 Resource (org.springframework.core.io.Resource)1