xdoclet.util
Class XmlValidator

java.lang.Object
  |
  +--org.xml.sax.helpers.DefaultHandler
        |
        +--xdoclet.util.XmlValidator
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

public class XmlValidator
extends org.xml.sax.helpers.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.7 $
Author:
Aslak Hellesøy

Constructor Summary
XmlValidator()
          Creates a new XmlValidator.
 
Method Summary
 void error(org.xml.sax.SAXParseException e)
          Called by parser if a error occurs
 void registerDTD(java.lang.String publicId, java.lang.String dtdFileName)
          Registers a local DTD document by its public id.
 org.xml.sax.InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId)
          Called by parser when a DTD declaration is encountered in the parsed XML document
 void validate(java.io.File xmlFile)
          Validates an XML file for conformance to a declared DTD or XMLSchema.
 void warning(org.xml.sax.SAXParseException e)
          Called by parser if a warning occurs
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
characters, endDocument, endElement, endPrefixMapping, fatalError, ignorableWhitespace, notationDecl, processingInstruction, setDocumentLocator, skippedEntity, startDocument, startElement, startPrefixMapping, unparsedEntityDecl
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlValidator

public XmlValidator()
Creates a new XmlValidator.
Method Detail

registerDTD

public void registerDTD(java.lang.String publicId,
                        java.lang.String dtdFileName)
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
dtdFileName - the file name of the local DTD, which must be loadable by the class passed in the constructor.

resolveEntity

public org.xml.sax.InputSource resolveEntity(java.lang.String publicId,
                                             java.lang.String systemId)
Called by parser when a DTD declaration is encountered in the parsed XML document
Overrides:
resolveEntity in class org.xml.sax.helpers.DefaultHandler
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 registerDTD(java.lang.String, java.lang.String) 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.

error

public void error(org.xml.sax.SAXParseException e)
           throws org.xml.sax.SAXParseException
Called by parser if a error occurs
Overrides:
error in class org.xml.sax.helpers.DefaultHandler
Parameters:
e - an exception describing the error
Throws:
org.xml.sax.SAXParseException - every time this method is called by the parser

warning

public void warning(org.xml.sax.SAXParseException e)
             throws org.xml.sax.SAXParseException
Called by parser if a warning occurs
Overrides:
warning in class org.xml.sax.helpers.DefaultHandler
Parameters:
e - an exception describing the warning
Throws:
org.xml.sax.SAXParseException - every time this method is called by the parser

validate

public void validate(java.io.File xmlFile)
              throws XDocletException
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