|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| package org.jconfig.utils; |
|
8 |
| |
|
9 |
| import java.io.PrintWriter; |
|
10 |
| |
|
11 |
| import org.xml.sax.ErrorHandler; |
|
12 |
| import org.xml.sax.SAXException; |
|
13 |
| import org.xml.sax.SAXParseException; |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| public class ConfigErrorHandler implements ErrorHandler { |
|
21 |
| |
|
22 |
| private PrintWriter out; |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
0
| public ConfigErrorHandler(PrintWriter out) {
|
|
29 |
0
| this.out = out;
|
|
30 |
| } |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
0
| private String getParseExceptionInfo(SAXParseException spe) {
|
|
39 |
0
| String systemId = spe.getSystemId();
|
|
40 |
0
| if (systemId == null) {
|
|
41 |
0
| systemId = "null";
|
|
42 |
| } |
|
43 |
0
| String info = "URI=" + systemId +
|
|
44 |
| " Line=" + spe.getLineNumber() + |
|
45 |
| ": " + spe.getMessage(); |
|
46 |
0
| return info;
|
|
47 |
| } |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
0
| public void warning(SAXParseException spe) throws SAXException {
|
|
56 |
0
| out.println("Warning: " + getParseExceptionInfo(spe));
|
|
57 |
| } |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
0
| public void error(SAXParseException spe) throws SAXException {
|
|
66 |
0
| String message = "Error: " + getParseExceptionInfo(spe);
|
|
67 |
0
| throw new SAXException(message);
|
|
68 |
| } |
|
69 |
| |
|
70 |
| |
|
71 |
| |
|
72 |
| |
|
73 |
| |
|
74 |
| |
|
75 |
| |
|
76 |
0
| public void fatalError(SAXParseException spe) throws SAXException {
|
|
77 |
0
| String message = "Fatal Error: " + getParseExceptionInfo(spe);
|
|
78 |
0
| throw new SAXException(message);
|
|
79 |
| } |
|
80 |
| } |
|
81 |
| |
|
82 |
| |