View Javadoc
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.eclipse.rdf4j.model.IRI;
21  import org.w3c.dom.Document;
22  
23  import java.net.URI;
24  import java.util.List;
25  
26  /**
27   * The validator class allows to perform validation - correction of
28   * related to <i>HTML</i> {@link org.w3c.dom.Document} instances.
29   *
30   * @author Michele Mostarda (mostarda@fbk.eu)
31   * @author Davide Palmisano (palmisano@fbk.eu)
32   */
33  public interface Validator {
34  
35      /**
36       * Performs a validation - fixing of the provided document.
37       *
38       * @param document the {@link DOMDocument} instance wrapping the
39       *        original <i>HTML</i> document.
40       * @param applyFix if <code>true</code> tries to fix the document.
41       * @return a report of the detected issues.
42       * @throws ValidatorException if an error occurs during the validation process.
43       */
44      ValidationReport validate(DOMDocument document, boolean applyFix) throws ValidatorException;
45  
46      /**
47       * Performs a validation - fixing of the provided document.
48       *
49       * @param documentIRI the document source IRI.
50       * @param document the original <i>HTML</i> document.
51       * @param applyFix if <code>true</code> tries to fix the document.
52       * @return a report of the detected issues.
53       * @throws ValidatorException if an error occurs during the validation process.
54       */
55      ValidationReport validate(URI documentIRI, Document document, boolean applyFix)
56      throws ValidatorException;
57  
58      /**
59       * Allows to register a new rule to this validator
60       *
61       * @param rule add a configured {@link org.apache.any23.validator.Rule}
62       */
63      void addRule(Class<? extends Rule> rule);
64  
65      /**
66       * Allows to register a new rule to this validator and associating it to a fix.
67       *
68       * @param rule add a configured {@link org.apache.any23.validator.Rule}
69       * @param fix add a configured {@link org.apache.any23.validator.Fix} for the rule
70       */
71      void addRule(Class<? extends Rule> rule, Class<? extends Fix> fix);
72  
73      /**
74       * Allows to remove a rule from the validator and all the related {@link Fix}es.
75       *
76       * @param rule {@link org.apache.any23.validator.Rule} to remove
77       */
78      void removeRule(Class<? extends Rule> rule);
79  
80      /**
81       * Returns all the registered rules.
82       *
83       * @return a not null list of rules.
84       */
85      List<Class<? extends Rule>> getAllRules();
86  
87      /**
88       * Returns all fixes registered for the give rule.
89       *
90       * @param rule {@link org.apache.any23.validator.Rule} to obtain fixes for.
91       * @return a not null list of fixes.
92       */
93      List<Class<? extends Fix>> getFixes(Class<? extends Rule> rule);
94  
95  }