1 7 package com.ibm.icu.text; 8 9 import java.text.ParseException ; 10 11 18 public class StringPrepParseException extends ParseException { 19 static final long serialVersionUID = 7160264827701651255L; 21 22 25 public static final int INVALID_CHAR_FOUND = 0; 26 29 public static final int ILLEGAL_CHAR_FOUND = 1; 30 33 public static final int PROHIBITED_ERROR = 2; 34 37 public static final int UNASSIGNED_ERROR = 3; 38 41 public static final int CHECK_BIDI_ERROR = 4; 42 45 public static final int STD3_ASCII_RULES_ERROR = 5; 46 49 public static final int ACE_PREFIX_ERROR = 6; 50 53 public static final int VERIFICATION_ERROR = 7; 54 57 public static final int LABEL_TOO_LONG_ERROR = 8; 58 61 public static final int BUFFER_OVERFLOW_ERROR = 9; 62 63 66 public static final int ZERO_LENGTH_LABEL = 10; 67 68 76 public StringPrepParseException(String message,int error){ 77 super(message, -1); 78 this.error = error; 79 this.line = 0; 80 } 81 82 92 public StringPrepParseException(String message,int error, String rules, int pos){ 93 super(message, -1); 94 this.error = error; 95 setContext(rules,pos); 96 this.line = 0; 97 } 98 112 public StringPrepParseException(String message, int error, String rules, int pos, int lineNumber){ 113 super(message, -1); 114 this.error = error; 115 setContext(rules,pos); 116 this.line = lineNumber; 117 } 118 127 public boolean equals(Object other){ 128 if(!(other instanceof StringPrepParseException)){ 129 return false; 130 } 131 return ((StringPrepParseException)other).error == this.error; 132 133 } 134 140 public String toString(){ 141 StringBuffer buf = new StringBuffer (); 142 buf.append(super.getMessage()); 143 buf.append(". preContext: "); 144 buf.append(preContext); 145 buf.append(". postContext: "); 146 buf.append(postContext); 147 buf.append("\n"); 148 return buf.toString(); 149 } 150 151 private int error; 152 153 161 private int line; 162 163 164 169 private StringBuffer preContext = new StringBuffer (); 170 171 176 private StringBuffer postContext = new StringBuffer (); 177 178 private static final int PARSE_CONTEXT_LEN = 16; 179 180 private void setPreContext(String str, int pos){ 181 setPreContext(str.toCharArray(),pos); 182 } 183 184 private void setPreContext(char[] str, int pos){ 185 int start = (pos <= PARSE_CONTEXT_LEN)? 0 : (pos - (PARSE_CONTEXT_LEN-1)); 186 int len = (start <= PARSE_CONTEXT_LEN)? start : PARSE_CONTEXT_LEN; 187 preContext.append(str,start,len); 188 189 } 190 191 private void setPostContext(String str, int pos){ 192 setPostContext(str.toCharArray(),pos); 193 } 194 195 private void setPostContext(char[] str, int pos){ 196 int start = pos; 197 int len = str.length - start; 198 postContext.append(str,start,len); 199 200 } 201 202 private void setContext(String str,int pos){ 203 setPreContext(str,pos); 204 setPostContext(str,pos); 205 } 206 } 207 | Popular Tags |