You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by ge...@locus.apache.org on 2000/12/27 15:31:57 UTC

cvs commit: jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node ASTAddNode.java ASTDivNode.java ASTModNode.java ASTMulNode.java ASTSubtractNode.java

geirm       00/12/27 06:31:56

  Modified:    src/java/org/apache/velocity/runtime/parser/node
                        ASTAddNode.java ASTDivNode.java ASTModNode.java
                        ASTMulNode.java ASTSubtractNode.java
  Log:
  A few things :
  - Added checks to ensure that args to math ops are not null (catch those pesky NPE's)
  - Put in log messages to tell user what is going on when math doesn't go as expected.
  - Contrained math operations to integers only (for now).
  - Did div0 checks for mod and division.
  - Added license info.
  
  Revision  Changes    Path
  1.2       +113 -3    jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTAddNode.java
  
  Index: ASTAddNode.java
  ===================================================================
  RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTAddNode.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ASTAddNode.java	2000/10/20 19:14:01	1.1
  +++ ASTAddNode.java	2000/12/27 14:31:52	1.2
  @@ -1,9 +1,76 @@
   /* Generated By:JJTree: Do not edit this line. ASTAddNode.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 apache@apache.org.
  + *
  + * 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/>.
  + */
  +
  +
  +/**
  + * Handles integer addition of nodes
  + *
  + * Please look at the Parser.jjt file which is
  + * what controls the generation of this class.
  + *
  + * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
  + * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
  + * @version $Id: ASTAddNode.java,v 1.2 2000/12/27 14:31:52 geirm Exp $ 
  +*/
  +
   package org.apache.velocity.runtime.parser.node;
   
   import org.apache.velocity.Context;
  -import org.apache.velocity.runtime.parser.*;
  +import org.apache.velocity.runtime.Runtime;
  +import org.apache.velocity.runtime.parser.Parser;
   
   public class ASTAddNode extends SimpleNode
   {
  @@ -23,10 +90,53 @@
           return visitor.visit(this, data);
       }
   
  +    /**
  +     *  computes the sum of the two nodes.  Currently only integer operations are 
  +     *  supported.
  +     *  @return Integer object with value, or null
  +     */
       public Object value(Context context)
       {
  -        return new Integer(((Integer) jjtGetChild(0).value(context)).intValue() +
  -            ((Integer) jjtGetChild(1).value(context)).intValue());
  +        /*
  +         *  get the two addends
  +         */
  +
  +        Object left = jjtGetChild(0).value( context );
  +        Object right = jjtGetChild(1).value( context );
  +
  +        /*
  +         *  if either is null, lets log and bail
  +         */
  +
  +        if (left == null || right == null)
  +        {
  +            Runtime.error( ( left == null ? "Left" : "Right" ) + " side of addition operation has null value."
  +                           + " Operation not possible. "
  +                           + context.getCurrentTemplateName() + " [line " + getLine() 
  +                           + ", column " + getColumn() + "]");
  +            return null;
  +        }
  +        
  +        /*
  +         *  if not an Integer, not much we can do either
  +         */
  +
  +        if ( !( left instanceof Integer )  || !( right instanceof Integer ))
  +        {
  +            Runtime.error( ( !( left instanceof Integer ) ? "Left" : "Right" ) 
  +                           + " side of addition operation is not a valid type. "
  +                           + "Currently only integers (1,2,3...) and Integer type is supported. "
  +                           + context.getCurrentTemplateName() + " [line " + getLine() 
  +                           + ", column " + getColumn() + "]");
  + 
  +            return null;
  +        }
  +
  +        return new Integer( ( (Integer) left ).intValue() + (  (Integer) right ).intValue() );
       }
   
   }
  +
  +
  +
  +
  
  
  
  1.2       +122 -4    jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTDivNode.java
  
  Index: ASTDivNode.java
  ===================================================================
  RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTDivNode.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ASTDivNode.java	2000/10/20 19:14:02	1.1
  +++ ASTDivNode.java	2000/12/27 14:31:53	1.2
  @@ -1,9 +1,76 @@
   /* Generated By:JJTree: Do not edit this line. ASTDivNode.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 apache@apache.org.
  + *
  + * 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/>.
  + */
  +
  +
  +/**
  + * Handles integer division of nodes
  + *
  + * Please look at the Parser.jjt file which is
  + * what controls the generation of this class.
  + *
  + * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
  + * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
  + * @version $Id: ASTDivNode.java,v 1.2 2000/12/27 14:31:53 geirm Exp $ 
  +*/
  +
   package org.apache.velocity.runtime.parser.node;
   
   import org.apache.velocity.Context;
  -import org.apache.velocity.runtime.parser.*;
  +import org.apache.velocity.runtime.Runtime;
  +import org.apache.velocity.runtime.parser.Parser;
   
   public class ASTDivNode extends SimpleNode
   {
  @@ -23,10 +90,61 @@
           return visitor.visit(this, data);
       }
   
  +    /**
  +     *  computes the result of the division. Currently limited to
  +     *  Integers.
  +     *  @return Integer(value) or null 
  +     */
       public Object value(Context context)
       {
  -        return new Integer(((Integer) jjtGetChild(0).value(context)).intValue() /
  -            ((Integer) jjtGetChild(1).value(context)).intValue());
  -    }
  +        /*
  +         *  get the two args
  +         */
  +
  +        Object left = jjtGetChild(0).value( context );
  +        Object right = jjtGetChild(1).value( context );
  +
  +        /*
  +         *  if either is null, lets log and bail
  +         */
  +
  +        if (left == null || right == null)
  +        {
  +            Runtime.error( ( left == null ? "Left" : "Right" ) + " side of division operation has null value."
  +                           + " Operation not possible. "
  +                           + context.getCurrentTemplateName() + " [line " + getLine() 
  +                           + ", column " + getColumn() + "]");
  +            return null;
  +        }
  +        
  +        /*
  +         *  if not an Integer, not much we can do either
  +         */
  +
  +        if ( !( left instanceof Integer )  || !( right instanceof Integer ))
  +        {
  +            Runtime.error( ( !( left instanceof Integer ) ? "Left" : "Right" ) 
  +                           + " side of division operation is not a valid type. "
  +                           + "Currently only integers (1,2,3...) and Integer type is supported. "
  +                           + context.getCurrentTemplateName() + " [line " + getLine() 
  +                           + ", column " + getColumn() + "]");
  + 
  +            return null;
  +        }
  +
  +        /*
  +         *  check for divide by 0
  +         */
  +
  +        if ( ( (Integer) right).intValue() == 0 )
  +        {
  +            Runtime.error( "Right side of division operation is zero. Must be non-zero. "
  +                           + context.getCurrentTemplateName() + " [line " + getLine() 
  +                           + ", column " + getColumn() + "]");
  + 
  +            return null;
  +        }
   
  +        return new Integer( ( (Integer) left ).intValue() / (  (Integer) right ).intValue() );
  +    }
   }
  
  
  
  1.2       +122 -1    jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTModNode.java
  
  Index: ASTModNode.java
  ===================================================================
  RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTModNode.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ASTModNode.java	2000/10/20 19:14:02	1.1
  +++ ASTModNode.java	2000/12/27 14:31:53	1.2
  @@ -1,8 +1,75 @@
   /* Generated By:JJTree: Do not edit this line. ASTModNode.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 apache@apache.org.
  + *
  + * 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/>.
  + */
  +
  +
  +/**
  + * Handles integer modulus division
  + *
  + * Please look at the Parser.jjt file which is
  + * what controls the generation of this class.
  + *
  + * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
  + * @version $Id: ASTModNode.java,v 1.2 2000/12/27 14:31:53 geirm Exp $ 
  +*/
  +
   package org.apache.velocity.runtime.parser.node;
   
  -import org.apache.velocity.runtime.parser.*;
  +import org.apache.velocity.Context;
  +import org.apache.velocity.runtime.Runtime;
  +import org.apache.velocity.runtime.parser.Parser;
   
   public class ASTModNode extends SimpleNode
   {
  @@ -21,4 +88,58 @@
       {
           return visitor.visit(this, data);
       }
  +
  +    public Object value(Context context)
  +    {
  +        /*
  +         *  get the two args
  +         */
  +
  +        Object left = jjtGetChild(0).value( context );
  +        Object right = jjtGetChild(1).value( context );
  +
  +        /*
  +         *  if either is null, lets log and bail
  +         */
  +
  +        if (left == null || right == null)
  +        {
  +            Runtime.error( ( left == null ? "Left" : "Right" ) + " side of modulus operation has null value."
  +                           + " Operation not possible. "
  +                           + context.getCurrentTemplateName() + " [line " + getLine() 
  +                           + ", column " + getColumn() + "]");
  +            return null;
  +        }
  +        
  +        /*
  +         *  if not an Integer, not much we can do either
  +         */
  +
  +        if ( !( left instanceof Integer )  || !( right instanceof Integer ))
  +        {
  +            Runtime.error( ( !( left instanceof Integer ) ? "Left" : "Right" ) 
  +                           + " side of modulus operation is not a valid type. "
  +                           + "Currently only integers (1,2,3...) and Integer type is supported. "
  +                           + context.getCurrentTemplateName() + " [line " + getLine() 
  +                           + ", column " + getColumn() + "]");
  + 
  +            return null;
  +        }
  +
  +        /*
  +         *  check for divide by 0
  +         */
  +
  +        if ( ( (Integer) right).intValue() == 0 )
  +        {
  +            Runtime.error( "Right side of modulus operation is zero. Must be non-zero. "
  +                           + context.getCurrentTemplateName() + " [line " + getLine() 
  +                           + ", column " + getColumn() + "]");
  + 
  +            return null;
  +        }
  +
  +        return new Integer( ( (Integer) left ).intValue() % (  (Integer) right ).intValue() );
  +    }
   }
  +
  
  
  
  1.2       +111 -5    jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTMulNode.java
  
  Index: ASTMulNode.java
  ===================================================================
  RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTMulNode.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ASTMulNode.java	2000/10/20 19:14:02	1.1
  +++ ASTMulNode.java	2000/12/27 14:31:53	1.2
  @@ -1,9 +1,75 @@
   /* Generated By:JJTree: Do not edit this line. ASTMulNode.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 apache@apache.org.
  + *
  + * 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/>.
  + */
  +
  +
  +/**
  + * Handles integer multiplication
  + *
  + * Please look at the Parser.jjt file which is
  + * what controls the generation of this class.
  + *
  + * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
  + * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
  + * @version $Id: ASTMulNode.java,v 1.2 2000/12/27 14:31:53 geirm Exp $ 
  +*/
   
   package org.apache.velocity.runtime.parser.node;
   
   import org.apache.velocity.Context;
  -import org.apache.velocity.runtime.parser.*;
  +import org.apache.velocity.runtime.Runtime;
  +import org.apache.velocity.runtime.parser.Parser;
   
   public class ASTMulNode extends SimpleNode
   {
  @@ -23,10 +89,50 @@
           return visitor.visit(this, data);
       }
   
  -    public Object value(Context context)
  +    /**
  +     *  computes the product of the two args.  Returns null if either arg is null
  +     *  or if either arg is not an integer
  +     */
  +    public Object value( Context context )
       {
  -        return new Integer(((Integer) jjtGetChild(0).value(context)).intValue() *
  -            ((Integer) jjtGetChild(1).value(context)).intValue());
  -    }
  +        /*
  +         *  get the two args
  +         */
  +
  +        Object left = jjtGetChild(0).value( context );
  +        Object right = jjtGetChild(1).value( context );
  +
  +        /*
  +         *  if either is null, lets log and bail
  +         */
  +
  +        if (left == null || right == null)
  +        {
  +            Runtime.error( ( left == null ? "Left" : "Right" ) + " side of multiplication operation has null value."
  +                           + " Operation not possible. "
  +                           + context.getCurrentTemplateName() + " [line " + getLine() 
  +                           + ", column " + getColumn() + "]");
  +            return null;
  +        }
  +        
  +        /*
  +         *  if not an Integer, not much we can do either
  +         */
  +
  +        if ( !( left instanceof Integer )  || !( right instanceof Integer ))
  +        {
  +            Runtime.error( ( !( left instanceof Integer ) ? "Left" : "Right" ) 
  +                           + " side of multiplication operation is not a valid type. "
  +                           + "Currently only integers (1,2,3...) and Integer type is supported. "
  +                           + context.getCurrentTemplateName() + " [line " + getLine() 
  +                           + ", column " + getColumn() + "]");
  + 
  +            return null;
  +        }
   
  +        return new Integer( ( (Integer) left ).intValue() * (  (Integer) right ).intValue() );
  +    }
   }
  +
  +
  +
  
  
  
  1.2       +111 -3    jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTSubtractNode.java
  
  Index: ASTSubtractNode.java
  ===================================================================
  RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTSubtractNode.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ASTSubtractNode.java	2000/10/20 19:14:02	1.1
  +++ ASTSubtractNode.java	2000/12/27 14:31:54	1.2
  @@ -1,9 +1,76 @@
   /* Generated By:JJTree: Do not edit this line. ASTSubtractNode.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 apache@apache.org.
  + *
  + * 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/>.
  + */
  +
  +
  +/**
  + * Handles integer subtraction of nodes (in #set() )
  + *
  + * Please look at the Parser.jjt file which is
  + * what controls the generation of this class.
  + *
  + * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
  + * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
  + * @version $Id: ASTSubtractNode.java,v 1.2 2000/12/27 14:31:54 geirm Exp $ 
  +*/
  +
   package org.apache.velocity.runtime.parser.node;
   
   import org.apache.velocity.Context;
  -import org.apache.velocity.runtime.parser.*;
  +import org.apache.velocity.runtime.Runtime;
  +import org.apache.velocity.runtime.parser.Parser;
   
   public class ASTSubtractNode extends SimpleNode
   {
  @@ -23,9 +90,50 @@
           return visitor.visit(this, data);
       }
   
  +    /**
  +     *  computes the value of the subtraction.  Currently
  +     *  limited to integers
  +     *  @return Integer(value) or null
  +     */
       public Object value(Context context)
       {
  -        return new Integer(((Integer) jjtGetChild(0).value(context)).intValue() -
  -            ((Integer) jjtGetChild(1).value(context)).intValue());
  +        /*
  +         *  get the two args
  +         */
  +
  +        Object left = jjtGetChild(0).value( context );
  +        Object right = jjtGetChild(1).value( context );
  +
  +        /*
  +         *  if either is null, lets log and bail
  +         */
  +
  +        if (left == null || right == null)
  +        {
  +            Runtime.error( ( left == null ? "Left" : "Right" ) + " side of subtraction operation has null value."
  +                           + " Operation not possible. "
  +                           + context.getCurrentTemplateName() + " [line " + getLine() 
  +                           + ", column " + getColumn() + "]");
  +            return null;
  +        }
  +        
  +        /*
  +         *  if not an Integer, not much we can do either
  +         */
  +
  +        if ( !( left instanceof Integer )  || !( right instanceof Integer ))
  +        {
  +            Runtime.error( ( !( left instanceof Integer ) ? "Left" : "Right" ) 
  +                           + " side of subtraction operation is not a valid type. "
  +                           + "Currently only integers (1,2,3...) and Integer type is supported. "
  +                           + context.getCurrentTemplateName() + " [line " + getLine() 
  +                           + ", column " + getColumn() + "]");
  + 
  +            return null;
  +        }
  +
  +        return new Integer( ( (Integer) left ).intValue() - (  (Integer) right ).intValue() );
       }
   }
  +
  +