1 package org.apache.velocity.runtime.parser.node; 2 3 18 19 import org.apache.velocity.context.InternalContextAdapter; 20 import org.apache.velocity.runtime.parser.Parser; 21 import org.apache.velocity.exception.MethodInvocationException; 22 23 24 public class ASTGTNode extends SimpleNode 25 { 26 public ASTGTNode(int id) 27 { 28 super(id); 29 } 30 31 public ASTGTNode(Parser p, int id) 32 { 33 super(p, id); 34 } 35 36 37 public Object jjtAccept(ParserVisitor visitor, Object data) 38 { 39 return visitor.visit(this, data); 40 } 41 42 public boolean evaluate(InternalContextAdapter context) 43 throws MethodInvocationException 44 { 45 48 49 Object left = jjtGetChild(0).value( context ); 50 Object right = jjtGetChild(1).value( context ); 51 52 55 56 if (left == null || right == null) 57 { 58 rsvc.error( ( left == null ? "Left" : "Right" ) 59 + " side (" 60 + jjtGetChild( (left == null? 0 : 1) ).literal() 61 + ") of '>' operation has null value." 62 + " Operation not possible. " 63 + context.getCurrentTemplateName() + " [line " 64 + getLine() 65 + ", column " + getColumn() + "]"); 66 return false; 67 } 68 69 72 73 if ( !( left instanceof Integer ) || !( right instanceof Integer )) 74 { 75 rsvc.error( ( !( left instanceof Integer ) ? "Left" : "Right" ) 76 + " side of '>' operation is not a valid type. " 77 + " It is a " + ( !( left instanceof Integer ) ? left.getClass() : right.getClass() ) 78 + ". Currently only integers (1,2,3...) and Integer type is supported. " 79 + context.getCurrentTemplateName() + " [line " + getLine() 80 + ", column " + getColumn() + "]"); 81 82 return false; 83 } 84 85 return ((Integer ) left).intValue() > ((Integer ) right).intValue(); 86 } 87 88 public Object value(InternalContextAdapter context) 89 throws MethodInvocationException 90 { 91 boolean val = evaluate(context); 92 93 return val ? Boolean.TRUE : Boolean.FALSE; 94 } 95 96 } 97 | Popular Tags |