Class ValidationDriver
java.lang.Object
com.thaiopensource.validate.ValidationDriver
Provides a simplified API for validating XML documents against schemas.
This class is neither reentrant nor safe for access from multiple threads.
- Author:
- James Clark
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA producer of SAX events. -
Constructor Summary
ConstructorsConstructorDescriptionEquivalent to ValidationDriver(PropertyMap.EMPTY, PropertyMap.EMPTY, null).ValidationDriver(PropertyMap properties) Equivalent to ValidationDriver(properties, properties, null).ValidationDriver(PropertyMap schemaProperties, PropertyMap instanceProperties) Equivalent to ValidationDriver(schemaProperties, instanceProperties, null).ValidationDriver(PropertyMap schemaProperties, PropertyMap instanceProperties, SchemaReader schemaReader) Creates and initializes a ValidationDriver.ValidationDriver(PropertyMap properties, SchemaReader sr) Equivalent to ValidationDriver(properties, properties, sr).Equivalent to ValidationDriver(PropertyMap.EMPTY, PropertyMap.EMPTY, null). -
Method Summary
Modifier and TypeMethodDescriptionstatic InputSourcefileInputSource(File file) Returns anInputSourcefor aFile.static InputSourcefileInputSource(String filename) Returns anInputSourcefor a filename.Get the actual properties of the loaded schemabooleanLoads a schema.static InputSourceuriOrFileInputSource(String uriOrFile) Returns anInputSourcefor a string that represents either a file or an absolute URI.booleanvalidate(ValidationDriver.SaxProducer saxProducer) Validates the events of a producer against the currently loaded schema.booleanvalidate(InputSource in) Validates a document against the currently loaded schema.
-
Constructor Details
-
ValidationDriver
public ValidationDriver(PropertyMap schemaProperties, PropertyMap instanceProperties, SchemaReader schemaReader) Creates and initializes a ValidationDriver.- Parameters:
schemaProperties- a PropertyMap specifying properties controlling schema creation; must not benullinstanceProperties- a PropertyMap specifying properties controlling validation; must not benullschemaReader- the SchemaReader to use; if this isnull, then the schema must be in XML, and the namespace URI of the root element will be used to determine what the schema language is
-
ValidationDriver
Equivalent to ValidationDriver(schemaProperties, instanceProperties, null).- See Also:
-
ValidationDriver
Equivalent to ValidationDriver(properties, properties, sr).- See Also:
-
ValidationDriver
Equivalent to ValidationDriver(properties, properties, null).- See Also:
-
ValidationDriver
Equivalent to ValidationDriver(PropertyMap.EMPTY, PropertyMap.EMPTY, null).- See Also:
-
ValidationDriver
public ValidationDriver()Equivalent to ValidationDriver(PropertyMap.EMPTY, PropertyMap.EMPTY, null).- See Also:
-
-
Method Details
-
loadSchema
Loads a schema. Subsequent calls tovalidatewill validate with respect the loaded schema. This can be called more than once to allow multiple documents to be validated against different schemas.- Parameters:
in- the InputSource for the schema- Returns:
trueif the schema was loaded successfully;falseotherwise- Throws:
IOException- if an I/O error occurredSAXException- if an XMLReader or ErrorHandler threw a SAXException
-
validate
Validates a document against the currently loaded schema. This can be called multiple times in order to validate multiple documents.- Parameters:
in- the InputSource for the document to be validated- Returns:
trueif the document is valid;falseotherwise- Throws:
IllegalStateException- if there is no currently loaded schemaIOException- if an I/O error occurredSAXException- if an XMLReader or ErrorHandler threw a SAXException
-
validate
Validates the events of a producer against the currently loaded schema. This can be called multiple times in order to validate multiple documents.- Parameters:
producer- a producer that delivers SAX events to the handlers.- Returns:
trueif the document is valid;falseotherwise- Throws:
IllegalStateException- if there is no currently loaded schemaIOException- if an I/O error occurredSAXException- if an XMLReader or ErrorHandler threw a SAXException
-
getSchemaProperties
Get the actual properties of the loaded schema- Returns:
- a PropertyMap with the schema properties
- Throws:
IllegalStateException- if there is no currently loaded schema
-
fileInputSource
Returns anInputSourcefor a filename.- Parameters:
filename- a String specifying the filename- Returns:
- an
InputSourcefor the filename
-
fileInputSource
Returns anInputSourcefor aFile.- Parameters:
file- theFile- Returns:
- an
InputSourcefor the filename
-
uriOrFileInputSource
Returns anInputSourcefor a string that represents either a file or an absolute URI. If the string looks like an absolute URI, it will be treated as an absolute URI, otherwise it will be treated as a filename.- Parameters:
uriOrFile- aStringrepresenting either a file or an absolute URI- Returns:
- an
InputSourcefor the file or absolute URI
-