1 16 package org.apache.cocoon.forms.validation; 17 18 import org.xml.sax.ContentHandler ; 19 import org.xml.sax.SAXException ; 20 import org.apache.cocoon.forms.util.I18nMessage; 21 import org.apache.cocoon.forms.util.StringMessage; 22 import org.apache.commons.lang.ObjectUtils; 23 import org.apache.excalibur.xml.sax.XMLizable; 24 25 32 public class ValidationError { 33 34 35 private final XMLizable saxFragment; 36 37 40 public ValidationError(String errorMessage, boolean i18n) { 41 if (i18n) { 42 this.saxFragment = new I18nMessage(errorMessage); 43 } else { 44 this.saxFragment = new StringMessage(errorMessage); 45 } 46 } 47 48 51 public ValidationError(String errorMessageKey) { 52 this(new I18nMessage(errorMessageKey)); 53 } 54 55 58 public ValidationError(String errorMessageKey, String [] parameters) { 59 this(new I18nMessage(errorMessageKey, parameters)); 60 } 61 62 65 public ValidationError(String errorMessageKey, String [] parameters, boolean[] keys) { 66 this(new I18nMessage(errorMessageKey, parameters, keys)); 67 } 68 69 75 public ValidationError(XMLizable errorMessage) { 76 this.saxFragment = errorMessage; 77 } 78 79 83 public void generateSaxFragment(ContentHandler contentHandler) throws SAXException { 84 if (this.saxFragment != null) { 85 this.saxFragment.toSAX(contentHandler); 86 } 87 } 88 89 public boolean equals(Object obj) { 90 if (obj instanceof ValidationError) { 91 return ObjectUtils.equals(this.saxFragment, ((ValidationError)obj).saxFragment); 92 } 93 return false; 94 } 95 } 96 | Popular Tags |