Package freemarker.template
Interface TransformControl
public interface TransformControl
An interface that can be implemented by writers returned from
TemplateTransformModel.getWriter(java.io.Writer, java.util.Map)
. The
methods on this
interfaces are callbacks that will be called by the template engine and that
give the writer a chance to better control the evaluation of the transform
body. The writer can instruct the engine to skip or to repeat body
evaluation, and gets notified about exceptions that are thrown during the
body evaluation.-
Field Summary
Modifier and TypeFieldDescriptionstatic int
Constant returned fromafterBody()
that tells the template engine to end the transform and close the writer.static int
Constant returned fromonStart()
that tells the template engine to evaluate the body.static int
Constant returned fromafterBody()
that tells the template engine to repeat transform body evaluation and feed it again to the transform.static int
Constant returned fromonStart()
that tells the template engine to skip evaluation of the body. -
Method Summary
Modifier and TypeMethodDescriptionint
Called after the body has been evaluated.void
Called if any exception occurs during the transform between theTemplateTransformModel.getWriter(java.io.Writer, java.util.Map)
call and theWriter.close()
call.int
onStart()
Called before the body is evaluated for the first time.
-
Field Details
-
REPEAT_EVALUATION
static final int REPEAT_EVALUATIONConstant returned fromafterBody()
that tells the template engine to repeat transform body evaluation and feed it again to the transform.- See Also:
- Constant Field Values
-
END_EVALUATION
static final int END_EVALUATIONConstant returned fromafterBody()
that tells the template engine to end the transform and close the writer.- See Also:
- Constant Field Values
-
SKIP_BODY
static final int SKIP_BODYConstant returned fromonStart()
that tells the template engine to skip evaluation of the body.- See Also:
- Constant Field Values
-
EVALUATE_BODY
static final int EVALUATE_BODYConstant returned fromonStart()
that tells the template engine to evaluate the body.- See Also:
- Constant Field Values
-
-
Method Details
-
onStart
Called before the body is evaluated for the first time.- Returns:
SKIP_BODY
if the transform wants to ignore the body. In this case, onlyWriter.close()
is called next and processing ends.EVALUATE_BODY
to normally evaluate the body of the transform and feed it to the writer
- Throws:
TemplateModelException
IOException
-
afterBody
Called after the body has been evaluated.- Returns:
END_EVALUATION
if the transformation should be ended.REPEAT_EVALUATION
to have the engine re-evaluate the transform body and feed it again to the writer.
- Throws:
TemplateModelException
IOException
-
onError
Called if any exception occurs during the transform between theTemplateTransformModel.getWriter(java.io.Writer, java.util.Map)
call and theWriter.close()
call.- Parameters:
t
- the throwable that represents the exception. It can be any non-checked throwable, as well asTemplateException
andIOException
.- Throws:
Throwable
- is recommended that the methods rethrow the received throwable. If the method wants to throw another throwable, it should either throw a non-checked throwable, or an instance ofTemplateException
andIOException
. Throwing any other checked exception will cause the engine to rethrow it as aUndeclaredThrowableException
.
-