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
  • Constructor Details

    • VelocityReferenceHandler

      public VelocityReferenceHandler(ITemplateEngine templateEngine)
      Create the references handler.
      Parameters:
      templateEngine - template engine
  • Method Details

    • setProperties

      public void setProperties(Properties properties)
      Set the properties of handler. This properties is refer to ITemplateEngine.getProperty(String)
      Parameters:
      properties - a properties to be set
    • setInvalidReferenceHandlerList

      public void setInvalidReferenceHandlerList(List<IInvalidReferenceHandler> invalidReferenceHandlerList)
      Set the list of IInvalidReferenceHandler.
      Parameters:
      invalidReferenceHandlerList - a list of IInvalidReferenceHandler to be set
    • setReferenceInsertionHandlerList

      public void setReferenceInsertionHandlerList(List<IReferenceInsertionHandler> referenceInsertionHandlerList)
      Parameters:
      referenceInsertionHandlerList - a list of IReferenceInsertionHandler to 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:
      invalidMethod in interface org.apache.velocity.app.event.InvalidReferenceEventHandler
      Overrides:
      invalidMethod in class org.apache.velocity.app.event.implement.ReportInvalidReferences
      Parameters:
      context - the context when the reference was found invalid
      reference - complete invalid reference
      object - the object referred to, or null if not found
      method - the property name from the reference
      info - 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 into IInvalidReferenceHandler sequencely. And stop process when IInvalidReferenceHandler.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:
      invalidGetMethod in interface org.apache.velocity.app.event.InvalidReferenceEventHandler
      Overrides:
      invalidGetMethod in class org.apache.velocity.app.event.implement.ReportInvalidReferences
      Parameters:
      context - the context when the reference was found invalid
      reference - string with complete invalid reference
      object - the object referred to, or null if not found
      property - the property name from the reference
      info - contains template, line, column details
      Returns:
      always returns null
    • referenceInsert

      public Object referenceInsert(String reference, Object value)
      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 each IReferenceInsertionHandler sequencely.
      
       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 its toString() 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:
      referenceInsert in interface org.apache.velocity.app.event.ReferenceInsertionEventHandler
    • methodException

      public Object methodException(Class clazz, String method, Exception e) throws RuntimeException
      Render the method exception, and optionally the exception message and stack trace. This method always return null to keep valid reference and property pass to invalidGetMethod(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 to
      method - the method
      e - the thrown exception
      Returns:
      an null object.
      Throws:
      Exception - an exception to be thrown instead inserting an object
      RuntimeException
    • 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:
      methodException in interface org.apache.velocity.app.event.MethodExceptionEventHandler
      Throws:
      RuntimeException