org.openstreetmap.josm.io
Class OsmReader

java.lang.Object
  extended by org.openstreetmap.josm.io.AbstractReader
      extended by org.openstreetmap.josm.io.OsmReader
Direct Known Subclasses:
OsmChangeReader

public class OsmReader
extends AbstractReader

Parser for the Osm Api. Read from an input stream and construct a dataset out of it. For each xml element, there is a dedicated method. The XMLStreamReader cursor points to the start of the element, when the method is entered, and it must point to the end of the same element, when it is exited.


Nested Class Summary
private static class OsmReader.OsmParsingException
           
 
Field Summary
protected  javax.xml.stream.XMLStreamReader parser
           
static java.util.ArrayList<OsmServerReadPostprocessor> postprocessors
          Used by plugins to register themselves as data postprocessors.
 
Fields inherited from class org.openstreetmap.josm.io.AbstractReader
ds, externalIdMap, relations, uploadChangeset, ways
 
Constructor Summary
protected OsmReader()
          constructor (for private and subclasses use only)
 
Method Summary
private  User createUser(java.lang.String uid, java.lang.String name)
           
static void deregisterPostprocessor(OsmServerReadPostprocessor pp)
          deregister a postprocessor previously registered with registerPostprocessor
protected  DataSet doParseDataSet(java.io.InputStream source, ProgressMonitor progressMonitor)
           
private  long getLong(java.lang.String name)
           
private  void jumpToEnd()
           
private  void jumpToEnd(boolean printWarning)
          When cursor is at the start of an element, moves it to the end tag of that element.
protected  void parse()
           
private  void parseBounds(java.lang.String generator)
           
private  void parseChangeset(java.lang.Long uploadChangesetId)
           
static DataSet parseDataSet(java.io.InputStream source, ProgressMonitor progressMonitor)
          Parse the given input source and return the dataset.
protected  Node parseNode()
           
private  void parseOsm()
           
protected  Relation parseRelation()
           
private  RelationMemberData parseRelationMember(Relation r)
           
protected  void parseRoot()
           
private  void parseTag(Tagged t)
           
protected  void parseUnknown()
           
protected  void parseUnknown(boolean printWarning)
           
protected  Way parseWay()
           
private  long parseWayNode(Way w)
           
private  void readCommon(PrimitiveData current)
          Read out the common attributes and put them into current OsmPrimitive.
static void registerPostprocessor(OsmServerReadPostprocessor pp)
          register a new postprocessor
protected  void setParser(javax.xml.stream.XMLStreamReader parser)
           
protected  void throwException(java.lang.String msg)
           
 
Methods inherited from class org.openstreetmap.josm.io.AbstractReader
getDataSet, prepareDataSet, processChangesetAfterParsing, processNodesAfterParsing, processRelationsAfterParsing, processWaysAfterParsing
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parser

protected javax.xml.stream.XMLStreamReader parser

postprocessors

public static java.util.ArrayList<OsmServerReadPostprocessor> postprocessors
Used by plugins to register themselves as data postprocessors.

Constructor Detail

OsmReader

protected OsmReader()
constructor (for private and subclasses use only)

See Also:
#parseDataSet(InputStream, DataSet, ProgressMonitor)
Method Detail

registerPostprocessor

public static void registerPostprocessor(OsmServerReadPostprocessor pp)
register a new postprocessor


deregisterPostprocessor

public static void deregisterPostprocessor(OsmServerReadPostprocessor pp)
deregister a postprocessor previously registered with registerPostprocessor


setParser

protected void setParser(javax.xml.stream.XMLStreamReader parser)

throwException

protected void throwException(java.lang.String msg)
                       throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

parse

protected void parse()
              throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

parseRoot

protected void parseRoot()
                  throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

parseOsm

private void parseOsm()
               throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

parseBounds

private void parseBounds(java.lang.String generator)
                  throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

parseNode

protected Node parseNode()
                  throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

parseWay

protected Way parseWay()
                throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

parseWayNode

private long parseWayNode(Way w)
                   throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

parseRelation

protected Relation parseRelation()
                          throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

parseRelationMember

private RelationMemberData parseRelationMember(Relation r)
                                        throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

parseChangeset

private void parseChangeset(java.lang.Long uploadChangesetId)
                     throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

parseTag

private void parseTag(Tagged t)
               throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

parseUnknown

protected void parseUnknown(boolean printWarning)
                     throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

parseUnknown

protected void parseUnknown()
                     throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

jumpToEnd

private void jumpToEnd(boolean printWarning)
                throws javax.xml.stream.XMLStreamException
When cursor is at the start of an element, moves it to the end tag of that element. Nested content is skipped. This is basically the same code as parseUnknown(), except for the warnings, which are displayed for inner elements and not at top level.

Throws:
javax.xml.stream.XMLStreamException

jumpToEnd

private void jumpToEnd()
                throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

createUser

private User createUser(java.lang.String uid,
                        java.lang.String name)
                 throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

readCommon

private void readCommon(PrimitiveData current)
                 throws javax.xml.stream.XMLStreamException
Read out the common attributes and put them into current OsmPrimitive.

Throws:
javax.xml.stream.XMLStreamException

getLong

private long getLong(java.lang.String name)
              throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

doParseDataSet

protected DataSet doParseDataSet(java.io.InputStream source,
                                 ProgressMonitor progressMonitor)
                          throws IllegalDataException
Throws:
IllegalDataException

parseDataSet

public static DataSet parseDataSet(java.io.InputStream source,
                                   ProgressMonitor progressMonitor)
                            throws IllegalDataException
Parse the given input source and return the dataset.

Parameters:
source - the source input stream. Must not be null.
progressMonitor - the progress monitor. If null, NullProgressMonitor.INSTANCE is assumed
Returns:
the dataset with the parsed data
Throws:
IllegalDataException - thrown if the an error was found while parsing the data from the source
java.lang.IllegalArgumentException - thrown if source is null


JOSM