Package org.jppf.utils
Class SchemaValidator
java.lang.Object
org.jppf.utils.SchemaValidator
Utility class to validate an XML document against an XML schema.
- Author:
- Laurent Cohen
-
Constructor Summary
ConstructorsConstructorDescriptionSchemaValidator(JPPFErrorReporter reporter) Initialize this validator with the specified error reporter. -
Method Summary
Modifier and TypeMethodDescriptionGet the schema factory for this validator.loadSchema(InputStream schemaStream) Load an XML schema from the specified input stream.loadSchema(Reader schemaReader) Load an XML schema from the specified reader.loadSchema(String schemaPath) Load an XML schema from the specified path.static voidEntry point to test this class.Print a trace of the specified sax parsing exception.static voidShow usage instructions for this validation toll, and exit the JVM.booleanValidate an XML document from a reader against an XML schema.booleanValidate an XML document in a file against an XML schema.
-
Constructor Details
-
SchemaValidator
Initialize this validator with the specified error reporter.- Parameters:
reporter- used to collect validation error and warning messages.
-
-
Method Details
-
main
Entry point to test this class.- Parameters:
args- not used.
-
usageAndExit
public static void usageAndExit()Show usage instructions for this validation toll, and exit the JVM. -
loadSchema
Load an XML schema from the specified path. This method looks up the schema first in the file system, then in the classpath if it is not found in the file system.- Parameters:
schemaPath- the path to the schema to load.- Returns:
- a
Schemainstance, or null if the schema file could not be found. - Throws:
IOException- if an IO error occurs while looking up the schema file.SAXException- if an error occurs while loading the schema.
-
loadSchema
Load an XML schema from the specified input stream. This method looks up the schema first in the file system, then in the classpath if it is not found in the file system.- Parameters:
schemaStream- the input stream to load the schema from.- Returns:
- a
Schemainstance, or null if the schema file could not be found. - Throws:
IOException- if an IO error occurs while looking up the schema file.SAXException- if an error occurs while loading the schema.
-
loadSchema
Load an XML schema from the specified reader. This method looks up the schema first in the file system, then in the classpath if it is not found in the file system.- Parameters:
schemaReader- the reader to load the schema from.- Returns:
- a
Schemainstance, or null if the schema file could not be found. - Throws:
IOException- if an IO error occurs while looking up the schema file.SAXException- if an error occurs while loading the schema.
-
validate
Validate an XML document in a file against an XML schema.- Parameters:
docPath- the path to the XML document.schemaPath- the path to the XML schema.- Returns:
- true if the XML document is valid, false otherwise.
- Throws:
IOException- if an IO error occurs while looking up one of the files.SAXException- if an error occurs while loading the schema or validating the document.
-
validate
Validate an XML document from a reader against an XML schema.- Parameters:
docReader- the reader used to access the document.schemaReader- the path to the XML schema.- Returns:
- true if the XML document is valid, false otherwise.
- Throws:
IOException- if an IO error occurs while looking up one of the files.SAXException- if an error occurs while loading the schema or validating the document.
-
getSchemaFactory
Get the schema factory for this validator.- Returns:
- a
SchemaFactoryinstance.
-
printSAXParseException
Print a trace of the specified sax parsing exception.- Parameters:
e- the exception to print.name- an identifier for the document being parsed.- Returns:
- the resulting message as a string.
-