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