jvanzyl     00/10/17 04:27:44

  Modified:    src/java/org/apache/velocity/runtime/parser
                        ASTReference.java Node.java SimpleNode.java
                        Token.java
  Log:
  - references that evaluate to null are now displayed in full
    literal form i.e. $data.Message as opposed to $data. Problem
    reported by Christoph Reck <[EMAIL PROTECTED]>. Thanks.
  
    Done in preparation for a full fleshing out of the logging system
    tomorrow.
  
  Revision  Changes    Path
  1.5       +22 -6     
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/ASTReference.java
  
  Index: ASTReference.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/ASTReference.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ASTReference.java 2000/10/09 21:27:10     1.4
  +++ ASTReference.java 2000/10/17 11:27:37     1.5
  @@ -149,26 +149,42 @@
           else if (t.image.equals("${"))
           {
               // ${provider.Title}
  -            nullString = t.next.image;   
  +            nullString = literal();
               return t.next.image;
           }            
           else
           {
               // $provider.Title
  -            nullString = t.image;
  +            nullString = literal();
               return t.image.substring(1);
           }            
       }
   
  +    /**
  +     * Return the literal string representation
  +     * of a reference. Used when a reference has
  +     * a null value.
  +     */
  +    public String literal()
  +    {
  +        Token t = getFirstToken();
  +        StringBuffer sb = new StringBuffer(t.image);
  +        
  +        while(t.next != null && t.next.last == false)
  +        {
  +            t = t.next;
  +            sb.append(t.image);
  +        }
  +        sb.append(getLastToken().image);
  +        
  +        return sb.toString();
  +    }
  +
       public Object getVariableValue(Context context, String variable)
       {
           if (context.containsKey(variable))
  -        {
               return context.get(variable);
  -        }            
           else
  -        {
               return null;
  -        }            
       }
   }
  
  
  
  1.4       +0 -1      
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/Node.java
  
  Index: Node.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/Node.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Node.java 2000/10/09 21:27:10     1.3
  +++ Node.java 2000/10/17 11:27:38     1.4
  @@ -57,7 +57,6 @@
           throws IOException;
   
       public Object execute(Object o, Context context);
  -
       public void setInfo(int info);
       public int getInfo();
   }
  
  
  
  1.4       +3 -5      
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/SimpleNode.java
  
  Index: SimpleNode.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/SimpleNode.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SimpleNode.java   2000/10/09 21:27:10     1.3
  +++ SimpleNode.java   2000/10/17 11:27:39     1.4
  @@ -32,11 +32,6 @@
           parser = p;
       }
   
  -    /* Added */
  -    public void interpret()
  -    {
  -    }
  -
       public void jjtOpen()
       {
           first = parser.getToken(1); // added
  @@ -45,6 +40,9 @@
       public void jjtClose()
       {
           last = parser.getToken(0); // added
  +        
  +        if (id == ParserTreeConstants.JJTREFERENCE)
  +            last.last = true;
       }
   
       public void setFirstToken(Token t)
  
  
  
  1.2       +1 -1      
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/Token.java
  
  Index: Token.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/Token.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Token.java        2000/09/30 17:04:24     1.1
  +++ Token.java        2000/10/17 11:27:41     1.2
  @@ -7,6 +7,7 @@
   
   public class Token
   {
  +    public boolean last = false;
   
       /**
        * An integer that describes the kind of this token.  This numbering
  @@ -79,5 +80,4 @@
                   return new Token();
           }
       }
  -
   }
  
  
  

Reply via email to