org.apache.crimson.parser
Class ValidatingParser

java.lang.Object
  extended byorg.apache.crimson.parser.Parser2
      extended byorg.apache.crimson.parser.ValidatingParser

public class ValidatingParser
extends Parser2

This parser tests XML documents against the validity constraints specified in the XML 1.0 specification as it parses them. It reports violations of those constraints using the standard SAX API.

This parser should be configured to use an ErrorHandler that reject documents with validity errors, otherwise they will be accepted despite errors. The default error handling, as specified by SAX, ignores all validity errors. The simplest way to have validity errors have a useful effect is to pass a boolean true value to the parser's constructor.

Note that most validity checks are performed during parsing by the base class, for efficiency. They're disabled by default in that class, and enabled by the constructor in this class.

Author:
David Brownell

Nested Class Summary
(package private)  class ValidatingParser.ChildrenValidator
           
(package private)  class ValidatingParser.EmptyValidator
           
(package private)  class ValidatingParser.MixedValidator
           
 
Nested classes inherited from class org.apache.crimson.parser.Parser2
Parser2.Catalog, Parser2.DocLocator, Parser2.NameCache, Parser2.NameCacheEntry
 
Field Summary
private  ValidatingParser.EmptyValidator EMPTY
           
private  SimpleHashtable ids
           
 
Fields inherited from class org.apache.crimson.parser.Parser2
entities, messages, notations, SECURITY_DEBUG, strANY, strEMPTY, SYSTEM_PROPERTY_DISALLOW_DOCTYPE_DECL, SYSTEM_PROPERTY_ELEMENT_ATTRIBUTE_LIMIT, SYSTEM_PROPERTY_ENTITY_EXPANSION_LIMIT
 
Constructor Summary
ValidatingParser()
          Constructs a SAX parser object.
ValidatingParser(boolean rejectValidityErrors)
          Constructs a SAX parser object, optionally assigning the error handler to report exceptions on recoverable errors (which include all validity errors) as well as fatal errors.
 
Method Summary
(package private)  void afterDocument()
           
(package private)  void afterRoot()
           
private  boolean isUnparsedEntity(String name)
           
(package private)  ContentModel newContentModel(char type, ContentModel next)
           
(package private)  ContentModel newContentModel(String tag)
           
(package private)  ElementValidator newValidator(ElementDecl element)
          To validate, subclassers should create an object that can accept valid streams of element names, text, and terminate.
(package private)  void validateAttributeSyntax(AttributeDecl attr, String value)
          To validate, subclassers should at this time make sure that values are of the declared types: ID and IDREF(S) values are Names NMTOKEN(S) are Nmtokens ENUMERATION values match one of the tokens NOTATION values match a notation name ENTITIY(IES) values match an unparsed external entity Separately, make sure IDREF values match some ID provided in the document (in the afterRoot method).
 
Methods inherited from class org.apache.crimson.parser.Parser2
chooseLocale, error, getLocale, isFastStandalone, parse, pushInputBuffer, setContentHandler, setDeclHandler, setDTDHandler, setEntityResolver, setErrorHandler, setFastStandalone, setIsValidating, setLexicalHandler, setLocale, setNamespaceFeatures, setSecurityConstraintValues
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ids

private SimpleHashtable ids

EMPTY

private final ValidatingParser.EmptyValidator EMPTY
Constructor Detail

ValidatingParser

public ValidatingParser()
Constructs a SAX parser object.


ValidatingParser

public ValidatingParser(boolean rejectValidityErrors)
Constructs a SAX parser object, optionally assigning the error handler to report exceptions on recoverable errors (which include all validity errors) as well as fatal errors.

Parameters:
rejectValidityErrors - When true, the parser will use an error handler which throws exceptions on recoverable errors. Otherwise it uses the default SAX error handler, which ignores such errors.
Method Detail

afterRoot

void afterRoot()
         throws org.xml.sax.SAXException
Overrides:
afterRoot in class Parser2
Throws:
org.xml.sax.SAXException

afterDocument

void afterDocument()
Overrides:
afterDocument in class Parser2

validateAttributeSyntax

void validateAttributeSyntax(AttributeDecl attr,
                             String value)
                       throws org.xml.sax.SAXException
Description copied from class: Parser2
To validate, subclassers should at this time make sure that values are of the declared types:

Separately, make sure IDREF values match some ID provided in the document (in the afterRoot method).

Overrides:
validateAttributeSyntax in class Parser2
Throws:
org.xml.sax.SAXException

newContentModel

ContentModel newContentModel(String tag)
Overrides:
newContentModel in class Parser2

newContentModel

ContentModel newContentModel(char type,
                             ContentModel next)
Overrides:
newContentModel in class Parser2

newValidator

ElementValidator newValidator(ElementDecl element)
Description copied from class: Parser2
To validate, subclassers should create an object that can accept valid streams of element names, text, and terminate.

Overrides:
newValidator in class Parser2

isUnparsedEntity

private boolean isUnparsedEntity(String name)