Class EventExample

java.lang.Object
org.slf4j.helpers.MarkerIgnoringBase
org.apache.velocity.example.EventExample
All Implemented Interfaces:
Serializable, org.apache.velocity.app.event.EventHandler, org.apache.velocity.app.event.InvalidReferenceEventHandler, org.apache.velocity.app.event.MethodExceptionEventHandler, org.apache.velocity.app.event.ReferenceInsertionEventHandler, org.slf4j.Logger

public class EventExample extends org.slf4j.helpers.MarkerIgnoringBase implements org.apache.velocity.app.event.ReferenceInsertionEventHandler, org.apache.velocity.app.event.MethodExceptionEventHandler, org.apache.velocity.app.event.InvalidReferenceEventHandler
This class is a simple demonstration of how the event handling features of the Velocity Servlet Engine are used. It uses a custom logger as well to check the log message stream when testing the InvalidReferenceEventHandler.
Version:
$Id$
See Also:
  • Field Details

    • logOutput

      private boolean logOutput
    • exceptionSwitch

      private boolean exceptionSwitch
    • LOG_LEVEL_TRACE

      public static final int LOG_LEVEL_TRACE
      See Also:
    • LOG_LEVEL_DEBUG

      public static final int LOG_LEVEL_DEBUG
      See Also:
    • LOG_LEVEL_INFO

      public static final int LOG_LEVEL_INFO
      See Also:
    • LOG_LEVEL_WARN

      public static final int LOG_LEVEL_WARN
      See Also:
    • LOG_LEVEL_ERROR

      public static final int LOG_LEVEL_ERROR
      See Also:
    • name

      protected String name
  • Constructor Details

    • EventExample

      public EventExample()
  • Method Details

    • main

      public static void main(String[] args)
    • throwException

      public void throwException() throws Exception
      silly method to throw an exception to demonstrate the method invocation exception event handling
      Throws:
      Exception
    • referenceInsert

      public Object referenceInsert(org.apache.velocity.context.Context context, String reference, Object value)
      Event handler for when a reference is inserted into the output stream.
      Specified by:
      referenceInsert in interface org.apache.velocity.app.event.ReferenceInsertionEventHandler
    • invalidGetMethod

      public Object invalidGetMethod(org.apache.velocity.context.Context context, String reference, Object object, String property, org.apache.velocity.util.introspection.Info info)
      Specified by:
      invalidGetMethod in interface org.apache.velocity.app.event.InvalidReferenceEventHandler
    • invalidMethod

      public Object invalidMethod(org.apache.velocity.context.Context context, String reference, Object object, String method, org.apache.velocity.util.introspection.Info info)
      Specified by:
      invalidMethod in interface org.apache.velocity.app.event.InvalidReferenceEventHandler
    • invalidSetMethod

      public boolean invalidSetMethod(org.apache.velocity.context.Context context, String leftreference, String rightreference, org.apache.velocity.util.introspection.Info info)
      Event handler for when the right hand side of a #set() directive is null, which results in a log message. This method gives the application a chance to 'vote' on msg generation
      Specified by:
      invalidSetMethod in interface org.apache.velocity.app.event.InvalidReferenceEventHandler
    • methodException

      public Object methodException(org.apache.velocity.context.Context context, Class claz, String method, Exception e, org.apache.velocity.util.introspection.Info info)
      Specified by:
      methodException in interface org.apache.velocity.app.event.MethodExceptionEventHandler
    • log

      public void log(int level, String message)
      This just prints the message and level to System.out.
    • log

      public void log(int level, String message, Throwable t)
      This prints the level, message, and the Throwable's message to System.out.
    • formatAndLog

      public void formatAndLog(int level, String format, Object... arguments)
      This prints the level and formatted message to System.out.
    • isLevelEnabled

      public boolean isLevelEnabled(int level)
      This always returns true because logging levels can't be disabled in this impl.
    • getName

      public String getName()
      Required init methods for Logger interface
      Specified by:
      getName in interface org.slf4j.Logger
    • isTraceEnabled

      public boolean isTraceEnabled()
      Specified by:
      isTraceEnabled in interface org.slf4j.Logger
    • trace

      public void trace(String msg)
      Specified by:
      trace in interface org.slf4j.Logger
    • trace

      public void trace(String format, Object param1)
      Specified by:
      trace in interface org.slf4j.Logger
    • trace

      public void trace(String format, Object param1, Object param2)
      Specified by:
      trace in interface org.slf4j.Logger
    • trace

      public void trace(String format, Object... argArray)
      Specified by:
      trace in interface org.slf4j.Logger
    • trace

      public void trace(String msg, Throwable t)
      Specified by:
      trace in interface org.slf4j.Logger
    • isDebugEnabled

      public boolean isDebugEnabled()
      Specified by:
      isDebugEnabled in interface org.slf4j.Logger
    • debug

      public void debug(String msg)
      Specified by:
      debug in interface org.slf4j.Logger
    • debug

      public void debug(String format, Object param1)
      Specified by:
      debug in interface org.slf4j.Logger
    • debug

      public void debug(String format, Object param1, Object param2)
      Specified by:
      debug in interface org.slf4j.Logger
    • debug

      public void debug(String format, Object... argArray)
      Specified by:
      debug in interface org.slf4j.Logger
    • debug

      public void debug(String msg, Throwable t)
      Specified by:
      debug in interface org.slf4j.Logger
    • isInfoEnabled

      public boolean isInfoEnabled()
      Specified by:
      isInfoEnabled in interface org.slf4j.Logger
    • info

      public void info(String msg)
      Specified by:
      info in interface org.slf4j.Logger
    • info

      public void info(String format, Object arg)
      Specified by:
      info in interface org.slf4j.Logger
    • info

      public void info(String format, Object arg1, Object arg2)
      Specified by:
      info in interface org.slf4j.Logger
    • info

      public void info(String format, Object... argArray)
      Specified by:
      info in interface org.slf4j.Logger
    • info

      public void info(String msg, Throwable t)
      Specified by:
      info in interface org.slf4j.Logger
    • isWarnEnabled

      public boolean isWarnEnabled()
      Specified by:
      isWarnEnabled in interface org.slf4j.Logger
    • warn

      public void warn(String msg)
      Specified by:
      warn in interface org.slf4j.Logger
    • warn

      public void warn(String format, Object arg)
      Specified by:
      warn in interface org.slf4j.Logger
    • warn

      public void warn(String format, Object arg1, Object arg2)
      Specified by:
      warn in interface org.slf4j.Logger
    • warn

      public void warn(String format, Object... argArray)
      Specified by:
      warn in interface org.slf4j.Logger
    • warn

      public void warn(String msg, Throwable t)
      Specified by:
      warn in interface org.slf4j.Logger
    • isErrorEnabled

      public boolean isErrorEnabled()
      Specified by:
      isErrorEnabled in interface org.slf4j.Logger
    • error

      public void error(String msg)
      Specified by:
      error in interface org.slf4j.Logger
    • error

      public void error(String format, Object arg)
      Specified by:
      error in interface org.slf4j.Logger
    • error

      public void error(String format, Object arg1, Object arg2)
      Specified by:
      error in interface org.slf4j.Logger
    • error

      public void error(String format, Object... argArray)
      Specified by:
      error in interface org.slf4j.Logger
    • error

      public void error(String msg, Throwable t)
      Specified by:
      error in interface org.slf4j.Logger
    • readResolve

      protected Object readResolve() throws ObjectStreamException
      Throws:
      ObjectStreamException