geirm 01/04/02 20:33:09
Modified: src/java/org/apache/velocity/runtime/parser/node
ASTGENode.java
Log:
Small fix - will fix the rest of these issues in here later tomorrow.
Revision Changes Path
1.4 +42 -2
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTGENode.java
Index: ASTGENode.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTGENode.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ASTGENode.java 2001/03/19 17:17:47 1.3
+++ ASTGENode.java 2001/04/03 03:33:09 1.4
@@ -58,6 +58,7 @@
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.runtime.parser.Parser;
import org.apache.velocity.exception.MethodInvocationException;
+import org.apache.velocity.runtime.Runtime;
public class ASTGENode extends SimpleNode
{
@@ -80,10 +81,49 @@
public boolean evaluate( InternalContextAdapter context)
throws MethodInvocationException
{
- if (((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 '>='
operation has null value."
+ + " Operation not possible. "
+ + context.getCurrentTemplateName() + " [line " +
getLine()
+ + ", column " + getColumn() + "]");
+ return false;
+ }
+
+ /*
+ * 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 '>=' operation is not a valid type. "
+ + "Currently only integers (1,2,3...) and Integer type
is supported. "
+ + context.getCurrentTemplateName() + " [line " +
getLine()
+ + ", column " + getColumn() + "]");
+
+ return false;
+ }
+
+ if ( ((Integer) left).intValue() >=
+ ((Integer) right).intValue() )
+ {
return true;
+ }
else
+ {
return false;
+ }
}
}