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.

Version:
$Id: TransformControl.java,v 1.11 2005/06/16 18:13:58 ddekany Exp $
Author:
Attila Szegedi

Field Summary
static int END_EVALUATION
          Constant returned from afterBody() that tells the template engine to end the transform and close the writer.
static int EVALUATE_BODY
          Constant returned from onStart() that tells the template engine to evaluate the body.
static int REPEAT_EVALUATION
          Constant returned from afterBody() that tells the template engine to repeat transform body evaluation and feed it again to the transform.
static int SKIP_BODY
          Constant returned from onStart() that tells the template engine to skip evaluation of the body.
 
Method Summary
 int afterBody()
          Called after the body has been evaluated.
 void onError(java.lang.Throwable t)
          Called if any exception occurs during the transform between the TemplateTransformModel.getWriter(java.io.Writer, java.util.Map) call and the Writer.close() call.
 int onStart()
          Called before the body is evaluated for the first time.
 

Field Detail

REPEAT_EVALUATION

static final int REPEAT_EVALUATION
Constant returned from afterBody() 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_EVALUATION
Constant returned from afterBody() that tells the template engine to end the transform and close the writer.

See Also:
Constant Field Values

SKIP_BODY

static final int SKIP_BODY
Constant returned from onStart() that tells the template engine to skip evaluation of the body.

See Also:
Constant Field Values

EVALUATE_BODY

static final int EVALUATE_BODY
Constant returned from onStart() that tells the template engine to evaluate the body.

See Also:
Constant Field Values
Method Detail

onStart

int onStart()
            throws TemplateModelException,
                   java.io.IOException
Called before the body is evaluated for the first time.

Returns:
  • SKIP_BODY if the transform wants to ignore the body. In this case, only Writer.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
java.io.IOException

afterBody

int afterBody()
              throws TemplateModelException,
                     java.io.IOException
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
java.io.IOException

onError

void onError(java.lang.Throwable t)
             throws java.lang.Throwable
Called if any exception occurs during the transform between the TemplateTransformModel.getWriter(java.io.Writer, java.util.Map) call and the Writer.close() call.

Parameters:
t - the throwable that represents the exception. It can be any non-checked throwable, as well as TemplateException and IOException.
Throws:
java.lang.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 of TemplateException and IOException. Throwing any other checked exception will cause the engine to rethrow it as a UndeclaredThrowableException.