fi.karppinen.gnu.xml.pipeline
Class DomConsumer.Handler

java.lang.Object
  extended by fi.karppinen.gnu.xml.pipeline.DomConsumer.Handler
All Implemented Interfaces:
ContentHandler, DTDHandler, DeclHandler, LexicalHandler
Enclosing class:
DomConsumer

public static class DomConsumer.Handler
extends Object
implements ContentHandler, 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
private  AttributesImpl attributes
           
protected  DomConsumer consumer
           
private  String currentEntity
           
private  Document document
           
private  DOMImplementation impl
           
private  boolean inCDATA
           
private  boolean inDTD
           
private  boolean isL2
           
private  Locator locator
           
private  boolean mergeCDATA
           
private  boolean recreatedAttrs
           
private  Node top
           
(package private) static String xmlnsURI
           
 
Constructor Summary
protected DomConsumer.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(char[] ch, int start, int length)
           
(package private)  Document clearDocument()
          Returns and forgets the document produced.
 void comment(char[] ch, int start, int length)
           
protected  Text createText(boolean isCDATA, char[] 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 endDocument()
           
 void endDTD()
           
 void endElement(String uri, String localName, String qName)
           
 void endEntity(String name)
           
 void endPrefixMapping(String prefix)
           
 void externalEntityDecl(String name, String publicId, String SystemId)
           
private  void fatal(String message, Exception x)
           
protected  Document getDocument()
          Returns the document under construction.
private  String getNamespace(String prefix, Attributes attrs)
           
private  String getPrefix(String name)
           
protected  Node getTop()
          Returns the current node being populated.
 void ignorableWhitespace(char[] ch, int start, int length)
           
 void internalEntityDecl(String name, String value)
           
private  void namespaceError(String description)
           
 void notationDecl(String name, String publicId, String SystemId)
           
private  void populateAttributes(Element element, Attributes attrs)
           
 void processingInstruction(String target, String data)
           
 void setDocumentLocator(Locator locator)
           
 void skippedEntity(String name)
           
 void startCDATA()
           
 void startDocument()
           
 void startDTD(String name, String publicId, String SystemId)
           
 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)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

consumer

protected DomConsumer consumer

impl

private DOMImplementation impl

document

private Document document

isL2

private boolean isL2

locator

private Locator locator

top

private Node top

inCDATA

private boolean inCDATA

mergeCDATA

private boolean mergeCDATA

inDTD

private boolean inDTD

currentEntity

private String currentEntity

recreatedAttrs

private boolean recreatedAttrs

attributes

private AttributesImpl attributes

xmlnsURI

static final String xmlnsURI
See Also:
Constant Field Values
Constructor Detail

DomConsumer.Handler

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

Throws:
SAXException
Method Detail

fatal

private void fatal(String message,
                   Exception x)
            throws SAXException
Throws:
SAXException

clearDocument

Document clearDocument()
Returns and forgets the document produced. If the handler is reused, a new document may be created.


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.


setDocumentLocator

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

startDocument

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

endDocument

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

processingInstruction

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

createText

protected Text createText(boolean isCDATA,
                          char[] 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 StringBuilder. 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.


characters

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

skippedEntity

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

startPrefixMapping

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

endPrefixMapping

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

startElement

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

populateAttributes

private void populateAttributes(Element element,
                                Attributes attrs)
                         throws SAXParseException
Throws:
SAXParseException

getPrefix

private String getPrefix(String name)

getNamespace

private String getNamespace(String prefix,
                            Attributes attrs)
                     throws SAXParseException
Throws:
SAXParseException

endElement

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

ignorableWhitespace

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

startCDATA

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

endCDATA

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

startDTD

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

endDTD

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

comment

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

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.


startEntity

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

endEntity

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

notationDecl

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

unparsedEntityDecl

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

elementDecl

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

attributeDecl

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

internalEntityDecl

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

externalEntityDecl

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

namespaceError

private void namespaceError(String description)
                     throws SAXParseException
Throws:
SAXParseException