com.thaiopensource.relaxng.util
Class ValidationEngine

java.lang.Object
  |
  +--com.thaiopensource.relaxng.util.ValidationEngine

public class ValidationEngine
extends Object

Provides a simplified API for validating XML documents against RELAX NG schemas. This class is neither reentrant nor safe for access from multiple threads.

Author:
James Clark
See Also:
SchemaFactory

Field Summary
static int CHECK_ID_IDREF
          Flag indicating that ID/IDREF/IDREFS should be checked.
static int COMPACT_SYNTAX
          Flag indicating that the schema is in the compact syntax rather than the XML syntax.
static int FEASIBLE
           
 
Constructor Summary
ValidationEngine()
          Default constructor.
ValidationEngine(XMLReaderCreator xrc, ErrorHandler eh, boolean checkIdIdref)
          Deprecated.  
ValidationEngine(XMLReaderCreator xrc, ErrorHandler eh, boolean checkIdIdref, boolean compactSyntax)
          Deprecated.  
ValidationEngine(XMLReaderCreator xrc, ErrorHandler eh, boolean checkIdIdref, boolean compactSyntax, boolean feasible)
          Deprecated.  
ValidationEngine(XMLReaderCreator xrc, ErrorHandler eh, int flags)
          Constructs a ValidationEngine.
 
Method Summary
static InputSource fileInputSource(File file)
          Returns an InputSource for a File.
static InputSource fileInputSource(String filename)
          Returns an InputSource for a filename.
 boolean loadSchema(InputSource in)
          Loads a schema.
static InputSource uriOrFileInputSource(String uriOrFile)
          Returns an InputSource for a string that represents either a file or an absolute URI.
 boolean validate(InputSource in)
          Validates a document against the currently loaded schema.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CHECK_ID_IDREF

public static final int CHECK_ID_IDREF
Flag indicating that ID/IDREF/IDREFS should be checked.

See Also:
ValidationEngine(XMLReaderCreator, ErrorHandler, int), Constant Field Values

COMPACT_SYNTAX

public static final int COMPACT_SYNTAX
Flag indicating that the schema is in the compact syntax rather than the XML syntax.

See Also:
ValidationEngine(XMLReaderCreator, ErrorHandler, int), Constant Field Values

FEASIBLE

public static final int FEASIBLE
See Also:
Constant Field Values
Constructor Detail

ValidationEngine

public ValidationEngine()
Default constructor. Equivalent to ValidationEngine(null, null, CHECK_ID_IDREF).


ValidationEngine

public ValidationEngine(XMLReaderCreator xrc,
                        ErrorHandler eh,
                        int flags)
Constructs a ValidationEngine.

Parameters:
xrc - the XMLReaderCreator to be used for constructing XMLReaders; if null uses Sax2XMLReaderCreator
eh - the ErrorHandler to be used for reporting errors; if null uses DraconianErrorHandler
flags - bitwise OR of flags selected from CHECK_ID_IDREF, COMPACT_SYNTAX, FEASIBLE, MNS
See Also:
DraconianErrorHandler, Sax2XMLReaderCreator, CHECK_ID_IDREF, COMPACT_SYNTAX, FEASIBLE

ValidationEngine

public ValidationEngine(XMLReaderCreator xrc,
                        ErrorHandler eh,
                        boolean checkIdIdref)
Deprecated.  

Constructs a ValidationEngine.

Parameters:
xrc - the XMLReaderCreator to be used for constructing XMLReaders; if null uses Sax2XMLReaderCreator
eh - the ErrorHandler to be used for reporting errors; if null uses DraconianErrorHandler
checkIdIdref - true if ID/IDREF/IDREFS should be checked; false otherwise
See Also:
DraconianErrorHandler, Sax2XMLReaderCreator

ValidationEngine

public ValidationEngine(XMLReaderCreator xrc,
                        ErrorHandler eh,
                        boolean checkIdIdref,
                        boolean compactSyntax)
Deprecated.  

Constructs a ValidationEngine.

Parameters:
xrc - the XMLReaderCreator to be used for constructing XMLReaders; if null uses Sax2XMLReaderCreator
eh - the ErrorHandler to be used for reporting errors; if null uses DraconianErrorHandler
checkIdIdref - true if ID/IDREF/IDREFS should be checked; false otherwise
compactSyntax - true if the compact syntax should be used to parse the schema; false if the XML syntax should be used
See Also:
DraconianErrorHandler, Sax2XMLReaderCreator

ValidationEngine

public ValidationEngine(XMLReaderCreator xrc,
                        ErrorHandler eh,
                        boolean checkIdIdref,
                        boolean compactSyntax,
                        boolean feasible)
Deprecated.  

Method Detail

loadSchema

public boolean loadSchema(InputSource in)
                   throws SAXException,
                          IOException
Loads a schema. Subsequent calls to validate will 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:
true if the schema was loaded successfully; false otherwise
Throws:
IOException - if an I/O error occurred
SAXException - if an XMLReader or ErrorHandler threw a SAXException

validate

public boolean validate(InputSource in)
                 throws SAXException,
                        IOException
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:
true if the document is valid; false otherwise
Throws:
IllegalStateException - if there is no currently loaded schema
IOException - if an I/O error occurred
SAXException - if an XMLReader or ErrorHandler threw a SAXException

fileInputSource

public static InputSource fileInputSource(String filename)
                                   throws MalformedURLException
Returns an InputSource for a filename.

Parameters:
filename - a String specifying the filename
Returns:
an InputSource for the filename
MalformedURLException

fileInputSource

public static InputSource fileInputSource(File file)
                                   throws MalformedURLException
Returns an InputSource for a File.

Parameters:
file - the File
Returns:
an InputSource for the filename
MalformedURLException

uriOrFileInputSource

public static InputSource uriOrFileInputSource(String uriOrFile)
                                        throws MalformedURLException
Returns an InputSource for 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 - a String representing either a file or an absolute URI
Returns:
an InputSource for the file or absolute URI
MalformedURLException