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 Summary
FieldsModifier and TypeFieldDescriptionprivate booleanstatic final intstatic final intstatic final intstatic final intstatic final intprivate booleanprotected StringFields inherited from interface org.slf4j.Logger
ROOT_LOGGER_NAME -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidformatAndLog(int level, String format, Object... arguments) This prints the level and formatted message to System.out.getName()Required init methods for Logger interfacevoidvoidvoidvoidvoidinvalidGetMethod(org.apache.velocity.context.Context context, String reference, Object object, String property, org.apache.velocity.util.introspection.Info info) invalidMethod(org.apache.velocity.context.Context context, String reference, Object object, String method, org.apache.velocity.util.introspection.Info info) booleaninvalidSetMethod(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.booleanbooleanbooleanbooleanisLevelEnabled(int level) This always returns true because logging levels can't be disabled in this impl.booleanbooleanvoidThis just prints the message and level to System.out.voidThis prints the level, message, and the Throwable's message to System.out.static voidmethodException(org.apache.velocity.context.Context context, Class claz, String method, Exception e, org.apache.velocity.util.introspection.Info info) protected ObjectreferenceInsert(org.apache.velocity.context.Context context, String reference, Object value) Event handler for when a reference is inserted into the output stream.voidsilly method to throw an exception to demonstrate the method invocation exception event handlingvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidMethods 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 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
-
-
Constructor Details
-
EventExample
public EventExample()
-
-
Method Details
-
main
-
throwException
-
referenceInsert
-
invalidGetMethod
-
invalidMethod
-
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:
invalidSetMethodin interfaceorg.apache.velocity.app.event.InvalidReferenceEventHandler
-
methodException
-
log
This just prints the message and level to System.out. -
log
-
formatAndLog
-
isLevelEnabled
public boolean isLevelEnabled(int level) This always returns true because logging levels can't be disabled in this impl. -
getName
Required init methods for Logger interface- Specified by:
getNamein interfaceorg.slf4j.Logger
-
isTraceEnabled
public boolean isTraceEnabled()- Specified by:
isTraceEnabledin interfaceorg.slf4j.Logger
-
trace
- Specified by:
tracein interfaceorg.slf4j.Logger
-
trace
-
trace
-
trace
-
trace
-
isDebugEnabled
public boolean isDebugEnabled()- Specified by:
isDebugEnabledin interfaceorg.slf4j.Logger
-
debug
- Specified by:
debugin interfaceorg.slf4j.Logger
-
debug
-
debug
-
debug
-
debug
-
isInfoEnabled
public boolean isInfoEnabled()- Specified by:
isInfoEnabledin interfaceorg.slf4j.Logger
-
info
- Specified by:
infoin interfaceorg.slf4j.Logger
-
info
-
info
-
info
-
info
-
isWarnEnabled
public boolean isWarnEnabled()- Specified by:
isWarnEnabledin interfaceorg.slf4j.Logger
-
warn
- Specified by:
warnin interfaceorg.slf4j.Logger
-
warn
-
warn
-
warn
-
warn
-
isErrorEnabled
public boolean isErrorEnabled()- Specified by:
isErrorEnabledin interfaceorg.slf4j.Logger
-
error
- Specified by:
errorin interfaceorg.slf4j.Logger
-
error
-
error
-
error
-
error
-
readResolve
- Throws:
ObjectStreamException
-