edu.ucsb.adl.reports
Class ValidatingXmlParser

java.lang.Object
  |
  +--com.microstar.xml.HandlerBase
        |
        +--edu.ucsb.adl.reports.ValidatingXmlParser
All Implemented Interfaces:
com.microstar.xml.XmlHandler

public final class ValidatingXmlParser
extends com.microstar.xml.HandlerBase

High-performance, DTD-based, table-driven validating XML parser.

This parser adds validation to the Ælfred lightweight (non-validating) XML parser. The validation is performed against a DTD supplied directly to the parser; any DTD information contained within documents being parsed is ignored. The supplied DTD must have been preprocessed into tabular form by class edu.ucsb.adl.reports.DtdTableGenerator.

Only a subset of XML is supported. The subset includes: elements; the element, pure #PCDATA, mixed, and EMPTY element content models; attributes; the CDATA and enumerated attribute content types; and attribute requiredness and default values. The ANY element content model is supported only to the extent that it is recognized and such content is skipped over. Namespaces, other attribute content types, XML schemas, and obscure XML features (processing instructions, etc.) are not supported.

Version:
$Header: /export/home/gjanee/utils/reports/edu/ucsb/adl/reports/RCS/ValidatingXmlParser.java,v 1.2 2003/03/18 17:56:30 gjanee Exp $

$Log: ValidatingXmlParser.java,v $ Revision 1.2 2003/03/18 17:56:30 gjanee
Added location information to low-level parse error exceptions.

Revision 1.1 2003/03/17 20:07:08 gjanee
Initial revision

Author:
Greg Janée
Alexandria Digital Library

Constructor Summary
ValidatingXmlParser(edu.ucsb.adl.reports.XmlDtd dtd, int stackSize, edu.ucsb.adl.reports.XmlHandler handler)
          Creates a ValidatingXmlParser.
 
Method Summary
 void attribute(java.lang.String name, java.lang.String value, boolean isSpecified)
          For use by XmlParser only.
 void charData(char[] string, int start, int length)
          For use by XmlParser only.
 void endElement(java.lang.String elementName)
          For use by XmlParser only.
 void parse(java.io.Reader reader)
          Parses a document with respect to a DTD.
 java.lang.Object resolveEntity(java.lang.String publicID, java.lang.String systemID)
          For use by XmlParser only.
 void startElement(java.lang.String elementName)
          For use by XmlParser only.
 
Methods inherited from class com.microstar.xml.HandlerBase
doctypeDecl, endDocument, endExternalEntity, error, ignorableWhitespace, processingInstruction, startDocument, startExternalEntity
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ValidatingXmlParser

public ValidatingXmlParser(edu.ucsb.adl.reports.XmlDtd dtd,
                           int stackSize,
                           edu.ucsb.adl.reports.XmlHandler handler)
Creates a ValidatingXmlParser. The parser may be invoked multiple times (whether it returns normally or throws an exception), but it is not multithread-safe.

Parameters:
dtd - The XML DTD to validate against. This argument is not checked for errors.
stackSize - The size of the parse stack. For non-recursive DTDs, a sufficient size is the maximum element nesting depth plus one.
handler - The event handler to invoke when parsing a document.
Throws:
java.lang.NullPointerException - If dtd or handler is null.
java.lang.IllegalArgumentException - If stackSize is less than 2.
Method Detail

parse

public void parse(java.io.Reader reader)
           throws XmlException
Parses a document with respect to a DTD. Any DTD information embedded within the document is ignored. This method is not multithread-safe.

Parameters:
reader - The primary source of the document.
Throws:
XmlException - If any parser or validation error occurs, or if an I/O error occurs reading from reader.

resolveEntity

public java.lang.Object resolveEntity(java.lang.String publicID,
                                      java.lang.String systemID)
For use by XmlParser only.

Specified by:
resolveEntity in interface com.microstar.xml.XmlHandler
Overrides:
resolveEntity in class com.microstar.xml.HandlerBase
Parameters:
publicID - Unused.
systemID - Unused.

startElement

public void startElement(java.lang.String elementName)
                  throws XmlException
For use by XmlParser only.

Specified by:
startElement in interface com.microstar.xml.XmlHandler
Overrides:
startElement in class com.microstar.xml.HandlerBase
Parameters:
elementName - The name of the new element.
Throws:
XmlException - If any error occurs.

endElement

public void endElement(java.lang.String elementName)
                throws XmlException
For use by XmlParser only.

Specified by:
endElement in interface com.microstar.xml.XmlHandler
Overrides:
endElement in class com.microstar.xml.HandlerBase
Parameters:
elementName - The name of the current element.
Throws:
XmlException - If any error occurs.

charData

public void charData(char[] string,
                     int start,
                     int length)
              throws XmlException
For use by XmlParser only.

Specified by:
charData in interface com.microstar.xml.XmlHandler
Overrides:
charData in class com.microstar.xml.HandlerBase
Parameters:
string - A fragment of element text.
start - The position at which the fragment starts.
length - The length of the fragment.
Throws:
XmlException - If any error occurs.

attribute

public void attribute(java.lang.String name,
                      java.lang.String value,
                      boolean isSpecified)
For use by XmlParser only.

Specified by:
attribute in interface com.microstar.xml.XmlHandler
Overrides:
attribute in class com.microstar.xml.HandlerBase
Parameters:
name - The attribute name.
value - The attribute value.
isSpecified - Unused.