velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cbris...@apache.org
Subject svn commit: r1773548 - in /velocity/engine/trunk: ./ velocity-engine-core/src/main/java/org/apache/velocity/app/event/ velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/ velocity-engine-core/src/main/java/org/apache/velocity/ru...
Date Sun, 11 Dec 2016 08:27:15 GMT
Author: cbrisson
Date: Sun Dec 11 08:27:14 2016
New Revision: 1773548

URL: http://svn.apache.org/viewvc?rev=1773548&view=rev
Log:
[engine] review event handling

1) Add a Context argument for all events.
2) Get rid of the Executor pattern ; event handlers are directly called by the cartridge.


Removed:
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/EventHandlerMethodExecutor.java
Modified:
    velocity/engine/trunk/pom.xml
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/EventCartridge.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/EventHandlerUtil.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/IncludeEventHandler.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/InvalidReferenceEventHandler.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/MethodExceptionEventHandler.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/ReferenceInsertionEventHandler.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/EscapeReference.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/IncludeNotFound.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/IncludeRelativePath.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/PrintExceptions.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java
    velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/BuiltInEventHandlerTestCase.java
    velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/EventHandlingTestCase.java
    velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/IncludeEventHandlingTestCase.java
    velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/eventhandler/Handler1.java
    velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/eventhandler/Handler2.java
    velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity758TestCase.java
    velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/misc/ExceptionGeneratingEventHandler.java
    velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/util/introspection/ConversionHandlerTestCase.java
    velocity/engine/trunk/velocity-engine-examples/src/main/java/org/apache/velocity/example/EventExample.java

Modified: velocity/engine/trunk/pom.xml
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/pom.xml?rev=1773548&r1=1773547&r2=1773548&view=diff
==============================================================================
--- velocity/engine/trunk/pom.xml (original)
+++ velocity/engine/trunk/pom.xml Sun Dec 11 08:27:14 2016
@@ -68,8 +68,8 @@
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-compiler-plugin</artifactId>
         <configuration>
-          <debug>false</debug>
-          <optimize>true</optimize>
+          <debug>true</debug>
+          <optimize>false</optimize>
           <showDeprecation>true</showDeprecation>
           <showWarning>true</showWarning>
           <source>1.7</source>

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/EventCartridge.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/EventCartridge.java?rev=1773548&r1=1773547&r2=1773548&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/EventCartridge.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/EventCartridge.java Sun Dec 11 08:27:14 2016
@@ -20,13 +20,17 @@ package org.apache.velocity.app.event;
  */
 
 import org.apache.velocity.context.Context;
+import org.apache.velocity.context.InternalContextAdapter;
 import org.apache.velocity.context.InternalEventContext;
+import org.apache.velocity.exception.VelocityException;
 import org.apache.velocity.runtime.RuntimeServices;
 import org.apache.velocity.util.RuntimeServicesAware;
+import org.apache.velocity.util.introspection.Info;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.util.ArrayList;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
@@ -53,16 +57,72 @@ import java.util.Set;
  */
 public class EventCartridge
   {
-    private List referenceHandlers = new ArrayList();
-    private List methodExceptionHandlers = new ArrayList();
-    private List includeHandlers = new ArrayList();
-    private List invalidReferenceHandlers = new ArrayList();
+    private List<ReferenceInsertionEventHandler> referenceHandlers = new ArrayList();
+    private MethodExceptionEventHandler methodExceptionHandler = null;
+    private List<IncludeEventHandler> includeHandlers = new ArrayList();
+    private List<InvalidReferenceEventHandler> invalidReferenceHandlers = new ArrayList();
 
     /**
      * Ensure that handlers are not initialized more than once.
      */
     Set initializedHandlers = new HashSet();
 
+      protected RuntimeServices rsvc = null;
+
+      protected Logger getLog()
+      {
+          return rsvc == null ? LoggerFactory.getLogger(EventCartridge.class) : rsvc.getLog();
+      }
+
+      /**
+       * runtime services setter, called during initialization
+       * @param rs runtime services
+       * @since 2.0
+       */
+      public synchronized void setRuntimeServices(RuntimeServices rs)
+      {
+          if (rsvc == null)
+          {
+              rsvc = rs;
+              /* allow for this method to be called *after* adding event handlers */
+              for (EventHandler handler : referenceHandlers)
+              {
+                  if (handler instanceof RuntimeServicesAware && !initializedHandlers.contains(handler))
+                  {
+                      ((RuntimeServicesAware)handler).setRuntimeServices(rs);
+                      initializedHandlers.add(handler);
+                  }
+              }
+              if (methodExceptionHandler != null &&
+                  methodExceptionHandler instanceof RuntimeServicesAware &&
+                  !initializedHandlers.contains(methodExceptionHandler))
+              {
+                  ((RuntimeServicesAware)methodExceptionHandler).setRuntimeServices(rs);
+                  initializedHandlers.add(methodExceptionHandler);
+              }
+              for (EventHandler handler : includeHandlers)
+              {
+                  if (handler instanceof RuntimeServicesAware && !initializedHandlers.contains(handler))
+                  {
+                      ((RuntimeServicesAware)handler).setRuntimeServices(rs);
+                      initializedHandlers.add(handler);
+                  }
+              }
+              for (EventHandler handler : invalidReferenceHandlers)
+              {
+                  if (handler instanceof RuntimeServicesAware && !initializedHandlers.contains(handler))
+                  {
+                      ((RuntimeServicesAware)handler).setRuntimeServices(rs);
+                      initializedHandlers.add(handler);
+                  }
+              }
+          }
+          else if (rsvc != rs)
+          {
+              throw new VelocityException("an event cartridge cannot be used by several different runtime services instances");
+          }
+      }
+
     /**
      *  Adds an event handler(s) to the Cartridge.  This method
      *  will find all possible event handler interfaces supported
@@ -88,22 +148,28 @@ public class EventCartridge
 
         if ( ev instanceof MethodExceptionEventHandler )
         {
-            addMethodExceptionHandler( (MethodExceptionEventHandler) ev );
+            addMethodExceptionHandler((MethodExceptionEventHandler) ev);
             found = true;
         }
 
         if ( ev instanceof IncludeEventHandler )
         {
-            addIncludeEventHandler( (IncludeEventHandler) ev );
+            addIncludeEventHandler((IncludeEventHandler) ev);
             found = true;
         }
 
         if ( ev instanceof InvalidReferenceEventHandler )
         {
-            addInvalidReferenceEventHandler( (InvalidReferenceEventHandler) ev );
+            addInvalidReferenceEventHandler((InvalidReferenceEventHandler) ev);
             found = true;
         }
 
+        if (found && rsvc != null && ev instanceof RuntimeServicesAware && !initializedHandlers.contains(ev))
+        {
+            ((RuntimeServicesAware)ev).setRuntimeServices(rsvc);
+            initializedHandlers.add(ev);
+        }
+
         return found;
     }
 
@@ -126,7 +192,14 @@ public class EventCartridge
      */
     public void addMethodExceptionHandler( MethodExceptionEventHandler ev )
     {
-        methodExceptionHandlers.add( ev );
+        if (methodExceptionHandler == null)
+        {
+            methodExceptionHandler = ev;
+        }
+        else
+        {
+            getLog().warn("ignoring extra method exception handler");
+        }
     }
 
     /**
@@ -168,153 +241,181 @@ public class EventCartridge
             return false;
         }
 
-        boolean found = false;
-
         if ( ev instanceof ReferenceInsertionEventHandler )
-            return referenceHandlers.remove( ev );
+        {
+            return referenceHandlers.remove(ev);
+        }
 
         if ( ev instanceof MethodExceptionEventHandler )
-            return methodExceptionHandlers.remove(ev );
+        {
+            if (ev == methodExceptionHandler)
+            {
+                methodExceptionHandler = null;
+                return true;
+            }
+        }
 
         if ( ev instanceof IncludeEventHandler )
-            return includeHandlers.remove( ev );
+        {
+            return includeHandlers.remove(ev);
+        }
 
         if ( ev instanceof InvalidReferenceEventHandler )
-            return invalidReferenceHandlers.remove( ev );
-
-        return found;
-    }
+        {
+            return invalidReferenceHandlers.remove(ev);
+        }
 
-    /**
-     * Iterate through all the stored ReferenceInsertionEventHandler objects
-     * 
-     * @return iterator of handler objects, null if there are not handlers
-     * @since 1.5
-     */
-    public Iterator getReferenceInsertionEventHandlers()
-    {
-        return referenceHandlers.size() == 0 ? null : referenceHandlers.iterator();
+        return false;
     }
 
     /**
-     * Iterate through all the stored MethodExceptionEventHandler objects
+     * Call reference insertion handlers
      * 
-     * @return iterator of handler objects
-     * @since 1.5
+     * @return value returned by handlers
+     * @since 2.0
      */
-    public Iterator getMethodExceptionEventHandlers()
+    public Object referenceInsert(InternalContextAdapter context, String reference, Object value)
     {
-        return methodExceptionHandlers.iterator();
+        for (ReferenceInsertionEventHandler handler : referenceHandlers)
+        {
+            value = handler.referenceInsert(context, reference, value);
+        }
+        return value;
     }
 
-    /**
-     * Iterate through all the stored IncludeEventHandlers objects
-     * 
-     * @return iterator of handler objects
-     */
-    public Iterator getIncludeEventHandlers()
-    {
-        return includeHandlers.iterator();
-    }
+      /**
+       * Check whether this event cartridge has a method exception event handler
+       * @return true if a method exception event handler has been registered
+       * @since 2.0
+       */
+      boolean hasMethodExceptionEventHandler()
+      {
+          return methodExceptionHandler != null;
+      }
 
     /**
-     * Iterate through all the stored InvalidReferenceEventHandlers objects
+     * Call method exception event handler
      * 
-     * @return iterator of handler objects
-     * @since 1.5
-     */
-    public Iterator getInvalidReferenceEventHandlers()
-    {
-        return invalidReferenceHandlers.iterator();
-    }
-
-    /**
-     *  Attached the EventCartridge to the context
-     *
-     *  Final because not something one should mess with lightly :)
-     *
-     *  @param context context to attach to
-     *  @return true if successful, false otherwise
+     * @return value returned by handler
+     * @since 2.0
      */
-    public final boolean attachToContext( Context context )
+    public Object methodException(Context context, Class claz, String method, Exception e, Info info )
     {
-        if (  context instanceof InternalEventContext )
+        if (methodExceptionHandler != null)
         {
-            InternalEventContext iec = (InternalEventContext) context;
-
-            iec.attachEventCartridge( this );
-
-            /**
-             * while it's tempting to call setContext on each handler from here,
-             * this needs to be done before each method call.  This is
-             * because the specific context will change as inner contexts
-             * are linked in through macros, foreach, or directly by the user.
-             */
-
-            return true;
-        }
-        else
-        {
-            return false;
+            return methodExceptionHandler.methodException(context, claz, method, e, info);
         }
+        return null;
     }
 
     /**
-     * Initialize the handlers.  For global handlers this is called when Velocity
-     * is initialized. For local handlers this is called when the first handler
-     * is executed.  Handlers will not be initialized more than once.
+     * Call include event handlers
      * 
-     * @param rs
-     * @since 1.5
+     * @return include path
+     * @since 2.0
      */
-    public void initialize (RuntimeServices rs)
+    public String includeEvent(Context context, String includeResourcePath, String currentResourcePath, String directiveName)
     {
-
-        for ( Iterator i = referenceHandlers.iterator(); i.hasNext(); )
-        {
-            EventHandler eh = ( EventHandler ) i.next();
-            if ( (eh instanceof RuntimeServicesAware) &&
-                    !initializedHandlers.contains(eh) )
-            {
-                ((RuntimeServicesAware) eh).setRuntimeServices ( rs );
-                initializedHandlers.add( eh );
-            }
-        }
-
-        for ( Iterator i = methodExceptionHandlers.iterator(); i.hasNext(); )
-        {
-            EventHandler eh = ( EventHandler ) i.next();
-            if ( (eh instanceof RuntimeServicesAware) &&
-                    !initializedHandlers.contains(eh) )
-            {
-                ((RuntimeServicesAware) eh).setRuntimeServices ( rs );
-                initializedHandlers.add( eh );
-            }
-        }
-
-        for ( Iterator i = includeHandlers.iterator(); i.hasNext(); )
+        for (IncludeEventHandler handler : includeHandlers)
         {
-            EventHandler eh = ( EventHandler ) i.next();
-            if ( (eh instanceof RuntimeServicesAware) &&
-                    !initializedHandlers.contains(eh) )
+            includeResourcePath = handler.includeEvent(context, includeResourcePath, currentResourcePath, directiveName);
+            /* reflect 1.x behavior: exit after at least one execution whenever a null include path has been found */
+            if (includeResourcePath == null)
             {
-                ((RuntimeServicesAware) eh).setRuntimeServices ( rs );
-                initializedHandlers.add( eh );
+                break;
             }
         }
-
-        for ( Iterator i = invalidReferenceHandlers.iterator(); i.hasNext(); )
-        {
-            EventHandler eh = ( EventHandler ) i.next();
-            if ( (eh instanceof RuntimeServicesAware) &&
-                    !initializedHandlers.contains(eh) )
-            {
-                ((RuntimeServicesAware) eh).setRuntimeServices ( rs );
-                initializedHandlers.add( eh );
-            }
-        }
-
+        return includeResourcePath;
     }
 
-
-}
+      /**
+       * Call invalid reference handlers for an invalid getter
+       *
+       * @return value returned by handlers
+       * @since 2.0
+       */
+      public Object invalidGetMethod(Context context, String reference, Object object, String property, Info info)
+      {
+          Object result = null;
+          for (InvalidReferenceEventHandler handler : invalidReferenceHandlers)
+          {
+              result = handler.invalidGetMethod(context, reference, object, property, info);
+              /* reflect 1.x behavior: exit after at least one execution whenever a non-null value has been found */
+              if (result != null)
+              {
+                  break;
+              }
+          }
+          return result;
+      }
+
+      /**
+       * Call invalid reference handlers for an invalid setter
+       *
+       * @return whether to stop further chaining in the next cartridge
+       * @since 2.0
+       */
+      public boolean invalidSetMethod(Context context, String leftreference, String rightreference, Info info)
+      {
+          for (InvalidReferenceEventHandler handler : invalidReferenceHandlers)
+          {
+              if (handler.invalidSetMethod(context, leftreference, rightreference, info))
+              {
+                  return true;
+              }
+          }
+          return false;
+      }
+
+      /**
+       * Call invalid reference handlers for an invalid method call
+       *
+       * @return value returned by handlers
+       * @since 2.0
+       */
+      public Object invalidMethod(Context context, String reference, Object object, String method, Info info)
+      {
+          Object result = null;
+          for (InvalidReferenceEventHandler handler : invalidReferenceHandlers)
+          {
+              result = handler.invalidMethod(context, reference, object, method, info);
+              /* reflect 1.x behavior: exit after at least one execution whenever a non-null value has been found */
+              if (result != null)
+              {
+                  break;
+              }
+          }
+          return result;
+      }
+
+      /**
+       *  Attached the EventCartridge to the context
+       *
+       *  Final because not something one should mess with lightly :)
+       *
+       *  @param context context to attach to
+       *  @return true if successful, false otherwise
+       */
+      public final boolean attachToContext( Context context )
+      {
+          if (  context instanceof InternalEventContext )
+          {
+              InternalEventContext iec = (InternalEventContext) context;
+
+              iec.attachEventCartridge( this );
+
+              /**
+               * while it's tempting to call setContext on each handler from here,
+               * this needs to be done before each method call.  This is
+               * because the specific context will change as inner contexts
+               * are linked in through macros, foreach, or directly by the user.
+               */
+
+              return true;
+          }
+          else
+          {
+              return false;
+          }
+      }
+  }

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/EventHandlerUtil.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/EventHandlerUtil.java?rev=1773548&r1=1773547&r2=1773548&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/EventHandlerUtil.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/EventHandlerUtil.java Sun Dec 11 08:27:14 2016
@@ -56,49 +56,16 @@ public class EventHandlerUtil {
     public static Object referenceInsert(RuntimeServices rsvc,
             InternalContextAdapter context, String reference, Object value)
     {
-        // app level cartridges have already been initialized
-        
-        /*
-         * Performance modification: EventCartridge.getReferenceInsertionEventHandlers
-         * now returns a null if there are no handlers. Thus we can avoid creating the
-         * Iterator object.
-         */
-        EventCartridge ev1 = rsvc.getApplicationEventCartridge();
-        Iterator applicationEventHandlerIterator = 
-            (ev1 == null) ? null: ev1.getReferenceInsertionEventHandlers();              
-        
-        EventCartridge ev2 = context.getEventCartridge();
-        initializeEventCartridge(rsvc, ev2);
-        Iterator contextEventHandlerIterator = 
-            (ev2 == null) ? null: ev2.getReferenceInsertionEventHandlers();              
-        
-        try 
-        {
-            /*
-             * Performance modification: methodExecutor is created only if one of the
-             * iterators is not null.
-             */
-            
-            EventHandlerMethodExecutor methodExecutor = null; 
-
-            if( applicationEventHandlerIterator != null )
-            {
-                methodExecutor = 
-                    new ReferenceInsertionEventHandler.referenceInsertExecutor(context, reference, value);
-                iterateOverEventHandlers(applicationEventHandlerIterator, methodExecutor);
-            }
-
-            if( contextEventHandlerIterator != null )
+        try
+        {
+            value = rsvc.getApplicationEventCartridge().referenceInsert(context, reference, value);
+            EventCartridge contextCartridge = context.getEventCartridge();
+            if (contextCartridge != null)
             {
-                if( methodExecutor == null )
-                    methodExecutor = 
-                        new ReferenceInsertionEventHandler.referenceInsertExecutor(context, reference, value);
-                    
-                iterateOverEventHandlers(contextEventHandlerIterator, methodExecutor);
+                contextCartridge.setRuntimeServices(rsvc);
+                value = contextCartridge.referenceInsert(context, reference, value);
             }
-
-            
-            return methodExecutor != null ? methodExecutor.getReturnValue() : value;   
+            return value;
         }
         catch (RuntimeException e)
         {
@@ -109,7 +76,7 @@ public class EventHandlerUtil {
             throw new VelocityException("Exception in event handler.",e);
         }
     }
-    
+
     /**
      * Called when a method exception is generated during Velocity merge. Only
      * the first valid event handler in the sequence is called. The default
@@ -131,30 +98,31 @@ public class EventHandlerUtil {
             InternalContextAdapter context, Class claz, String method,
             Exception e, Info info) throws Exception
     {
-        // app level cartridges have already been initialized
-        EventCartridge ev1 = rsvc.getApplicationEventCartridge();
-        Iterator applicationEventHandlerIterator = 
-            (ev1 == null) ? null: ev1.getMethodExceptionEventHandlers();              
-        
-        EventCartridge ev2 = context.getEventCartridge();
-        initializeEventCartridge(rsvc, ev2);
-        Iterator contextEventHandlerIterator = 
-            (ev2 == null) ? null: ev2.getMethodExceptionEventHandlers();              
-        
-        EventHandlerMethodExecutor methodExecutor = 
-            new MethodExceptionEventHandler.MethodExceptionExecutor(context, claz, method, e, info);
-        
-        if ( ((applicationEventHandlerIterator == null) || !applicationEventHandlerIterator.hasNext()) &&
-                ((contextEventHandlerIterator == null) || !contextEventHandlerIterator.hasNext()) )
+        try
         {
-            throw e;
+            EventCartridge ev = rsvc.getApplicationEventCartridge();
+            if (ev.hasMethodExceptionEventHandler())
+            {
+                return ev.methodException(context, claz, method, e, info);
+            }
+            EventCartridge contextCartridge = context.getEventCartridge();
+            if (contextCartridge != null)
+            {
+                contextCartridge.setRuntimeServices(rsvc);
+                return contextCartridge.methodException(context, claz, method, e, info);
+            }
+        }
+        catch (RuntimeException re)
+        {
+            throw re;
+        }
+        catch (Exception ex)
+        {
+            throw new VelocityException("Exception in event handler.", ex);
         }
-            
-        callEventHandlers(
-                applicationEventHandlerIterator, 
-                contextEventHandlerIterator, methodExecutor);
-        
-        return methodExecutor.getReturnValue();
+
+        /* default behaviour is to re-throw exception */
+        throw e;
     }
     
     /**
@@ -181,28 +149,16 @@ public class EventHandlerUtil {
             InternalContextAdapter context, String includeResourcePath,
             String currentResourcePath, String directiveName)
     {
-        // app level cartridges have already been initialized
-        EventCartridge ev1 = rsvc.getApplicationEventCartridge();
-        Iterator applicationEventHandlerIterator = 
-            (ev1 == null) ? null: ev1.getIncludeEventHandlers();              
-        
-        EventCartridge ev2 = context.getEventCartridge();
-        initializeEventCartridge(rsvc, ev2);
-        Iterator contextEventHandlerIterator = 
-            (ev2 == null) ? null: ev2.getIncludeEventHandlers();              
-        
-        try 
-        {
-            EventHandlerMethodExecutor methodExecutor = 
-                new IncludeEventHandler.IncludeEventExecutor(
-                        context, includeResourcePath, 
-                        currentResourcePath, directiveName);
-            
-            callEventHandlers(
-                    applicationEventHandlerIterator, 
-                    contextEventHandlerIterator, methodExecutor);
-            
-            return (String) methodExecutor.getReturnValue();
+        try
+        {
+            includeResourcePath = rsvc.getApplicationEventCartridge().includeEvent(context, includeResourcePath, currentResourcePath, directiveName);
+            EventCartridge contextCartridge = context.getEventCartridge();
+            if (contextCartridge != null)
+            {
+                contextCartridge.setRuntimeServices(rsvc);
+                includeResourcePath = contextCartridge.includeEvent(context, includeResourcePath, currentResourcePath, directiveName);
+            }
+            return includeResourcePath;
         }
         catch (RuntimeException e)
         {
@@ -230,15 +186,27 @@ public class EventHandlerUtil {
             InternalContextAdapter context, String reference, 
             Object object, String property, Info info)
     {
-        return  
-        invalidReferenceHandlerCall (
-                new InvalidReferenceEventHandler.InvalidGetMethodExecutor
-                (context, reference, object, property, info),
-                rsvc, 
-                context);       
+        try
+        {
+            Object result = rsvc.getApplicationEventCartridge().invalidGetMethod(context, reference, object, property, info);
+            EventCartridge contextCartridge = context.getEventCartridge();
+            if (contextCartridge != null)
+            {
+                contextCartridge.setRuntimeServices(rsvc);
+                result = contextCartridge.invalidGetMethod(context, reference, object, property, info);
+            }
+            return result;
+        }
+        catch (RuntimeException e)
+        {
+            throw e;
+        }
+        catch (Exception e)
+        {
+            throw new VelocityException("Exception in event handler.",e);
+        }
     }
-        
-        
+
    /**
      * Called when an invalid set method is encountered.
      * 
@@ -252,14 +220,26 @@ public class EventHandlerUtil {
             InternalContextAdapter context, String leftreference, 
             String rightreference, Info info)
     {
-        /**
-         * ignore return value
-         */
-        invalidReferenceHandlerCall (
-                new InvalidReferenceEventHandler.InvalidSetMethodExecutor
-                (context, leftreference, rightreference, info),
-                rsvc, 
-                context);   
+        try
+        {
+            if (!rsvc.getApplicationEventCartridge().invalidSetMethod(context, leftreference, rightreference, info))
+            {
+                EventCartridge contextCartridge = context.getEventCartridge();
+                if (contextCartridge != null)
+                {
+                    contextCartridge.setRuntimeServices(rsvc);
+                    contextCartridge.invalidSetMethod(context, leftreference, rightreference, info);
+                }
+            }
+        }
+        catch (RuntimeException e)
+        {
+            throw e;
+        }
+        catch (Exception e)
+        {
+            throw new VelocityException("Exception in event handler.",e);
+        }
     }
     
     /**
@@ -277,45 +257,16 @@ public class EventHandlerUtil {
             InternalContextAdapter context,  String reference,
             Object object, String method, Info info)
     {
-        return 
-        invalidReferenceHandlerCall (
-                new InvalidReferenceEventHandler.InvalidMethodExecutor
-                (context, reference, object, method, info),
-                rsvc, 
-                context);       
-    }
-    
-    
-    /**
-     * Calls event handler method with appropriate chaining across event handlers.
-     * 
-     * @param methodExecutor
-     * @param rsvc current instance of RuntimeServices
-     * @param context The current context
-     * @return return value from method, or null if no return value
-     */
-    public static Object invalidReferenceHandlerCall(
-            EventHandlerMethodExecutor methodExecutor, 
-            RuntimeServices rsvc,
-            InternalContextAdapter context)
-    {
-        // app level cartridges have already been initialized
-        EventCartridge ev1 = rsvc.getApplicationEventCartridge();
-        Iterator applicationEventHandlerIterator = 
-            (ev1 == null) ? null: ev1.getInvalidReferenceEventHandlers();              
-        
-        EventCartridge ev2 = context.getEventCartridge();
-        initializeEventCartridge(rsvc, ev2);
-        Iterator contextEventHandlerIterator = 
-            (ev2 == null) ? null: ev2.getInvalidReferenceEventHandlers();              
-        
         try
         {
-            callEventHandlers(
-                    applicationEventHandlerIterator, 
-                    contextEventHandlerIterator, methodExecutor);
-            
-            return methodExecutor.getReturnValue();
+            Object result = rsvc.getApplicationEventCartridge().invalidMethod(context, reference, object, method, info);
+            EventCartridge contextCartridge = context.getEventCartridge();
+            if (contextCartridge != null)
+            {
+                contextCartridge.setRuntimeServices(rsvc);
+                result = contextCartridge.invalidMethod(context, reference, object, method, info);
+            }
+            return result;
         }
         catch (RuntimeException e)
         {
@@ -325,77 +276,5 @@ public class EventHandlerUtil {
         {
             throw new VelocityException("Exception in event handler.",e);
         }
-        
     }
-
-    /**
-     * Initialize the event cartridge if appropriate.
-     * 
-     * @param rsvc current instance of RuntimeServices
-     * @param eventCartridge the event cartridge to be initialized
-     */
-    private static void initializeEventCartridge(RuntimeServices rsvc, EventCartridge eventCartridge)
-    {
-        if (eventCartridge != null)
-        {
-            try
-            {
-                eventCartridge.initialize(rsvc);
-            }
-            catch (Exception e)
-            {
-                throw new VelocityException("Couldn't initialize event cartridge : ", e);
-            }
-        }
-    }
-    
-    
-    /**
-     * Loop through both the application level and context-attached event handlers.
-     * 
-     * @param applicationEventHandlerIterator Iterator that loops through all global event handlers declared at application level
-     * @param contextEventHandlerIterator Iterator that loops through all global event handlers attached to context
-     * @param eventExecutor Strategy object that executes event handler method
-     */
-    private static void callEventHandlers(
-            Iterator applicationEventHandlerIterator, 
-            Iterator contextEventHandlerIterator,
-            EventHandlerMethodExecutor eventExecutor)
-    {
-        /**
-         * First loop through the event handlers configured at the app level
-         * in the properties file.
-         */
-        iterateOverEventHandlers(applicationEventHandlerIterator, eventExecutor);
-        
-        /**
-         * Then loop through the event handlers attached to the context.
-         */
-        iterateOverEventHandlers(contextEventHandlerIterator, eventExecutor);
-    }
-    
-    /**
-     * Loop through a given iterator of event handlers.
-     * 
-     * @param handlerIterator Iterator that loops through event handlers
-     * @param eventExecutor Strategy object that executes event handler method
-     */
-    private static void iterateOverEventHandlers(
-            Iterator handlerIterator,
-            EventHandlerMethodExecutor eventExecutor)
-    {
-        if (handlerIterator != null)
-        {
-            for (Iterator i = handlerIterator; i.hasNext();)
-            {
-                EventHandler eventHandler = (EventHandler) i.next();
-                
-                if (!eventExecutor.isDone())
-                {
-                    eventExecutor.execute(eventHandler);
-                }
-            }            
-        }
-    }
-    
 }

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/IncludeEventHandler.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/IncludeEventHandler.java?rev=1773548&r1=1773547&r2=1773548&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/IncludeEventHandler.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/IncludeEventHandler.java Sun Dec 11 08:27:14 2016
@@ -39,6 +39,7 @@ public interface  IncludeEventHandler ex
      * registered IncludeEventHandlers are called unless null is returned. If
      * none are registered the template at the includeResourcePath is retrieved.
      *
+     * @param context current context
      * @param includeResourcePath  the path as given in the include directive.
      * @param currentResourcePath the path of the currently rendering template that includes the
      *            include directive.
@@ -48,62 +49,5 @@ public interface  IncludeEventHandler ex
      * @return a new resource path for the directive, or null to block the
      *         include from occurring.
      */
-    public String includeEvent( String includeResourcePath, String currentResourcePath, String directiveName );
-
-
-
-    /**
-     * Defines the execution strategy for includeEvent
-     */
-    static class IncludeEventExecutor implements EventHandlerMethodExecutor
-    {
-        private Context context;
-        private String includeResourcePath;
-        private String currentResourcePath;
-        private String directiveName;
-        
-        private boolean executed = false;
-        
-        IncludeEventExecutor(
-                Context context, 
-                String includeResourcePath,
-                String currentResourcePath,
-                String directiveName)
-        {
-            this.context = context;
-            this.includeResourcePath = includeResourcePath;
-            this.currentResourcePath = currentResourcePath;
-            this.directiveName = directiveName;
-        }
-
-        /**
-         * Call the method includeEvent()
-         *  
-         * @param handler call the appropriate method on this handler
-         */
-        public void execute(EventHandler handler)
-        {
-            IncludeEventHandler eh = (IncludeEventHandler) handler;
-            
-            if (eh instanceof ContextAware)
-                ((ContextAware) eh).setContext(context);
-
-            executed = true;
-            includeResourcePath = ((IncludeEventHandler) handler)
-                .includeEvent(includeResourcePath, currentResourcePath, directiveName); 
-        }
-
-        public Object getReturnValue()
-        {
-            return includeResourcePath;
-        }
-
-        public boolean isDone()
-        {
-            return executed && (includeResourcePath == null);
-        }        
-        
-        
-    }
-
+    public String includeEvent(Context context, String includeResourcePath, String currentResourcePath, String directiveName);
 }

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/InvalidReferenceEventHandler.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/InvalidReferenceEventHandler.java?rev=1773548&r1=1773547&r2=1773548&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/InvalidReferenceEventHandler.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/InvalidReferenceEventHandler.java Sun Dec 11 08:27:14 2016
@@ -85,154 +85,4 @@ public interface InvalidReferenceEventHa
      */
     public Object invalidMethod(Context context, String reference,  
             Object object, String method, Info info);
-    
-    
-    /**
-     * Defines the execution strategy for invalidGetMethod
-     */
-    static class InvalidGetMethodExecutor implements EventHandlerMethodExecutor 
-    {
-        private Context context;
-        private String reference;
-        private Object object;
-        private String property;
-        private Info info;
-        
-        private Object result;
-        
-        InvalidGetMethodExecutor(
-                Context context, 
-                String reference, 
-                Object object, 
-                String property, 
-                Info info)
-        {
-            this.context = context;
-            this.reference = reference;
-            this.object = object;
-            this.property = property;
-            this.info = info;
-        }
-
-        /**
-         * Call the method invalidGetMethod()
-         *  
-         * @param handler call the appropriate method on this handler
-         */
-        public void execute(EventHandler handler)
-        {
-            result = ((InvalidReferenceEventHandler) handler).invalidGetMethod(
-                    context, reference, object, property, info);
-        }
-
-        public Object getReturnValue()
-        {
-            return result;
-        }
-
-        public boolean isDone()
-        {
-            return (result != null);
-        }                
-    }
-
-    /**
-     * Defines the execution strategy for invalidGetMethod
-     */
-    static class InvalidSetMethodExecutor implements EventHandlerMethodExecutor 
-    {
-        private Context context;
-        private String leftreference;
-        private String rightreference;
-        private Info info;
-        
-        private boolean result;
-        
-        InvalidSetMethodExecutor(
-                Context context, 
-                String leftreference, 
-                String rightreference, 
-                Info info)
-        {
-            this.context = context;
-            this.leftreference = leftreference;
-            this.rightreference = rightreference;
-            this.info = info;
-        }
-
-        /**
-         * Call the method invalidSetMethod()
-         *  
-         * @param handler call the appropriate method on this handler
-         */
-        public void execute(EventHandler handler)
-        {
-            result = ((InvalidReferenceEventHandler) handler).invalidSetMethod(
-                    context, leftreference, rightreference, info);            
-        }        
-    
-        public Object getReturnValue()
-        {
-            return null;
-        }
-
-        public boolean isDone()
-        {
-            return result;
-        }        
-
-    }
-
-    /**
-     * Defines the execution strategy for invalidGetMethod
-     */
-    static class InvalidMethodExecutor implements EventHandlerMethodExecutor
-    {
-        private Context context;
-        private String reference;
-        private Object object;
-        private String method;
-        private Info info;
-
-        private Object result;
-        private boolean executed = false;
-        
-        InvalidMethodExecutor(
-                Context context, 
-                String reference, 
-                Object object,
-                String method,
-                Info info)
-        {
-            this.context = context;
-            this.reference = reference;
-            this.object = object;
-            this.method = method;
-            this.info = info;
-        }
-
-        /**
-         * Call the method invalidMethod()
-         *  
-         * @param handler call the appropriate method on this handler
-         */
-        public void execute(EventHandler handler)
-        {
-            executed = true;
-            result = ((InvalidReferenceEventHandler) handler).invalidMethod(
-                    context, reference, object, method, info);
-        }
-        
-        public Object getReturnValue()
-        {
-            return result;
-        }
-
-        public boolean isDone()
-        {
-            return executed && (result != null);
-        }        
-
-    }
-
 }

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/MethodExceptionEventHandler.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/MethodExceptionEventHandler.java?rev=1773548&r1=1773547&r2=1773548&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/MethodExceptionEventHandler.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/MethodExceptionEventHandler.java Sun Dec 11 08:27:14 2016
@@ -41,6 +41,7 @@ public interface MethodExceptionEventHan
      * Only the first registered MethodExceptionEventHandler is called.  If
      * none are registered a MethodInvocationException is thrown.
      *
+     * @param context current context
      * @param claz the class of the object the method is being applied to
      * @param method the method
      * @param e the thrown exception
@@ -48,70 +49,5 @@ public interface MethodExceptionEventHan
      * @return an object to insert in the page
      * @throws RuntimeException an exception to be thrown instead inserting an object
      */
-    public Object methodException( Class claz, String method, Exception e, Info info );
-
-    /**
-     * Defines the execution strategy for methodException
-     * @since 1.5
-     */
-    static class MethodExceptionExecutor implements EventHandlerMethodExecutor
-    {
-        private Context context;
-        private Class claz;
-        private String method;
-        private Exception e;
-        private Info info;
-        
-        private Object result;
-        private boolean executed = false;
-    
-        MethodExceptionExecutor(
-                Context context, 
-                Class claz,
-                String method,
-                Exception e,
-                Info info)
-        {
-            this.context = context;
-            this.claz = claz;
-            this.method = method;
-            this.e = e;
-            this.info = info;
-        }
-
-        /**
-         * Call the method methodException()
-         *  
-         * @param handler call the appropriate method on this handler
-         * @exception Exception generic exception thrown by methodException event handler method call
-         */
-        public void execute(EventHandler handler)
-        {
-            MethodExceptionEventHandler eh = (MethodExceptionEventHandler) handler;
-            
-            if (eh instanceof ContextAware)
-                ((ContextAware) eh).setContext(context);
-
-            executed = true;
-            result = ((MethodExceptionEventHandler) handler).methodException(claz, method, e, info);
-        }
-
-        public Object getReturnValue()
-        {
-            return result;
-        }
-
-        /**
-         * Only run the first MethodExceptionEventHandler
-         * 
-         * @return true after this is executed once.
-         */
-        public boolean isDone()
-        {
-           return executed;
-        }        
-        
-        
-    }
-
+    public Object methodException(Context context, Class claz, String method, Exception e, Info info);
 }

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/ReferenceInsertionEventHandler.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/ReferenceInsertionEventHandler.java?rev=1773548&r1=1773547&r2=1773548&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/ReferenceInsertionEventHandler.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/ReferenceInsertionEventHandler.java Sun Dec 11 08:27:14 2016
@@ -20,7 +20,6 @@ package org.apache.velocity.app.event;
  */
 
 import org.apache.velocity.context.Context;
-import org.apache.velocity.util.ContextAware;
 
 /**
  *  Reference 'Stream insertion' event handler.  Called with object
@@ -41,66 +40,14 @@ public interface  ReferenceInsertionEven
      * ReferenceInsertionEventHandlers are are registered then reference value
      * is inserted into the output stream as is.
      *
+     *
+     * @param context current context
      * @param reference Reference from template about to be inserted.
      * @param value Value about to be inserted (after its <code>toString()</code>
      *            method is called).
      * @return Object on which <code>toString()</code> should be called for
      *         output.
      */
-    public Object referenceInsert( String reference, Object value  );
-
-    /**
-     * Defines the execution strategy for referenceInsert
-     * @since 1.5
-     */
-    static class referenceInsertExecutor implements EventHandlerMethodExecutor
-    {
-        private Context context;
-        private String reference;
-        private Object value;
-
-        referenceInsertExecutor(
-                Context context, 
-                String reference, 
-                Object value)
-        {
-            this.context = context;
-            this.reference = reference;
-            this.value = value;
-        }
-
-        /**
-         * Call the method referenceInsert()
-         *  
-         * @param handler call the appropriate method on this handler
-         */
-        public void execute(EventHandler handler)
-        {
-            ReferenceInsertionEventHandler eh = (ReferenceInsertionEventHandler) handler;
-            
-            if (eh instanceof ContextAware)
-                ((ContextAware) eh).setContext(context);
-
-            /**
-             * Every successive call will alter the same value
-             */
-            value = ((ReferenceInsertionEventHandler) handler).referenceInsert(reference, value); 
-        }
-
-        public Object getReturnValue()
-        {
-            return value;
-        }
-
-        /**
-         * Continue to end of event handler iteration
-         * 
-         * @return always returns false
-         */
-        public boolean isDone()
-        {
-            return false;
-        }        
-    }
+    public Object referenceInsert( Context context, String reference, Object value  );
 
 }

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/EscapeReference.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/EscapeReference.java?rev=1773548&r1=1773547&r2=1773548&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/EscapeReference.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/EscapeReference.java Sun Dec 11 08:27:14 2016
@@ -20,6 +20,7 @@ package org.apache.velocity.app.event.im
  */
 
 import org.apache.velocity.app.event.ReferenceInsertionEventHandler;
+import org.apache.velocity.context.Context;
 import org.apache.velocity.runtime.RuntimeConstants;
 import org.apache.velocity.runtime.RuntimeServices;
 import org.apache.velocity.util.RuntimeServicesAware;
@@ -90,7 +91,7 @@ public abstract class EscapeReference im
      * @param value
      * @return Escaped text.
      */
-    public Object referenceInsert(String reference, Object value)
+    public Object referenceInsert(Context context, String reference, Object value)
     {
         if(value == null)
         {

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/IncludeNotFound.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/IncludeNotFound.java?rev=1773548&r1=1773547&r2=1773548&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/IncludeNotFound.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/IncludeNotFound.java Sun Dec 11 08:27:14 2016
@@ -74,6 +74,7 @@ public class IncludeNotFound implements
      * @return message.
      */
     public String includeEvent(
+        Context context,
         String includeResourcePath,
         String currentResourcePath,
         String directiveName)

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/IncludeRelativePath.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/IncludeRelativePath.java?rev=1773548&r1=1773547&r2=1773548&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/IncludeRelativePath.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/IncludeRelativePath.java Sun Dec 11 08:27:14 2016
@@ -20,6 +20,7 @@ package org.apache.velocity.app.event.im
  */
 
 import org.apache.velocity.app.event.IncludeEventHandler;
+import org.apache.velocity.context.Context;
 
 /**
  * <p>Event handler that looks for included files relative to the path of the
@@ -44,6 +45,7 @@ public class IncludeRelativePath impleme
      * @return new path relative to the current template's path
      */
     public String includeEvent(
+        Context context,
         String includeResourcePath,
         String currentResourcePath,
         String directiveName)

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/PrintExceptions.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/PrintExceptions.java?rev=1773548&r1=1773547&r2=1773548&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/PrintExceptions.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/PrintExceptions.java Sun Dec 11 08:27:14 2016
@@ -20,6 +20,7 @@ package org.apache.velocity.app.event.im
  */
 
 import org.apache.velocity.app.event.MethodExceptionEventHandler;
+import org.apache.velocity.context.Context;
 import org.apache.velocity.runtime.RuntimeServices;
 import org.apache.velocity.util.RuntimeServicesAware;
 import org.apache.velocity.util.introspection.Info;
@@ -57,14 +58,15 @@ public class PrintExceptions implements
 
     /**
      * Render the method exception, and optionally the exception message and stack trace.
-     * 
+     *
+     * @param context current context
      * @param claz the class of the object the method is being applied to
      * @param method the method
      * @param e the thrown exception
      * @param info template name and line, column informations
      * @return an object to insert in the page
      */
-    public Object methodException(Class claz, String method, Exception e, Info info)
+    public Object methodException(Context context, Class claz, String method, Exception e, Info info)
     {
         boolean showTemplateInfo = rs.getBoolean(SHOW_TEMPLATE_INFO, false);
         boolean showStackTrace = rs.getBoolean(SHOW_STACK_TRACE,false);

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java?rev=1773548&r1=1773547&r2=1773548&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java Sun Dec 11 08:27:14 2016
@@ -789,6 +789,7 @@ public class RuntimeInstance implements
     {
 
         eventCartridge = new EventCartridge();
+        eventCartridge.setRuntimeServices(this);
 
         /**
          * For each type of event handler, get the class name, instantiate it, and store it.

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java?rev=1773548&r1=1773547&r2=1773548&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java Sun Dec 11 08:27:14 2016
@@ -218,8 +218,7 @@ public class ASTIdentifier extends Simpl
 
                 /**
                  * If the event handler throws an exception, then wrap it
-                 * in a MethodInvocationException.  Don't pass through RuntimeExceptions like other
-                 * similar catchall code blocks.
+                 * in a MethodInvocationException.
                  */
                 catch( Exception e )
                 {

Modified: velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/BuiltInEventHandlerTestCase.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/BuiltInEventHandlerTestCase.java?rev=1773548&r1=1773547&r2=1773548&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/BuiltInEventHandlerTestCase.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/BuiltInEventHandlerTestCase.java Sun Dec 11 08:27:14 2016
@@ -175,9 +175,9 @@ public class BuiltInEventHandlerTestCase
     public void testEscapeHtml() throws Exception
     {
         EscapeReference esc = new EscapeHtmlReference();
-        assertEquals("test string&amp;another&lt;b&gt;bold&lt;/b&gt;test",esc.referenceInsert("","test string&another<b>bold</b>test"));
-        assertEquals("&lt;&quot;&gt;",esc.referenceInsert("","<\">"));
-        assertEquals("test string",esc.referenceInsert("","test string"));
+        assertEquals("test string&amp;another&lt;b&gt;bold&lt;/b&gt;test",esc.referenceInsert(null,"","test string&another<b>bold</b>test"));
+        assertEquals("&lt;&quot;&gt;",esc.referenceInsert(null,"","<\">"));
+        assertEquals("test string",esc.referenceInsert(null,"","test string"));
 
         log("Correctly escaped HTML");
 
@@ -190,10 +190,10 @@ public class BuiltInEventHandlerTestCase
     public void testEscapeXml() throws Exception
     {
         EscapeReference esc = new EscapeXmlReference();
-        assertEquals("test string&amp;another&lt;b&gt;bold&lt;/b&gt;test",esc.referenceInsert("","test string&another<b>bold</b>test"));
-        assertEquals("&lt;&quot;&gt;",esc.referenceInsert("","<\">"));
-        assertEquals("&apos;",esc.referenceInsert("","'"));
-        assertEquals("test string",esc.referenceInsert("","test string"));
+        assertEquals("test string&amp;another&lt;b&gt;bold&lt;/b&gt;test",esc.referenceInsert(null,"","test string&another<b>bold</b>test"));
+        assertEquals("&lt;&quot;&gt;",esc.referenceInsert(null,"","<\">"));
+        assertEquals("&apos;",esc.referenceInsert(null,"","'"));
+        assertEquals("test string",esc.referenceInsert(null,"","test string"));
 
         log("Correctly escaped XML");
 
@@ -206,8 +206,8 @@ public class BuiltInEventHandlerTestCase
     public void testEscapeSql() throws Exception
     {
         EscapeReference esc = new EscapeSqlReference();
-        assertEquals("Jimmy''s Pizza",esc.referenceInsert("","Jimmy's Pizza"));
-        assertEquals("test string",esc.referenceInsert("","test string"));
+        assertEquals("Jimmy''s Pizza",esc.referenceInsert(null,"","Jimmy's Pizza"));
+        assertEquals("test string",esc.referenceInsert(null,"","test string"));
 
         log("Correctly escaped SQL");
 
@@ -220,8 +220,8 @@ public class BuiltInEventHandlerTestCase
     public void testEscapeJavaScript() throws Exception
     {
         EscapeReference esc = new EscapeJavaScriptReference();
-        assertEquals("Jimmy\\'s Pizza",esc.referenceInsert("","Jimmy's Pizza"));
-        assertEquals("test string",esc.referenceInsert("","test string"));
+        assertEquals("Jimmy\\'s Pizza",esc.referenceInsert(null,"","Jimmy's Pizza"));
+        assertEquals("test string",esc.referenceInsert(null,"","test string"));
 
 
         log("Correctly escaped Javascript");

Modified: velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/EventHandlingTestCase.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/EventHandlingTestCase.java?rev=1773548&r1=1773547&r2=1773548&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/EventHandlingTestCase.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/EventHandlingTestCase.java Sun Dec 11 08:27:14 2016
@@ -199,7 +199,7 @@ public class EventHandlingTestCase exten
         /**
          *  Event handler for when a reference is inserted into the output stream.
          */
-        public Object referenceInsert( String reference, Object value  )
+        public Object referenceInsert( Context context, String reference, Object value  )
         {
             // as a test, make sure this EventHandler is initialized
             if (rs == null)
@@ -233,7 +233,7 @@ public class EventHandlingTestCase exten
         /**
          *  Handles exceptions thrown during in-template method access
          */
-        public Object methodException( Class claz, String method, Exception e, Info info )
+        public Object methodException( Context context, Class claz, String method, Exception e, Info info )
         {
             // as a test, make sure this EventHandler is initialized
             if (rs == null)

Modified: velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/IncludeEventHandlingTestCase.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/IncludeEventHandlingTestCase.java?rev=1773548&r1=1773547&r2=1773548&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/IncludeEventHandlingTestCase.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/IncludeEventHandlingTestCase.java Sun Dec 11 08:27:14 2016
@@ -204,7 +204,7 @@ public class IncludeEventHandlingTestCas
     /**
      * Sample handler with different behaviors for the different tests.
      */
-    public String includeEvent( String includeResourcePath, String currentResourcePath, String directiveName)
+    public String includeEvent( Context context, String includeResourcePath, String currentResourcePath, String directiveName)
     {
         if (EventHandlerBehavior == PASS_THROUGH)
             return includeResourcePath;

Modified: velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/eventhandler/Handler1.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/eventhandler/Handler1.java?rev=1773548&r1=1773547&r2=1773548&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/eventhandler/Handler1.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/eventhandler/Handler1.java Sun Dec 11 08:27:14 2016
@@ -22,6 +22,7 @@ package org.apache.velocity.test.eventha
 import org.apache.velocity.app.event.IncludeEventHandler;
 import org.apache.velocity.app.event.MethodExceptionEventHandler;
 import org.apache.velocity.app.event.ReferenceInsertionEventHandler;
+import org.apache.velocity.context.Context;
 import org.apache.velocity.util.introspection.Info;
 
 /**
@@ -36,7 +37,7 @@ public class Handler1
         /**
          * display output twice, once uppercase and once lowercase
          */
-        public Object referenceInsert(String reference, Object value)
+        public Object referenceInsert(Context context, String reference, Object value)
         {
             if (value == null)
                 return null;
@@ -47,7 +48,7 @@ public class Handler1
         /**
          * throw the exception
          */
-        public Object methodException(Class claz, String method, Exception e, Info info)
+        public Object methodException(Context context, Class claz, String method, Exception e, Info info)
         {
             throw new RuntimeException(e);
         }
@@ -56,6 +57,7 @@ public class Handler1
          * redirect all requests to a page "login.vm" (simulates access control).
          */
         public String includeEvent(
+            Context context,
             String includeResourcePath,
             String currentResourcePath,
             String directiveName)

Modified: velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/eventhandler/Handler2.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/eventhandler/Handler2.java?rev=1773548&r1=1773547&r2=1773548&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/eventhandler/Handler2.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/eventhandler/Handler2.java Sun Dec 11 08:27:14 2016
@@ -22,6 +22,7 @@ package org.apache.velocity.test.eventha
 import org.apache.velocity.app.event.IncludeEventHandler;
 import org.apache.velocity.app.event.MethodExceptionEventHandler;
 import org.apache.velocity.app.event.ReferenceInsertionEventHandler;
+import org.apache.velocity.context.Context;
 import org.apache.velocity.util.introspection.Info;
 
 /**
@@ -36,7 +37,7 @@ public class Handler2
     /**
      * convert output to upper case
      */
-    public Object referenceInsert(String reference, Object value)
+    public Object referenceInsert(Context context, String reference, Object value)
     {
         if (value == null)
             return null;
@@ -47,7 +48,7 @@ public class Handler2
     /**
      * print the exception
      */
-    public Object methodException(Class claz, String method, Exception e, Info info)
+    public Object methodException(Context context, Class claz, String method, Exception e, Info info)
     {
         return "Exception: " + e;
     }
@@ -56,6 +57,7 @@ public class Handler2
      * redirect all requests to a new directory "subdir" (simulates localization).
      */
     public String includeEvent(
+        Context context,
         String includeResourcePath,
         String currentResourcePath,
         String directiveName)

Modified: velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity758TestCase.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity758TestCase.java?rev=1773548&r1=1773547&r2=1773548&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity758TestCase.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity758TestCase.java Sun Dec 11 08:27:14 2016
@@ -21,6 +21,7 @@ package org.apache.velocity.test.issues;
 
 import org.apache.velocity.app.event.EventCartridge;
 import org.apache.velocity.app.event.IncludeEventHandler;
+import org.apache.velocity.context.Context;
 import org.apache.velocity.test.BaseTestCase;
 
 /**
@@ -52,7 +53,7 @@ public class Velocity758TestCase extends
 
     public static class Handler implements IncludeEventHandler
     {
-        public String includeEvent(String parsePath, String parentPath, String directive)
+        public String includeEvent(Context context, String parsePath, String parentPath, String directive)
         {
             if (parsePath == null)
             {

Modified: velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/misc/ExceptionGeneratingEventHandler.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/misc/ExceptionGeneratingEventHandler.java?rev=1773548&r1=1773547&r2=1773548&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/misc/ExceptionGeneratingEventHandler.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/misc/ExceptionGeneratingEventHandler.java Sun Dec 11 08:27:14 2016
@@ -22,6 +22,7 @@ package org.apache.velocity.test.misc;
 import org.apache.velocity.app.event.IncludeEventHandler;
 import org.apache.velocity.app.event.MethodExceptionEventHandler;
 import org.apache.velocity.app.event.ReferenceInsertionEventHandler;
+import org.apache.velocity.context.Context;
 import org.apache.velocity.util.introspection.Info;
 
 /**
@@ -35,15 +36,15 @@ public class ExceptionGeneratingEventHan
         MethodExceptionEventHandler, ReferenceInsertionEventHandler
 {
 
-    public String includeEvent(String includeResourcePath, String currentResourcePath,
+    public String includeEvent(Context context, String includeResourcePath, String currentResourcePath,
             String directiveName)
     {
         throw new RuntimeException("exception");
     }
 
-    public Object methodException(Class claz, String method, Exception e, Info info) { throw new RuntimeException("exception"); }
+    public Object methodException(Context context, Class claz, String method, Exception e, Info info) { throw new RuntimeException("exception"); }
 
-    public Object referenceInsert(String reference, Object value)
+    public Object referenceInsert(Context context, String reference, Object value)
     {
         throw new RuntimeException("exception");
     }

Modified: velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/util/introspection/ConversionHandlerTestCase.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/util/introspection/ConversionHandlerTestCase.java?rev=1773548&r1=1773547&r2=1773548&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/util/introspection/ConversionHandlerTestCase.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/util/introspection/ConversionHandlerTestCase.java Sun Dec 11 08:27:14 2016
@@ -24,6 +24,7 @@ import org.apache.velocity.VelocityConte
 import org.apache.velocity.app.Velocity;
 import org.apache.velocity.app.VelocityEngine;
 import org.apache.velocity.app.event.MethodExceptionEventHandler;
+import org.apache.velocity.context.Context;
 import org.apache.velocity.runtime.RuntimeConstants;
 import org.apache.velocity.runtime.RuntimeInstance;
 import org.apache.velocity.test.BaseTestCase;
@@ -200,7 +201,8 @@ public class ConversionHandlerTestCase e
 
     public static class PrintException implements MethodExceptionEventHandler
     {
-        public Object methodException(Class claz,
+        public Object methodException(Context context,
+                                      Class claz,
                                       String method,
                                       Exception e,
                                       Info info)

Modified: velocity/engine/trunk/velocity-engine-examples/src/main/java/org/apache/velocity/example/EventExample.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-examples/src/main/java/org/apache/velocity/example/EventExample.java?rev=1773548&r1=1773547&r2=1773548&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-examples/src/main/java/org/apache/velocity/example/EventExample.java (original)
+++ velocity/engine/trunk/velocity-engine-examples/src/main/java/org/apache/velocity/example/EventExample.java Sun Dec 11 08:27:14 2016
@@ -20,6 +20,7 @@ package org.apache.velocity.example;
 
 import java.io.StringWriter;
 
+import org.apache.velocity.context.Context;
 import org.apache.velocity.util.introspection.Info;
 import org.slf4j.helpers.FormattingTuple;
 import org.slf4j.helpers.MarkerIgnoringBase;
@@ -240,7 +241,7 @@ public class EventExample extends Marker
     /**
      *  Event handler for when a reference is inserted into the output stream.
      */
-    public Object referenceInsert( String reference, Object value  )
+    public Object referenceInsert( Context context, String reference, Object value  )
     {
         /*
          *  if we have a value
@@ -281,7 +282,7 @@ public class EventExample extends Marker
         return true;
     }
 
-    public Object methodException( Class claz, String method, Exception e, Info info )   {
+    public Object methodException( Context context, Class claz, String method, Exception e, Info info )   {
         /*
          *  only do processing if the switch is on
          */



Mime
View raw message