1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.any23.validator;
19
20 import org.apache.any23.extractor.html.DomUtils;
21 import org.w3c.dom.Node;
22
23 import java.io.Serializable;
24 import java.util.List;
25 import java.util.Locale;
26
27
28
29
30
31
32
33
34
35
36
37 public interface ValidationReport extends Serializable {
38
39
40
41
42 enum IssueLevel {
43 ERROR, WARNING, INFO
44 }
45
46
47
48
49
50
51 List<Issue> getIssues();
52
53
54
55
56
57
58 List<RuleActivation> getRuleActivations();
59
60
61
62
63
64
65 List<Error> getErrors();
66
67
68
69
70 class Issue implements Serializable {
71
72
73
74
75 private static final long serialVersionUID = 1L;
76 private final IssueLevel level;
77 private final String message;
78 private final transient Node origin;
79
80 public Issue(IssueLevel level, String message, Node origin) {
81 if (level == null) {
82 throw new NullPointerException("level cannot be null.");
83 }
84 if (message == null) {
85 throw new NullPointerException("message cannot be null.");
86 }
87 if (origin == null) {
88 throw new NullPointerException("origin cannot be null.");
89 }
90 this.level = level;
91 this.message = message;
92 this.origin = origin;
93 }
94
95 public String getMessage() {
96 return message;
97 }
98
99 public IssueLevel getLevel() {
100 return level;
101 }
102
103 public Node getOrigin() {
104 return origin;
105 }
106
107 @Override
108 public String toString() {
109 return String.format(Locale.ROOT, "Issue %s '%s' %s", level, message, DomUtils.getXPathForNode(origin));
110 }
111 }
112
113
114
115
116 class RuleActivation implements Serializable {
117
118
119
120
121 private static final long serialVersionUID = 1L;
122 private final String ruleStr;
123
124 public RuleActivation(Rule r) {
125 if (r == null) {
126 throw new NullPointerException("rule cannot be null.");
127 }
128 ruleStr = r.getHRName();
129 }
130
131 public String getRuleStr() {
132 return ruleStr;
133 }
134
135 @Override
136 public String toString() {
137 return ruleStr;
138 }
139 }
140
141
142
143
144 abstract class Error implements Serializable {
145
146
147
148
149 private static final long serialVersionUID = 1L;
150 private final Exception cause;
151 private final String message;
152
153 public Error(Exception e, String msg) {
154 if (e == null) {
155 throw new NullPointerException("exception cannot be null.");
156 }
157 if (msg == null) {
158 throw new NullPointerException("message cannot be null.");
159 }
160 cause = e;
161 message = msg;
162 }
163
164 public Exception getCause() {
165 return cause;
166 }
167
168 public String getMessage() {
169 return message;
170 }
171
172 @Override
173 public String toString() {
174 return String.format(Locale.ROOT, "%s %s %s", this.getClass().getName(), cause, message);
175 }
176 }
177
178
179
180
181 class RuleError extends Error {
182
183
184
185
186 private static final long serialVersionUID = 1L;
187 private final Rule origin;
188
189 public RuleError(Rule r, Exception e, String msg) {
190 super(e, msg);
191 if (r == null) {
192 throw new NullPointerException("rule cannot be null.");
193 }
194 origin = r;
195 }
196
197 public Rule getOrigin() {
198 return origin;
199 }
200
201 @Override
202 public String toString() {
203 return String.format(Locale.ROOT, "%s - %s", super.toString(), origin.getHRName());
204 }
205 }
206
207
208
209
210 class FixError extends Error {
211
212
213
214
215 private static final long serialVersionUID = 1L;
216 private final Fix origin;
217
218 public FixError(Fix f, Exception e, String msg) {
219 super(e, msg);
220 origin = f;
221 }
222
223 public Fix getOrigin() {
224 return origin;
225 }
226
227 @Override
228 public String toString() {
229 return String.format(Locale.ROOT, "%s - %s", super.toString(), origin.getHRName());
230 }
231 }
232
233 }