1 16 package dlog4j.util.tags; 17 18 import javax.servlet.jsp.JspException ; 19 import javax.servlet.jsp.tagext.TagSupport ; 20 21 25 public class CompareTag extends TagSupport { 26 27 public final static int EQUAL = 0; public final static int NOT_EQUAL = 1; public final static int GREATER_THAN = 2; public final static int NOT_GREATER_THAN = 3; public final static int LESS_THAN = 4; public final static int NOT_LESS_THAN = 5; public final static int QUOTIENT = 100; public final static int COMPLIMENT_ZERO = 101; public final static int COMPLIMENT_NOT_ZERO = 102; 37 String num1; 38 String num2; 39 int method = 0; 40 41 public int doEndTag() throws JspException { 42 return EVAL_PAGE; 44 } 45 51 54 public int doStartTag() throws JspException { 55 Object obj1 = pageContext.findAttribute(num1); 56 Object obj2 = pageContext.findAttribute(num2); 57 String s1 = (obj1!=null)?obj1.toString():num1; 58 String s2 = (obj2!=null)?obj2.toString():num2; 59 return compare(s1,s2,method)?EVAL_BODY_INCLUDE:SKIP_BODY; 60 } 61 68 public boolean compare(String s1, String s2, int extend){ 69 if(s1==null||s2==null) 70 return false; 71 int i1 = Integer.parseInt(s1); 72 int i2 = Integer.parseInt(s2); 73 if(extend==EQUAL && i1==i2) 74 return true; 75 if(extend==NOT_EQUAL && i1!=i2) 76 return true; 77 if(extend==GREATER_THAN && i1>i2) 78 return true; 79 if(extend==LESS_THAN && i1<i2) 80 return true; 81 if(extend==NOT_LESS_THAN && i1>=i2) 82 return true; 83 if(extend==NOT_GREATER_THAN && i1<=i2) 84 return true; 85 if(extend==COMPLIMENT_ZERO) 86 return (i1 % i2) == 0; 87 if(extend==COMPLIMENT_NOT_ZERO) 88 return (i1 % i2) > 0; 89 90 return false; 91 } 92 93 96 public String getNum1() { 97 return num1; 98 } 99 100 103 public String getNum2() { 104 return num2; 105 } 106 107 110 public void setNum1(String string) { 111 num1 = string; 112 } 113 116 public void setNum2(String string) { 117 num2 = string; 118 } 119 120 123 public int getMethod() { 124 return method; 125 } 126 127 130 public void setMethod(int i) { 131 method = i; 132 } 133 134 } 135 | Popular Tags |