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 import org.apache.log4j.*; 27 28 38 public class DateValidator extends DefaultFormValidator { 39 40 44 public DateValidator() { 45 super(); 46 } 47 48 53 public DateValidator(String ierrmsg) { 54 super(ierrmsg); 55 } 56 57 75 public void validateFormElement(Object val, FormElement element, boolean deferExceptions) throws ValidationException { 76 if (this.isNull(val, element)) 79 return; 80 82 100 102 if (element==null) throw new ValidationException(val, "Object val:"+val+" is associated with a null FormElement"); 106 107 FormType formType = element.getType(); 108 if (!(formType.equals(FormType.DATE) || formType.equals(FormType.STRING))) { 109 throw new ValidationException(val, "Unsupported validation: "+ 110 val+" is of FormType " + 111 formType.toString() + 112 " and cannot be validated by this validator"); 113 } 114 115 116 if (val instanceof Date){ 120 return; 121 } 122 else if (formType.equals(FormType.DATE) && element.getParseException()!=null) { 123 throw this.generateException(element, deferExceptions, val.toString() 124 + " is not a valid date, because " 125 + element.getParseException()); 126 } 127 else if (formType.equals(FormType.STRING)) { 128 try { 129 Date dateVal = (Date)FormType.DATE.parse(val.toString()); 130 if (localLogger.isInfoEnabled()) 131 localLogger.info("Date val = " + dateVal.toString()); 132 } catch (ParseException ex) { 133 throw this.generateException(element, deferExceptions, val.toString() 134 + " is not a valid date, because " 135 + ex); 136 } 137 } 138 140 157 } 159 } 160 | Popular Tags |