Class ReportInvalidReferences

  • All Implemented Interfaces:
    EventHandler, InvalidReferenceEventHandler, RuntimeServicesAware

    public class ReportInvalidReferences
    extends java.lang.Object
    implements InvalidReferenceEventHandler, RuntimeServicesAware
    Use this event handler to flag invalid references. Since this is intended to be used for a specific request, this should be used as a local event handler attached to a specific context instead of being globally defined in the Velocity properties file.

    Note that InvalidReferenceHandler can be used in two modes. If the Velocity properties file contains the following:

     eventhandler.invalidreference.exception = true
     
    then the event handler will throw a ParseErrorRuntimeException upon hitting the first invalid reference. This stops processing and is passed through to the application code. The ParseErrorRuntimeException contain information about the template name, line number, column number, and invalid reference.

    If this configuration setting is false or omitted then the page will be processed as normal, but all invalid references will be collected in a List of InvalidReferenceInfo objects.

    This feature should be regarded as experimental.

    Since:
    1.5
    Version:
    $Id: ReportInvalidReferences.java 685685 2008-08-13 21:43:27Z nbubna $
    • Field Detail

      • EVENTHANDLER_INVALIDREFERENCE_EXCEPTION

        public static final java.lang.String EVENTHANDLER_INVALIDREFERENCE_EXCEPTION
        See Also:
        Constant Field Values
      • invalidReferences

        java.util.List invalidReferences
        List of InvalidReferenceInfo objects
      • stopOnFirstInvalidReference

        private boolean stopOnFirstInvalidReference
        If true, stop at the first invalid reference and throw an exception.
    • Constructor Detail

      • ReportInvalidReferences

        public ReportInvalidReferences()
    • Method Detail

      • invalidGetMethod

        public java.lang.Object invalidGetMethod​(Context context,
                                                 java.lang.String reference,
                                                 java.lang.Object object,
                                                 java.lang.String property,
                                                 Info info)
        Collect the error and/or throw an exception, depending on configuration.
        Specified by:
        invalidGetMethod in interface InvalidReferenceEventHandler
        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
        Throws:
        ParseErrorException
      • invalidMethod

        public java.lang.Object invalidMethod​(Context context,
                                              java.lang.String reference,
                                              java.lang.Object object,
                                              java.lang.String method,
                                              Info info)
        Collect the error and/or throw an exception, depending on configuration.
        Specified by:
        invalidMethod in interface InvalidReferenceEventHandler
        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
      • invalidSetMethod

        public boolean invalidSetMethod​(Context context,
                                        java.lang.String leftreference,
                                        java.lang.String rightreference,
                                        Info info)
        Collect the error and/or throw an exception, depending on configuration.
        Specified by:
        invalidSetMethod in interface InvalidReferenceEventHandler
        Parameters:
        context - the context when the reference was found invalid
        leftreference - left reference being assigned to
        rightreference - invalid reference on the right
        info - contains info on template, line, col
        Returns:
        loop to end -- always returns false
      • reportInvalidReference

        private void reportInvalidReference​(java.lang.String reference,
                                            Info info)
        Check for an invalid reference and collect the error or throw an exception (depending on configuration).
        Parameters:
        reference - the invalid reference
        info - line, column, template name
      • getInvalidReferences

        public java.util.List getInvalidReferences()
        All invalid references during the processing of this page.
        Returns:
        a List of InvalidReferenceInfo objects
      • setRuntimeServices

        public void setRuntimeServices​(RuntimeServices rs)
        Called automatically when event cartridge is initialized.
        Specified by:
        setRuntimeServices in interface RuntimeServicesAware
        Parameters:
        rs - RuntimeServices object assigned during initialization