com.endeca.portal.export
Class CSVSAXHandler

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by com.endeca.portal.export.CSVSAXHandler
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

public class CSVSAXHandler
extends org.xml.sax.helpers.DefaultHandler

This file was written with the goal of parsing large blocks of XML consisting of records from the conversation service, and converting them into a CSV format. Use this ContentHandler with an XML reader when the using the default ContentHandler is impractical because of the size of the XML object being read. Example: ContentHandler saxWriter = new CSVSAXHandler(outputStream, gridColumnNames); XMLReader xr = XMLReaderFactory.createXMLReader(); xr.setContentHandler(saxWriter); High-level processing flow of this class: 1) At the start of every XML element, call startElement(). a) if the XML element is a , set writingRecord flag to true b) if writingRecord is already true, it means we are parsing an attribute inside a record i) if the current attribute has a display value, insert/append that value to the attribute in the column map and set the useElementContents to false 2) For the text content between start/end of every XML element, call characters() a) if the writingRecord and useElementContents flags are both true, insert/append the text content to the attribute in the column map b) If this is the second time characters has been called in a row without another call to startElement, this is treated as a continuation of the string by the parser, and not a multi-assign. As such, it is not delimited. 3) At the end of every XML element, call endElement(). a) if the XML element is a , then: i) set writingRecord flag to false ii) write everything in the column map to the browser as CSV iii) clear the column map


Constructor Summary
CSVSAXHandler(java.io.OutputStream outFile, java.lang.String[] gridCols, java.util.List<Formatter> attributeFormatterList, java.lang.String propertySeparator, java.lang.String propertyEncloser)
           
 
Method Summary
 void characters(char[] ch, int start, int length)
           
 void endElement(java.lang.String nameSpaceURI, java.lang.String localName, java.lang.String qName)
           
 void startElement(java.lang.String nameSpaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts)
           
 
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

CSVSAXHandler

public CSVSAXHandler(java.io.OutputStream outFile,
                     java.lang.String[] gridCols,
                     java.util.List<Formatter> attributeFormatterList,
                     java.lang.String propertySeparator,
                     java.lang.String propertyEncloser)
Method Detail

startElement

public void startElement(java.lang.String nameSpaceURI,
                         java.lang.String localName,
                         java.lang.String qName,
                         org.xml.sax.Attributes atts)
                  throws org.xml.sax.SAXException
Specified by:
startElement in interface org.xml.sax.ContentHandler
Overrides:
startElement in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws org.xml.sax.SAXException
Specified by:
characters in interface org.xml.sax.ContentHandler
Overrides:
characters in class org.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:
endElement in interface org.xml.sax.ContentHandler
Overrides:
endElement in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException