gnu.xml.dom
Class Consumer.Backdoor

java.lang.Object
  |
  +--gnu.xml.pipeline.DomConsumer.Handler
        |
        +--gnu.xml.dom.Consumer.Backdoor
All Implemented Interfaces:
ContentHandler, DeclHandler, DTDHandler, LexicalHandler
Enclosing class:
Consumer

public static class Consumer.Backdoor
extends DomConsumer.Handler

Implements the backdoors needed by DOM. All methods in this class use implementation-specific APIs that are implied by the DOM specification (needed to implement testable behavior) but which are excluded from the DOM specification.


Field Summary
 
Fields inherited from class gnu.xml.pipeline.DomConsumer.Handler
consumer
 
Constructor Summary
protected Consumer.Backdoor(DomConsumer consumer)
          Constructor.
 
Method Summary
 void attributeDecl(java.lang.String ename, java.lang.String aname, java.lang.String type, java.lang.String mode, java.lang.String value)
          Report an attribute type declaration.
 boolean canPopulateEntityRefs()
          May be overridden by subclasses to return true, indicating that entity reference nodes can be populated and then made read-only.
protected  org.w3c.dom.Text createText(boolean isCDATA, char[] buf, int off, int len)
          Subclasses may overrride this method to provide a more efficient way to construct text nodes.
 void endDocument()
          Receive notification of the end of a document.
 void endDTD()
          Report the end of DTD declarations.
 void endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName)
          Receive notification of the end of an element.
 void endEntity(java.lang.String name)
          Report the end of an entity.
 void externalEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
          Report a parsed external entity declaration.
 void internalEntityDecl(java.lang.String name, java.lang.String value)
          Report an internal entity declaration.
 void notationDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
          Receive notification of a notation declaration event.
 void startDocument()
          Receive notification of the beginning of a document.
 void startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
          Report the start of DTD declarations, if any.
 void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, Attributes atts)
          Receive notification of the beginning of an element.
 void startEntity(java.lang.String name)
          Report the beginning of some internal and external XML entities.
 void unparsedEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId, java.lang.String notationName)
          Receive notification of an unparsed entity declaration event.
 
Methods inherited from class gnu.xml.pipeline.DomConsumer.Handler
characters, comment, elementDecl, endCDATA, endPrefixMapping, getDocument, getTop, ignorableWhitespace, processingInstruction, setDocumentLocator, skippedEntity, startCDATA, startPrefixMapping
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Consumer.Backdoor

protected Consumer.Backdoor(DomConsumer consumer)
                     throws SAXException
Constructor.

Parameters:
consumer - must have been initialized to use the DomDocument class (or a subclass) for constructing DOM trees
Method Detail

startDTD

public void startDTD(java.lang.String name,
                     java.lang.String publicId,
                     java.lang.String systemId)
              throws SAXException
Description copied from interface: LexicalHandler
Report the start of DTD declarations, if any.

This method is intended to report the beginning of the DOCTYPE declaration; if the document has no DOCTYPE declaration, this method will not be invoked.

All declarations reported through DTDHandler or DeclHandler events must appear between the startDTD and endDTD events. Declarations are assumed to belong to the internal DTD subset unless they appear between startEntity and endEntity events. Comments and processing instructions from the DTD should also be reported between the startDTD and endDTD events, in their original order of (logical) occurrence; they are not required to appear in their correct locations relative to DTDHandler or DeclHandler events, however.

Note that the start/endDTD events will appear within the start/endDocument events from ContentHandler and before the first startElement event.

Specified by:
startDTD in interface LexicalHandler
Overrides:
startDTD in class DomConsumer.Handler
Parameters:
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. (Note that this is not resolved against the document base URI.)
Throws:
SAXException - The application may raise an exception.
See Also:
LexicalHandler.endDTD(), LexicalHandler.startEntity(java.lang.String)

endDTD

public void endDTD()
            throws SAXException
Description copied from interface: LexicalHandler
Report the end of DTD declarations.

This method is intended to report the end of the DOCTYPE declaration; if the document has no DOCTYPE declaration, this method will not be invoked.

Specified by:
endDTD in interface LexicalHandler
Overrides:
endDTD in class DomConsumer.Handler
Throws:
SAXException - The application may raise an exception.
See Also:
LexicalHandler.startDTD(java.lang.String, java.lang.String, java.lang.String)

notationDecl

public void notationDecl(java.lang.String name,
                         java.lang.String publicId,
                         java.lang.String systemId)
                  throws SAXException
Description copied from interface: DTDHandler
Receive notification of a notation declaration event.

It is up to the application to record the notation for later reference, if necessary; notations may appear as attribute values and in unparsed entity declarations, and are sometime used with processing instruction target names.

At least one of publicId and systemId must be non-null. If a system identifier is present, and it is a URL, the SAX parser must resolve it fully before passing it to the application through this event.

There is no guarantee that the notation declaration will be reported before any unparsed entities that use it.

Specified by:
notationDecl in interface DTDHandler
Overrides:
notationDecl in class DomConsumer.Handler
Parameters:
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.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
DTDHandler.unparsedEntityDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String), Attributes

unparsedEntityDecl

public void unparsedEntityDecl(java.lang.String name,
                               java.lang.String publicId,
                               java.lang.String systemId,
                               java.lang.String notationName)
                        throws SAXException
Description copied from interface: DTDHandler
Receive notification of an unparsed entity declaration event.

Note that the notation name corresponds to a notation reported by the notationDecl event. It is up to the application to record the entity for later reference, if necessary; unparsed entities may appear as attribute values.

If the system identifier is a URL, the parser must resolve it fully before passing it to the application.

Specified by:
unparsedEntityDecl in interface DTDHandler
Overrides:
unparsedEntityDecl in class DomConsumer.Handler
Parameters:
name - The unparsed entity's name.
publicId - The entity's public identifier, or null if none was given.
systemId - The entity's system identifier.
notationName - The name of the associated notation.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
DTDHandler.notationDecl(java.lang.String, java.lang.String, java.lang.String), Attributes

internalEntityDecl

public void internalEntityDecl(java.lang.String name,
                               java.lang.String value)
                        throws SAXException
Description copied from interface: DeclHandler
Report an internal entity declaration.

Only the effective (first) declaration for each entity will be reported. All parameter entities in the value will be expanded, but general entities will not.

Specified by:
internalEntityDecl in interface DeclHandler
Overrides:
internalEntityDecl in class DomConsumer.Handler
Parameters:
name - The name of the entity. If it is a parameter entity, the name will begin with '%'.
value - The replacement text of the entity.
Throws:
SAXException - The application may raise an exception.
See Also:
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)

externalEntityDecl

public void externalEntityDecl(java.lang.String name,
                               java.lang.String publicId,
                               java.lang.String systemId)
                        throws SAXException
Description copied from interface: DeclHandler
Report a parsed external entity declaration.

Only the effective (first) declaration for each entity will be reported.

Specified by:
externalEntityDecl in interface DeclHandler
Overrides:
externalEntityDecl in class DomConsumer.Handler
Parameters:
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.
Throws:
SAXException - The application may raise an exception.
See Also:
DeclHandler.internalEntityDecl(java.lang.String, java.lang.String), DTDHandler.unparsedEntityDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String)

startElement

public void startElement(java.lang.String uri,
                         java.lang.String localName,
                         java.lang.String qName,
                         Attributes atts)
                  throws SAXException
Description copied from interface: ContentHandler
Receive notification of the beginning of an element.

The Parser will invoke this method at the beginning of every element in the XML document; there will be a corresponding endElement event for every startElement event (even when the element is empty). All of the element's content will be reported, in order, before the corresponding endElement event.

This event allows up to three name components for each element:

  1. the Namespace URI;
  2. the local name; and
  3. the qualified (prefixed) name.

Any or all of these may be provided, depending on the values of the http://xml.org/sax/features/namespaces and the http://xml.org/sax/features/namespace-prefixes properties:

Note that the attribute list provided will contain only attributes with explicit values (specified or defaulted): #IMPLIED attributes will be omitted. The attribute list will contain attributes used for Namespace declarations (xmlns* attributes) only if the http://xml.org/sax/features/namespace-prefixes property is true (it is false by default, and support for a true value is optional).

Specified by:
startElement in interface ContentHandler
Overrides:
startElement in class DomConsumer.Handler
Parameters:
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.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ContentHandler.endElement(java.lang.String, java.lang.String, java.lang.String), Attributes

endElement

public void endElement(java.lang.String uri,
                       java.lang.String localName,
                       java.lang.String qName)
                throws SAXException
Description copied from interface: ContentHandler
Receive notification of the end of an element.

The SAX parser will invoke this method at the end of every element in the XML document; there will be a corresponding startElement event for every endElement event (even when the element is empty).

For information on the names, see startElement.

Specified by:
endElement in interface ContentHandler
Overrides:
endElement in class DomConsumer.Handler
Parameters:
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.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.

createText

protected org.w3c.dom.Text createText(boolean isCDATA,
                                      char[] buf,
                                      int off,
                                      int len)
Description copied from class: DomConsumer.Handler
Subclasses may overrride this method to provide a more efficient way to construct text nodes. Typically, copying the text into a single character array will be more efficient than doing that as well as allocating other needed for a String, including an internal StringBuffer. Those additional memory and CPU costs can be incurred later, if ever needed. Unfortunately the standard DOM factory APIs encourage those costs to be incurred early.

Overrides:
createText in class DomConsumer.Handler

attributeDecl

public void attributeDecl(java.lang.String ename,
                          java.lang.String aname,
                          java.lang.String type,
                          java.lang.String mode,
                          java.lang.String value)
                   throws SAXException
Description copied from interface: DeclHandler
Report an attribute type declaration.

Only the effective (first) declaration for an attribute will be reported. The type will be one of the strings "CDATA", "ID", "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES", a parenthesized token group with the separator "|" and all whitespace removed, or the word "NOTATION" followed by a space followed by a parenthesized token group with all whitespace removed.

The value will be the value as reported to applications, appropriately normalized and with entity and character references expanded.

Specified by:
attributeDecl in interface DeclHandler
Overrides:
attributeDecl in class DomConsumer.Handler
Parameters:
ename - The name of the associated element.
aname - The name of the attribute.
type - A string representing the attribute type.
mode - A string representing the attribute defaulting mode ("#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.
Throws:
SAXException - The application may raise an exception.

startDocument

public void startDocument()
                   throws SAXException
Description copied from interface: ContentHandler
Receive notification of the beginning of a document.

The SAX parser will invoke this method only once, before any other methods in this interface or in DTDHandler (except for setDocumentLocator).

Specified by:
startDocument in interface ContentHandler
Overrides:
startDocument in class DomConsumer.Handler
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ContentHandler.endDocument()

endDocument

public void endDocument()
                 throws SAXException
Description copied from interface: ContentHandler
Receive notification of the end of a document.

The SAX parser will invoke this method only once, and it will be the last method invoked during the parse. The parser shall not invoke this method until it has either abandoned parsing (because of an unrecoverable error) or reached the end of input.

Specified by:
endDocument in interface ContentHandler
Overrides:
endDocument in class DomConsumer.Handler
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ContentHandler.startDocument()

canPopulateEntityRefs

public boolean canPopulateEntityRefs()
Description copied from class: DomConsumer.Handler
May be overridden by subclasses to return true, indicating that entity reference nodes can be populated and then made read-only.

Overrides:
canPopulateEntityRefs in class DomConsumer.Handler

startEntity

public void startEntity(java.lang.String name)
                 throws SAXException
Description copied from interface: LexicalHandler
Report the beginning of some internal and external XML entities.

The reporting of parameter entities (including the external DTD subset) is optional, and SAX2 drivers that report LexicalHandler events may not implement it; you can use the http://xml.org/sax/features/lexical-handler/parameter-entities feature to query or control the reporting of parameter entities.

General entities are reported with their regular names, parameter entities have '%' prepended to their names, and the external DTD subset has the pseudo-entity name "[dtd]".

When a SAX2 driver is providing these events, all other events must be properly nested within start/end entity events. There is no additional requirement that events from DeclHandler or DTDHandler be properly ordered.

Note that skipped entities will be reported through the skippedEntity event, which is part of the ContentHandler interface.

Because of the streaming event model that SAX uses, some entity boundaries cannot be reported under any circumstances:

These will be silently expanded, with no indication of where the original entity boundaries were.

Note also that the boundaries of character references (which are not really entities anyway) are not reported.

All start/endEntity events must be properly nested.

Specified by:
startEntity in interface LexicalHandler
Overrides:
startEntity in class DomConsumer.Handler
Parameters:
name - The name of the entity. If it is a parameter entity, the name will begin with '%', and if it is the external DTD subset, it will be "[dtd]".
Throws:
SAXException - The application may raise an exception.
See Also:
LexicalHandler.endEntity(java.lang.String), DeclHandler.internalEntityDecl(java.lang.String, java.lang.String), DeclHandler.externalEntityDecl(java.lang.String, java.lang.String, java.lang.String)

endEntity

public void endEntity(java.lang.String name)
               throws SAXException
Description copied from interface: LexicalHandler
Report the end of an entity.

Specified by:
endEntity in interface LexicalHandler
Overrides:
endEntity in class DomConsumer.Handler
Parameters:
name - The name of the entity that is ending.
Throws:
SAXException - The application may raise an exception.
See Also:
LexicalHandler.startEntity(java.lang.String)


Source code is under GPL (with library exception) in the JAXP project at http://www.gnu.org/software/classpathx/jaxp
This documentation was derived from that source code on 2003-06-07.