View Javadoc

1   /*
2    * Copyright 2008-2010 Digital Enterprise Research Institute (DERI)
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *          http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.deri.any23.validator;
18  
19  import org.w3c.dom.Document;
20  
21  import java.net.URI;
22  import java.util.List;
23  
24  /**
25   * The validator class allows to perform validation - correction of
26   * related to <i>HTML</i> {@link org.w3c.dom.Document} instances.
27   *
28   * @author Michele Mostarda (mostarda@fbk.eu)
29   * @author Davide Palmisano (palmisano@fbk.eu)
30   */
31  public interface Validator {
32  
33      /**
34       * Performs a validation - fixing of the provided document.
35       *
36       * @param document the {@link org.deri.any23.validator.DOMDocument} instance wrapping the
37       *        original <i>HTML</i> document.
38       * @param applyFix if <code>true</code> tries to fix the document.
39       * @return a report of the detected issues.
40       * @throws ValidatorException if an error occurs during the validation process.
41       */
42      ValidationReport validate(DOMDocument document, boolean applyFix) throws ValidatorException;
43  
44      /**
45       * Performs a validation - fixing of the provided document.
46       *
47       * @param documentURI the document source URI.
48       * @param document the original <i>HTML</i> document.
49       * @param applyFix if <code>true</code> tries to fix the document.
50       * @return a report of the detected issues.
51       * @throws ValidatorException if an error occurs during the validation process.
52       */
53      ValidationReport validate(URI documentURI, Document document, boolean applyFix)
54      throws ValidatorException;
55  
56      /**
57       * Allows to register a new rule to this validator
58       *
59       * @param rule
60       */
61      void addRule(Class<? extends Rule> rule);
62  
63      /**
64       * Allows to register a new rule to this validator and associating it to a fix.
65       *
66       * @param rule
67       * @param fix
68       */
69      void addRule(Class<? extends Rule> rule, Class<? extends Fix> fix);
70  
71      /**
72       * Allows to remove a rule from the validator and all the related {@link org.deri.any23.validator.Fix}es. 
73       *
74       * @param rule
75       */
76      void removeRule(Class<? extends Rule> rule);
77  
78      /**
79       * Returns all the registered rules.
80       *
81       * @return a not null list of rules.
82       */
83      List<Class<? extends Rule>> getAllRules();
84  
85      /**
86       * Returns all fixes registered for the give rule.
87       *
88       * @param rule
89       * @return a not null list of fixes.
90       */
91      List<Class<? extends Fix>> getFixes(Class<? extends Rule> rule);
92  
93  }