Class XmlProductSource

  • All Implemented Interfaces:
    ProductSource, org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler
    Direct Known Subclasses:
    SearchResponseXmlProductSource

    public class XmlProductSource
    extends org.xml.sax.helpers.DefaultHandler
    implements ProductSource
    Load a product from an InputStream containing XML.
    • Constructor Summary

      Constructors 
      Constructor Description
      XmlProductSource​(ProductHandler out)
      Create a new XmlProductSource for embedding in another default handler.
      XmlProductSource​(java.io.InputStream in)
      Create a new XmlProductSource.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void characters​(char[] ch, int start, int length)
      Override DefaultHandler characters.
      void close()
      Free any resources associated with this handler.
      void closeContent()
      Closes an open output stream
      void endElement​(java.lang.String uri, java.lang.String localName, java.lang.String qName)
      Override DefaultHandler endElement.
      protected ProductHandler getHandler()  
      java.io.InputStream openContentStream​(boolean encoded)
      Set up a piped output stream used during parsing.
      protected void setHandler​(ProductHandler out)  
      void startElement​(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.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
    • Constructor Detail

      • XmlProductSource

        public XmlProductSource​(java.io.InputStream in)
        Create a new XmlProductSource.
        Parameters:
        in - the input stream where xml is read.
      • XmlProductSource

        public XmlProductSource​(ProductHandler out)
        Create a new XmlProductSource for embedding in another default handler.
        Parameters:
        out - the ProductHandler to receive product events.
    • Method Detail

      • streamTo

        public void streamTo​(ProductHandler out)
                      throws java.lang.Exception
        Begin reading the input stream, sending events to out.
        Specified by:
        streamTo in interface ProductSource
        Parameters:
        out - the receiving ProductOutput.
        Throws:
        java.lang.Exception - if error occurs
      • startElement

        public void startElement​(java.lang.String uri,
                                 java.lang.String localName,
                                 java.lang.String qName,
                                 org.xml.sax.Attributes attributes)
                          throws org.xml.sax.SAXException
        Override DefaultHandler startElement. Adds a new element content buffer and calls onStartElement.
        Specified by:
        startElement in interface org.xml.sax.ContentHandler
        Overrides:
        startElement in class org.xml.sax.helpers.DefaultHandler
        Parameters:
        uri - element uri.
        localName - element localName.
        qName - element qName.
        attributes - element attributes.
        Throws:
        org.xml.sax.SAXException - if onStartElement throws a SAXException.
      • endElement

        public void endElement​(java.lang.String uri,
                               java.lang.String localName,
                               java.lang.String qName)
                        throws org.xml.sax.SAXException
        Override DefaultHandler endElement. Retrieves element content buffer and passes it to onEndElement.
        Specified by:
        endElement in interface org.xml.sax.ContentHandler
        Overrides:
        endElement in class org.xml.sax.helpers.DefaultHandler
        Parameters:
        uri - element uri.
        localName - element localName.
        qName - element qName.
        Throws:
        org.xml.sax.SAXException - if onEndElement throws a SAXException.
      • characters

        public void characters​(char[] ch,
                               int start,
                               int length)
                        throws org.xml.sax.SAXException
        Override DefaultHandler characters. Appends content to current element buffer, or skips if before first element.
        Specified by:
        characters in interface org.xml.sax.ContentHandler
        Overrides:
        characters in class org.xml.sax.helpers.DefaultHandler
        Parameters:
        ch - content.
        start - position in content to read.
        length - lenth of content to read.
        Throws:
        org.xml.sax.SAXException - never.
      • getHandler

        protected ProductHandler getHandler()
        Returns:
        ProductHandler
      • setHandler

        protected void setHandler​(ProductHandler out)
        Parameters:
        out - ProductHandler to set
      • close

        public void close()
        Free any resources associated with this handler.
        Specified by:
        close in interface ProductSource
      • openContentStream

        public java.io.InputStream openContentStream​(boolean encoded)
                                              throws java.io.IOException
        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 in closeContent(). 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:
        java.io.IOException - if io error occurs
      • closeContent

        public void closeContent()
        Closes an open output stream