1 17 18 19 20 package org.apache.lenya.lucene.html; 21 22 public class TokenMgrError extends Error { 23 26 27 28 static final int LEXICAL_ERROR = 0; 29 30 31 static final int STATIC_LEXER_ERROR = 1; 32 33 34 static final int INVALID_LEXICAL_STATE = 2; 35 36 37 static final int LOOP_DETECTED = 3; 38 39 40 int errorCode; 41 42 45 public TokenMgrError() { 46 } 47 48 54 public TokenMgrError(String message, int reason) { 55 super(message); 56 errorCode = reason; 57 } 58 59 70 public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, 71 String errorAfter, char curChar, int reason) { 72 this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); 73 } 74 75 83 protected static final String addEscapes(String str) { 84 StringBuffer retval = new StringBuffer (); 85 char ch; 86 87 for (int i = 0; i < str.length(); i++) { 88 switch (str.charAt(i)) { 89 case 0: 90 91 continue; 92 93 case '\b': 94 retval.append("\\b"); 95 96 continue; 97 98 case '\t': 99 retval.append("\\t"); 100 101 continue; 102 103 case '\n': 104 retval.append("\\n"); 105 106 continue; 107 108 case '\f': 109 retval.append("\\f"); 110 111 continue; 112 113 case '\r': 114 retval.append("\\r"); 115 116 continue; 117 118 case '\"': 119 retval.append("\\\""); 120 121 continue; 122 123 case '\'': 124 retval.append("\\\'"); 125 126 continue; 127 128 case '\\': 129 retval.append("\\\\"); 130 131 continue; 132 133 default: 134 135 if (((ch = str.charAt(i)) < 0x20) || (ch > 0x7e)) { 136 String s = "0000" + Integer.toString(ch, 16); 137 retval.append("\\u" + s.substring(s.length() - 4, s.length())); 138 } else { 139 retval.append(ch); 140 } 141 142 continue; 143 } 144 } 145 146 return retval.toString(); 147 } 148 149 166 private static final String LexicalError(boolean EOFSeen, int lexState, int errorLine, 167 int errorColumn, String errorAfter, char curChar) { 168 return ("Lexical error at line " + errorLine + ", column " + errorColumn + 169 ". Encountered: " + 170 (EOFSeen ? "<EOF> " 171 : (("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int) curChar + 172 "), ")) + "after : \"" + addEscapes(errorAfter) + "\""); 173 } 174 175 183 public String getMessage() { 184 return super.getMessage(); 185 } 186 } 187 | Popular Tags |