|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| package org.qedeq.kernel.common; |
|
19 |
| |
|
20 |
| import java.net.URL; |
|
21 |
| |
|
22 |
| import org.xml.sax.SAXParseException; |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| public final class SyntaxException extends QedeqException { |
|
34 |
| |
|
35 |
| |
|
36 |
| public static final int SAX_PARSER_EXCEPTION = 9001; |
|
37 |
| |
|
38 |
| |
|
39 |
| public static final int UNEXPECTED_TAG_CODE = 9002; |
|
40 |
| |
|
41 |
| |
|
42 |
| public static final String UNEXPECTED_TAG_TEXT = "Unexpected tag: "; |
|
43 |
| |
|
44 |
| |
|
45 |
| public static final int UNEXPECTED_DATA_CODE = 9003; |
|
46 |
| |
|
47 |
| |
|
48 |
| public static final String UNEXPECTED_DATA_TEXT = "Unexpected character data in tag: "; |
|
49 |
| |
|
50 |
| |
|
51 |
| public static final int MISSING_ATTRIBUTE_CODE = 9004; |
|
52 |
| |
|
53 |
| |
|
54 |
| public static final String MISSING_ATTRIBUTE_TEXT_1 = "Missing attribute: "; |
|
55 |
| |
|
56 |
| |
|
57 |
| public static final String MISSING_ATTRIBUTE_TEXT_2 = " in tag: "; |
|
58 |
| |
|
59 |
| |
|
60 |
| public static final int EMPTY_ATTRIBUTE_CODE = 9004; |
|
61 |
| |
|
62 |
| |
|
63 |
| public static final String EMPTY_ATTRIBUTE_TEXT_1 = "Missing attribute: "; |
|
64 |
| |
|
65 |
| |
|
66 |
| public static final String EMPTY_ATTRIBUTE_TEXT_2 = " in tag: "; |
|
67 |
| |
|
68 |
| |
|
69 |
| public static final int PROGRAMMING_ERROR_CODE = 9999; |
|
70 |
| |
|
71 |
| |
|
72 |
| public static final String PROGRAMMING_ERROR_TEXT = "A programming error occurred."; |
|
73 |
| |
|
74 |
| |
|
75 |
| private SourcePosition position; |
|
76 |
| |
|
77 |
| |
|
78 |
| |
|
79 |
| |
|
80 |
| |
|
81 |
| |
|
82 |
| |
|
83 |
| |
|
84 |
| |
|
85 |
0
| private SyntaxException(final int code, final String message) {
|
|
86 |
0
| super(code, message);
|
|
87 |
| } |
|
88 |
| |
|
89 |
| |
|
90 |
| |
|
91 |
| |
|
92 |
| |
|
93 |
| |
|
94 |
| |
|
95 |
| |
|
96 |
0
| private SyntaxException(final int code, final String message, final RuntimeException e) {
|
|
97 |
0
| super(code, message, e);
|
|
98 |
| } |
|
99 |
| |
|
100 |
| |
|
101 |
| |
|
102 |
| |
|
103 |
| |
|
104 |
| |
|
105 |
| |
|
106 |
11
| private SyntaxException(final SAXParseException e, final URL url) {
|
|
107 |
11
| super(SAX_PARSER_EXCEPTION, e.getMessage(), e);
|
|
108 |
11
| position = new SourcePosition(url, e.getLineNumber(),
|
|
109 |
| e.getColumnNumber()); |
|
110 |
| } |
|
111 |
| |
|
112 |
| |
|
113 |
| |
|
114 |
| |
|
115 |
| |
|
116 |
| |
|
117 |
37
| public final SourcePosition getErrorPosition() {
|
|
118 |
37
| return position;
|
|
119 |
| } |
|
120 |
| |
|
121 |
| |
|
122 |
| |
|
123 |
| |
|
124 |
| |
|
125 |
| |
|
126 |
| |
|
127 |
0
| public final void setErrorPosition(final SourcePosition position) {
|
|
128 |
0
| this.position = position;
|
|
129 |
| } |
|
130 |
| |
|
131 |
| |
|
132 |
| |
|
133 |
| |
|
134 |
| |
|
135 |
| |
|
136 |
| |
|
137 |
0
| public static final SyntaxException createUnexpectedTagException(final String name) {
|
|
138 |
0
| return new SyntaxException(UNEXPECTED_TAG_CODE, UNEXPECTED_TAG_TEXT + name);
|
|
139 |
| } |
|
140 |
| |
|
141 |
| |
|
142 |
| |
|
143 |
| |
|
144 |
| |
|
145 |
| |
|
146 |
| |
|
147 |
| |
|
148 |
0
| public static final SyntaxException createUnexpectedTextDataException(final String name,
|
|
149 |
| final String value) { |
|
150 |
0
| return new SyntaxException(UNEXPECTED_DATA_CODE, UNEXPECTED_DATA_TEXT + name);
|
|
151 |
| } |
|
152 |
| |
|
153 |
| |
|
154 |
| |
|
155 |
| |
|
156 |
| |
|
157 |
| |
|
158 |
| |
|
159 |
| |
|
160 |
0
| public static final SyntaxException createMissingAttributeException(final String name,
|
|
161 |
| final String attribute) { |
|
162 |
0
| return new SyntaxException(MISSING_ATTRIBUTE_CODE, MISSING_ATTRIBUTE_TEXT_1 + attribute
|
|
163 |
| + MISSING_ATTRIBUTE_TEXT_2 + name); |
|
164 |
| } |
|
165 |
| |
|
166 |
| |
|
167 |
| |
|
168 |
| |
|
169 |
| |
|
170 |
| |
|
171 |
| |
|
172 |
| |
|
173 |
0
| public static final SyntaxException createEmptyAttributeException(final String name,
|
|
174 |
| final String attribute) { |
|
175 |
0
| return new SyntaxException(EMPTY_ATTRIBUTE_CODE, EMPTY_ATTRIBUTE_TEXT_1 + attribute
|
|
176 |
| + EMPTY_ATTRIBUTE_TEXT_2 + name); |
|
177 |
| } |
|
178 |
| |
|
179 |
| |
|
180 |
| |
|
181 |
| |
|
182 |
| |
|
183 |
| |
|
184 |
| |
|
185 |
| |
|
186 |
11
| public static final SyntaxException createBySAXParseException(final SAXParseException e,
|
|
187 |
| final URL url) { |
|
188 |
11
| return new SyntaxException(e, url);
|
|
189 |
| } |
|
190 |
| |
|
191 |
| |
|
192 |
| |
|
193 |
| |
|
194 |
| |
|
195 |
| |
|
196 |
| |
|
197 |
0
| public static final SyntaxException createByRuntimeException(final RuntimeException e) {
|
|
198 |
0
| return new SyntaxException(PROGRAMMING_ERROR_CODE, PROGRAMMING_ERROR_TEXT, e);
|
|
199 |
| } |
|
200 |
| |
|
201 |
| } |