private class NodeCreateRule.NodeBuilder
extends org.xml.sax.helpers.DefaultHandler
Modifier and Type | Field and Description |
---|---|
protected int |
depth
Depth of the current node, relative to the element where the content
handler was put into action.
|
protected org.w3c.dom.Document |
doc
A DOM Document used to create the various Node instances.
|
protected org.xml.sax.ContentHandler |
oldContentHandler
The content handler used by Digester before it was set to this
content handler.
|
protected org.w3c.dom.Node |
root
The DOM node that will be pushed on Digester's stack.
|
protected org.w3c.dom.Node |
top
The current top DOM mode.
|
protected java.lang.StringBuffer |
topText
The text content of the current top DOM node.
|
Constructor and Description |
---|
NodeBuilder(org.w3c.dom.Document doc,
org.w3c.dom.Node root)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
private void |
addTextIfPresent()
Appends a
Text node to the current node
if the content reported by the parser is not purely whitespace. |
void |
characters(char[] ch,
int start,
int length)
Handle notification about text embedded within the current node.
|
void |
endElement(java.lang.String namespaceURI,
java.lang.String localName,
java.lang.String qName)
Checks whether control needs to be returned to Digester.
|
void |
processingInstruction(java.lang.String target,
java.lang.String data)
Adds a new
ProcessingInstruction to
the current node. |
void |
startElement(java.lang.String namespaceURI,
java.lang.String localName,
java.lang.String qName,
org.xml.sax.Attributes atts)
Adds a new child
Element to the current
node. |
protected org.xml.sax.ContentHandler oldContentHandler
protected int depth
protected org.w3c.dom.Document doc
protected org.w3c.dom.Node root
protected org.w3c.dom.Node top
protected java.lang.StringBuffer topText
public NodeBuilder(org.w3c.dom.Document doc, org.w3c.dom.Node root) throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException
Stores the content handler currently used by Digester so it can be reset when done, and initializes the DOM objects needed to build the node.
doc
- the document to use to create nodesroot
- the root nodejavax.xml.parsers.ParserConfigurationException
- if the DocumentBuilderFactory
could not be instantiatedorg.xml.sax.SAXException
- if the XMLReader could not be instantiated by
Digester (should not happen)private void addTextIfPresent() throws org.xml.sax.SAXException
Text
node to the current node
if the content reported by the parser is not purely whitespace.org.xml.sax.SAXException
public void characters(char[] ch, int start, int length) throws org.xml.sax.SAXException
An xml parser calls this when text is found. We need to ensure that this text gets attached to the new Node we are creating - except in the case where the only text in the node is whitespace.
There is a catch, however. According to the sax specification, a parser does not need to pass all of the text content of a node in one go; it can make multiple calls passing part of the data on each call. In particular, when the body of an element includes xml entity-references, at least some parsers make a separate call to this method to pass just the entity content.
In this method, we therefore just append the provided text to a "current text" buffer. When the element end is found, or a child element is found then we can check whether we have all-whitespace. See method addTextIfPresent.
characters
in interface org.xml.sax.ContentHandler
characters
in class org.xml.sax.helpers.DefaultHandler
ch
- the characters from the XML documentstart
- the start position in the arraylength
- the number of characters to read from the arrayorg.xml.sax.SAXException
- if the DOM implementation throws an exceptionpublic void endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName) throws org.xml.sax.SAXException
endElement
in interface org.xml.sax.ContentHandler
endElement
in class org.xml.sax.helpers.DefaultHandler
namespaceURI
- the namespace URIlocalName
- the local nameqName
- the qualified (prefixed) nameorg.xml.sax.SAXException
- if the DOM implementation throws an exceptionpublic void processingInstruction(java.lang.String target, java.lang.String data) throws org.xml.sax.SAXException
ProcessingInstruction
to
the current node.processingInstruction
in interface org.xml.sax.ContentHandler
processingInstruction
in class org.xml.sax.helpers.DefaultHandler
target
- the processing instruction targetdata
- the processing instruction data, or null if none was
suppliedorg.xml.sax.SAXException
- if the DOM implementation throws an exceptionpublic void startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts) throws org.xml.sax.SAXException
Element
to the current
node.startElement
in interface org.xml.sax.ContentHandler
startElement
in class org.xml.sax.helpers.DefaultHandler
namespaceURI
- the namespace URIlocalName
- the local nameqName
- the qualified (prefixed) nameatts
- the list of attributesorg.xml.sax.SAXException
- if the DOM implementation throws an exception