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 StringBufferbuffer to hold contents of cdata section across multiple characters eventsprivate ElementThe current element we are onprivate intThe number of namespaces that are declared in the current scopeprivate DocumentThe document that is being builtprivate DOMDocumentFactoryThe factory used to create newDocumentinstancesprivate ElementStackstack ofElementobjectsprivate EntityResolverThe entity resolverprivate booleanShould we ignore commentsprivate InputSourceprivate booleanFlag used to indicate that we are inside a CDATA sectionprivate Locatorthe Locatorprivate booleanWhether adjacent text nodes should be mergedprivate NamespaceStackstack ofNamespaceandQNameobjectsprivate booleanHolds value of property stripWhitespaceText.private StringBufferBuffer used to concatenate text togetherprivate booleanHave we added text to the buffer -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddAttributes(Element element, Attributes attributes) protected voidaddDeclaredNamespaces(Element element) protected StringattributeNameForNamespace(Namespace namespace) voidcharacters(char[] ch, int start, int end) voidcomment(char[] ch, int start, int end) protected voidprotected Documentprotected ElementStackvoidendCDATA()voidvoidendDTD()voidendElement(String namespaceURI, String localName, String qName) voidvoidendPrefixMapping(String prefix) voiderror(SAXParseException exception) This method is called when an error is detected during parsing such as a validation error.voidfatalError(SAXParseException exception) This method is called when a fatal error occurs during parsing.Retrieves w3c document object built via generated sax events.private StringbooleanReturns whether we should ignore comments or not.booleanReturns whether adjacent text nodes should be merged together.booleanSets whether whitespace between element start and end tags should be ignoredvoidprocessingInstruction(String target, String data) voidsetDocumentLocator(Locator documentLocator) voidsetElementStack(ElementStack elementStack) voidsetEntityResolver(EntityResolver entityResolver) voidsetIgnoreComments(boolean ignoreComments) Sets whether we should ignore comments or not.voidsetInputSource(InputSource inputSource) voidsetMergeAdjacentText(boolean mergeAdjacentText) Sets whether or not adjacent text nodes should be merged together when parsing.voidsetStripWhitespaceText(boolean stripWhitespaceText) Sets whether whitespace between element start and end tags should be ignored.voidvoidvoidvoidstartElement(String namespaceURI, String localName, String qualifiedName, Attributes attributes) voidstartEntity(String name) voidstartPrefixMapping(String prefix, String uri) voidwarning(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, unparsedEntityDeclMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ContentHandler
declaration
-
Field Details
-
documentFactory
The factory used to create newDocumentinstances -
document
The document that is being built -
elementStack
stack ofElementobjects -
namespaceStack
stack ofNamespaceandQNameobjects -
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:
setDocumentLocatorin interfaceContentHandler- Overrides:
setDocumentLocatorin classDefaultHandler
-
processingInstruction
- Specified by:
processingInstructionin interfaceContentHandler- Overrides:
processingInstructionin classDefaultHandler- Throws:
SAXException
-
startPrefixMapping
- Specified by:
startPrefixMappingin interfaceContentHandler- Overrides:
startPrefixMappingin classDefaultHandler- Throws:
SAXException
-
endPrefixMapping
- Specified by:
endPrefixMappingin interfaceContentHandler- Overrides:
endPrefixMappingin classDefaultHandler- Throws:
SAXException
-
startDocument
- Specified by:
startDocumentin interfaceContentHandler- Overrides:
startDocumentin classDefaultHandler- Throws:
SAXException
-
endDocument
- Specified by:
endDocumentin interfaceContentHandler- Overrides:
endDocumentin classDefaultHandler- Throws:
SAXException
-
startElement
public void startElement(String namespaceURI, String localName, String qualifiedName, Attributes attributes) throws SAXException - Specified by:
startElementin interfaceContentHandler- Overrides:
startElementin classDefaultHandler- Throws:
SAXException
-
endElement
- Specified by:
endElementin interfaceContentHandler- Overrides:
endElementin classDefaultHandler- Throws:
SAXException
-
characters
- Specified by:
charactersin interfaceContentHandler- Overrides:
charactersin classDefaultHandler- Throws:
SAXException
-
warning
This method is called when a warning occurs during the parsing of the document. This method does nothing.- Specified by:
warningin interfaceErrorHandler- Overrides:
warningin 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:
errorin interfaceErrorHandler- Overrides:
errorin 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:
fatalErrorin interfaceErrorHandler- Overrides:
fatalErrorin classDefaultHandler- Parameters:
exception- DOCUMENT ME!- Throws:
SAXException- DOCUMENT ME!
-
startDTD
- Specified by:
startDTDin interfaceLexicalHandler- Throws:
SAXException
-
endDTD
- Specified by:
endDTDin interfaceLexicalHandler- Throws:
SAXException
-
startEntity
- Specified by:
startEntityin interfaceLexicalHandler- Throws:
SAXException
-
endEntity
- Specified by:
endEntityin interfaceLexicalHandler- Throws:
SAXException
-
startCDATA
- Specified by:
startCDATAin interfaceLexicalHandler- Throws:
SAXException
-
endCDATA
- Specified by:
endCDATAin interfaceLexicalHandler- Throws:
SAXException
-
comment
- Specified by:
commentin 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
-