geirm       00/11/02 19:27:06

  Modified:    src/java/org/apache/velocity/runtime/parser/node
                        ASTReference.java
  Log:
  Changes to assist in correct escape handling.
  
  Revision  Changes    Path
  1.8       +121 -8    
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java
  
  Index: ASTReference.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ASTReference.java 2000/11/02 22:24:20     1.7
  +++ ASTReference.java 2000/11/03 03:27:05     1.8
  @@ -1,5 +1,72 @@
  -//* Generated By:JJTree: Do not edit this line. ASTReference.java */
  +/* Generated By:JJTree: Do not edit this line. ASTReference.java */
   
  +/*
  + * The Apache Software License, Version 1.1
  + *
  + * Copyright (c) 2000 The Apache Software Foundation.  All rights
  + * reserved.
  + *
  + * Redistribution and use in source and binary forms, with or without
  + * modification, are permitted provided that the following conditions
  + * are met:
  + *
  + * 1. Redistributions of source code must retain the above copyright
  + *    notice, this list of conditions and the following disclaimer.
  + *
  + * 2. Redistributions in binary form must reproduce the above copyright
  + *    notice, this list of conditions and the following disclaimer in
  + *    the documentation and/or other materials provided with the
  + *    distribution.
  + *
  + * 3. The end-user documentation included with the redistribution, if
  + *    any, must include the following acknowlegement:
  + *       "This product includes software developed by the
  + *        Apache Software Foundation (http://www.apache.org/)."
  + *    Alternately, this acknowlegement may appear in the software itself,
  + *    if and wherever such third-party acknowlegements normally appear.
  + *
  + * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
  + *    Foundation" must not be used to endorse or promote products derived
  + *    from this software without prior written permission. For written
  + *    permission, please contact [EMAIL PROTECTED]
  + *
  + * 5. Products derived from this software may not be called "Apache"
  + *    nor may "Apache" appear in their names without prior written
  + *    permission of the Apache Group.
  + *
  + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  + * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  + * SUCH DAMAGE.
  + * ====================================================================
  + *
  + * This software consists of voluntary contributions made by many
  + * individuals on behalf of the Apache Software Foundation.  For more
  + * information on the Apache Software Foundation, please see
  + * <http://www.apache.org/>.
  + */
  +
  +
  +/**
  + * This class is responsible for handling the references in
  + * VTL ($foo).
  + * 
  + * Please look at the Parser.jjt file which is
  + * what controls the generation of this class.
  + *
  + * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
  + * @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
  + * @version $Id: ASTReference.java,v 1.8 2000/11/03 03:27:05 geirm Exp $ 
  +*/
  +
   package org.apache.velocity.runtime.parser.node;
   
   import java.io.Writer;
  @@ -24,6 +91,7 @@
       private Object rootObject;
       private Object value;
       private String rootString;
  +    private boolean bIsEscaped_ = false;
       
       public ASTReference(int id)
       {
  @@ -83,6 +151,28 @@
       {
           value = execute(null, context);
           
  +        /*
  +         *  if this reference is escaped (\$foo) then we want to do one of two 
things :
  +         *  1) if this is a reference in the context, then we want to print $foo
  +         *  2) if not, then \$foo  (its considered shmoo, not VTL)
  +         *
  +         *  I am not wild about this specialText() stuff...
  +         */
  +
  +        if (bIsEscaped_)
  +        {
  +            if ( value == null )
  +                writer.write( NodeUtils.specialText(getFirstToken()) + "\\" + 
nullString );
  +            else
  +                writer.write( NodeUtils.specialText(getFirstToken()) + nullString );
  +        
  +            return true;
  +        }
  +
  +        /*
  +         *  the normal processing
  +         */
  +
           if (value == null)
           {
               writer.write(NodeUtils
  @@ -126,9 +216,12 @@
   
       public boolean setValue(Context context, Object value)
       {
  -        // The rootOfIntrospection is the object we will
  -        // retrieve from the Context. This is the base
  -        // object we will apply reflection to.
  +        /*
  +         *  The rootOfIntrospection is the object we will
  +         *  retrieve from the Context. This is the base
  +         *  object we will apply reflection to.
  +         */
  +
           Object result = getVariableValue(context, rootString);
           
           if (result == null)
  @@ -137,7 +230,10 @@
               return false;
           }                          
           
  -        // How many child nodes do we have?
  +        /*
  +         * How many child nodes do we have?
  +         */
  +
           int children = jjtGetNumChildren();
   
           for (int i = 0; i < children - 1; i++)
  @@ -161,6 +257,7 @@
            * $provider may be in the context, but Monkey is
            * not a method of $provider.
            */
  +
           try
           {
               Class c = result.getClass();
  @@ -179,10 +276,26 @@
       private String getRoot()
       {
           Token t = getFirstToken();
  -        
  +         
  +        /*
  +         *  we need to see if this reference is escaped.  if so
  +         *  we will clean off the leading \ and let the 
  +         *  regular behavior determine if we should output this
  +         *  as \$foo or $foo later on in render(). Lazyness..
  +         */
  +
  +        bIsEscaped_ = false;
  +
  +        if ( t.image.startsWith("\\"))
  +        {
  +            bIsEscaped_ = true;
  +
  +            t.image = t.image.substring(1);
  +        }
  + 
           /*
  -         *  geirm :   changed Parser.jjt to handle $foo! 
  -         *  so the tree structure changed.  Leaving this stuff here
  +         *  geirm :   changed Parser.jjt to handle the $foo! bug 
  +         *  and the tree structure changed.  Leaving this stuff here
            *  for a little while in case something bad happens. :)
            *  following line was ->  if (t.image.equals("$!"))
            */
  
  
  

Reply via email to