1 20 package org.enhydra.barracuda.core.forms.validators; 21 22 import java.util.*; 23 24 import org.enhydra.barracuda.core.forms.*; 25 import org.enhydra.barracuda.plankton.*; 26 27 30 public class MinLengthValidator extends DefaultFormValidator { 31 32 protected int min = 0; 33 34 37 public MinLengthValidator() { 38 this(0, null); 39 } 40 41 46 public MinLengthValidator(int imin) { 47 this(imin, null); 48 } 49 50 56 public MinLengthValidator(int imin, String ierrmsg) { 57 super(ierrmsg); 58 min = imin; 59 } 60 61 67 public int getMinLength() { 68 return min; 69 } 70 71 84 public void validateFormElement(Object val, FormElement element, boolean deferExceptions) throws ValidationException { 85 86 if (this.isNull(val, element)) 89 return; 90 92 if (element==null) throw new ValidationException(val, "Object val:"+val+" is associated with a null FormElement"); 96 if (element.getType().equals(FormType.BOOLEAN)) throw new ValidationException(val, "Unsupported validation: "+val+" is of FormType.BOOLEAN and cannot be validated by this validator"); 97 if (element.getType().equals(FormType.DATE)) throw new ValidationException(val, "Unsupported validation: "+val+" is of FormType.DATE and cannot be validated by this validator"); 98 99 String s = (null!=val) ? val.toString(): "" ; 101 102 if (localLogger.isInfoEnabled()) localLogger.info("validating to see if length of val {"+s+"} >= "+min); 103 if (s.length()<min) { 104 throw this.generateException(element, deferExceptions, "Length of val {"+val+"} fails to meet minimum length of "+min); 105 } 106 } 107 108 } 109 | Popular Tags |