geirm 01/04/02 23:01:11
Modified: src/java/org/apache/velocity/runtime/parser/node
ASTGTNode.java
Log:
And this one too :)
Revision Changes Path
1.4 +44 -2
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTGTNode.java
Index: ASTGTNode.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTGTNode.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ASTGTNode.java 2001/03/19 17:17:48 1.3
+++ ASTGTNode.java 2001/04/03 06:01:10 1.4
@@ -58,6 +58,7 @@
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.runtime.parser.*;
import org.apache.velocity.exception.MethodInvocationException;
+import org.apache.velocity.runtime.Runtime;
public class ASTGTNode extends SimpleNode
{
@@ -80,10 +81,51 @@
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;
+ }
}
}