Class VelocityReferenceHandler
java.lang.Object
org.apache.velocity.app.event.implement.ReportInvalidReferences
com.nomagic.magicreport.engine.velocity.VelocityReferenceHandler
- All Implemented Interfaces:
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.apache.velocity.util.RuntimeServicesAware
@OpenApiAll
public class VelocityReferenceHandler
extends org.apache.velocity.app.event.implement.ReportInvalidReferences
implements org.apache.velocity.app.event.ReferenceInsertionEventHandler, org.apache.velocity.app.event.MethodExceptionEventHandler
Event handler called when an invalid reference is encountered.
- Since:
- Jun 18, 2007
-
Field Summary
Fields inherited from class org.apache.velocity.app.event.implement.ReportInvalidReferences
EVENTHANDLER_INVALIDREFERENCE_EXCEPTION, OLD_EVENTHANDLER_INVALIDREFERENCE_EXCEPTION -
Constructor Summary
ConstructorsConstructorDescriptionVelocityReferenceHandler(ITemplateEngine templateEngine) Create the references handler. -
Method Summary
Modifier and TypeMethodDescriptioninvalidGetMethod(org.apache.velocity.context.Context context, String reference, Object object, String property, org.apache.velocity.util.introspection.Info info) Collect the error and/or throw an exception, depending on configuration.invalidMethod(org.apache.velocity.context.Context context, String reference, Object object, String method, org.apache.velocity.util.introspection.Info info) Collect the error and/or throw an exception, depending on configuration.methodException(Class clazz, String method, Exception e) Render the method exception, and optionally the exception message and stack trace.methodException(org.apache.velocity.context.Context context, Class<?> clazz, String method, Exception e, org.apache.velocity.util.introspection.Info info) referenceInsert(String reference, Object value) A call-back which is executed during Velocity merge before a reference value is inserted into the output stream.referenceInsert(org.apache.velocity.context.Context context, String reference, Object value) voidsetInvalidReferenceHandlerList(List<IInvalidReferenceHandler> invalidReferenceHandlerList) Set the list ofIInvalidReferenceHandler.voidsetProperties(Properties properties) Set the properties of handler.voidsetReferenceInsertionHandlerList(List<IReferenceInsertionHandler> referenceInsertionHandlerList) Set the list ofIReferenceInsertionHandler.Methods inherited from class org.apache.velocity.app.event.implement.ReportInvalidReferences
getInvalidReferences, invalidSetMethod, setRuntimeServices
-
Constructor Details
-
VelocityReferenceHandler
Create the references handler.- Parameters:
templateEngine- template engine
-
-
Method Details
-
setProperties
Set the properties of handler. This properties is refer toITemplateEngine.getProperty(String)- Parameters:
properties- a properties to be set
-
setInvalidReferenceHandlerList
public void setInvalidReferenceHandlerList(List<IInvalidReferenceHandler> invalidReferenceHandlerList) Set the list ofIInvalidReferenceHandler.- Parameters:
invalidReferenceHandlerList- a list ofIInvalidReferenceHandlerto be set
-
setReferenceInsertionHandlerList
public void setReferenceInsertionHandlerList(List<IReferenceInsertionHandler> referenceInsertionHandlerList) Set the list ofIReferenceInsertionHandler.- Parameters:
referenceInsertionHandlerList- a list ofIReferenceInsertionHandlerto be set
-
invalidMethod
public Object invalidMethod(org.apache.velocity.context.Context context, String reference, Object object, String method, org.apache.velocity.util.introspection.Info info) Collect the error and/or throw an exception, depending on configuration.- Specified by:
invalidMethodin interfaceorg.apache.velocity.app.event.InvalidReferenceEventHandler- Overrides:
invalidMethodin classorg.apache.velocity.app.event.implement.ReportInvalidReferences- Parameters:
context- the context when the reference was found invalidreference- complete invalid referenceobject- the object referred to, or null if not foundmethod- the property name from the referenceinfo- contains template, line, column details- Returns:
- always returns null
- Throws:
ParseErrorException- error when cannot parse method
-
invalidGetMethod
public Object invalidGetMethod(org.apache.velocity.context.Context context, String reference, Object object, String property, org.apache.velocity.util.introspection.Info info) Collect the error and/or throw an exception, depending on configuration. This method will pass the input object intoIInvalidReferenceHandlersequencely. And stop process whenIInvalidReferenceHandler.invalidReference(String, Object, String, Properties)return Object.
for (Iterator it = invalidReferenceHandlerList.iterator(); it.hasNext();) { if ((result = invalidReferenceHandler.invalidReference(reference, object, property, properties)) != null) break; } return result;- Specified by:
invalidGetMethodin interfaceorg.apache.velocity.app.event.InvalidReferenceEventHandler- Overrides:
invalidGetMethodin classorg.apache.velocity.app.event.implement.ReportInvalidReferences- Parameters:
context- the context when the reference was found invalidreference- string with complete invalid referenceobject- the object referred to, or null if not foundproperty- the property name from the referenceinfo- contains template, line, column details- Returns:
- always returns null
-
referenceInsert
A call-back which is executed during Velocity merge before a reference value is inserted into the output stream. All registered ReferenceInsertionEventHandlers are called in sequence. If no ReferenceInsertionEventHandlers are are registered then reference value is inserted into the output stream as is. This method will pass the result of eachIReferenceInsertionHandlersequencely.
for (Iterator it = referenceInsertionHandlerList.iterator(); it.hasNext();) { result = referenceInsertionHandler.referenceInsert(reference, result, properties)); } return result;- Parameters:
reference- Reference from template about to be inserted.value- Value about to be inserted (after itstoString()method is called).- Returns:
- Object on which
toString()should be called for output.
-
referenceInsert
public Object referenceInsert(org.apache.velocity.context.Context context, String reference, Object value) - Specified by:
referenceInsertin interfaceorg.apache.velocity.app.event.ReferenceInsertionEventHandler
-
methodException
Render the method exception, and optionally the exception message and stack trace. This method always returnnullto keep valid reference and property pass toinvalidGetMethod(org.apache.velocity.context.Context, java.lang.String, java.lang.Object, java.lang.String, org.apache.velocity.util.introspection.Info)- Parameters:
clazz- the class of the object the method is being applied tomethod- the methode- the thrown exception- Returns:
- an
nullobject. - Throws:
Exception- an exception to be thrown instead inserting an objectRuntimeException
-
methodException
public Object methodException(org.apache.velocity.context.Context context, Class<?> clazz, String method, Exception e, org.apache.velocity.util.introspection.Info info) throws RuntimeException - Specified by:
methodExceptionin interfaceorg.apache.velocity.app.event.MethodExceptionEventHandler- Throws:
RuntimeException
-