org.jppf.utils
Class SchemaValidator

java.lang.Object
  extended by org.jppf.utils.SchemaValidator

public class SchemaValidator
extends Object

Utility class to validate an XML docuement against an XML schema.

Author:
Laurent Cohen

Constructor Summary
SchemaValidator(JPPFErrorReporter reporter)
          Initialize this validator with the specified error reporter.
 
Method Summary
 SchemaFactory getSchemaFactory()
          Get the schema factory for this validator.
 Schema loadSchema(InputStream schemaStream)
          Load an XML schema from the specified input stream.
 Schema loadSchema(Reader schemaReader)
          Load an XML schema from the specified reader.
 Schema loadSchema(String schemaPath)
          Load an XML schema from the specified path.
static void main(String... args)
          Entry point to test this class.
 String printSAXParseException(SAXParseException e, String name)
          Print a trace of the specified sax parsing exception.
static void usageAndExit()
          Show usage instructions for this validation toll, and exit the JVM.
 boolean validate(Reader docReader, Reader schemaReader)
          Validate an XML document from a reader against an XML schema.
 boolean validate(String docPath, String schemaPath)
          Validate an XML document in a file against an XML schema.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SchemaValidator

public SchemaValidator(JPPFErrorReporter reporter)
Initialize this validator with the specified error reporter.

Parameters:
reporter - used to collect validation error and warning messages.
Method Detail

main

public static void main(String... args)
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

public Schema loadSchema(String schemaPath)
                  throws IOException,
                         SAXException
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 Schema instance, 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

public Schema loadSchema(InputStream schemaStream)
                  throws IOException,
                         SAXException
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 Schema instance, 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

public Schema loadSchema(Reader schemaReader)
                  throws IOException,
                         SAXException
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 Schema instance, 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

public boolean validate(String docPath,
                        String schemaPath)
                 throws IOException,
                        SAXException
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 docuement 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

public boolean validate(Reader docReader,
                        Reader schemaReader)
                 throws IOException,
                        SAXException
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 docuement 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

public SchemaFactory getSchemaFactory()
Get the schema factory for this validator.

Returns:
a SchemaFactory instance.

printSAXParseException

public String printSAXParseException(SAXParseException e,
                                     String name)
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.


Copyright © 2005-2010 JPPF Team.