1 /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */
3 * Copyright 2004 the mime4j project
\r
5 * Licensed under the Apache License, Version 2.0 (the "License");
\r
6 * you may not use this file except in compliance with the License.
\r
7 * You may obtain a copy of the License at
\r
9 * http://www.apache.org/licenses/LICENSE-2.0
\r
11 * Unless required by applicable law or agreed to in writing, software
\r
12 * distributed under the License is distributed on an "AS IS" BASIS,
\r
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
14 * See the License for the specific language governing permissions and
\r
15 * limitations under the License.
\r
17 package org.apache.james.mime4j.field.datetime.parser;
19 public class TokenMgrError extends Error
22 * Ordinals for various reasons why an Error of this type can be thrown.
26 * Lexical error occured.
28 static final int LEXICAL_ERROR = 0;
31 * An attempt wass made to create a second instance of a static token manager.
33 static final int STATIC_LEXER_ERROR = 1;
36 * Tried to change to an invalid lexical state.
38 static final int INVALID_LEXICAL_STATE = 2;
41 * Detected (and bailed out of) an infinite loop in the token manager.
43 static final int LOOP_DETECTED = 3;
46 * Indicates the reason why the exception is thrown. It will have
47 * one of the above 4 values.
52 * Replaces unprintable characters by their espaced (or unicode escaped)
53 * equivalents in the given string
55 protected static final String addEscapes(String str) {
56 StringBuffer retval = new StringBuffer();
58 for (int i = 0; i < str.length(); i++) {
59 switch (str.charAt(i))
79 retval.append("\\\"");
82 retval.append("\\\'");
85 retval.append("\\\\");
88 if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
89 String s = "0000" + Integer.toString(ch, 16);
90 retval.append("\\u" + s.substring(s.length() - 4, s.length()));
97 return retval.toString();
101 * Returns a detailed message for the Error when it is thrown by the
102 * token manager to indicate a lexical error.
104 * EOFSeen : indicates if EOF caused the lexicl error
105 * curLexState : lexical state in which this error occured
106 * errorLine : line number when the error occured
107 * errorColumn : column number when the error occured
108 * errorAfter : prefix that was seen before this error occured
109 * curchar : the offending character
110 * Note: You can customize the lexical error message by modifying this method.
112 protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
113 return("Lexical error at line " +
114 errorLine + ", column " +
115 errorColumn + ". Encountered: " +
116 (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
117 "after : \"" + addEscapes(errorAfter) + "\"");
121 * You can also modify the body of this method to customize your error messages.
122 * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
123 * of end-users concern, so you can return something like :
125 * "Internal Error : Please file a bug report .... "
127 * from this method for such cases in the release version of your parser.
129 public String getMessage() {
130 return super.getMessage();
134 * Constructors of various flavors follow.
137 public TokenMgrError() {
140 public TokenMgrError(String message, int reason) {
145 public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
146 this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);