Class FilteredSaxHandler
- java.lang.Object
-
- org.xml.sax.helpers.DefaultHandler
-
- org.jdom.input.SAXHandler
-
- com.biomatters.geneious.publicapi.utilities.xml.FilteredSaxHandler
-
- All Implemented Interfaces:
org.xml.sax.ContentHandler
,org.xml.sax.DTDHandler
,org.xml.sax.EntityResolver
,org.xml.sax.ErrorHandler
,org.xml.sax.ext.DeclHandler
,org.xml.sax.ext.LexicalHandler
public class FilteredSaxHandler extends org.jdom.input.SAXHandler
A Sax Handler that provides full jdom Elements for specified element names. The elements are detached from their parent elements, which allows parsing of XML files that are too large to fit in memory. Typically this class is used withFastSaxBuilder
by overridingFastSaxBuilder.createContentHandler()
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
FilteredSaxHandler.ElementHandler
-
Constructor Summary
Constructors Constructor Description FilteredSaxHandler(java.util.List<java.lang.String> elementNamesToMatch, FilteredSaxHandler.ElementHandler elementHandler, long maximumExpectedSize)
Creates a sax handler that provides elements matching a given name pattern to a callback.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
characters(char[] ch, int start, int length)
void
clearTextBufferCache()
void
endElement(java.lang.String namespace, java.lang.String localName, java.lang.String qName)
protected void
flushCharacters()
protected void
flushCharactersAtElementEnd()
void
setIgnoreBoundaryWhitespaceWithSiblings(boolean ignoringWhiteWithSiblings)
Similar toSAXHandler.setIgnoringBoundaryWhitespace(boolean)
except that we only eliminate text nodes that have siblings.void
startElement(java.lang.String namespace, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attributes)
-
Methods inherited from class org.jdom.input.SAXHandler
attributeDecl, comment, elementDecl, endCDATA, endDTD, endEntity, externalEntityDecl, flushCharacters, getCurrentElement, getDocument, getDocumentLocator, getExpandEntities, getFactory, getIgnoringBoundaryWhitespace, getIgnoringElementContentWhitespace, ignorableWhitespace, internalEntityDecl, notationDecl, processingInstruction, pushElement, setDocumentLocator, setExpandEntities, setIgnoringBoundaryWhitespace, setIgnoringElementContentWhitespace, skippedEntity, startCDATA, startDocument, startDTD, startEntity, startPrefixMapping, unparsedEntityDecl
-
-
-
-
Constructor Detail
-
FilteredSaxHandler
public FilteredSaxHandler(java.util.List<java.lang.String> elementNamesToMatch, FilteredSaxHandler.ElementHandler elementHandler, long maximumExpectedSize)
Creates a sax handler that provides elements matching a given name pattern to a callback.- Parameters:
elementNamesToMatch
- the names of elements to report to elementHandler. These are slash (/) separated element names where * represents any element name. e.g. "rootElementName/childElementName" or "rootElementName/*"elementHandler
- a callback to report all elements matching elementNamesToMatch are reported to. The matching elements will be detached from their parent element, allowing parsing of XML files that are too large to fit in memory.maximumExpectedSize
- the maximum size in bytes of the data that will be read from the input stream. This is used to allocate more appropriate buffer sizes and hence reduce memory usage and increase speed. This may be <=0 in which case performance and memory usage may not be as good.
-
-
Method Detail
-
startElement
public void startElement(java.lang.String namespace, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attributes) throws org.xml.sax.SAXException
- Specified by:
startElement
in interfaceorg.xml.sax.ContentHandler
- Overrides:
startElement
in classorg.jdom.input.SAXHandler
- Throws:
org.xml.sax.SAXException
-
endElement
public void endElement(java.lang.String namespace, java.lang.String localName, java.lang.String qName) throws org.xml.sax.SAXException
- Specified by:
endElement
in interfaceorg.xml.sax.ContentHandler
- Overrides:
endElement
in classorg.jdom.input.SAXHandler
- Throws:
org.xml.sax.SAXException
-
setIgnoreBoundaryWhitespaceWithSiblings
public void setIgnoreBoundaryWhitespaceWithSiblings(boolean ignoringWhiteWithSiblings)
Similar toSAXHandler.setIgnoringBoundaryWhitespace(boolean)
except that we only eliminate text nodes that have siblings. e.g.<x><y> </y></x>
will preserve the space text in y.
But<x><y> <z></z></y></x>
will not preserve the space text in y which is a sibling to "z".- Parameters:
ignoringWhiteWithSiblings
- Whether to ignore only whitespace content
-
characters
public void characters(char[] ch, int start, int length) throws org.xml.sax.SAXException
- Specified by:
characters
in interfaceorg.xml.sax.ContentHandler
- Overrides:
characters
in classorg.jdom.input.SAXHandler
- Throws:
org.xml.sax.SAXException
-
flushCharacters
protected void flushCharacters() throws org.xml.sax.SAXException
- Overrides:
flushCharacters
in classorg.jdom.input.SAXHandler
- Throws:
org.xml.sax.SAXException
-
flushCharactersAtElementEnd
protected void flushCharactersAtElementEnd() throws org.xml.sax.SAXException
- Overrides:
flushCharactersAtElementEnd
in classorg.jdom.input.SAXHandler
- Throws:
org.xml.sax.SAXException
-
clearTextBufferCache
public void clearTextBufferCache()
-
-