xdoclet.util

Class XmlValidator

public class XmlValidator extends DefaultHandler

This handler implementation is capable of providing dtds from a local storage instead of accessing them over the net. Further, it will throw an exception if the parsed xml is not acording to the DTD it specifies.

Version: $Revision: 1.19 $

Author: Aslak Helleso?=y

UNKNOWN: September 18, 2001 Deal with Translator.getString()'s exception better in resolveEntity(String, String)

Field Summary
protected ClassLoaderclassLoader
static StringDEFAULT_XML_READER_CLASSNAME
The crimson implementation is shipped with ant.
protected StringreaderClassName
protected XMLReaderxmlReader
XMLReader used for validation
Constructor Summary
XmlValidator(ClassLoader classLoader)
Describe what the XmlValidator constructor does
Method Summary
voiderror(SAXParseException e)
Called by parser if a error occurs
static XmlValidatorgetInstance()
Gets the Instance attribute of the XmlValidator class
voidregisterDTD(String publicId, URL dtdURL)
Registers a local DTD document by its public id.
voidregisterSchema(URL schemaURL)
Registers a local XSD document by its public id.
voidreset()
Resets the Validator
InputSourceresolveEntity(String publicId, String systemId)
Called by parser when a DTD declaration is encountered in the parsed XML document
static voidsetInstance(XmlValidator instance)
Sets the Instance attribute of the XmlValidator class
voidvalidate(File xmlFile)
Validates an XML file for conformance to a declared DTD or XMLSchema.
voidwarning(SAXParseException e)
Called by parser if a warning occurs

Field Detail

classLoader

protected ClassLoader classLoader

DEFAULT_XML_READER_CLASSNAME

public static final String DEFAULT_XML_READER_CLASSNAME
The crimson implementation is shipped with ant.

readerClassName

protected String readerClassName

xmlReader

protected XMLReader xmlReader
XMLReader used for validation

Constructor Detail

XmlValidator

public XmlValidator(ClassLoader classLoader)
Describe what the XmlValidator constructor does

Parameters: classLoader Describe what the parameter does

Method Detail

error

public void error(SAXParseException e)
Called by parser if a error occurs

Parameters: e an exception describing the error

Throws: SAXParseException every time this method is called by the parser

getInstance

public static XmlValidator getInstance()
Gets the Instance attribute of the XmlValidator class

Returns: The Instance value

registerDTD

public void registerDTD(String publicId, URL dtdURL)
Registers a local DTD document by its public id. This is necessary to avoid DTD loading over the net.

Parameters: publicId the publicId of the DTD dtdURL the URL of the local DTD, which must be loadable by the class passed in the constructor. This URL typically points inside a local jar file

registerSchema

public void registerSchema(URL schemaURL)
Registers a local XSD document by its public id. This is necessary to avoid loading XML Schemas over the net.

Parameters: schemaURL

reset

public void reset()
Resets the Validator

resolveEntity

public InputSource resolveEntity(String publicId, String systemId)
Called by parser when a DTD declaration is encountered in the parsed XML document

Parameters: publicId the public id of the DTD systemId the system id of the DTD

Returns: an InputSource from containing the DTD document, provided it has been previously registered via the XmlValidator method. If not, null will be returned, and the parser will atempt to load the DTD from the systemId value, Usually an Internet http URL.

setInstance

public static void setInstance(XmlValidator instance)
Sets the Instance attribute of the XmlValidator class

Parameters: instance The new Instance value

validate

public void validate(File xmlFile)
Validates an XML file for conformance to a declared DTD or XMLSchema. This method is useful for subclasses that wish to verify that a generated XML file is ok. Please note that the callers should make sure to register any DTDs required for validation on the handler object.

Parameters: xmlFile Description of Parameter

Throws: XDocletException Description of Exception

warning

public void warning(SAXParseException e)
Called by parser if a warning occurs

Parameters: e an exception describing the warning

Throws: SAXParseException every time this method is called by the parser