View Javadoc

1   /*
2    * Copyright 2005-2011 the original author or authors.
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.springframework.xml.validation;
18  
19  import java.io.IOException;
20  import javax.xml.transform.Source;
21  
22  import org.xml.sax.SAXParseException;
23  
24  /**
25   * Simple processor that validates a given {@link Source}. Can be created via the {@link XmlValidatorFactory}.
26   * <p/>
27   * Instances of this class are designed to be thread safe.
28   *
29   * @author Arjen Poutsma
30   * @see XmlValidatorFactory#createValidator(org.springframework.core.io.Resource, String)
31   * @since 1.0.0
32   */
33  public interface XmlValidator {
34  
35      /**
36       * Validates the given {@link Source}, and returns an array of {@link SAXParseException}s as result. The array will
37       * be empty if no validation errors are found.
38       *
39       * @param source the input document
40       * @return an array of <code>SAXParseException</code>s
41       * @throws IOException            if the <code>source</code> cannot be read
42       * @throws XmlValidationException if the <code>source</code> cannot be validated
43       */
44      SAXParseException[] validate(Source source) throws IOException;
45  
46      /**
47       * Validates the given {@link Source} and {@link ValidationErrorHandler}, and returns an array of {@link
48       * SAXParseException}s as result. The array will be empty if no validation errors are found.
49       *
50       * @param source the input document
51       * @param errorHandler the error handler to use. May be {@code null}, in which case a default will be used.
52       * @return an array of <code>SAXParseException</code>s
53       * @throws IOException            if the <code>source</code> cannot be read
54       * @throws XmlValidationException if the <code>source</code> cannot be validated
55       */
56      SAXParseException[] validate(Source source, ValidationErrorHandler errorHandler) throws IOException;
57  
58  }