Class DOMSAXContentHandler
java.lang.Object
org.xml.sax.helpers.DefaultHandler
org.dom4j.io.DOMSAXContentHandler
- All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler, LexicalHandler
SAXContentHandler
builds W3C DOM object via SAX events.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate StringBuffer
buffer to hold contents of cdata section across multiple characters eventsprivate Element
The current element we are onprivate int
The number of namespaces that are declared in the current scopeprivate Document
The document that is being builtprivate DOMDocumentFactory
The factory used to create newDocument
instancesprivate ElementStack
stack ofElement
objectsprivate EntityResolver
The entity resolverprivate boolean
Should we ignore commentsprivate InputSource
private boolean
Flag used to indicate that we are inside a CDATA sectionprivate Locator
the Locatorprivate boolean
Whether adjacent text nodes should be mergedprivate NamespaceStack
stack ofNamespace
andQName
objectsprivate boolean
Holds value of property stripWhitespaceText.private StringBuffer
Buffer used to concatenate text togetherprivate boolean
Have we added text to the buffer -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addAttributes
(Element element, Attributes attributes) protected void
addDeclaredNamespaces
(Element element) protected String
attributeNameForNamespace
(Namespace namespace) void
characters
(char[] ch, int start, int end) void
comment
(char[] ch, int start, int end) protected void
protected Document
protected ElementStack
void
endCDATA()
void
void
endDTD()
void
endElement
(String namespaceURI, String localName, String qName) void
void
endPrefixMapping
(String prefix) void
error
(SAXParseException exception) This method is called when an error is detected during parsing such as a validation error.void
fatalError
(SAXParseException exception) This method is called when a fatal error occurs during parsing.Retrieves w3c document object built via generated sax events.private String
boolean
Returns whether we should ignore comments or not.boolean
Returns whether adjacent text nodes should be merged together.boolean
Sets whether whitespace between element start and end tags should be ignoredvoid
processingInstruction
(String target, String data) void
setDocumentLocator
(Locator documentLocator) void
setElementStack
(ElementStack elementStack) void
setEntityResolver
(EntityResolver entityResolver) void
setIgnoreComments
(boolean ignoreComments) Sets whether we should ignore comments or not.void
setInputSource
(InputSource inputSource) void
setMergeAdjacentText
(boolean mergeAdjacentText) Sets whether or not adjacent text nodes should be merged together when parsing.void
setStripWhitespaceText
(boolean stripWhitespaceText) Sets whether whitespace between element start and end tags should be ignored.void
void
void
void
startElement
(String namespaceURI, String localName, String qualifiedName, Attributes attributes) void
startEntity
(String name) void
startPrefixMapping
(String prefix, String uri) void
warning
(SAXParseException exception) This method is called when a warning occurs during the parsing of the document.Methods inherited from class DefaultHandler
ignorableWhitespace, notationDecl, resolveEntity, skippedEntity, unparsedEntityDecl
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface ContentHandler
declaration
-
Field Details
-
documentFactory
The factory used to create newDocument
instances -
document
The document that is being built -
elementStack
stack ofElement
objects -
namespaceStack
stack ofNamespace
andQName
objects -
locator
the Locator -
insideCDATASection
private boolean insideCDATASectionFlag used to indicate that we are inside a CDATA section -
cdataText
buffer to hold contents of cdata section across multiple characters events -
declaredNamespaceIndex
private int declaredNamespaceIndexThe number of namespaces that are declared in the current scope -
inputSource
-
currentElement
The current element we are on -
entityResolver
The entity resolver -
mergeAdjacentText
private boolean mergeAdjacentTextWhether adjacent text nodes should be merged -
textInTextBuffer
private boolean textInTextBufferHave we added text to the buffer -
ignoreComments
private boolean ignoreCommentsShould we ignore comments -
textBuffer
Buffer used to concatenate text together -
stripWhitespaceText
private boolean stripWhitespaceTextHolds value of property stripWhitespaceText.
-
-
Constructor Details
-
DOMSAXContentHandler
public DOMSAXContentHandler() -
DOMSAXContentHandler
-
-
Method Details
-
getDocument
Retrieves w3c document object built via generated sax events.- Returns:
- the document that has been or is being built
-
setDocumentLocator
- Specified by:
setDocumentLocator
in interfaceContentHandler
- Overrides:
setDocumentLocator
in classDefaultHandler
-
processingInstruction
- Specified by:
processingInstruction
in interfaceContentHandler
- Overrides:
processingInstruction
in classDefaultHandler
- Throws:
SAXException
-
startPrefixMapping
- Specified by:
startPrefixMapping
in interfaceContentHandler
- Overrides:
startPrefixMapping
in classDefaultHandler
- Throws:
SAXException
-
endPrefixMapping
- Specified by:
endPrefixMapping
in interfaceContentHandler
- Overrides:
endPrefixMapping
in classDefaultHandler
- Throws:
SAXException
-
startDocument
- Specified by:
startDocument
in interfaceContentHandler
- Overrides:
startDocument
in classDefaultHandler
- Throws:
SAXException
-
endDocument
- Specified by:
endDocument
in interfaceContentHandler
- Overrides:
endDocument
in classDefaultHandler
- Throws:
SAXException
-
startElement
public void startElement(String namespaceURI, String localName, String qualifiedName, Attributes attributes) throws SAXException - Specified by:
startElement
in interfaceContentHandler
- Overrides:
startElement
in classDefaultHandler
- Throws:
SAXException
-
endElement
- Specified by:
endElement
in interfaceContentHandler
- Overrides:
endElement
in classDefaultHandler
- Throws:
SAXException
-
characters
- Specified by:
characters
in interfaceContentHandler
- Overrides:
characters
in classDefaultHandler
- Throws:
SAXException
-
warning
This method is called when a warning occurs during the parsing of the document. This method does nothing.- Specified by:
warning
in interfaceErrorHandler
- Overrides:
warning
in classDefaultHandler
- Parameters:
exception
- DOCUMENT ME!- Throws:
SAXException
- DOCUMENT ME!
-
error
This method is called when an error is detected during parsing such as a validation error. This method rethrows the exception- Specified by:
error
in interfaceErrorHandler
- Overrides:
error
in classDefaultHandler
- Parameters:
exception
- DOCUMENT ME!- Throws:
SAXException
- DOCUMENT ME!
-
fatalError
This method is called when a fatal error occurs during parsing. This method rethrows the exception- Specified by:
fatalError
in interfaceErrorHandler
- Overrides:
fatalError
in classDefaultHandler
- Parameters:
exception
- DOCUMENT ME!- Throws:
SAXException
- DOCUMENT ME!
-
startDTD
- Specified by:
startDTD
in interfaceLexicalHandler
- Throws:
SAXException
-
endDTD
- Specified by:
endDTD
in interfaceLexicalHandler
- Throws:
SAXException
-
startEntity
- Specified by:
startEntity
in interfaceLexicalHandler
- Throws:
SAXException
-
endEntity
- Specified by:
endEntity
in interfaceLexicalHandler
- Throws:
SAXException
-
startCDATA
- Specified by:
startCDATA
in interfaceLexicalHandler
- Throws:
SAXException
-
endCDATA
- Specified by:
endCDATA
in interfaceLexicalHandler
- Throws:
SAXException
-
comment
- Specified by:
comment
in interfaceLexicalHandler
- Throws:
SAXException
-
getElementStack
-
setElementStack
-
getEntityResolver
-
setEntityResolver
-
getInputSource
-
setInputSource
-
isMergeAdjacentText
public boolean isMergeAdjacentText()Returns whether adjacent text nodes should be merged together.- Returns:
- Value of property mergeAdjacentText.
-
setMergeAdjacentText
public void setMergeAdjacentText(boolean mergeAdjacentText) Sets whether or not adjacent text nodes should be merged together when parsing.- Parameters:
mergeAdjacentText
- New value of property mergeAdjacentText.
-
isStripWhitespaceText
public boolean isStripWhitespaceText()Sets whether whitespace between element start and end tags should be ignored- Returns:
- Value of property stripWhitespaceText.
-
setStripWhitespaceText
public void setStripWhitespaceText(boolean stripWhitespaceText) Sets whether whitespace between element start and end tags should be ignored.- Parameters:
stripWhitespaceText
- New value of property stripWhitespaceText.
-
isIgnoreComments
public boolean isIgnoreComments()Returns whether we should ignore comments or not.- Returns:
- boolean
-
setIgnoreComments
public void setIgnoreComments(boolean ignoreComments) Sets whether we should ignore comments or not.- Parameters:
ignoreComments
- whether we should ignore comments or not.
-
completeCurrentTextNode
protected void completeCurrentTextNode() -
createDocument
-
getEncoding
-
addDeclaredNamespaces
-
addAttributes
-
createElementStack
-
attributeNameForNamespace
-