Author: byron
Date: Sat Feb  7 11:50:28 2009
New Revision: 741882

URL: http://svn.apache.org/viewvc?rev=741882&view=rev
Log:
VELOCITY-680 Add a context frame to resources called with #parse so that local 
scope context modifications are local to the parsed resource

Modified:
    
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Parse.java

Modified: 
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Parse.java
URL: 
http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Parse.java?rev=741882&r1=741881&r2=741882&view=diff
==============================================================================
--- 
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Parse.java
 (original)
+++ 
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Parse.java
 Sat Feb  7 11:50:28 2009
@@ -27,6 +27,7 @@
 import org.apache.velocity.Template;
 import org.apache.velocity.app.event.EventHandlerUtil;
 import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.context.ProxyVMContext;
 import org.apache.velocity.exception.MethodInvocationException;
 import org.apache.velocity.exception.ParseErrorException;
 import org.apache.velocity.exception.ResourceNotFoundException;
@@ -65,6 +66,11 @@
 {
     private int maxDepth;
 
+    /** 
+     * If the set directive operates on the global or local scope.
+     */
+    boolean localscope = false;    
+    
     /**
      * Return name of this directive.
      * @return The name of this directive.
@@ -96,6 +102,9 @@
         super.init(rs, context, node);
 
         this.maxDepth = rsvc.getInt(RuntimeConstants.PARSE_DIRECTIVE_MAXDEPTH, 
10);
+
+        // support for local context scope feature, where all references are 
local
+        localscope = rsvc.getBoolean(RuntimeConstants.VM_CONTEXT_LOCALSCOPE, 
false);        
     }
 
     /**
@@ -246,9 +255,15 @@
          */
         try
         {
+            boolean localscope = true;
             if (!blockinput) {
                 context.pushCurrentTemplateName(arg);
-                ((SimpleNode) t.getData()).render( context, writer );
+                
+                // Create a context frame for the parsed resource so that 
context
+                // changes are local.
+                ProxyVMContext vmc = new ProxyVMContext(context, localscope);
+                
+                ((SimpleNode) t.getData()).render(vmc, writer);
             }
         }
         /**


Reply via email to