1 20 package org.enhydra.barracuda.contrib.sam.data; 21 22 import java.util.*; 23 import gnu.regexp.*; 25 26 import org.enhydra.barracuda.core.forms.*; 27 import org.enhydra.barracuda.plankton.*; 28 29 32 public class RegexValidator extends DefaultFormValidator { 33 34 protected RE re; 37 38 43 public RegexValidator(RE re ) { 46 super(); 47 this.re = re; 48 } 49 50 56 public RegexValidator(RE re, String ierrmsg) { 59 super(ierrmsg); 60 this.re = re; 61 } 62 63 73 public void validateFormElement(Object val, FormElement element, boolean deferExceptions) throws ValidationException { 74 if (this.isNull(val, element)) 75 return; 76 77 if (element==null) throw new ValidationException(val, "Object val:"+val+" is associated with a null FormElement"); 78 if (!element.getType().equals(FormType.STRING)) throw new ValidationException(val, "Unsupported validation: "+val+" is not of FormType.String and cannot be validated by this validator"); 79 80 String s = val.toString(); 81 if (!re.isMatch(s)) { 84 throw this.generateException(element, deferExceptions, "{" + val + "}" + " does not match Pattern " + re.toString()); 87 } 88 } 89 90 } 91 | Popular Tags |