gnu.xml.pipeline

Class DomConsumer.Handler

Enclosing Class:
DomConsumer
Implemented Interfaces:
ContentHandler, ContentHandler2, DeclHandler, DTDHandler, LexicalHandler
Known Direct Subclasses:
Consumer.Backdoor

public static class DomConsumer.Handler
extends java.lang.Object
implements ContentHandler2, LexicalHandler, DTDHandler, DeclHandler

Class used to intercept various parsing events and use them to populate a DOM document. Subclasses would typically know and use backdoors into specific DOM implementations, used to implement DTD-related functionality.

Note that if this ever throws a DOMException (runtime exception) that will indicate a bug in the DOM (e.g. doesn't support something per specification) or the parser (e.g. emitted an illegal name, or accepted illegal input data).

Field Summary

protected DomConsumer
consumer

Constructor Summary

Handler(DomConsumer consumer)
Subclasses may use SAX2 events to provide additional behaviors in the resulting DOM.

Method Summary

void
attributeDecl(String eName, String aName, String type, String mode, String value)
boolean
canPopulateEntityRefs()
May be overridden by subclasses to return true, indicating that entity reference nodes can be populated and then made read-only.
void
characters(ch[] , int start, int length)
void
comment(ch[] , int start, int length)
protected Text
createText(boolean isCDATA, ch[] , int start, int length)
Subclasses may overrride this method to provide a more efficient way to construct text nodes.
void
elementDecl(String name, String model)
void
endCDATA()
void
endDTD()
void
endDocument()
void
endElement(String uri, String localName, String qName)
void
endEntity(String name)
void
endPrefixMapping(String prefix)
void
externalEntityDecl(String name, String publicId, String SystemId)
protected Document
getDocument()
Returns the document under construction.
protected Node
getTop()
Returns the current node being populated.
void
ignorableWhitespace(ch[] , int start, int length)
void
internalEntityDecl(String name, String value)
void
notationDecl(String name, String publicId, String SystemId)
void
processingInstruction(String target, String data)
void
setDocumentLocator(Locator locator)
void
skippedEntity(String name)
void
startCDATA()
void
startDTD(String name, String publicId, String SystemId)
void
startDocument()
void
startElement(String uri, String localName, String qName, Attributes atts)
void
startEntity(String name)
void
startPrefixMapping(String prefix, String uri)
void
unparsedEntityDecl(String name, String publicId, String SystemId, String notationName)
void
xmlDecl(String version, String encoding, boolean standalone, String inputEncoding)
Reports the XML declaration.

Field Details

consumer

protected DomConsumer consumer

Constructor Details

Handler

protected Handler(DomConsumer consumer)
            throws SAXException
Subclasses may use SAX2 events to provide additional behaviors in the resulting DOM.

Method Details

attributeDecl

public void attributeDecl(String eName,
                          String aName,
                          String type,
                          String mode,
                          String value)
            throws SAXException
Specified by:
attributeDecl in interface DeclHandler

canPopulateEntityRefs

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

characters

public void characters(ch[] ,
                       int start,
                       int length)
            throws SAXException
Specified by:
characters in interface ContentHandler

comment

public void comment(ch[] ,
                    int start,
                    int length)
            throws SAXException
Specified by:
comment in interface LexicalHandler

createText

protected Text createText(boolean isCDATA,
                          ch[] ,
                          int start,
                          int length)
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.

elementDecl

public void elementDecl(String name,
                        String model)
            throws SAXException
Specified by:
elementDecl in interface DeclHandler

endCDATA

public void endCDATA()
            throws SAXException
Specified by:
endCDATA in interface LexicalHandler

endDTD

public void endDTD()
            throws SAXException
Specified by:
endDTD in interface LexicalHandler

endDocument

public void endDocument()
            throws SAXException
Specified by:
endDocument in interface ContentHandler

endElement

public void endElement(String uri,
                       String localName,
                       String qName)
            throws SAXException
Specified by:
endElement in interface ContentHandler

endEntity

public void endEntity(String name)
            throws SAXException
Specified by:
endEntity in interface LexicalHandler

endPrefixMapping

public void endPrefixMapping(String prefix)
            throws SAXException
Specified by:
endPrefixMapping in interface ContentHandler

externalEntityDecl

public void externalEntityDecl(String name,
                               String publicId,
                               String SystemId)
            throws SAXException
Specified by:
externalEntityDecl in interface DeclHandler

getDocument

protected Document getDocument()
Returns the document under construction.

getTop

protected Node getTop()
Returns the current node being populated. This is usually an Element or Document, but it might be an EntityReference node if some implementation-specific code knows how to put those into the result tree and later mark them as readonly.

ignorableWhitespace

public void ignorableWhitespace(ch[] ,
                                int start,
                                int length)
            throws SAXException
Specified by:
ignorableWhitespace in interface ContentHandler

internalEntityDecl

public void internalEntityDecl(String name,
                               String value)
            throws SAXException
Specified by:
internalEntityDecl in interface DeclHandler

notationDecl

public void notationDecl(String name,
                         String publicId,
                         String SystemId)
            throws SAXException
Specified by:
notationDecl in interface DTDHandler

processingInstruction

public void processingInstruction(String target,
                                  String data)
            throws SAXException
Specified by:
processingInstruction in interface ContentHandler

setDocumentLocator

public void setDocumentLocator(Locator locator)
Specified by:
setDocumentLocator in interface ContentHandler

skippedEntity

public void skippedEntity(String name)
            throws SAXException
Specified by:
skippedEntity in interface ContentHandler

startCDATA

public void startCDATA()
            throws SAXException
Specified by:
startCDATA in interface LexicalHandler

startDTD

public void startDTD(String name,
                     String publicId,
                     String SystemId)
            throws SAXException
Specified by:
startDTD in interface LexicalHandler

startDocument

public void startDocument()
            throws SAXException
Specified by:
startDocument in interface ContentHandler

startElement

public void startElement(String uri,
                         String localName,
                         String qName,
                         Attributes atts)
            throws SAXException
Specified by:
startElement in interface ContentHandler

startEntity

public void startEntity(String name)
            throws SAXException
Specified by:
startEntity in interface LexicalHandler

startPrefixMapping

public void startPrefixMapping(String prefix,
                               String uri)
            throws SAXException
Specified by:
startPrefixMapping in interface ContentHandler

unparsedEntityDecl

public void unparsedEntityDecl(String name,
                               String publicId,
                               String SystemId,
                               String notationName)
            throws SAXException
Specified by:
unparsedEntityDecl in interface DTDHandler

xmlDecl

public void xmlDecl(String version,
                    String encoding,
                    boolean standalone,
                    String inputEncoding)
            throws SAXException
Reports the XML declaration.
Specified by:
xmlDecl in interface ContentHandler2
Parameters:
version - the value of the version attribute in the XML declaration
encoding - the encoding specified in the XML declaration, if any
standalone - the standalone attribute from the XML declaration
inputEncoding - the encoding of the XML input