org.apache.cocoon.components.validation
Interface Validator

All Known Implementing Classes:
AbstractValidator, CachingValidator, DefaultValidator

public interface Validator

The Validator interface provides the abstraction of a component able to validate XML documents using schemas defined in different languages.

This is basically the main entry point of the validation API, allowing users to transparently access validators (in the form of ValidationHandlers receiving SAX events for the documents to be validated), in different grammar languages, using different implementations.

As more than one SchemaParser might be able to parse and create Schema instances for a particular grammar language, this interface defines a unique lookup method to allow selection of a particular SchemaParser implementation.

Assuming that two different SchemaParsers called first and second are both able to understand the RELAX NG grammar (identified by the http://relaxng.org/ns/structure/1.0 identifier) one could select between the two implementation using the following two strings:

As a rule (unless when this is impossible) the grammar identifier is equivalent to the namespace of the root element of a schema.


Field Summary
static String GRAMMAR_ISO_SCHEMATRON
          The ISO Schematron grammar identifer.
static String GRAMMAR_RELAX_CORE
          The RELAX Core grammar identifer.
static String GRAMMAR_RELAX_NG
          The RELAX NG grammar identifer.
static String GRAMMAR_RELAX_NS
          The RELAX Namespace grammar identifer.
static String GRAMMAR_SCHEMATRON
          The Schematron grammar identifer.
static String GRAMMAR_TREX
          The Trex grammar identifer.
static String GRAMMAR_XML_DTD
          The XML DTD grammar identifer.
static String GRAMMAR_XML_SCHEMA
          The XML Schema grammar identifer.
static String ROLE
          Avalon Role name of Validator components.
 
Method Summary
 ValidationHandler getValidationHandler(Source source)
          Return a ValidationHandler validating an XML document according to the schema found at the specified location.
 ValidationHandler getValidationHandler(Source source, ErrorHandler errorHandler)
          Return a ValidationHandler validating an XML document according to the schema found at the specified location.
 ValidationHandler getValidationHandler(Source source, String grammar)
          Return a ValidationHandler validating an XML document according to the schema found at the specified location.
 ValidationHandler getValidationHandler(Source source, String grammar, ErrorHandler errorHandler)
          Return a ValidationHandler validating an XML document according to the schema found at the specified location.
 ValidationHandler getValidationHandler(String uri)
          Return a ValidationHandler validating an XML document according to the schema found at the specified location.
 ValidationHandler getValidationHandler(String uri, ErrorHandler errorHandler)
          Return a ValidationHandler validating an XML document according to the schema found at the specified location.
 ValidationHandler getValidationHandler(String uri, String grammar)
          Return a ValidationHandler validating an XML document according to the schema found at the specified location.
 ValidationHandler getValidationHandler(String uri, String grammar, ErrorHandler errorHandler)
          Return a ValidationHandler validating an XML document according to the schema found at the specified location.
 

Field Detail

ROLE

static final String ROLE

Avalon Role name of Validator components.


GRAMMAR_ISO_SCHEMATRON

static final String GRAMMAR_ISO_SCHEMATRON

The ISO Schematron grammar identifer.

See Also:
Constant Field Values

GRAMMAR_RELAX_NG

static final String GRAMMAR_RELAX_NG

The RELAX NG grammar identifer.

See Also:
Constant Field Values

GRAMMAR_RELAX_CORE

static final String GRAMMAR_RELAX_CORE

The RELAX Core grammar identifer.

See Also:
Constant Field Values

GRAMMAR_RELAX_NS

static final String GRAMMAR_RELAX_NS

The RELAX Namespace grammar identifer.

See Also:
Constant Field Values

GRAMMAR_SCHEMATRON

static final String GRAMMAR_SCHEMATRON

The Schematron grammar identifer.

See Also:
Constant Field Values

GRAMMAR_TREX

static final String GRAMMAR_TREX

The Trex grammar identifer.

See Also:
Constant Field Values

GRAMMAR_XML_SCHEMA

static final String GRAMMAR_XML_SCHEMA

The XML Schema grammar identifer.

See Also:
Constant Field Values

GRAMMAR_XML_DTD

static final String GRAMMAR_XML_DTD

The XML DTD grammar identifer.

See Also:
Constant Field Values
Method Detail

getValidationHandler

ValidationHandler getValidationHandler(String uri)
                                       throws IOException,
                                              SAXException,
                                              ValidatorException

Return a ValidationHandler validating an XML document according to the schema found at the specified location.

The Validator will attempt to automatically detect the grammar language of the specified schema, and each error or warning occurring while validating the document will trigger a SAXException to be thrown back to the caller.

Parameters:
uri - the location of the schema to use to validate the document.
Returns:
a non null ValidationHandler able to SAX events from the original XML document to validate.
Throws:
IOException - if an I/O error occurred parsing the schema.
SAXException - if a grammar error occurred parsing the schema.
ValidatorException - if the grammar language of the specified schema could not be detected or was not supported.
See Also:
SchemaParser.parseSchema(Source, String), Schema.createValidator(ErrorHandler)

getValidationHandler

ValidationHandler getValidationHandler(String uri,
                                       String grammar)
                                       throws IOException,
                                              SAXException,
                                              ValidatorException

Return a ValidationHandler validating an XML document according to the schema found at the specified location.

Each error or warning occurring while validating the document will trigger a SAXException to be thrown back to the caller.

Parameters:
uri - the location of the schema to use to validate the document.
grammar - the grammar language of the schema to parse.
Returns:
a non null ValidationHandler able to SAX events from the original XML document to validate.
Throws:
IOException - if an I/O error occurred parsing the schema.
SAXException - if a grammar error occurred parsing the schema.
ValidatorException - if the specified grammar language wasn't supported.
See Also:
SchemaParser.parseSchema(Source, String), Schema.createValidator(ErrorHandler)

getValidationHandler

ValidationHandler getValidationHandler(String uri,
                                       ErrorHandler errorHandler)
                                       throws IOException,
                                              SAXException,
                                              ValidatorException

Return a ValidationHandler validating an XML document according to the schema found at the specified location.

The Validator will attempt to automatically detect the grammar language of the specified schema, while each validation error or warning will be passed to the specified ErrorHandler which will have the ability to generate and throw a SAXException back to the caller.

Parameters:
uri - the location of the schema to use to validate the document.
errorHandler - the ErrorHandler notified of validation problems.
Returns:
a non null ValidationHandler able to SAX events from the original XML document to validate.
Throws:
IOException - if an I/O error occurred parsing the schema.
SAXException - if a grammar error occurred parsing the schema.
ValidatorException - if the grammar language of the specified schema could not be detected or was not supported.
See Also:
SchemaParser.parseSchema(Source, String), Schema.createValidator(ErrorHandler)

getValidationHandler

ValidationHandler getValidationHandler(String uri,
                                       String grammar,
                                       ErrorHandler errorHandler)
                                       throws IOException,
                                              SAXException,
                                              ValidatorException

Return a ValidationHandler validating an XML document according to the schema found at the specified location.

Each validation error or warning will be passed to the specified ErrorHandler which will have the ability to generate and throw a SAXException back to the caller.

Parameters:
uri - the location of the schema to use to validate the document.
grammar - the grammar language of the schema to parse.
errorHandler - the ErrorHandler notified of validation problems.
Returns:
a non null ValidationHandler able to SAX events from the original XML document to validate.
Throws:
IOException - if an I/O error occurred parsing the schema.
SAXException - if a grammar error occurred parsing the schema.
ValidatorException - if the specified grammar language wasn't supported.
See Also:
SchemaParser.parseSchema(Source, String), Schema.createValidator(ErrorHandler)

getValidationHandler

ValidationHandler getValidationHandler(Source source)
                                       throws IOException,
                                              SAXException,
                                              ValidatorException

Return a ValidationHandler validating an XML document according to the schema found at the specified location.

The Validator will attempt to automatically detect the grammar language of the specified schema, and each error or warning occurring while validating the document will trigger a SAXException to be thrown back to the caller.

Parameters:
source - the Source identifying the schema to use for validation.
Returns:
a non null ValidationHandler able to SAX events from the original XML document to validate.
Throws:
IOException - if an I/O error occurred parsing the schema.
SAXException - if a grammar error occurred parsing the schema.
ValidatorException - if the grammar language of the specified schema could not be detected or was not supported.
See Also:
SchemaParser.parseSchema(Source, String), Schema.createValidator(ErrorHandler)

getValidationHandler

ValidationHandler getValidationHandler(Source source,
                                       String grammar)
                                       throws IOException,
                                              SAXException,
                                              ValidatorException

Return a ValidationHandler validating an XML document according to the schema found at the specified location.

Each error or warning occurring while validating the document will trigger a SAXException to be thrown back to the caller.

Parameters:
source - the Source identifying the schema to use for validation.
grammar - the grammar language of the schema to parse.
Returns:
a non null ValidationHandler able to SAX events from the original XML document to validate.
Throws:
IOException - if an I/O error occurred parsing the schema.
SAXException - if a grammar error occurred parsing the schema.
ValidatorException - if the specified grammar language wasn't supported.
See Also:
SchemaParser.parseSchema(Source, String), Schema.createValidator(ErrorHandler)

getValidationHandler

ValidationHandler getValidationHandler(Source source,
                                       ErrorHandler errorHandler)
                                       throws IOException,
                                              SAXException,
                                              ValidatorException

Return a ValidationHandler validating an XML document according to the schema found at the specified location.

The Validator will attempt to automatically detect the grammar language of the specified schema, while each validation error or warning will be passed to the specified ErrorHandler which will have the ability to generate and throw a SAXException back to the caller.

Parameters:
source - the Source identifying the schema to use for validation.
errorHandler - the ErrorHandler notified of validation problems.
Returns:
a non null ValidationHandler able to SAX events from the original XML document to validate.
Throws:
IOException - if an I/O error occurred parsing the schema.
SAXException - if a grammar error occurred parsing the schema.
ValidatorException - if the grammar language of the specified schema could not be detected or was not supported.
See Also:
SchemaParser.parseSchema(Source, String), Schema.createValidator(ErrorHandler)

getValidationHandler

ValidationHandler getValidationHandler(Source source,
                                       String grammar,
                                       ErrorHandler errorHandler)
                                       throws IOException,
                                              SAXException,
                                              ValidatorException

Return a ValidationHandler validating an XML document according to the schema found at the specified location.

Each validation error or warning will be passed to the specified ErrorHandler which will have the ability to generate and throw a SAXException back to the caller.

Parameters:
source - the Source identifying the schema to use for validation.
grammar - the grammar language of the schema to parse.
errorHandler - the ErrorHandler notified of validation problems.
Returns:
a non null ValidationHandler able to SAX events from the original XML document to validate.
Throws:
IOException - if an I/O error occurred parsing the schema.
SAXException - if a grammar error occurred parsing the schema.
ValidatorException - if the specified grammar language wasn't supported.
See Also:
SchemaParser.parseSchema(Source, String), Schema.createValidator(ErrorHandler)


Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.