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

Classes in this File | Line Coverage | Branch Coverage | Complexity
DefaultValidationReportBuilder |
0% | 0/37
0% | 0/26
| 2.625;2.625

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.w3c.dom.Node;
21 |  |
22 |  |
     import java.util.ArrayList;
23 |  |
     import java.util.Collections;
24 |  |
     import java.util.List;
25 |  |
26 |  |
     /**
27 |  |
      * Default implementation of {@link ValidationReportBuilder}.
28 |  |
      *
29 |  |
      * @author Michele Mostarda (mostarda@fbk.eu)
30 |  |
      * @author Davide Palmisano (palmisano@fbk.eu)
31 |  |
      */
32 |  |
     public class DefaultValidationReportBuilder implements ValidationReportBuilder {
33 |  |
34 |  |
         private List<ValidationReport.Issue> issues;
35 |  |
         private List<ValidationReport.RuleActivation> ruleActivations;
36 |  |
         private List<ValidationReport.Error> errors;
37 |  |
38 | 0 |
         public DefaultValidationReportBuilder() {}
39 |  |
40 |  |
         public ValidationReport getReport() {
41 | 0 |
             return new DefaultValidationReport(
42 |  |
                     issues == null ? Collections.<ValidationReport.Issue>emptyList() : issues,
43 |  |
                     ruleActivations == null ? Collections.<ValidationReport.RuleActivation>emptyList() : ruleActivations,
44 |  |
                     errors == null ? Collections.<ValidationReport.Error>emptyList() : errors
45 |  |
             );
46 |  |
         }
47 |  |
48 |  |
         public void reportIssue(ValidationReport.IssueLevel issueLevel, String message, Node n) {
49 | 0 |
             if(issues == null) {
50 | 0 |
                 issues = new ArrayList<ValidationReport.Issue>();
51 |  |
             }
52 | 0 |
             issues.add( new ValidationReport.Issue(issueLevel, message, n) );
53 | 0 |
         }
54 |  |
55 |  |
         public void reportIssue(ValidationReport.IssueLevel issueLevel, String message) {
56 | 0 |
             reportIssue(issueLevel, message, null);
57 | 0 |
         }
58 |  |
59 |  |
         public void traceRuleActivation(Rule r) {
60 | 0 |
             if(ruleActivations == null) {
61 | 0 |
                 ruleActivations = new ArrayList<ValidationReport.RuleActivation>();
62 |  |
             }
63 | 0 |
             ruleActivations.add( new ValidationReport.RuleActivation(r) );
64 | 0 |
         }
65 |  |
66 |  |
         public void reportRuleError(Rule r, Exception e, String msg) {
67 | 0 |
             if(errors == null) {
68 | 0 |
                 errors = new ArrayList<ValidationReport.Error>();
69 |  |
             }
70 | 0 |
             errors.add( new ValidationReport.RuleError(r, e, msg) );
71 | 0 |
         }
72 |  |
73 |  |
         public void reportFixError(Fix f, Exception e, String msg) {
74 | 0 |
             if(errors == null) {
75 | 0 |
                 errors = new ArrayList<ValidationReport.Error>();
76 |  |
             }
77 | 0 |
             errors.add( new ValidationReport.FixError(f, e, msg) );
78 |  |
79 | 0 |
         }
80 |  |
81 |  |
         @Override
82 |  |
         public String toString() {
83 | 0 |
             final StringBuilder sb = new StringBuilder();
84 | 0 |
             if(ruleActivations != null) {
85 | 0 |
                 sb.append("Rules {\n");
86 | 0 |
                 for(ValidationReport.RuleActivation ra :ruleActivations) {
87 | 0 |
                     sb.append(ra).append('\n');
88 |  |
                 }
89 | 0 |
                 sb.append("}\n");
90 |  |
             }
91 | 0 |
             if(issues != null) {
92 | 0 |
                 sb.append("Issues {\n");
93 | 0 |
                 for(ValidationReport.Issue issue : issues) {
94 | 0 |
                     sb.append( issue.toString() ).append('\n');
95 |  |
                 }
96 | 0 |
                 sb.append("}\n");
97 |  |
             }
98 | 0 |
             if (errors != null) {
99 | 0 |
                 sb.append("Errors {\n");
100 | 0 |
                 for (ValidationReport.Error error : errors) {
101 | 0 |
                     sb.append( error.toString() ).append('\n');
102 |  |
                 }
103 | 0 |
                 sb.append("}\n");
104 |  |
             }
105 | 0 |
             return sb.toString();
106 |  |
         }
107 |  |
108 |  |
     }