freemarker.template
Class SimpleEventAdapter

java.lang.Object
  extended by freemarker.template.SimpleEventAdapter
All Implemented Interfaces:
TemplateRuntimeHandler

public final class SimpleEventAdapter
extends java.lang.Object
implements TemplateRuntimeHandler

Adapter class for firing events that could happen at Template runtime. At most one listener can be registered for different events that can occur. This event adapter is an immutable class so that singleton instances can't have their behaviour changed.

Usage example:

 // Configure Log4j
 ...

 // Set up the template
 Template template = new Template(filename);

 // Set up the model
 TemplateModelRoot modelRoot = (...)

 // Set up the listener
 SimpleEventAdapter adapter = new SimpleEventAdapter( new Log4jExceptionListener() );

 // Call the template
 template.process( modelRoot, writer, adapter );
 

Since:
1.8
Version:
$Id: SimpleEventAdapter.java 1153 2013-04-15 10:59:37Z run2000 $
See Also:
TemplateEventAdapter

Nested Class Summary
 
Nested classes/interfaces inherited from interface freemarker.template.TemplateRuntimeHandler
TemplateRuntimeHandler.Severity
 
Constructor Summary
SimpleEventAdapter()
          Creates a new SimpleEventAdapter.
SimpleEventAdapter(TemplateExceptionListener exceptionListener)
          Creates a new SimpleEventAdapter with the given exception listener as the target of the exception events generated.
 
Method Summary
 void fireExceptionThrown(java.lang.Object source, java.lang.Exception exception, java.io.Writer output, java.lang.String sourceName, TemplateRuntimeHandler.Severity severity)
          Fires a TemplateExceptionEvent to the current listener.
 java.lang.String toString()
          Returns a string representation of the object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SimpleEventAdapter

public SimpleEventAdapter()
Creates a new SimpleEventAdapter.


SimpleEventAdapter

public SimpleEventAdapter(TemplateExceptionListener exceptionListener)
Creates a new SimpleEventAdapter with the given exception listener as the target of the exception events generated.

Parameters:
exceptionListener - the single event listener to received exception events
Method Detail

fireExceptionThrown

public void fireExceptionThrown(java.lang.Object source,
                                java.lang.Exception exception,
                                java.io.Writer output,
                                java.lang.String sourceName,
                                TemplateRuntimeHandler.Severity severity)
Fires a TemplateExceptionEvent to the current listener.

Specified by:
fireExceptionThrown in interface TemplateRuntimeHandler
Parameters:
source - the source object of the event
exception - the exception that caused the event to be fired
output - the current Template output stream
sourceName - the name of the source class and method that fired the event
severity - the severity of the exception

toString

public java.lang.String toString()
Returns a string representation of the object.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the object.