001 package nu.validator.relaxng.exceptions; 002 003 import java.util.Iterator; 004 import java.util.Map; 005 006 import org.xml.sax.Locator; 007 008 import com.thaiopensource.relaxng.impl.NameFormatter; 009 import com.thaiopensource.xml.util.Name; 010 011 public class BadAttributeValueException extends AbstractValidationException { 012 013 private static String formatMessage(Name currentElement, Name attributeName, String attributeValue, Map exceptions) { 014 if (exceptions.isEmpty()) { 015 Object[] values = new Object[3]; 016 values[0] = NameFormatter.format(attributeName); 017 values[1] = NameFormatter.format(currentElement); 018 values[2] = attributeValue; 019 return localizer.message("bad_attribute_value", values); 020 } else { 021 StringBuffer sb = new StringBuffer(); 022 for (Iterator iter = exceptions.keySet().iterator(); iter.hasNext();) { 023 String msg = (String) iter.next(); 024 sb.append(' '); 025 sb.append(msg); 026 } 027 Object[] values = new Object[4]; 028 values[0] = NameFormatter.format(attributeName); 029 values[1] = NameFormatter.format(currentElement); 030 values[2] = attributeValue; 031 values[3] = sb; 032 return localizer.message("bad_attribute_value_explain", values); 033 } 034 } 035 036 private final Name attributeName; 037 038 private final String attributeValue; 039 040 private final Map exceptions; 041 042 public BadAttributeValueException(Locator locator, 043 Name currentElement, Name parent, Name attributeName, String attributeValue, Map exceptions) { 044 super(formatMessage(currentElement, attributeName, attributeValue, exceptions), locator, currentElement, parent); 045 this.attributeName = attributeName; 046 this.attributeValue = attributeValue; 047 this.exceptions = exceptions; 048 } 049 050 /** 051 * Returns the attributeName. 052 * 053 * @return the attributeName 054 */ 055 public Name getAttributeName() { 056 return attributeName; 057 } 058 059 /** 060 * Returns the attributeValue. 061 * 062 * @return the attributeValue 063 */ 064 public String getAttributeValue() { 065 return attributeValue; 066 } 067 068 /** 069 * Returns the exceptions. 070 * 071 * @return the exceptions 072 */ 073 public Map getExceptions() { 074 return exceptions; 075 } 076 077 }