Search in sources :

Example 1 with RenderingException

use of ninja.exceptions.RenderingException in project ninja by ninjaframework.

the class TemplateEngineFreemarker method throwRenderingException.

public void throwRenderingException(Context context, Result result, Exception cause, String knownTemplateSourcePath) {
    // a more useful ParseException
    if (cause instanceof IOException && cause.getCause() != null && cause.getCause() instanceof ParseException) {
        cause = (ParseException) cause.getCause();
    }
    if (cause instanceof TemplateNotFoundException) {
        // inner cause will be better to display
        throw new RenderingException(cause.getMessage(), cause, result, "FreeMarker template not found", knownTemplateSourcePath, -1);
    } else if (cause instanceof TemplateException) {
        TemplateException te = (TemplateException) cause;
        String templateSourcePath = te.getTemplateSourceName();
        if (templateSourcePath == null) {
            templateSourcePath = knownTemplateSourcePath;
        }
        throw new RenderingException(cause.getMessage(), cause, result, "FreeMarker render exception", templateSourcePath, te.getLineNumber());
    } else if (cause instanceof ParseException) {
        ParseException pe = (ParseException) cause;
        String templateSourcePath = pe.getTemplateName();
        if (templateSourcePath == null) {
            templateSourcePath = knownTemplateSourcePath;
        }
        throw new RenderingException(cause.getMessage(), cause, result, "FreeMarker parser exception", templateSourcePath, pe.getLineNumber());
    }
    // fallback to throwing generic rendering exception
    throw new RenderingException(cause.getMessage(), cause, result, knownTemplateSourcePath, -1);
}
Also used : TemplateException(freemarker.template.TemplateException) RenderingException(ninja.exceptions.RenderingException) TemplateNotFoundException(freemarker.template.TemplateNotFoundException) IOException(java.io.IOException) ParseException(freemarker.core.ParseException)

Aggregations

ParseException (freemarker.core.ParseException)1 TemplateException (freemarker.template.TemplateException)1 TemplateNotFoundException (freemarker.template.TemplateNotFoundException)1 IOException (java.io.IOException)1 RenderingException (ninja.exceptions.RenderingException)1