Class NodeCreateRule.NodeBuilder
- All Implemented Interfaces:
ContentHandler
,DTDHandler
,EntityResolver
,ErrorHandler
- Enclosing class:
NodeCreateRule
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
Depth of the current node, relative to the element where the content handler was put into action.protected Document
A DOM Document used to create the various Node instances.protected ContentHandler
The content handler used by Digester before it was set to this content handler.protected Node
The DOM node that will be pushed on Digester's stack.protected Node
The current top DOM mode.protected StringBuffer
The text content of the current top DOM node. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
Appends aText
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
(String namespaceURI, String localName, String qName) Checks whether control needs to be returned to Digester.void
processingInstruction
(String target, String data) Adds a newProcessingInstruction
to the current node.void
startElement
(String namespaceURI, String localName, String qName, Attributes atts) Adds a new childElement
to the current node.Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
-
Field Details
-
oldContentHandler
The content handler used by Digester before it was set to this content handler. -
depth
protected int depthDepth of the current node, relative to the element where the content handler was put into action. -
doc
A DOM Document used to create the various Node instances. -
root
The DOM node that will be pushed on Digester's stack. -
top
The current top DOM mode. -
topText
The text content of the current top DOM node.
-
-
Constructor Details
-
NodeBuilder
Constructor.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.
- Parameters:
doc
- the document to use to create nodesroot
- the root node- Throws:
ParserConfigurationException
- if the DocumentBuilderFactory could not be instantiatedSAXException
- if the XMLReader could not be instantiated by Digester (should not happen)
-
-
Method Details
-
addTextIfPresent
Appends aText
node to the current node if the content reported by the parser is not purely whitespace.- Throws:
SAXException
-
characters
Handle notification about text embedded within the current node.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.
- Specified by:
characters
in interfaceContentHandler
- Overrides:
characters
in classDefaultHandler
- Parameters:
ch
- the characters from the XML documentstart
- the start position in the arraylength
- the number of characters to read from the array- Throws:
SAXException
- if the DOM implementation throws an exception
-
endElement
Checks whether control needs to be returned to Digester.- Specified by:
endElement
in interfaceContentHandler
- Overrides:
endElement
in classDefaultHandler
- Parameters:
namespaceURI
- the namespace URIlocalName
- the local nameqName
- the qualified (prefixed) name- Throws:
SAXException
- if the DOM implementation throws an exception
-
processingInstruction
Adds a newProcessingInstruction
to the current node.- Specified by:
processingInstruction
in interfaceContentHandler
- Overrides:
processingInstruction
in classDefaultHandler
- Parameters:
target
- the processing instruction targetdata
- the processing instruction data, or null if none was supplied- Throws:
SAXException
- if the DOM implementation throws an exception
-
startElement
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException Adds a new childElement
to the current node.- Specified by:
startElement
in interfaceContentHandler
- Overrides:
startElement
in classDefaultHandler
- Parameters:
namespaceURI
- the namespace URIlocalName
- the local nameqName
- the qualified (prefixed) nameatts
- the list of attributes- Throws:
SAXException
- if the DOM implementation throws an exception
-