xelem.3.0

nl.fountain.xelem.lex
Class ExcelReader

java.lang.Object
  extended by nl.fountain.xelem.lex.ExcelReader

public class ExcelReader
extends Object

Basic class for reading xml-spreadsheets of type spreadsheetML.

An ExcelReader can deliver the contents of an xml-file or an xml-InputSource as a fully populated Workbook.

Furthermore, it can dispatch events, values and instances of XLElements to listeners registered at this ExcelReader while parsing an xml-file or xml-InputSource.

Since:
xelem.2.0
See Also:
package overview

Constructor Summary
ExcelReader()
          Constructs a new ExcelReader.
ExcelReader(SAXParser parser)
          Constructs a new ExcelReader.
 
Method Summary
 void addExcelReaderListener(ExcelReaderListener listener)
          Registers the given listener on this ExcelReader.
 void clearExcelReaderListeners()
          Remove all listeners on this ExcelReader
 void clearReadArea()
          Clears the read area.
 List<ExcelReaderListener> getListeners()
          Gets a list of registered listeners on this ExcelReader.
 Map<String,String> getPrefixMap()
          Gets a map of prefixes (keys) and uri's recieved while reading.
 Area getReadArea()
          Gets the area that restricts reading on this ExcelReader.
 SAXParser getSaxParser()
          Returns the SAXParser that is used by this ExcelReader.
 Workbook getWorkbook(InputSource source)
          Delivers the contents of the given InputSource as a fully populated Workbook.
 Workbook getWorkbook(String fileName)
          Delivers the contents of the specified file as a fully populated Workbook.
 boolean hasReadArea()
          Specifies whether reading is restricted on this ExcelReader.
 void read(InputSource source)
          Reads the stream of the given InputSource and dispatches events to registered ExcelReaderListeners.
 void read(String fileName)
          Reads the file with the given name and dispatches events to registered ExcelReaderListeners.
 boolean removeExcelReaderListener(ExcelReaderListener listener)
          Removes the passed listener on this ExcelReader.
 void setReadArea(Area area)
          Sets the area that is to be read.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExcelReader

public ExcelReader()
            throws ParserConfigurationException,
                   SAXException
Constructs a new ExcelReader. Obtains a SAXParser from an instance of SAXParserFactory to do the parsing. There is no need to configure factory parameters.

Throws:
ParserConfigurationException - if a parser cannot be created which satisfies the current configuration
SAXException - for SAX errors

ExcelReader

public ExcelReader(SAXParser parser)
            throws ParserConfigurationException
Constructs a new ExcelReader. Uses the given parser. The parser should be namespace aware.

Parameters:
parser - a SAXParser that is namespace aware
Throws:
ParserConfigurationException - if the parser is not namespace aware
Method Detail

getSaxParser

public SAXParser getSaxParser()
Returns the SAXParser that is used by this ExcelReader. (Just to see what we've got under the hood.)

Under Java 1.4 we might see a org.apache.crimson.jaxp.SAXParserImpl, it could be a com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl under Java 1.5.

Returns:
the SAXParser that is used by this ExcelReader

setReadArea

public void setReadArea(Area area)
Sets the area that is to be read. Reading will be restricted to the specified area until another area is set or until the read area has been cleared.

Parameters:
area - the area to read
See Also:
package overview

clearReadArea

public void clearReadArea()
Clears the read area. Reading will not be rerstricted after a call to this method.


getReadArea

public Area getReadArea()
Gets the area that restricts reading on this ExcelReader. May be null if no read area was set or if the read area was cleared.

Returns:
the read area

hasReadArea

public boolean hasReadArea()
Specifies whether reading is restricted on this ExcelReader.


getListeners

public List<ExcelReaderListener> getListeners()
Gets a list of registered listeners on this ExcelReader.

Returns:
a list of registered listeners

addExcelReaderListener

public void addExcelReaderListener(ExcelReaderListener listener)
Registers the given listener on this ExcelReader.

Parameters:
listener - the ExcelReaderListener to be registered
See Also:
package overview

removeExcelReaderListener

public boolean removeExcelReaderListener(ExcelReaderListener listener)
Removes the passed listener on this ExcelReader.

Parameters:
listener - the ExcelReaderListener to be removed
Returns:
true if the passed listener was registered, false otherwise

clearExcelReaderListeners

public void clearExcelReaderListeners()
Remove all listeners on this ExcelReader


getWorkbook

public Workbook getWorkbook(String fileName)
                     throws IOException,
                            SAXException
Delivers the contents of the specified file as a fully populated Workbook. If a read area was set on this ExcelReader its worksheets are only populated in the specified area. If listeners are registered, this ExcelReader dispatches events to these listeners during the read. Performs a read.

Parameters:
fileName - the name of the file to be read
Returns:
a fully populated Workbook
Throws:
IOException - signals a failed or interrupted I/O operation
SAXException - signals a general SAX error or warning
See Also:
read(String)

getWorkbook

public Workbook getWorkbook(InputSource source)
                     throws IOException,
                            SAXException
Delivers the contents of the given InputSource as a fully populated Workbook. If a read area was set on this ExcelReader its worksheets are only populated in the specified area. If listeners are registered, this ExcelReader dispatches events to these listeners during the read. Performs a read.

Parameters:
source - the Inputsource streaming spreadsheetML
Returns:
a fully populated Workbook
Throws:
IOException - signals a failed or interrupted I/O operation
SAXException - signals a general SAX error or warning
See Also:
read(InputSource)

read

public void read(String fileName)
          throws IOException,
                 SAXException
Reads the file with the given name and dispatches events to registered ExcelReaderListeners. If a read area was set on this ExcelReader, only events occuring within the limits of the area are dispatched.

When trying to read non-xml files, under java 1.5 a com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException might be thrown. The MalformedByteSequenceException is unknown under java 1.4 and previous releases. Releases prior to java 1.5 will throw a org.xml.sax.SAXParseException under these adverse conditions.

Parameters:
fileName - the name of the file to be read
Throws:
IOException - signals a failed or interrupted I/O operation
SAXException - signals a general SAX error or warning

read

public void read(InputSource source)
          throws IOException,
                 SAXException
Reads the stream of the given InputSource and dispatches events to registered ExcelReaderListeners. If a read area was set on this ExcelReader, only events occuring within the limits of the area are dispatched.

When trying to read non-xml streams, under java 1.5 a com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException might be thrown. The MalformedByteSequenceException is unknown under java 1.4 and previous releases. Releases prior to java 1.5 will throw a org.xml.sax.SAXParseException under these adverse conditions.

Parameters:
source - the Inputsource streaming spreadsheetML
Throws:
IOException - signals a failed or interrupted I/O operation
SAXException - signals a general SAX error or warning

getPrefixMap

public Map<String,String> getPrefixMap()
Gets a map of prefixes (keys) and uri's recieved while reading. May be obtained after a read. Performing a new read will clear any previously recorded entries from the map.

Returns:
a map of prefixes (keys) and uri's recieved while reading

xelem.3.0