1 package net.sourceforge.formview.util; 2 3 import java.util.Map ; 4 5 public class FormulaUtil { 6 7 public static boolean executeCondition(String formula, Map attributeMap) { 8 boolean equalCondition = true; 11 int indexBeforeOp = formula.indexOf("=="); 12 if (indexBeforeOp == - 1) { 13 indexBeforeOp = formula.indexOf("!="); 14 equalCondition = false; 15 } 16 17 if (indexBeforeOp != -1) { 18 String leftOp = formula.substring(0, indexBeforeOp); 19 20 21 String rightOp = formula.substring(indexBeforeOp + 2, formula.length()); 22 23 if (leftOp != null && leftOp.length() > 0 && 24 rightOp != null && rightOp.length() > 0 ) { 25 26 leftOp = leftOp.replace('{', ' '); 27 leftOp = leftOp.replace('$', ' '); 28 leftOp = leftOp.trim(); 29 30 String valueOfLeftMap = (String )attributeMap.get(leftOp); 31 if (valueOfLeftMap != null) 32 valueOfLeftMap = valueOfLeftMap.toUpperCase(); 33 else 34 valueOfLeftMap = "NULL"; 35 36 rightOp = rightOp.replace('}', ' '); 37 rightOp = rightOp.replace('$', ' '); 38 39 rightOp = rightOp.trim().toUpperCase(); 40 41 if (equalCondition) { 42 return rightOp.equals(valueOfLeftMap); 43 } 44 else { 45 return !rightOp.equals(valueOfLeftMap); 46 } 47 } 48 } 49 return false; 50 } 51 52 53 } 54 | Popular Tags |