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