##### Coverage Report - org.apache.any23.validator.ValidationReport

Classes in this File | Line Coverage | Branch Coverage | Complexity
ValidationReport |
N/A | N/A
N/A | N/A
| 1.6666666666666667;1.667
ValidationReport$Error |
0% | 0/11
0% | 0/4
| 1.6666666666666667;1.667
ValidationReport$FixError |
0% | 0/5
N/A | N/A
| 1.6666666666666667;1.667
ValidationReport$Issue |
0% | 0/15
0% | 0/6
| 1.6666666666666667;1.667
ValidationReport$IssueLevel |
0% | 0/4
N/A | N/A
| 1.6666666666666667;1.667
ValidationReport$RuleActivation |
0% | 0/7
0% | 0/2
| 1.6666666666666667;1.667
ValidationReport$RuleError |
0% | 0/7
0% | 0/2
| 1.6666666666666667;1.667

1 |  |
     /*
2 |  |
      * Licensed to the Apache Software Foundation (ASF) under one or more
3 |  |
      * contributor license agreements.  See the NOTICE file distributed with
4 |  |
      * this work for additional information regarding copyright ownership.
5 |  |
      * The ASF licenses this file to You under the Apache License, Version 2.0
6 |  |
      * (the "License"); you may not use this file except in compliance with
7 |  |
      * the License.  You may obtain a copy of the License at
8 |  |
      *
9 |  |
      *  http://www.apache.org/licenses/LICENSE-2.0
10 |  |
      *
11 |  |
      * Unless required by applicable law or agreed to in writing, software
12 |  |
      * distributed under the License is distributed on an "AS IS" BASIS,
13 |  |
      * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 |  |
      * See the License for the specific language governing permissions and
15 |  |
      * limitations under the License.
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 |  |
      * This class contains the report of a validation performed by
28 |  |
      * the {@link Validator} class.
29 |  |
      *
30 |  |
      * @see Validator
31 |  |
      * @see ValidationReportBuilder
32 |  |
      * @author Michele Mostarda (mostarda@fbk.eu)
33 |  |
      * @author Davide Palmisano (palmisano@fbk.eu)
34 |  |
      */
35 |  |
     // TODO: merge with ErrorReporter
36 |  |
     public interface ValidationReport extends Serializable {
37 |  |
38 |  |
         /**
39 |  |
          * Defines the different issue levels.
40 |  |
          */
41 | 0 |
         enum IssueLevel {
42 | 0 |
             error,
43 | 0 |
             warning,
44 | 0 |
             info
45 |  |
         }
46 |  |
47 |  |
         /**
48 |  |
          * Returns the list of detected issues.
49 |  |
          *
50 |  |
          * @return list of detected issues.
51 |  |
          */
52 |  |
         List<Issue> getIssues();
53 |  |
54 |  |
         /**
55 |  |
          * Returns the list of activated rules.
56 |  |
          *
57 |  |
          * @return list of activated rules.
58 |  |
          */
59 |  |
         List<RuleActivation> getRuleActivations();
60 |  |
61 |  |
         /**
62 |  |
          * Returns the list of detected errors.
63 |  |
          *
64 |  |
          * @return list of detected errors.
65 |  |
          */
66 |  |
         List<Error> getErrors();
67 |  |
68 |  |
         /**
69 |  |
          * An issue found during the validation process.
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 |  |
          * This class describes the activation of a rule.
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 |  |
          * An error occurred while performing the validation process.
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 |  |
          * An error occurred while executing a rule.
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 |  |
          * An error occurred while executing a fix.
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 |  |
     }