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 TypeMethodDescriptionvoidcharacters(char[] ch, int start, int length) Override DefaultHandler characters.voidclose()Free any resources associated with this handler.voidCloses an open output streamvoidendElement(String uri, String localName, String qName) Override DefaultHandler endElement.protected ProductHandleropenContentStream(boolean encoded) Set up a piped output stream used during parsing.protected voidsetHandler(ProductHandler out) voidstartElement(String uri, String localName, String qName, Attributes attributes) Override DefaultHandler startElement.voidstreamTo(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, warningMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:
streamToin 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:
startElementin interfaceContentHandler- Overrides:
startElementin 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:
endElementin interfaceContentHandler- Overrides:
endElementin 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:
charactersin interfaceContentHandler- Overrides:
charactersin 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:
closein 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
-