Package org.dom4j.io
Class DOMSAXContentHandler
- java.lang.Object
-
- org.xml.sax.helpers.DefaultHandler
-
- org.dom4j.io.DOMSAXContentHandler
-
- All Implemented Interfaces:
org.xml.sax.ContentHandler,org.xml.sax.DTDHandler,org.xml.sax.EntityResolver,org.xml.sax.ErrorHandler,org.xml.sax.ext.LexicalHandler
public class DOMSAXContentHandler extends org.xml.sax.helpers.DefaultHandler implements org.xml.sax.ext.LexicalHandlerSAXContentHandlerbuilds W3C DOM object via SAX events.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringBuffercdataTextbuffer to hold contents of cdata section across multiple characters eventsprivate ElementcurrentElementThe current element we are onprivate intdeclaredNamespaceIndexThe number of namespaces that are declared in the current scopeprivate DocumentdocumentThe document that is being builtprivate DOMDocumentFactorydocumentFactoryThe factory used to create newDocumentinstancesprivate ElementStackelementStackstack ofElementobjectsprivate org.xml.sax.EntityResolverentityResolverThe entity resolverprivate booleanignoreCommentsShould we ignore commentsprivate org.xml.sax.InputSourceinputSourceprivate booleaninsideCDATASectionFlag used to indicate that we are inside a CDATA sectionprivate org.xml.sax.Locatorlocatorthe Locatorprivate booleanmergeAdjacentTextWhether adjacent text nodes should be mergedprivate NamespaceStacknamespaceStackstack ofNamespaceandQNameobjectsprivate booleanstripWhitespaceTextHolds value of property stripWhitespaceText.private java.lang.StringBuffertextBufferBuffer used to concatenate text togetherprivate booleantextInTextBufferHave we added text to the buffer
-
Constructor Summary
Constructors Constructor Description DOMSAXContentHandler()DOMSAXContentHandler(DOMDocumentFactory documentFactory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddAttributes(Element element, org.xml.sax.Attributes attributes)protected voidaddDeclaredNamespaces(Element element)protected java.lang.StringattributeNameForNamespace(Namespace namespace)voidcharacters(char[] ch, int start, int end)voidcomment(char[] ch, int start, int end)protected voidcompleteCurrentTextNode()protected DocumentcreateDocument()protected ElementStackcreateElementStack()voidendCDATA()voidendDocument()voidendDTD()voidendElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName)voidendEntity(java.lang.String name)voidendPrefixMapping(java.lang.String prefix)voiderror(org.xml.sax.SAXParseException exception)This method is called when an error is detected during parsing such as a validation error.voidfatalError(org.xml.sax.SAXParseException exception)This method is called when a fatal error occurs during parsing.org.w3c.dom.DocumentgetDocument()Retrieves w3c document object built via generated sax events.ElementStackgetElementStack()private java.lang.StringgetEncoding()org.xml.sax.EntityResolvergetEntityResolver()org.xml.sax.InputSourcegetInputSource()booleanisIgnoreComments()Returns whether we should ignore comments or not.booleanisMergeAdjacentText()Returns whether adjacent text nodes should be merged together.booleanisStripWhitespaceText()Sets whether whitespace between element start and end tags should be ignoredvoidprocessingInstruction(java.lang.String target, java.lang.String data)voidsetDocumentLocator(org.xml.sax.Locator documentLocator)voidsetElementStack(ElementStack elementStack)voidsetEntityResolver(org.xml.sax.EntityResolver entityResolver)voidsetIgnoreComments(boolean ignoreComments)Sets whether we should ignore comments or not.voidsetInputSource(org.xml.sax.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.voidstartCDATA()voidstartDocument()voidstartDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId)voidstartElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qualifiedName, org.xml.sax.Attributes attributes)voidstartEntity(java.lang.String name)voidstartPrefixMapping(java.lang.String prefix, java.lang.String uri)voidwarning(org.xml.sax.SAXParseException exception)This method is called when a warning occurs during the parsing of the document.
-
-
-
Field Detail
-
documentFactory
private DOMDocumentFactory documentFactory
The factory used to create newDocumentinstances
-
document
private Document document
The document that is being built
-
elementStack
private ElementStack elementStack
stack ofElementobjects
-
namespaceStack
private NamespaceStack namespaceStack
stack ofNamespaceandQNameobjects
-
locator
private org.xml.sax.Locator locator
the Locator
-
insideCDATASection
private boolean insideCDATASection
Flag used to indicate that we are inside a CDATA section
-
cdataText
private java.lang.StringBuffer cdataText
buffer to hold contents of cdata section across multiple characters events
-
declaredNamespaceIndex
private int declaredNamespaceIndex
The number of namespaces that are declared in the current scope
-
inputSource
private org.xml.sax.InputSource inputSource
-
currentElement
private Element currentElement
The current element we are on
-
entityResolver
private org.xml.sax.EntityResolver entityResolver
The entity resolver
-
mergeAdjacentText
private boolean mergeAdjacentText
Whether adjacent text nodes should be merged
-
textInTextBuffer
private boolean textInTextBuffer
Have we added text to the buffer
-
ignoreComments
private boolean ignoreComments
Should we ignore comments
-
textBuffer
private java.lang.StringBuffer textBuffer
Buffer used to concatenate text together
-
stripWhitespaceText
private boolean stripWhitespaceText
Holds value of property stripWhitespaceText.
-
-
Constructor Detail
-
DOMSAXContentHandler
public DOMSAXContentHandler()
-
DOMSAXContentHandler
public DOMSAXContentHandler(DOMDocumentFactory documentFactory)
-
-
Method Detail
-
getDocument
public org.w3c.dom.Document getDocument()
Retrieves w3c document object built via generated sax events.- Returns:
- the document that has been or is being built
-
setDocumentLocator
public void setDocumentLocator(org.xml.sax.Locator documentLocator)
- Specified by:
setDocumentLocatorin interfaceorg.xml.sax.ContentHandler- Overrides:
setDocumentLocatorin classorg.xml.sax.helpers.DefaultHandler
-
processingInstruction
public void processingInstruction(java.lang.String target, java.lang.String data) throws org.xml.sax.SAXException- Specified by:
processingInstructionin interfaceorg.xml.sax.ContentHandler- Overrides:
processingInstructionin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
startPrefixMapping
public void startPrefixMapping(java.lang.String prefix, java.lang.String uri) throws org.xml.sax.SAXException- Specified by:
startPrefixMappingin interfaceorg.xml.sax.ContentHandler- Overrides:
startPrefixMappingin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
endPrefixMapping
public void endPrefixMapping(java.lang.String prefix) throws org.xml.sax.SAXException- Specified by:
endPrefixMappingin interfaceorg.xml.sax.ContentHandler- Overrides:
endPrefixMappingin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
startDocument
public void startDocument() throws org.xml.sax.SAXException- Specified by:
startDocumentin interfaceorg.xml.sax.ContentHandler- Overrides:
startDocumentin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
endDocument
public void endDocument() throws org.xml.sax.SAXException- Specified by:
endDocumentin interfaceorg.xml.sax.ContentHandler- Overrides:
endDocumentin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
startElement
public void startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qualifiedName, org.xml.sax.Attributes attributes) throws org.xml.sax.SAXException- Specified by:
startElementin interfaceorg.xml.sax.ContentHandler- Overrides:
startElementin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
endElement
public void endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName) throws org.xml.sax.SAXException- Specified by:
endElementin interfaceorg.xml.sax.ContentHandler- Overrides:
endElementin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
characters
public void characters(char[] ch, int start, int end) throws org.xml.sax.SAXException- Specified by:
charactersin interfaceorg.xml.sax.ContentHandler- Overrides:
charactersin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
warning
public void warning(org.xml.sax.SAXParseException exception) throws org.xml.sax.SAXExceptionThis method is called when a warning occurs during the parsing of the document. This method does nothing.- Specified by:
warningin interfaceorg.xml.sax.ErrorHandler- Overrides:
warningin classorg.xml.sax.helpers.DefaultHandler- Parameters:
exception- DOCUMENT ME!- Throws:
org.xml.sax.SAXException- DOCUMENT ME!
-
error
public void error(org.xml.sax.SAXParseException exception) throws org.xml.sax.SAXExceptionThis method is called when an error is detected during parsing such as a validation error. This method rethrows the exception- Specified by:
errorin interfaceorg.xml.sax.ErrorHandler- Overrides:
errorin classorg.xml.sax.helpers.DefaultHandler- Parameters:
exception- DOCUMENT ME!- Throws:
org.xml.sax.SAXException- DOCUMENT ME!
-
fatalError
public void fatalError(org.xml.sax.SAXParseException exception) throws org.xml.sax.SAXExceptionThis method is called when a fatal error occurs during parsing. This method rethrows the exception- Specified by:
fatalErrorin interfaceorg.xml.sax.ErrorHandler- Overrides:
fatalErrorin classorg.xml.sax.helpers.DefaultHandler- Parameters:
exception- DOCUMENT ME!- Throws:
org.xml.sax.SAXException- DOCUMENT ME!
-
startDTD
public void startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId) throws org.xml.sax.SAXException- Specified by:
startDTDin interfaceorg.xml.sax.ext.LexicalHandler- Throws:
org.xml.sax.SAXException
-
endDTD
public void endDTD() throws org.xml.sax.SAXException- Specified by:
endDTDin interfaceorg.xml.sax.ext.LexicalHandler- Throws:
org.xml.sax.SAXException
-
startEntity
public void startEntity(java.lang.String name) throws org.xml.sax.SAXException- Specified by:
startEntityin interfaceorg.xml.sax.ext.LexicalHandler- Throws:
org.xml.sax.SAXException
-
endEntity
public void endEntity(java.lang.String name) throws org.xml.sax.SAXException- Specified by:
endEntityin interfaceorg.xml.sax.ext.LexicalHandler- Throws:
org.xml.sax.SAXException
-
startCDATA
public void startCDATA() throws org.xml.sax.SAXException- Specified by:
startCDATAin interfaceorg.xml.sax.ext.LexicalHandler- Throws:
org.xml.sax.SAXException
-
endCDATA
public void endCDATA() throws org.xml.sax.SAXException- Specified by:
endCDATAin interfaceorg.xml.sax.ext.LexicalHandler- Throws:
org.xml.sax.SAXException
-
comment
public void comment(char[] ch, int start, int end) throws org.xml.sax.SAXException- Specified by:
commentin interfaceorg.xml.sax.ext.LexicalHandler- Throws:
org.xml.sax.SAXException
-
getElementStack
public ElementStack getElementStack()
-
setElementStack
public void setElementStack(ElementStack elementStack)
-
getEntityResolver
public org.xml.sax.EntityResolver getEntityResolver()
-
setEntityResolver
public void setEntityResolver(org.xml.sax.EntityResolver entityResolver)
-
getInputSource
public org.xml.sax.InputSource getInputSource()
-
setInputSource
public void setInputSource(org.xml.sax.InputSource inputSource)
-
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
protected Document createDocument()
-
getEncoding
private java.lang.String getEncoding()
-
addDeclaredNamespaces
protected void addDeclaredNamespaces(Element element)
-
addAttributes
protected void addAttributes(Element element, org.xml.sax.Attributes attributes)
-
createElementStack
protected ElementStack createElementStack()
-
attributeNameForNamespace
protected java.lang.String attributeNameForNamespace(Namespace namespace)
-
-