Package org.apache.velocity.example
Class EventExample
- java.lang.Object
-
- org.slf4j.helpers.MarkerIgnoringBase
-
- org.apache.velocity.example.EventExample
-
- All Implemented Interfaces:
java.io.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.InvalidReferenceEventHandlerThis 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:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private booleanexceptionSwitchstatic intLOG_LEVEL_DEBUGstatic intLOG_LEVEL_ERRORstatic intLOG_LEVEL_INFOstatic intLOG_LEVEL_TRACEstatic intLOG_LEVEL_WARNprivate booleanlogOutputprotected java.lang.Stringname
-
Constructor Summary
Constructors Constructor Description EventExample()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddebug(java.lang.String msg)voiddebug(java.lang.String format, java.lang.Object param1)voiddebug(java.lang.String format, java.lang.Object... argArray)voiddebug(java.lang.String format, java.lang.Object param1, java.lang.Object param2)voiddebug(java.lang.String msg, java.lang.Throwable t)voiderror(java.lang.String msg)voiderror(java.lang.String format, java.lang.Object arg)voiderror(java.lang.String format, java.lang.Object... argArray)voiderror(java.lang.String format, java.lang.Object arg1, java.lang.Object arg2)voiderror(java.lang.String msg, java.lang.Throwable t)voidformatAndLog(int level, java.lang.String format, java.lang.Object... arguments)This prints the level and formatted message to System.out.java.lang.StringgetName()Required init methods for Logger interfacevoidinfo(java.lang.String msg)voidinfo(java.lang.String format, java.lang.Object arg)voidinfo(java.lang.String format, java.lang.Object... argArray)voidinfo(java.lang.String format, java.lang.Object arg1, java.lang.Object arg2)voidinfo(java.lang.String msg, java.lang.Throwable t)java.lang.ObjectinvalidGetMethod(org.apache.velocity.context.Context context, java.lang.String reference, java.lang.Object object, java.lang.String property, org.apache.velocity.util.introspection.Info info)java.lang.ObjectinvalidMethod(org.apache.velocity.context.Context context, java.lang.String reference, java.lang.Object object, java.lang.String method, org.apache.velocity.util.introspection.Info info)booleaninvalidSetMethod(org.apache.velocity.context.Context context, java.lang.String leftreference, java.lang.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.booleanisDebugEnabled()booleanisErrorEnabled()booleanisInfoEnabled()booleanisLevelEnabled(int level)This always returns true because logging levels can't be disabled in this impl.booleanisTraceEnabled()booleanisWarnEnabled()voidlog(int level, java.lang.String message)This just prints the message and level to System.out.voidlog(int level, java.lang.String message, java.lang.Throwable t)This prints the level, message, and the Throwable's message to System.out.static voidmain(java.lang.String[] args)java.lang.ObjectmethodException(org.apache.velocity.context.Context context, java.lang.Class claz, java.lang.String method, java.lang.Exception e, org.apache.velocity.util.introspection.Info info)protected java.lang.ObjectreadResolve()java.lang.ObjectreferenceInsert(org.apache.velocity.context.Context context, java.lang.String reference, java.lang.Object value)Event handler for when a reference is inserted into the output stream.voidthrowException()silly method to throw an exception to demonstrate the method invocation exception event handlingvoidtrace(java.lang.String msg)voidtrace(java.lang.String format, java.lang.Object param1)voidtrace(java.lang.String format, java.lang.Object... argArray)voidtrace(java.lang.String format, java.lang.Object param1, java.lang.Object param2)voidtrace(java.lang.String msg, java.lang.Throwable t)voidwarn(java.lang.String msg)voidwarn(java.lang.String format, java.lang.Object arg)voidwarn(java.lang.String format, java.lang.Object... argArray)voidwarn(java.lang.String format, java.lang.Object arg1, java.lang.Object arg2)voidwarn(java.lang.String msg, java.lang.Throwable t)-
Methods inherited from class org.slf4j.helpers.MarkerIgnoringBase
debug, debug, debug, debug, debug, error, error, error, error, error, info, info, info, info, info, isDebugEnabled, isErrorEnabled, isInfoEnabled, isTraceEnabled, isWarnEnabled, toString, trace, trace, trace, trace, trace, warn, warn, warn, warn, warn
-
-
-
-
Field Detail
-
logOutput
private boolean logOutput
-
exceptionSwitch
private boolean exceptionSwitch
-
LOG_LEVEL_TRACE
public static final int LOG_LEVEL_TRACE
- See Also:
- Constant Field Values
-
LOG_LEVEL_DEBUG
public static final int LOG_LEVEL_DEBUG
- See Also:
- Constant Field Values
-
LOG_LEVEL_INFO
public static final int LOG_LEVEL_INFO
- See Also:
- Constant Field Values
-
LOG_LEVEL_WARN
public static final int LOG_LEVEL_WARN
- See Also:
- Constant Field Values
-
LOG_LEVEL_ERROR
public static final int LOG_LEVEL_ERROR
- See Also:
- Constant Field Values
-
name
protected java.lang.String name
-
-
Method Detail
-
main
public static void main(java.lang.String[] args)
-
throwException
public void throwException() throws java.lang.Exceptionsilly method to throw an exception to demonstrate the method invocation exception event handling- Throws:
java.lang.Exception
-
referenceInsert
public java.lang.Object referenceInsert(org.apache.velocity.context.Context context, java.lang.String reference, java.lang.Object value)Event handler for when a reference is inserted into the output stream.- Specified by:
referenceInsertin interfaceorg.apache.velocity.app.event.ReferenceInsertionEventHandler
-
invalidGetMethod
public java.lang.Object invalidGetMethod(org.apache.velocity.context.Context context, java.lang.String reference, java.lang.Object object, java.lang.String property, org.apache.velocity.util.introspection.Info info)- Specified by:
invalidGetMethodin interfaceorg.apache.velocity.app.event.InvalidReferenceEventHandler
-
invalidMethod
public java.lang.Object invalidMethod(org.apache.velocity.context.Context context, java.lang.String reference, java.lang.Object object, java.lang.String method, org.apache.velocity.util.introspection.Info info)- Specified by:
invalidMethodin interfaceorg.apache.velocity.app.event.InvalidReferenceEventHandler
-
invalidSetMethod
public boolean invalidSetMethod(org.apache.velocity.context.Context context, java.lang.String leftreference, java.lang.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:
invalidSetMethodin interfaceorg.apache.velocity.app.event.InvalidReferenceEventHandler
-
methodException
public java.lang.Object methodException(org.apache.velocity.context.Context context, java.lang.Class claz, java.lang.String method, java.lang.Exception e, org.apache.velocity.util.introspection.Info info)- Specified by:
methodExceptionin interfaceorg.apache.velocity.app.event.MethodExceptionEventHandler
-
log
public void log(int level, java.lang.String message)This just prints the message and level to System.out.
-
log
public void log(int level, java.lang.String message, java.lang.Throwable t)This prints the level, message, and the Throwable's message to System.out.
-
formatAndLog
public void formatAndLog(int level, java.lang.String format, java.lang.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 java.lang.String getName()
Required init methods for Logger interface- Specified by:
getNamein interfaceorg.slf4j.Logger
-
isTraceEnabled
public boolean isTraceEnabled()
- Specified by:
isTraceEnabledin interfaceorg.slf4j.Logger
-
trace
public void trace(java.lang.String msg)
- Specified by:
tracein interfaceorg.slf4j.Logger
-
trace
public void trace(java.lang.String format, java.lang.Object param1)- Specified by:
tracein interfaceorg.slf4j.Logger
-
trace
public void trace(java.lang.String format, java.lang.Object param1, java.lang.Object param2)- Specified by:
tracein interfaceorg.slf4j.Logger
-
trace
public void trace(java.lang.String format, java.lang.Object... argArray)- Specified by:
tracein interfaceorg.slf4j.Logger
-
trace
public void trace(java.lang.String msg, java.lang.Throwable t)- Specified by:
tracein interfaceorg.slf4j.Logger
-
isDebugEnabled
public boolean isDebugEnabled()
- Specified by:
isDebugEnabledin interfaceorg.slf4j.Logger
-
debug
public void debug(java.lang.String msg)
- Specified by:
debugin interfaceorg.slf4j.Logger
-
debug
public void debug(java.lang.String format, java.lang.Object param1)- Specified by:
debugin interfaceorg.slf4j.Logger
-
debug
public void debug(java.lang.String format, java.lang.Object param1, java.lang.Object param2)- Specified by:
debugin interfaceorg.slf4j.Logger
-
debug
public void debug(java.lang.String format, java.lang.Object... argArray)- Specified by:
debugin interfaceorg.slf4j.Logger
-
debug
public void debug(java.lang.String msg, java.lang.Throwable t)- Specified by:
debugin interfaceorg.slf4j.Logger
-
isInfoEnabled
public boolean isInfoEnabled()
- Specified by:
isInfoEnabledin interfaceorg.slf4j.Logger
-
info
public void info(java.lang.String msg)
- Specified by:
infoin interfaceorg.slf4j.Logger
-
info
public void info(java.lang.String format, java.lang.Object arg)- Specified by:
infoin interfaceorg.slf4j.Logger
-
info
public void info(java.lang.String format, java.lang.Object arg1, java.lang.Object arg2)- Specified by:
infoin interfaceorg.slf4j.Logger
-
info
public void info(java.lang.String format, java.lang.Object... argArray)- Specified by:
infoin interfaceorg.slf4j.Logger
-
info
public void info(java.lang.String msg, java.lang.Throwable t)- Specified by:
infoin interfaceorg.slf4j.Logger
-
isWarnEnabled
public boolean isWarnEnabled()
- Specified by:
isWarnEnabledin interfaceorg.slf4j.Logger
-
warn
public void warn(java.lang.String msg)
- Specified by:
warnin interfaceorg.slf4j.Logger
-
warn
public void warn(java.lang.String format, java.lang.Object arg)- Specified by:
warnin interfaceorg.slf4j.Logger
-
warn
public void warn(java.lang.String format, java.lang.Object arg1, java.lang.Object arg2)- Specified by:
warnin interfaceorg.slf4j.Logger
-
warn
public void warn(java.lang.String format, java.lang.Object... argArray)- Specified by:
warnin interfaceorg.slf4j.Logger
-
warn
public void warn(java.lang.String msg, java.lang.Throwable t)- Specified by:
warnin interfaceorg.slf4j.Logger
-
isErrorEnabled
public boolean isErrorEnabled()
- Specified by:
isErrorEnabledin interfaceorg.slf4j.Logger
-
error
public void error(java.lang.String msg)
- Specified by:
errorin interfaceorg.slf4j.Logger
-
error
public void error(java.lang.String format, java.lang.Object arg)- Specified by:
errorin interfaceorg.slf4j.Logger
-
error
public void error(java.lang.String format, java.lang.Object arg1, java.lang.Object arg2)- Specified by:
errorin interfaceorg.slf4j.Logger
-
error
public void error(java.lang.String format, java.lang.Object... argArray)- Specified by:
errorin interfaceorg.slf4j.Logger
-
error
public void error(java.lang.String msg, java.lang.Throwable t)- Specified by:
errorin interfaceorg.slf4j.Logger
-
readResolve
protected java.lang.Object readResolve() throws java.io.ObjectStreamException- Throws:
java.io.ObjectStreamException
-
-