Package gov.usgs.earthquake.product.io
Class XmlProductSource
java.lang.Object
org.xml.sax.helpers.DefaultHandler
gov.usgs.earthquake.product.io.XmlProductSource
- All Implemented Interfaces:
ProductSource
,ContentHandler
,DTDHandler
,EntityResolver
,ErrorHandler
- Direct Known Subclasses:
SearchResponseXmlProductSource
Load a product from an InputStream containing XML.
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a new XmlProductSource for embedding in another default handler.Create a new XmlProductSource. -
Method Summary
Modifier and TypeMethodDescriptionvoid
characters
(char[] ch, int start, int length) Override DefaultHandler characters.void
close()
Free any resources associated with this handler.void
Closes an open output streamvoid
endElement
(String uri, String localName, String qName) Override DefaultHandler endElement.protected ProductHandler
openContentStream
(boolean encoded) Set up a piped output stream used during parsing.protected void
setHandler
(ProductHandler out) void
startElement
(String uri, String localName, String qName, Attributes attributes) Override DefaultHandler startElement.void
streamTo
(ProductHandler out) Begin reading the input stream, sending events to out.Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.xml.sax.ContentHandler
declaration
-
Constructor Details
-
XmlProductSource
Create a new XmlProductSource.- Parameters:
in
- the input stream where xml is read.
-
XmlProductSource
Create a new XmlProductSource for embedding in another default handler.- Parameters:
out
- the ProductHandler to receive product events.
-
-
Method Details
-
streamTo
Begin reading the input stream, sending events to out.- Specified by:
streamTo
in interfaceProductSource
- Parameters:
out
- the receiving ProductOutput.- Throws:
Exception
- if error occurs
-
startElement
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException Override DefaultHandler startElement. Adds a new element content buffer and calls onStartElement.- Specified by:
startElement
in interfaceContentHandler
- Overrides:
startElement
in classDefaultHandler
- Parameters:
uri
- element uri.localName
- element localName.qName
- element qName.attributes
- element attributes.- Throws:
SAXException
- if onStartElement throws a SAXException.
-
endElement
Override DefaultHandler endElement. Retrieves element content buffer and passes it to onEndElement.- Specified by:
endElement
in interfaceContentHandler
- Overrides:
endElement
in classDefaultHandler
- Parameters:
uri
- element uri.localName
- element localName.qName
- element qName.- Throws:
SAXException
- if onEndElement throws a SAXException.
-
characters
Override DefaultHandler characters. Appends content to current element buffer, or skips if before first element.- Specified by:
characters
in interfaceContentHandler
- Overrides:
characters
in classDefaultHandler
- Parameters:
ch
- content.start
- position in content to read.length
- lenth of content to read.- Throws:
SAXException
- never.
-
getHandler
- Returns:
- ProductHandler
-
setHandler
- Parameters:
out
- ProductHandler to set
-
close
public void close()Free any resources associated with this handler.- Specified by:
close
in interfaceProductSource
-
openContentStream
Set up a piped output stream used during parsing. The XmlProductSource parsing thread starts a background thread to deliver content to the handler, then continues parsing XML and delivers parsed content via the piped streams. If xml parsing completes as expected, the parsing thread will close the connection incloseContent()
. If errors occur, the objects handling the product source object call closeContent to ensure the resource is closed.- Parameters:
encoded
- if it needs to decode base 64 content- Returns:
- a input stream of the Piped output stream
- Throws:
IOException
- if io error occurs
-
closeContent
public void closeContent()Closes an open output stream
-