Search in sources :

Example 6 with UndeclaredThrowableException

use of freemarker.template.utility.UndeclaredThrowableException in project freemarker by apache.

the class PageContextFactory method getCurrentPageContext.

static FreeMarkerPageContext getCurrentPageContext() throws TemplateModelException {
    Environment env = Environment.getCurrentEnvironment();
    TemplateModel pageContextModel = env.getGlobalVariable(PageContext.PAGECONTEXT);
    if (pageContextModel instanceof FreeMarkerPageContext) {
        return (FreeMarkerPageContext) pageContextModel;
    }
    try {
        FreeMarkerPageContext pageContext = (FreeMarkerPageContext) pageContextImpl.newInstance();
        env.setGlobalVariable(PageContext.PAGECONTEXT, pageContext);
        return pageContext;
    } catch (IllegalAccessException e) {
        throw new IllegalAccessError(e.getMessage());
    } catch (InstantiationException e) {
        throw new UndeclaredThrowableException(e);
    }
}
Also used : UndeclaredThrowableException(freemarker.template.utility.UndeclaredThrowableException) Environment(freemarker.core.Environment) TemplateModel(freemarker.template.TemplateModel)

Example 7 with UndeclaredThrowableException

use of freemarker.template.utility.UndeclaredThrowableException in project be5 by DevelopmentOnTheEdge.

the class Environment method visitAndTransform.

/**
 * "Visit" the template element, passing the output
 * through a TemplateTransformModel
 * @param element the element to visit through a transform
 * @param transform the transform to pass the element output
 * through
 * @param args optional arguments fed to the transform
 */
void visitAndTransform(TemplateElement element, TemplateTransformModel transform, Map args) throws TemplateException, IOException {
    try {
        Writer tw = transform.getWriter(out, args);
        if (tw == null)
            tw = EMPTY_BODY_WRITER;
        TransformControl tc = tw instanceof TransformControl ? (TransformControl) tw : null;
        Writer prevOut = out;
        out = tw;
        try {
            if (tc == null || tc.onStart() != TransformControl.SKIP_BODY) {
                do {
                    if (element != null) {
                        visitByHiddingParent(element);
                    }
                } while (tc != null && tc.afterBody() == TransformControl.REPEAT_EVALUATION);
            }
        } catch (Throwable t) {
            try {
                if (tc != null) {
                    tc.onError(t);
                } else {
                    throw t;
                }
            } catch (TemplateException e) {
                throw e;
            } catch (IOException e) {
                throw e;
            } catch (RuntimeException e) {
                throw e;
            } catch (Error e) {
                throw e;
            } catch (Throwable e) {
                throw new UndeclaredThrowableException(e);
            }
        } finally {
            out = prevOut;
            tw.close();
        }
    } catch (TemplateException te) {
        handleTemplateException(te);
    }
}
Also used : TemplateException(freemarker.template.TemplateException) TransformControl(freemarker.template.TransformControl) UndeclaredThrowableException(freemarker.template.utility.UndeclaredThrowableException) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter) Writer(java.io.Writer) NullWriter(freemarker.template.utility.NullWriter) StringWriter(java.io.StringWriter)

Aggregations

UndeclaredThrowableException (freemarker.template.utility.UndeclaredThrowableException)7 IOException (java.io.IOException)4 TemplateException (freemarker.template.TemplateException)3 TemplateModel (freemarker.template.TemplateModel)2 TemplateModelException (freemarker.template.TemplateModelException)2 TransformControl (freemarker.template.TransformControl)2 NullWriter (freemarker.template.utility.NullWriter)2 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 Writer (java.io.Writer)2 Environment (freemarker.core.Environment)1 MalformedTemplateNameException (freemarker.template.MalformedTemplateNameException)1 TemplateDirectiveBody (freemarker.template.TemplateDirectiveBody)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Socket (java.net.Socket)1 RemoteException (java.rmi.RemoteException)1 MessageDigest (java.security.MessageDigest)1 ArrayList (java.util.ArrayList)1