|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| package org.qedeq.kernel.xml.parser; |
|
19 |
| |
|
20 |
| import java.util.ArrayList; |
|
21 |
| import java.util.List; |
|
22 |
| |
|
23 |
| import org.xml.sax.SAXException; |
|
24 |
| import org.xml.sax.SAXParseException; |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| public final class ExceptionList { |
|
34 |
| |
|
35 |
| |
|
36 |
| private List exceptions; |
|
37 |
| |
|
38 |
| |
|
39 |
| public static final int MAXIMUM = 10; |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
212
| public ExceptionList() {
|
|
45 |
212
| exceptions = new ArrayList(MAXIMUM);
|
|
46 |
| } |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
0
| public final void add(final Exception e) throws SAXException {
|
|
56 |
0
| if (e == null) {
|
|
57 |
0
| final NullPointerException ex = new NullPointerException("Exception expected!");
|
|
58 |
0
| exceptions.add(ex);
|
|
59 |
0
| throw ex;
|
|
60 |
| } |
|
61 |
0
| if (size() < MAXIMUM) {
|
|
62 |
0
| exceptions.add(e);
|
|
63 |
| } else { |
|
64 |
0
| throw new SAXException("Too much errors already occurred.");
|
|
65 |
| } |
|
66 |
| } |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
| |
|
71 |
| |
|
72 |
| |
|
73 |
212
| public final int size() {
|
|
74 |
212
| return exceptions.size();
|
|
75 |
| } |
|
76 |
| |
|
77 |
| |
|
78 |
| |
|
79 |
| |
|
80 |
| |
|
81 |
| |
|
82 |
| |
|
83 |
0
| public final Exception get(final int i) {
|
|
84 |
0
| return (Exception) exceptions.get(i);
|
|
85 |
| } |
|
86 |
| |
|
87 |
| |
|
88 |
| |
|
89 |
| |
|
90 |
| |
|
91 |
| |
|
92 |
0
| public final Exception[] toArray() {
|
|
93 |
0
| return (Exception[]) exceptions.toArray(new Exception[0]);
|
|
94 |
| } |
|
95 |
| |
|
96 |
0
| public String toString() {
|
|
97 |
0
| final StringBuffer buffer = new StringBuffer();
|
|
98 |
0
| for (int i = 0; i < size(); i++) {
|
|
99 |
0
| if (i != 0) {
|
|
100 |
0
| buffer.append("\n");
|
|
101 |
| } |
|
102 |
0
| final Exception e = get(i);
|
|
103 |
0
| if (e instanceof SAXParseException) {
|
|
104 |
0
| final SAXParseException ex = (SAXParseException) e;
|
|
105 |
0
| buffer.append(ex.getSystemId() != null ? ex.getPublicId() + " " : "");
|
|
106 |
0
| buffer.append(ex.getSystemId() != null ? ex.getSystemId() + " " : "");
|
|
107 |
0
| buffer.append(ex.getLineNumber() != -1 ? "Row: " + ex.getLineNumber() + ". " : "");
|
|
108 |
0
| buffer.append(ex.getColumnNumber() != -1
|
|
109 |
| ? "Column: " + ex.getColumnNumber() + ". " |
|
110 |
| : ""); |
|
111 |
0
| buffer.append((ex.getException() != null
|
|
112 |
| ? ex.getException().getMessage() |
|
113 |
| : ex.getMessage())); |
|
114 |
| } else { |
|
115 |
0
| buffer.append(get(i));
|
|
116 |
| } |
|
117 |
| } |
|
118 |
0
| return buffer.toString();
|
|
119 |
| } |
|
120 |
| |
|
121 |
| } |