|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.brownell.xml.pipeline.EventFilter | +--org.brownell.xml.pipeline.ValidationConsumer
This class checks SAX2 events to report validity errors; it works as both a filter and a terminus on an event pipeline. It relies on the producer of SAX events to:
xmlns*
attributes (rather than omitting either or both). At this writing, almost all SAX parsers read such entities, and report ignorable whitespace as such, though few of them are very conformant to the XML specification. It's harder to get Lexical/Decl handler support. (A suitably enhanced version of Ælfred is available, as is a version pre configured to use this component to validate its output.)
Note that because this is a layered validator, it has to duplicate some work that the parser is doing; there are also other cost to layering. However, because of layering it doesn't need a parser in order to work! You can use it with anything that generates SAX events, such as an application component that wants to detect invalid content in a changed area without validating an entire document, or which wants to ensure that it doesn't write invalid data to a communications partner.
Also, note that because this is a layered validator, the line numbers reported for some errors may seem strange. For example, if an element does not permit character content, the validator will use the locator provided to it. That might reflect the last character of a characters event callback, rather than the first non-whitespace character.
Current limitations of the validation performed are in roughly three categories.
The first category represents constraints which demand violations of software layering: exposing lexical details, one of the first things that application programming interfaces (APIs) hide. These invariably relate to XML entity handling, and to historical oddities of the XML validation semantics. Curiously, recent (Autumn 1999) conformance testing showed that these constraints are among those handled worst by existing XML validating parsers. Arguments have been made that each of these VCs should be turned into WFCs (most of them) or discarded (popular for the standalone declaration); in short, that these are bugs in the XML specification (not all via SGML):
The second category of limitations on this validation represent constraints associated with information that is not guaranteed to be available (or in one case, is guaranteed not to be available, through the SAX2 API:
A third category relates to ease of implementation. Rather than attempting to implement the voluminous character tables in the XML specification, Unicode rules are used directly. This problem has actually become more fixable lately.
SAXDriver
,
Validator
Fields inherited from class org.brownell.xml.pipeline.EventFilter |
HANDLER_URI |
Constructor Summary | |
ValidationConsumer()
Creates a pipeline terminus which consumes all events passed to it; this will report validity errors as if they were fatal errors, unless an error handler is assigned. |
|
ValidationConsumer(EventConsumer next)
Creates a pipeline filter which reports validity errors and then passes events on to the next consumer if they were not fatal. |
|
ValidationConsumer(java.lang.String rootName,
java.lang.String publicId,
java.lang.String systemId,
java.lang.String internalSubset,
EntityResolver resolver,
java.lang.String minimalDocument)
Creates a validation consumer which is preloaded with the DTD provided. |
Method Summary | |
void |
attributeDecl(java.lang.String element,
java.lang.String attribute,
java.lang.String type,
java.lang.String mode,
java.lang.String value)
DecllHandler Records attribute declaration for later use in validating document content, and checks validity constraints that are applicable to attribute declarations. |
void |
characters(char[] buf,
int offset,
int length)
ContentHandler Reports a validity error if the element's content model does not permit character data. |
void |
elementDecl(java.lang.String name,
java.lang.String model)
DecllHandler Records the element declaration for later use when checking document content, and checks validity constraints that apply to element declarations. |
void |
endDocument()
ContentHandler Checks whether all ID values that were referenced have been declared, and releases all resources. |
void |
endDTD()
LexicalHandler Verifies that all referenced notations and unparsed entities have been declared. |
void |
endElement(java.lang.String uri,
java.lang.String local,
java.lang.String name)
ContentHandler Reports a validity error if the element's content model does not permit end-of-element yet, or a well formedness error if there was no matching startElement call. |
void |
externalEntityDecl(java.lang.String name,
java.lang.String pubId,
java.lang.String sysId)
DecllHandler passed to the next consumer, unless this one was preloaded with a particular DTD |
void |
internalEntityDecl(java.lang.String name,
java.lang.String value)
DecllHandler passed to the next consumer, unless this one was preloaded with a particular DTD |
void |
notationDecl(java.lang.String name,
java.lang.String publicId,
java.lang.String systemId)
DTDHandler Records the notation name, for checking NOTATIONS attribute values and declararations of unparsed entities. |
void |
setDocumentLocator(Locator locator)
ContentHandler Records the locator for use in diagnostics. |
void |
skippedEntity(java.lang.String name)
ContentHandler Reports a fatal exception. |
void |
startDocument()
ContentHandler Ensures that state from any previous parse has been deleted. |
void |
startDTD(java.lang.String name,
java.lang.String publicId,
java.lang.String systemId)
LexicalHandler Records the declaration of the root element, so it can be verified later. |
void |
startElement(java.lang.String uri,
java.lang.String local,
java.lang.String name,
Attributes attributes)
ContentHandler Performs validity checks against element (and document) content models, and attribute values. |
void |
unparsedEntityDecl(java.lang.String name,
java.lang.String publicId,
java.lang.String systemId,
java.lang.String notation)
DTDHandler Records the entity name, for checking ENTITY and ENTITIES attribute values; records the notation name if it hasn't yet been declared. |
Methods inherited from class org.brownell.xml.pipeline.EventFilter |
comment,
endCDATA,
endEntity,
endPrefixMapping,
getContentHandler,
getDTDHandler,
getErrorHandler,
getNext,
getProperty,
ignorableWhitespace,
processingInstruction,
setContentHandler,
setDTDHandler,
setErrorHandler,
setProperty,
startCDATA,
startEntity,
startPrefixMapping |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Constructor Detail |
public ValidationConsumer()
EventFilter.setErrorHandler(org.xml.sax.ErrorHandler)
public ValidationConsumer(EventConsumer next)
EventFilter.setErrorHandler(org.xml.sax.ErrorHandler)
public ValidationConsumer(java.lang.String rootName, java.lang.String publicId, java.lang.String systemId, java.lang.String internalSubset, EntityResolver resolver, java.lang.String minimalDocument) throws SAXException, java.io.IOException
The resulting validation consumer will only validate against the specified DTD, regardless of whether some other DTD is found in a document being parsed.
rootName
- The name of the required root element; if this is
null, any root element name will be accepted.publicId
- If non-null and there is a non-null systemId, this
identifier provides an alternate access identifier for the DTD's
external subset.systemId
- If non-null, this is a URI (normally URL) that
may be used to access the DTD's external subset.internalSubset
- If non-null, holds literal markup declarations
comprising the DTD's internal subset.resolver
- If non-null, this will be provided to the paraser for
use when resolving parameter entities (including any external subset).resolver
- If non-null, this will be provided to the paraser for
use when resolving parameter entities (including any external subset).minimalElement
- If non-null, a minimal valid document.Method Detail |
public void startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId) throws SAXException
name
- The document type name.publicId
- The declared public identifier for the
external DTD subset, or null if none was declared.systemId
- The declared system identifier for the
external DTD subset, or null if none was declared.LexicalHandler.endDTD()
,
LexicalHandler.startEntity(java.lang.String)
public void endDTD() throws SAXException
LexicalHandler.startDTD(java.lang.String, java.lang.String, java.lang.String)
public void attributeDecl(java.lang.String element, java.lang.String attribute, java.lang.String type, java.lang.String mode, java.lang.String value) throws SAXException
eName
- The name of the associated element.aName
- The name of the attribute.type
- A string representing the attribute type.valueDefault
- A string representing the attribute default
("#IMPLIED", "#REQUIRED", or "#FIXED") or null if
none of these applies.value
- A string representing the attribute's default value,
or null if there is none.public void elementDecl(java.lang.String name, java.lang.String model) throws SAXException
name
- The element type name.model
- The content model as a normalized string.public void internalEntityDecl(java.lang.String name, java.lang.String value) throws SAXException
name
- The name of the entity. If it is a parameter
entity, the name will begin with '%'.value
- The replacement text of the entity.DeclHandler.externalEntityDecl(java.lang.String, java.lang.String, java.lang.String)
,
DTDHandler.unparsedEntityDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
public void externalEntityDecl(java.lang.String name, java.lang.String pubId, java.lang.String sysId) throws SAXException
name
- The name of the entity. If it is a parameter
entity, the name will begin with '%'.publicId
- The declared public identifier of the entity, or
null if none was declared.systemId
- The declared system identifier of the entity.DeclHandler.internalEntityDecl(java.lang.String, java.lang.String)
,
DTDHandler.unparsedEntityDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
public void notationDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId) throws SAXException
name
- The notation name.publicId
- The notation's public identifier, or null if
none was given.systemId
- The notation's system identifier, or null if
none was given.DTDHandler.unparsedEntityDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
,
AttributeList
public void unparsedEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId, java.lang.String notation) throws SAXException
name
- The unparsed entity's name.publicId
- The entity's public identifier, or null if none
was given.systemId
- The entity's system identifier.notation
- name The name of the associated notation.DTDHandler.notationDecl(java.lang.String, java.lang.String, java.lang.String)
,
AttributeList
public void setDocumentLocator(Locator locator)
locator
- An object that can return the location of
any SAX document event.Locator
public void startDocument() throws SAXException
ContentHandler.endDocument()
public void skippedEntity(java.lang.String name) throws SAXException
name
- The name of the skipped entity. If it is a
parameter entity, the name will begin with '%', and if
it is the external DTD subset, it will be the string
"[dtd]".public void startElement(java.lang.String uri, java.lang.String local, java.lang.String name, Attributes attributes) throws SAXException
uri
- The Namespace URI, or the empty string if the
element has no Namespace URI or if Namespace
processing is not being performed.localName
- The local name (without prefix), or the
empty string if Namespace processing is not being
performed.qName
- The qualified name (with prefix), or the
empty string if qualified names are not available.atts
- The attributes attached to the element. If
there are no attributes, it shall be an empty
Attributes object.ContentHandler.endElement(java.lang.String, java.lang.String, java.lang.String)
,
Attributes
public void characters(char[] buf, int offset, int length) throws SAXException
ch
- The characters from the XML document.start
- The start position in the array.length
- The number of characters to read from the array.ContentHandler.ignorableWhitespace(char[], int, int)
,
Locator
public void endElement(java.lang.String uri, java.lang.String local, java.lang.String name) throws SAXException
uri
- The Namespace URI, or the empty string if the
element has no Namespace URI or if Namespace
processing is not being performed.localName
- The local name (without prefix), or the
empty string if Namespace processing is not being
performed.qName
- The qualified XML 1.0 name (with prefix), or the
empty string if qualified names are not available.public void endDocument() throws SAXException
setDocumentLocator(org.xml.sax.Locator)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |