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 StringNotAllowedException extends AbstractValidationException {
012
013 private static String formatMessage(Name currentElement, String value, Map exceptions) {
014 if (exceptions.isEmpty()) {
015 Object[] values = new Object[3];
016 values[0] = NameFormatter.format(currentElement);
017 values[1] = value;
018 return localizer.message("string_not_allowed", values);
019 } else {
020 StringBuffer sb = new StringBuffer();
021 for (Iterator iter = exceptions.keySet().iterator(); iter.hasNext();) {
022 String msg = (String) iter.next();
023 sb.append(' ');
024 sb.append(msg);
025 }
026 Object[] values = new Object[4];
027 values[0] = NameFormatter.format(currentElement);
028 values[1] = value;
029 values[2] = sb;
030 return localizer.message("string_not_allowed_explain", values);
031 }
032 }
033
034 private final String value;
035
036 private final Map exceptions;
037
038 public StringNotAllowedException(Locator locator,
039 Name currentElement, Name parent, String value, Map exceptions) {
040 super(formatMessage(currentElement, value, exceptions), locator, currentElement, parent);
041 this.value = value;
042 this.exceptions = exceptions;
043 }
044
045 /**
046 * Returns the value.
047 *
048 * @return the value
049 */
050 public String getValue() {
051 return value;
052 }
053
054 /**
055 * Returns the exceptions.
056 *
057 * @return the exceptions
058 */
059 public Map getExceptions() {
060 return exceptions;
061 }
062
063 }