1 7 package org.jahia.security.license; 8 9 import java.util.ArrayList ; 10 import java.util.Iterator ; 11 import org.jahia.resourcebundle.ResourceMessage; 12 13 20 public class ListLimitValue extends LimitValue { 21 22 private static final String LIST_SEPERATOR = ";"; 23 24 private ArrayList limitValues = new ArrayList (); 25 private boolean lastCheckResult = false; 26 27 public ListLimitValue(String value) { 28 super(value); 29 int listSepPos = value.indexOf(LIST_SEPERATOR); 30 int curStrPos = 0; 31 while (listSepPos != -1) { 32 String curLimitStr = value.substring(curStrPos, listSepPos); 33 LimitValue subLimit = null; 34 if (RangeLimitValue.isRangeValue(curLimitStr)) { 35 subLimit = new RangeLimitValue(curLimitStr); 36 } else { 37 subLimit = new LimitValue(curLimitStr); 38 } 39 limitValues.add(subLimit); 40 curStrPos = listSepPos + LIST_SEPERATOR.length(); 41 listSepPos = value.indexOf(LIST_SEPERATOR, curStrPos); 42 } 43 String curLimitStr = value.substring(curStrPos); 45 LimitValue subLimit = null; 46 if (RangeLimitValue.isRangeValue(curLimitStr)) { 47 subLimit = new RangeLimitValue(curLimitStr); 48 } else { 49 subLimit = new LimitValue(curLimitStr); 50 } 51 limitValues.add(subLimit); 52 } 53 54 public static boolean isListValue(String value) { 55 return (value.indexOf(LIST_SEPERATOR) != -1); 56 } 57 58 61 public ArrayList getLimitValues() { 62 return limitValues; 63 } 64 65 public boolean check(Validator validator) { 66 Iterator valueIter = limitValues.iterator(); 67 while (valueIter.hasNext()) { 68 LimitValue curLimitValue = (LimitValue) valueIter.next(); 69 if (curLimitValue.check(validator)) { 70 lastCheckResult = true; 71 return true; 72 } 73 } 74 lastCheckResult = false; 75 return false; 76 } 77 78 public ResourceMessage getErrorMessage(Validator validator) { 79 if (lastCheckResult == true) { 80 return null; 81 } 82 Iterator valueIter = limitValues.iterator(); 83 while (valueIter.hasNext()) { 84 LimitValue curLimitValue = (LimitValue) valueIter.next(); 85 ResourceMessage curResourceMessage = curLimitValue.getErrorMessage(validator); 86 if (curResourceMessage != null) { 87 return curResourceMessage; 88 } 89 } 90 return null; 91 } 92 93 } 94 | Popular Tags |