com.davisor.graphics.chart
Class ChartXMLDocumentHandler

java.lang.Object
  extended bycom.davisor.xml.sax.MultiDocumentHandler
      extended bycom.davisor.graphics.chart.ChartXMLDocumentHandler
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DocumentHandler, org.xml.sax.ErrorHandler

public class ChartXMLDocumentHandler
extends com.davisor.xml.sax.MultiDocumentHandler
implements org.xml.sax.ErrorHandler

ChartXMLDocumentHandler parses ChartAttributes and ChartXMLDataBuffers from XML documents. This DocumentHandler delegates the parsing of the XML document to either ChartXMLDataBuffer or ChartXMLAttributes depending on the tag that it encounters. The chart XML document starts with a <chart> root tag that contains <data> and <attributes> tags. The data tag starts a data section, which is parsed by a ChartXMLDataBuffer created at the time that ChartXMLDocumentHandler encounters the tag. The content of the attribute tag is parsed by ChartXMLAttributes, respectively. Data buffers and attributes constructed during the parsing are available through the getDataBuffer, getDataBuffers, getChartAttributes and getChartAttributesIterator methods.

See Also:
ChartXMLDataBuffer, ChartXMLAttributes

Field Summary
protected  org.xml.sax.ErrorHandler M_errorHandler
          XML error handler for reporting parsing errors.
 
Fields inherited from class com.davisor.xml.sax.MultiDocumentHandler
M_currentContentHandler, M_currentDocumentHandler, M_currentDocumentHandlers, M_currentDocumentTag, M_finishedDocumentHandlers, M_knownDocumentFactories, M_parser, M_xmlReader
 
Constructor Summary
ChartXMLDocumentHandler()
          Default constructor.
ChartXMLDocumentHandler(java.net.URL context)
          Constructs a new ChartXMLDocumentHandler that uses the specified URL context for loading images and textures.
ChartXMLDocumentHandler(java.net.URL context, java.util.Map extAttributes)
          Constructs a new ChartXMLDocumentHandler that uses the specified URL context for loading images and textures.
ChartXMLDocumentHandler(java.net.URL context, java.util.Map extAttributes, org.xml.sax.ErrorHandler errorHandler)
          Constructs a new ChartXMLDocumentHandler that uses the specified URL context for loading images and textures, and the specified error handler for reporting parsing errors.
ChartXMLDocumentHandler(java.net.URL context, java.io.Reader reader)
          Constructs a new ChartXMLDocumentHandler that will consume the character input stream and produce corresponding data buffers and attributes.
ChartXMLDocumentHandler(java.net.URL context, java.io.Reader reader, org.xml.sax.ErrorHandler errorHandler)
          Constructs a new ChartXMLDocumentHandler that will consume the character input stream and produce corresponding data buffers and attributes.
 
Method Summary
 Chart createChart()
          Creates a new chart from Chart XML.
 Chart createChart(java.lang.Number width, java.lang.Number height, java.lang.String chartType, java.lang.String contentType)
          Creates a new chart from Chart XML.
 void error(org.xml.sax.SAXParseException e)
          Receive notification of a recoverable error.
 void fatalError(org.xml.sax.SAXParseException e)
          Receive notification of a non-recoverable error.
 java.util.Iterator getAttributes()
          Gets an iterator over all chart attributes parsed from XML documents.
 java.util.Iterator getBuffers()
          Gets an iterator over all chart data buffers parsed from XML documents.
 ChartXMLAttributes getFirstAttributes()
          Gets the first chart attributes object parsed from XML documents
 ChartXMLDataBuffer getFirstDataBuffer()
          Gets the first chart data buffer parsed from XML documents
 void parse(java.io.Reader reader)
          Parses the input character stream and constructs ChartXMLDataBuffers and ChartXMLAttributes from that input.
 void parse(java.io.Reader reader, org.xml.sax.ErrorHandler errorHandler)
          Parses the input character stream and constructs ChartXMLDataBuffers and ChartXMLAttributes from that input.
 void warning(org.xml.sax.SAXParseException e)
          Receive notification of a warning.
 
Methods inherited from class com.davisor.xml.sax.MultiDocumentHandler
addDocumentHandlerFactory, addDocumentHandlerFactory, addDocumentHandlerFactory, addDocumentHandlerFactory, addDocumentHandlerFactory, addDocumentHandlerFactory, characters, endDocument, endElement, endElement, endPrefixMapping, getDocumentHandlers, getDocumentHandlers, getTags, ignorableWhitespace, popHandler, processingInstruction, pushHandler, removeDocumentHandlerFactory, removeDocumentHandlerFactory, removeDocumentHandlerFactory, removeDocumentHandlerFactory, removeDocumentHandlerFactory, removeDocumentHandlerFactory, removeDocumentHandlerFactory, setDocumentLocator, skippedEntity, startDocument, startElement, startElement, startPrefixMapping
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

M_errorHandler

protected org.xml.sax.ErrorHandler M_errorHandler
XML error handler for reporting parsing errors.

Constructor Detail

ChartXMLDocumentHandler

public ChartXMLDocumentHandler()
Default constructor.


ChartXMLDocumentHandler

public ChartXMLDocumentHandler(java.net.URL context,
                               java.util.Map extAttributes)
Constructs a new ChartXMLDocumentHandler that uses the specified URL context for loading images and textures.

Parameters:
context - URL context
extAttributes - external runtime attribute map (may be null)

ChartXMLDocumentHandler

public ChartXMLDocumentHandler(java.net.URL context)
Constructs a new ChartXMLDocumentHandler that uses the specified URL context for loading images and textures.


ChartXMLDocumentHandler

public ChartXMLDocumentHandler(java.net.URL context,
                               java.io.Reader reader)
                        throws java.io.IOException
Constructs a new ChartXMLDocumentHandler that will consume the character input stream and produce corresponding data buffers and attributes. The URL context is used for loading images and textures.


ChartXMLDocumentHandler

public ChartXMLDocumentHandler(java.net.URL context,
                               java.io.Reader reader,
                               org.xml.sax.ErrorHandler errorHandler)
                        throws java.io.IOException
Constructs a new ChartXMLDocumentHandler that will consume the character input stream and produce corresponding data buffers and attributes. The URL context is used for loading images and textures, and the error handler is used for reporting parsing errors.


ChartXMLDocumentHandler

public ChartXMLDocumentHandler(java.net.URL context,
                               java.util.Map extAttributes,
                               org.xml.sax.ErrorHandler errorHandler)
Constructs a new ChartXMLDocumentHandler that uses the specified URL context for loading images and textures, and the specified error handler for reporting parsing errors.

Parameters:
context - URL context
extAttributes - external runtime attribute map (may be null)
errorHandler - handler for reporting parsing errors (may be null)
Method Detail

error

public void error(org.xml.sax.SAXParseException e)
           throws org.xml.sax.SAXException
Receive notification of a recoverable error. Throws the error forward.

Specified by:
error in interface org.xml.sax.ErrorHandler
Throws:
org.xml.sax.SAXException

fatalError

public void fatalError(org.xml.sax.SAXParseException e)
                throws org.xml.sax.SAXException
Receive notification of a non-recoverable error. Throws the error forward.

Specified by:
fatalError in interface org.xml.sax.ErrorHandler
Throws:
org.xml.sax.SAXException

warning

public void warning(org.xml.sax.SAXParseException e)
             throws org.xml.sax.SAXException
Receive notification of a warning. Throws the warning error forward.

Specified by:
warning in interface org.xml.sax.ErrorHandler
Throws:
org.xml.sax.SAXException

getAttributes

public java.util.Iterator getAttributes()
Gets an iterator over all chart attributes parsed from XML documents.


getBuffers

public java.util.Iterator getBuffers()
Gets an iterator over all chart data buffers parsed from XML documents.


getFirstDataBuffer

public ChartXMLDataBuffer getFirstDataBuffer()
Gets the first chart data buffer parsed from XML documents

Returns:
the data buffer or null, if the document contained no chart data

getFirstAttributes

public ChartXMLAttributes getFirstAttributes()
Gets the first chart attributes object parsed from XML documents

Returns:
the chart attributes obejct or null, if the document contained no attributes

createChart

public Chart createChart()
                  throws ChartException
Creates a new chart from Chart XML.

Throws:
ChartException - if chart generation fails

createChart

public Chart createChart(java.lang.Number width,
                         java.lang.Number height,
                         java.lang.String chartType,
                         java.lang.String contentType)
                  throws ChartException
Creates a new chart from Chart XML. Any given non-null parameters will override corresponding XML attribute value. However, the original chart type will always remain available in underlying ChartXMLAttributes object, from where it can be retrieved with ChartXMLAttributes.getXMLChartType() method.

Parameters:
width - width (may be null)
height - height (may be null)
chartType - chart type (may be null)
contentType - image mime type (may be null)
Throws:
ChartException - if chart generation fails

parse

public void parse(java.io.Reader reader)
           throws java.io.IOException
Parses the input character stream and constructs ChartXMLDataBuffers and ChartXMLAttributes from that input. The URL context for images and textures, and error handler must have been provided at content or document handler construction time.

This implementation calls parse(Reader, ErrorHandler) with the set ErrorHandler, which might be null.

Parameters:
reader - character stream reader
Throws:
java.io.IOException
See Also:
parse(Reader, ErrorHandler)

parse

public void parse(java.io.Reader reader,
                  org.xml.sax.ErrorHandler errorHandler)
           throws java.io.IOException
Parses the input character stream and constructs ChartXMLDataBuffers and ChartXMLAttributes from that input. The URL context for images and textures, and error handler must have been provided at content or document handler construction time.

This implementation tries to use SAX2 compliant XMLReader constructed in MultiDocumentHandler for parsing. If XMLReader is not constructed but SAX1 compliant Parser is, uses Parser. If neither has been constructed, fails.

If the given ErrorHandler is null, this ChartXMLDocumentHandler is used as an ErrorHandler.

Parameters:
reader - character stream reader
errorHandler - handler for handling parsing errors (may be null)
Throws:
java.io.IOException
See Also:
ErrorHandler


Copyright © 2001-2004 Davisor Oy. All Rights Reserved.