jimm.datavision
Class ReportReader

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by jimm.datavision.ReportReader
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler
Direct Known Subclasses:
DbConnReader

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

A report reader reads an XML file and creates the innards of a report.

Author:
Jim Menard, jimm@io.com

Nested Class Summary
(package private) static class ReportReader.FormulaConversion
          This class is used when we are converting formulas from the old pre-DTD_VERSION_FORMULA_IDS format to the new format.
 
Field Summary
protected  Border border
           
protected static double DEFAULT_DTD_VERSION
          If there is no report element dtd-version attribute, this is the default value to use.
protected static double DTD_VERSION_FORMULA_IDS
          This is the DTD version where formula ids were introduced.
protected  double dtdVersion
           
protected  Field field
           
protected  Formula formula
           
protected  java.util.HashMap formulasToConvert
           
protected  Group group
           
protected  boolean inSubreportJoins
           
protected  Line line
           
protected  boolean missingColumnSeen
           
protected  int nextSectionLocation
           
protected  Parameter parameter
           
protected  Report report
           
protected  Section section
           
protected  Subreport subreport
           
protected  java.util.Stack tagNameStack
           
protected  java.lang.String textData
           
protected  UserColumn usercol
           
 
Constructor Summary
ReportReader(Report report)
          Constructor.
 
Method Summary
protected  void addSectionToReport()
          Adds the last seen section to the report.
protected  void border(org.xml.sax.Attributes attributes)
          Reads and creates a new field border.
protected  void bounds(org.xml.sax.Attributes attributes)
          Reads and sets the current field's bounds rectangle.
 void characters(char[] ch, int start, int length)
          Reads text data.
protected  void charSepSource(org.xml.sax.Attributes attributes)
          Reads and creates a CharSepSource.
protected  void column(org.xml.sax.Attributes attributes)
           
protected  void convertFormulas()
          Revisits each formula and let it convert formula names to formula id numbers within its eval string.
protected  void database(org.xml.sax.Attributes attributes)
          Reads the database tag and creates the database object.
protected  void defaultLanguage(org.xml.sax.Attributes attributes)
           
protected  void edge(org.xml.sax.Attributes attributes)
          Reads and creates a new border edge.
 void endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName)
          Handle elements expecting text data.
protected  void ensureNotEmpty(SectionArea area)
          Ensures that the specified collection of sections is not empty.
protected  void field(org.xml.sax.Attributes attributes)
          Reads and creates a field.
protected  Column findColumn(java.lang.String fullName)
          Returns the column identified by its name.
protected  Selectable findSelectable(java.lang.String idStr, java.lang.String typeStr)
          Returns the selectable identified by its id and type.
protected  void footer(java.lang.String parentTag)
           
protected  void format(org.xml.sax.Attributes attributes)
          Reads and creates the current field's format.
protected  void formula(java.lang.String parentTag, org.xml.sax.Attributes attributes)
          Reads a formula.
protected  Report getReport()
           
protected  void group(org.xml.sax.Attributes attributes)
          Creates a group and adds it to the report.
protected  void header(java.lang.String parentTag)
           
protected  void join(org.xml.sax.Attributes attributes)
           
protected  void language(org.xml.sax.Attributes attributes)
           
protected  void line(org.xml.sax.Attributes attributes)
          Reads and creates a new line.
protected  void ncDatabaseSource(org.xml.sax.Attributes attributes)
          Reads and creates an NCDatabase data source.
protected  void paper(org.xml.sax.Attributes attributes)
          Reads paper size name and orientation.
protected  void parameter(org.xml.sax.Attributes attributes)
           
protected  java.awt.Color parseColor(java.lang.String val)
          Parses color string and returns a java.awt.Color.
protected  void point(org.xml.sax.Attributes attributes)
          Reads a line's point and adds it to the current line.
protected  void postParse()
          Performed after a parse, we convert old-style formulas if necessary and ensure that certain report sections are non-empty.
protected  void query(org.xml.sax.Attributes attributes)
          Reads the query.
 void read(java.io.File f)
          Reads an XML file and builds the innards of the report.
 void read(org.xml.sax.InputSource in)
          Uses the InputSource to find the XML, reads it, and builds the innards of the report.
protected  void removeReportSections()
          Removes the report sections that are created when a report is created.
protected  void report(org.xml.sax.Attributes attributes)
          Reads the report tag.
protected  java.lang.String rubyLanguageNameHack(java.lang.String lang)
           
protected  void section(org.xml.sax.Attributes attributes)
          Creates an empty section and adds it to the report.
protected  void sort(org.xml.sax.Attributes attributes)
           
 void startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attributes)
           
protected  void subreport(org.xml.sax.Attributes attributes)
           
protected  void suppressionProc(org.xml.sax.Attributes attributes)
          Reads suppression proc.
protected  void usercol(org.xml.sax.Attributes attributes)
          Reads a user column.
 
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
 

Field Detail

DEFAULT_DTD_VERSION

protected static final double DEFAULT_DTD_VERSION
If there is no report element dtd-version attribute, this is the default value to use. That's because DataVision XML files before version 0.2 didn't include version numbers.

See Also:
Constant Field Values

DTD_VERSION_FORMULA_IDS

protected static final double DTD_VERSION_FORMULA_IDS
This is the DTD version where formula ids were introduced. Versions before this one require runtime conversion.

See Also:
Constant Field Values

tagNameStack

protected java.util.Stack tagNameStack

report

protected Report report

subreport

protected Subreport subreport

parameter

protected Parameter parameter

formula

protected Formula formula

usercol

protected UserColumn usercol

section

protected Section section

group

protected Group group

field

protected Field field

textData

protected java.lang.String textData

border

protected Border border

line

protected Line line

dtdVersion

protected double dtdVersion

formulasToConvert

protected java.util.HashMap formulasToConvert

nextSectionLocation

protected int nextSectionLocation

missingColumnSeen

protected boolean missingColumnSeen

inSubreportJoins

protected boolean inSubreportJoins
Constructor Detail

ReportReader

public ReportReader(Report report)
Constructor.

Parameters:
report - the report we are building
Method Detail

read

public void read(org.xml.sax.InputSource in)
          throws java.lang.Exception
Uses the InputSource to find the XML, reads it, and builds the innards of the report. To specify a URL, use new InputSource("http://...").

Parameters:
in - the input source
Throws:
java.lang.Exception

read

public void read(java.io.File f)
          throws java.lang.Exception
Reads an XML file and builds the innards of the report.

Parameters:
f - the XML file
Throws:
java.lang.Exception

removeReportSections

protected void removeReportSections()
Removes the report sections that are created when a report is created.


postParse

protected void postParse()
                  throws org.xml.sax.SAXException
Performed after a parse, we convert old-style formulas if necessary and ensure that certain report sections are non-empty.

Throws:
org.xml.sax.SAXException

ensureNotEmpty

protected void ensureNotEmpty(SectionArea area)
Ensures that the specified collection of sections is not empty. If we do create a section, it is marked as suppressed.

Parameters:
area - collection of sections sections

getReport

protected Report getReport()

startElement

public void startElement(java.lang.String namespaceURI,
                         java.lang.String localName,
                         java.lang.String qName,
                         org.xml.sax.Attributes attributes)
                  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

header

protected void header(java.lang.String parentTag)

footer

protected void footer(java.lang.String parentTag)

endElement

public void endElement(java.lang.String namespaceURI,
                       java.lang.String localName,
                       java.lang.String qName)
                throws org.xml.sax.SAXException
Handle elements expecting text data.

Specified by:
endElement in interface org.xml.sax.ContentHandler
Overrides:
endElement in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException

characters

public void characters(char[] ch,
                       int start,
                       int length)
Reads text data. Text data inside a single tag can be broken up into multiple calls to this method.

Specified by:
characters in interface org.xml.sax.ContentHandler
Overrides:
characters in class org.xml.sax.helpers.DefaultHandler

report

protected void report(org.xml.sax.Attributes attributes)
Reads the report tag.


defaultLanguage

protected void defaultLanguage(org.xml.sax.Attributes attributes)

language

protected void language(org.xml.sax.Attributes attributes)

rubyLanguageNameHack

protected java.lang.String rubyLanguageNameHack(java.lang.String lang)

database

protected void database(org.xml.sax.Attributes attributes)
Reads the database tag and creates the database object. If the report already has a data source (for example, someone has called Report.setDataSource or Report.setDatabaseConnection), then we don't do anything.

See Also:
Report.hasDataSource(), Report.setDatabaseConnection(java.sql.Connection)

query

protected void query(org.xml.sax.Attributes attributes)
Reads the query. Nothing to do, since the data source already has an empty query.


charSepSource

protected void charSepSource(org.xml.sax.Attributes attributes)
Reads and creates a CharSepSource.


ncDatabaseSource

protected void ncDatabaseSource(org.xml.sax.Attributes attributes)
Reads and creates an NCDatabase data source.


column

protected void column(org.xml.sax.Attributes attributes)

join

protected void join(org.xml.sax.Attributes attributes)

sort

protected void sort(org.xml.sax.Attributes attributes)

subreport

protected void subreport(org.xml.sax.Attributes attributes)

parameter

protected void parameter(org.xml.sax.Attributes attributes)
                  throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

formula

protected void formula(java.lang.String parentTag,
                       org.xml.sax.Attributes attributes)
                throws org.xml.sax.SAXException
Reads a formula. If the XML format is really old, we need to give each formula an id number and translate its formula text so references to other formulas use the other formula's id number instead of its name.

Throws:
org.xml.sax.SAXException

usercol

protected void usercol(org.xml.sax.Attributes attributes)
                throws org.xml.sax.SAXException
Reads a user column. Value of user column will be read later.

Throws:
org.xml.sax.SAXException

convertFormulas

protected void convertFormulas()
                        throws org.xml.sax.SAXException
Revisits each formula and let it convert formula names to formula id numbers within its eval string.

Throws:
org.xml.sax.SAXException

group

protected void group(org.xml.sax.Attributes attributes)
Creates a group and adds it to the report.


section

protected void section(org.xml.sax.Attributes attributes)
Creates an empty section and adds it to the report.


addSectionToReport

protected void addSectionToReport()
Adds the last seen section to the report. The value of nextSectionLocation determines where the section belongs.


field

protected void field(org.xml.sax.Attributes attributes)
Reads and creates a field. If the XML format is really old, we need to convert formula fields by changing their values from the formula name to the formula id.


bounds

protected void bounds(org.xml.sax.Attributes attributes)
Reads and sets the current field's bounds rectangle.


format

protected void format(org.xml.sax.Attributes attributes)
Reads and creates the current field's format.


parseColor

protected java.awt.Color parseColor(java.lang.String val)
Parses color string and returns a java.awt.Color.


border

protected void border(org.xml.sax.Attributes attributes)
Reads and creates a new field border.


edge

protected void edge(org.xml.sax.Attributes attributes)
Reads and creates a new border edge.


line

protected void line(org.xml.sax.Attributes attributes)
Reads and creates a new line.


point

protected void point(org.xml.sax.Attributes attributes)
Reads a line's point and adds it to the current line.


paper

protected void paper(org.xml.sax.Attributes attributes)
Reads paper size name and orientation.


suppressionProc

protected void suppressionProc(org.xml.sax.Attributes attributes)
Reads suppression proc.


findColumn

protected Column findColumn(java.lang.String fullName)
Returns the column identified by its name. The first time we can not find a column, we report an error to the user.

Parameters:
fullName - a column name
Returns:
a dataSource column

findSelectable

protected Selectable findSelectable(java.lang.String idStr,
                                    java.lang.String typeStr)
Returns the selectable identified by its id and type. The first time we can not find one, we report an error to the user.

Parameters:
idStr - an id string
typeStr - a type string ("column", "usercol")
Returns:
a dataSource column