jwo.landserf.process.io
Class MasterMapReader

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by jwo.landserf.process.io.MasterMapReader
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler

public class MasterMapReader
extends DefaultHandler

Reads in an Ordnance Survey MasterMap file in serial fashion using a SAX parser.

Version:
2.3, 11th October, 2007.
Author:
Jo Wood

Constructor Summary
MasterMapReader(String fileName, GISFrame gisFrame, LSThread lsThread)
          Starts the parsing of the given XML file, and gathers information about the attribute types.
MasterMapReader(String fileName, VectorMap vectorMap, GISFrame gisFrame, LSThread lsThread)
          Starts the parsing of the given XML file, placing all objects into the given vector map and reporting progress to the GISFrame.
MasterMapReader(String fileName, VectorMap vectorMap, TreeMap attributeTypes, int readStyle, boolean storeObjectIDs, GISFrame gisFrame, LSThread lsThread)
          Starts the parsing of the given XML file.
 
Method Summary
 void characters(char[] text, int offset, int length)
          Called by the parser when character text is found.
protected  void display(String message, boolean position)
          Displays the given message with an option of identifying the approximate currently parsed line and column identified by the parser Locator.
 void endDocument()
          Called by the parser when the document represented by the XML is finally closed.
 void endElement(String uri, String sName, String qName)
          Called by the parser when the end of an element is found.
 void error(SAXParseException e)
          Called when the parser encounters a non-fatal error.
 void fatalError(SAXParseException e)
          Called when the parser encounters a fatal error.
 TreeMap getAttributeTypes()
          Reports a list of feature codes and descriptions found after scanning the XML file.
 String getLastError()
          Reports last error that was generated by the parser, or null if no error or warning has occurred.
 void setDocumentLocator(Locator locator)
          This method is called by the parser when the XML file for parsing is first opened.
 void startDocument()
          Called by the parser when the document represented by the XML is first opened.
 void startElement(String uri, String sName, String qName, Attributes atts)
          Called by the parser when the start of an element is found.
 void warning(SAXParseException e)
          Called when the parser encounters a non-fatal warning.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endPrefixMapping, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, skippedEntity, startPrefixMapping, unparsedEntityDecl
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MasterMapReader

public MasterMapReader(String fileName,
                       VectorMap vectorMap,
                       GISFrame gisFrame,
                       LSThread lsThread)
Starts the parsing of the given XML file, placing all objects into the given vector map and reporting progress to the GISFrame.

Parameters:
fileName - Name of XML file to process.
vectorMap - Vector map to contain XML data.
gisFrame - GIS Frame in which to report progress.
lsThread - Thread which called this method (allows it to be interrupted). Can be null if no external interruption allowed.

MasterMapReader

public MasterMapReader(String fileName,
                       GISFrame gisFrame,
                       LSThread lsThread)
Starts the parsing of the given XML file, and gathers information about the attribute types. Does not load any geometry or create a vector map. The results of the parsing can be retrieved by calling getAttributeTypes().

Parameters:
fileName - Name of XML file to process.
gisFrame - GIS Frame in which to report progress.
lsThread - Thread which called this method (allows it to be interrupted). Can be null if no external interruption allowed.

MasterMapReader

public MasterMapReader(String fileName,
                       VectorMap vectorMap,
                       TreeMap attributeTypes,
                       int readStyle,
                       boolean storeObjectIDs,
                       GISFrame gisFrame,
                       LSThread lsThread)
Starts the parsing of the given XML file. If readStyle is GATHER_INFO, then the XML file is scanned for attribute groups and geometry data are not loaded. If readStyle is LOAD_ALL, all objects are placed into the given vector map. If readStyle is LOAD_SELECTED, only those attributes identified in the given attributeTypes collection are read into the vector map.

Parameters:
fileName - Name of XML file to process.
vectorMap - Vector map to contain XML data.
attributeTypes - Ordered list of attribute feature codes to be read (only applied to LOAD_SELECTED).
readStyle - Determines how file is processed.
storeObjectIDs - If true, object IDs are stored as attributes.
gisFrame - GIS Frame in which to report progress.
lsThread - Thread which called this method (allows it to be interrupted). Can be null if no external interruption allowed.
Method Detail

getAttributeTypes

public TreeMap getAttributeTypes()
Reports a list of feature codes and descriptions found after scanning the XML file. Each attribute type is identified by a unique OSGB featureCode. Each value is an array of three strings representing the descriptive group and optional descriptive term(s) and the feature type (point, line, area, text, symbol etc.).

Returns:
A sorted list of feature codes and descriptions found in the XML file.

getLastError

public String getLastError()
Reports last error that was generated by the parser, or null if no error or warning has occurred.

Returns:
Text representing last parsing error or null if no errors.

setDocumentLocator

public void setDocumentLocator(Locator locator)
This method is called by the parser when the XML file for parsing is first opened. It stores a Locator that keeps track of the name of the XML file and the position in the file currently being processed.

Specified by:
setDocumentLocator in interface ContentHandler
Overrides:
setDocumentLocator in class DefaultHandler
Parameters:
locator - Keeps track of the parsing process.

startDocument

public void startDocument()
Called by the parser when the document represented by the XML is first opened.

Specified by:
startDocument in interface ContentHandler
Overrides:
startDocument in class DefaultHandler

endDocument

public void endDocument()
Called by the parser when the document represented by the XML is finally closed.

Specified by:
endDocument in interface ContentHandler
Overrides:
endDocument in class DefaultHandler

startElement

public void startElement(String uri,
                         String sName,
                         String qName,
                         Attributes atts)
                  throws SAXException
Called by the parser when the start of an element is found. Displays the element and its attributes.

Specified by:
startElement in interface ContentHandler
Overrides:
startElement in class DefaultHandler
Parameters:
uri - Namespace reference (ignored).
sName - Simple name of the element.
qName - Fully qualified name of the element.
atts - Attributes associated with the element.
Throws:
SAXException - if problem parsing XML file.

endElement

public void endElement(String uri,
                       String sName,
                       String qName)
                throws SAXException
Called by the parser when the end of an element is found. Can process any preceding character elements such as coordinates or labels.

Specified by:
endElement in interface ContentHandler
Overrides:
endElement in class DefaultHandler
Parameters:
uri - Namespace reference (ignored).
sName - Simple name of the element.
qName - Fully qualified name of the element.
Throws:
SAXException - if problem parsing end of element.

characters

public void characters(char[] text,
                       int offset,
                       int length)
Called by the parser when character text is found. For example between element tags. Displays text found.

Specified by:
characters in interface ContentHandler
Overrides:
characters in class DefaultHandler
Parameters:
text - Array of characters.
offset - Position in array where characters start.
length - Number of characters to use from text array.

warning

public void warning(SAXParseException e)
Called when the parser encounters a non-fatal warning. Displays the warning in the standard error stream.

Specified by:
warning in interface ErrorHandler
Overrides:
warning in class DefaultHandler
Parameters:
e - Exception that caused the warning.

error

public void error(SAXParseException e)
Called when the parser encounters a non-fatal error. Displays the error in the standard error stream.

Specified by:
error in interface ErrorHandler
Overrides:
error in class DefaultHandler
Parameters:
e - Exception that caused the warning.

fatalError

public void fatalError(SAXParseException e)
Called when the parser encounters a fatal error. Displays the error in the standard error stream.

Specified by:
fatalError in interface ErrorHandler
Overrides:
fatalError in class DefaultHandler
Parameters:
e - Exception that caused the warning.

display

protected void display(String message,
                       boolean position)
Displays the given message with an option of identifying the approximate currently parsed line and column identified by the parser Locator.

Parameters:
message - Message to display.
position - Position in the file identified if true.


Copyright Jo Wood, 1996-2009, last modified, 17th April, 2009