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 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
public interface ValidationReport extends Serializable { |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | 0 | enum IssueLevel { |
42 | 0 | error, |
43 | 0 | warning, |
44 | 0 | info |
45 | |
} |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
List<Issue> getIssues(); |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
List<RuleActivation> getRuleActivations(); |
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
List<Error> getErrors(); |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
class Issue implements Serializable { |
72 | |
|
73 | |
private final IssueLevel level; |
74 | |
private final String message; |
75 | |
private final Node origin; |
76 | |
|
77 | 0 | public Issue(IssueLevel level, String message, Node origin) { |
78 | 0 | if(level == null) { |
79 | 0 | throw new NullPointerException("level cannot be null."); |
80 | |
} |
81 | 0 | if(message == null) { |
82 | 0 | throw new NullPointerException("message cannot be null."); |
83 | |
} |
84 | 0 | if(origin == null) { |
85 | 0 | throw new NullPointerException("origin cannot be null."); |
86 | |
} |
87 | 0 | this.level = level; |
88 | 0 | this.message = message; |
89 | 0 | this.origin = origin; |
90 | 0 | } |
91 | |
|
92 | |
public String getMessage() { |
93 | 0 | return message; |
94 | |
} |
95 | |
|
96 | |
public IssueLevel getLevel() { |
97 | 0 | return level; |
98 | |
} |
99 | |
|
100 | |
public Node getOrigin() { |
101 | 0 | return origin; |
102 | |
} |
103 | |
|
104 | |
@Override |
105 | |
public String toString() { |
106 | 0 | return String.format( |
107 | |
"Issue %s '%s' %s", |
108 | |
level, |
109 | |
message, |
110 | |
DomUtils.getXPathForNode(origin) |
111 | |
); |
112 | |
} |
113 | |
} |
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
class RuleActivation implements Serializable { |
119 | |
|
120 | |
private final String ruleStr; |
121 | |
|
122 | 0 | public RuleActivation(Rule r) { |
123 | 0 | if(r == null) { |
124 | 0 | throw new NullPointerException("rule cannot be null."); |
125 | |
} |
126 | 0 | ruleStr = r.getHRName(); |
127 | 0 | } |
128 | |
|
129 | |
public String getRuleStr() { |
130 | 0 | return ruleStr; |
131 | |
} |
132 | |
|
133 | |
@Override |
134 | |
public String toString() { |
135 | 0 | return ruleStr; |
136 | |
} |
137 | |
} |
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
abstract class Error implements Serializable { |
143 | |
|
144 | |
private final Exception cause; |
145 | |
private final String message; |
146 | |
|
147 | 0 | public Error(Exception e, String msg) { |
148 | 0 | if(e == null) { |
149 | 0 | throw new NullPointerException("exception cannot be null."); |
150 | |
} |
151 | 0 | if(msg == null) { |
152 | 0 | throw new NullPointerException("message cannot be null."); |
153 | |
} |
154 | 0 | cause = e; |
155 | 0 | message = msg; |
156 | 0 | } |
157 | |
|
158 | |
public Exception getCause() { |
159 | 0 | return cause; |
160 | |
} |
161 | |
|
162 | |
public String getMessage() { |
163 | 0 | return message; |
164 | |
} |
165 | |
|
166 | |
@Override |
167 | |
public String toString() { |
168 | 0 | return String.format("%s %s %s", this.getClass().getName(), cause, message); |
169 | |
} |
170 | |
} |
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
class RuleError extends Error { |
176 | |
|
177 | |
private final Rule origin; |
178 | |
|
179 | |
public RuleError(Rule r, Exception e, String msg) { |
180 | 0 | super(e, msg); |
181 | 0 | if(r == null) { |
182 | 0 | throw new NullPointerException("rule cannot be null."); |
183 | |
} |
184 | 0 | origin = r; |
185 | 0 | } |
186 | |
|
187 | |
public Rule getOrigin() { |
188 | 0 | return origin; |
189 | |
} |
190 | |
|
191 | |
@Override |
192 | |
public String toString() { |
193 | 0 | return String.format("%s - %s", super.toString(), origin.getHRName()); |
194 | |
} |
195 | |
} |
196 | |
|
197 | |
|
198 | |
|
199 | |
|
200 | |
class FixError extends Error { |
201 | |
|
202 | |
private final Fix origin; |
203 | |
|
204 | |
public FixError(Fix f, Exception e, String msg) { |
205 | 0 | super(e, msg); |
206 | 0 | origin = f; |
207 | 0 | } |
208 | |
|
209 | |
public Fix getOrigin() { |
210 | 0 | return origin; |
211 | |
} |
212 | |
|
213 | |
@Override |
214 | |
public String toString() { |
215 | 0 | return String.format("%s - %s", super.toString(), origin.getHRName()); |
216 | |
} |
217 | |
} |
218 | |
|
219 | |
} |