use of freemarker.template.TransformControl in project freemarker by apache.
the class Environment method visitAndTransform.
/**
* "Visit" the template element, passing the output through a TemplateTransformModel
*
* @param elementBuffer
* the element to visit through a transform; might contains trailing {@code null}-s
* @param transform
* the transform to pass the element output through
* @param args
* optional arguments fed to the transform
*/
void visitAndTransform(TemplateElement[] elementBuffer, 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 {
visit(elementBuffer);
} while (tc != null && tc.afterBody() == TransformControl.REPEAT_EVALUATION);
}
} catch (Throwable t) {
try {
if (tc != null && !(t instanceof FlowControlException && getConfiguration().getIncompatibleImprovements().intValue() >= _TemplateAPI.VERSION_INT_2_3_27)) {
tc.onError(t);
} else {
throw t;
}
} catch (TemplateException e) {
throw e;
} catch (IOException e) {
throw e;
} catch (Error e) {
throw e;
} catch (Throwable e) {
if (EvalUtil.shouldWrapUncheckedException(e, this)) {
throw new _MiscTemplateException(e, this, "Transform has thrown an unchecked exception; see the cause exception.");
} else if (e instanceof RuntimeException) {
throw (RuntimeException) e;
} else {
throw new UndeclaredThrowableException(e);
}
}
} finally {
out = prevOut;
if (prevOut != tw) {
tw.close();
}
}
} catch (TemplateException te) {
handleTemplateException(te);
}
}
use of freemarker.template.TransformControl 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);
}
}
Aggregations