Return-Path: Delivered-To: apmail-velocity-commits-archive@minotaur.apache.org Received: (qmail 97833 invoked from network); 6 Feb 2009 04:55:36 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 6 Feb 2009 04:55:36 -0000 Received: (qmail 37358 invoked by uid 500); 6 Feb 2009 04:55:30 -0000 Delivered-To: apmail-velocity-commits-archive@velocity.apache.org Received: (qmail 37339 invoked by uid 500); 6 Feb 2009 04:55:30 -0000 Mailing-List: contact commits-help@velocity.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@velocity.apache.org Delivered-To: mailing list commits@velocity.apache.org Received: (qmail 37324 invoked by uid 99); 6 Feb 2009 04:55:30 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Feb 2009 20:55:29 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 06 Feb 2009 04:55:29 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 25FBA23888A0; Fri, 6 Feb 2009 04:55:09 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r741408 - /velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Foreach.java Date: Fri, 06 Feb 2009 04:55:08 -0000 To: commits@velocity.apache.org From: byron@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090206045509.25FBA23888A0@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: byron Date: Fri Feb 6 04:55:08 2009 New Revision: 741408 URL: http://svn.apache.org/viewvc?rev=741408&view=rev Log: Remove NullHolderContext for foreach since the standard contexts do handle null keys Modified: velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Foreach.java Modified: velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Foreach.java URL: http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Foreach.java?rev=741408&r1=741407&r2=741408&view=diff ============================================================================== --- velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Foreach.java (original) +++ velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/directive/Foreach.java Fri Feb 6 04:55:08 2009 @@ -23,7 +23,6 @@ import java.io.Writer; import java.util.Iterator; -import org.apache.velocity.context.ChainedInternalContextAdapter; import org.apache.velocity.context.InternalContextAdapter; import org.apache.velocity.exception.MethodInvocationException; import org.apache.velocity.exception.ParseErrorException; @@ -50,82 +49,6 @@ public class Foreach extends Directive { /** - * A special context to use when the foreach iterator returns a null. This - * is required since the standard context may not support nulls. - * All puts and gets are passed through, except for the foreach iterator key. - * @since 1.5 - */ - protected static class NullHolderContext extends ChainedInternalContextAdapter - { - private String loopVariableKey = ""; - private boolean active = true; - - /** - * Create the context as a wrapper to be used within the foreach - * @param key the reference used in the foreach - * @param context the parent context - */ - private NullHolderContext( String key, InternalContextAdapter context ) - { - super(context); - if( key != null ) - loopVariableKey = key; - } - - /** - * Get an object from the context, or null if the key is equal to the loop variable - * @see org.apache.velocity.context.InternalContextAdapter#get(java.lang.String) - * @exception MethodInvocationException passes on potential exception from reference method call - */ - public Object get( String key ) throws MethodInvocationException - { - return ( active && loopVariableKey.equals(key) ) - ? null - : super.get(key); - } - - /** - * @see org.apache.velocity.context.InternalContextAdapter#put(java.lang.String key, java.lang.Object value) - */ - public Object put( String key, Object value ) - { - if( loopVariableKey.equals(key) && (value == null) ) - { - active = true; - } - - return super.put( key, value ); - } - - /** - * Allows callers to explicitly put objects in the local context. - * Objects added to the context through this method always end up - * in the top-level context of possible wrapped contexts. - * - * @param key name of item to set. - * @param value object to set to key. - * @see org.apache.velocity.context.InternalWrapperContext#localPut(String, Object) - */ - public Object localPut(final String key, final Object value) - { - return put(key, value); - } - - /** - * Remove an object from the context - * @see org.apache.velocity.context.InternalContextAdapter#remove(java.lang.Object key) - */ - public Object remove(Object key) - { - if( loopVariableKey.equals(key) ) - { - active = false; - } - return super.remove(key); - } - } - - /** * Return name of this directive. * @return The name of this directive. */ @@ -332,13 +255,6 @@ Object savedCounter = context.get(counterName); Object nextFlag = context.get(hasNextName); - /* - * Instantiate the null holder context if a null value - * is returned by the foreach iterator. Only one instance is - * created - it's reused for every null value. - */ - NullHolderContext nullHolderContext = null; - while (!maxNbrLoopsExceeded && i.hasNext()) { put(context, counterName , Integer.valueOf(counter)); @@ -348,22 +264,7 @@ try { - /* - * If the value is null, use the special null holder context - */ - if (value == null) - { - if (nullHolderContext == null) - { - // lazy instantiation - nullHolderContext = new NullHolderContext(elementKey, context); - } - node.jjtGetChild(3).render(nullHolderContext, writer); - } - else - { - node.jjtGetChild(3).render(context, writer); - } + node.jjtGetChild(3).render(context, writer); } catch (Break.BreakException ex) {