Package org.openstreetmap.josm.io
Class OsmReader
- java.lang.Object
-
- org.openstreetmap.josm.io.AbstractReader
-
- org.openstreetmap.josm.io.OsmReader
-
- Direct Known Subclasses:
OsmChangeReader
,OverpassDownloadReader.OverpassOsmReader
public class OsmReader extends AbstractReader
Parser for the Osm API (XML output). 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
Nested Classes Modifier and Type Class Description static class
OsmReader.Options
Options are used to change how the xml data is parsed.private static class
OsmReader.OsmParsingCanceledException
Exception thrown after user cancelation.-
Nested classes/interfaces inherited from class org.openstreetmap.josm.io.AbstractReader
AbstractReader.CommonReader, AbstractReader.NodeReader, AbstractReader.ParserWorker, AbstractReader.RelationReader, AbstractReader.WayReader
-
-
Field Summary
Fields Modifier and Type Field Description private static Set<String>
COMMON_XML_ATTRIBUTES
protected Collection<OsmReader.Options>
options
TheOsmReader.Options
to use when parsing the xml dataprotected XMLStreamReader
parser
-
Fields inherited from class org.openstreetmap.josm.io.AbstractReader
cancel, ds, externalIdMap, relations, uploadChangeset, ways
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
OsmReader()
constructor (for private and subclasses use only)protected
OsmReader(OsmReader.Options... options)
constructor (for private and subclasses use only)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected DataSet
doParseDataSet(InputStream source, ProgressMonitor progressMonitor)
private long
getLong(String name)
private void
handleIllegalDataException(IllegalDataException e)
protected void
jumpToEnd()
protected 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(String generator)
private void
parseChangeset(Long uploadChangesetId)
static DataSet
parseDataSet(InputStream source, ProgressMonitor progressMonitor)
Parse the given input source and return the dataset.static DataSet
parseDataSet(InputStream source, ProgressMonitor progressMonitor, OsmReader.Options... options)
Parse the given input source and return the dataset.protected Node
parseNode()
private void
parseNodeTags(NodeData n)
private void
parseOsm()
protected Relation
parseRelation()
private RelationMemberData
parseRelationMember(RelationData r)
private void
parseRelationMembersAndTags(RelationData r, Collection<RelationMemberData> members)
private void
parseRemark()
protected void
parseRoot()
private void
parseTag(Tagged t)
protected void
parseUnknown()
protected void
parseUnknown(boolean printWarning)
protected Way
parseWay()
private long
parseWayNode(WayData w)
private void
parseWayNodesAndTags(WayData w, Collection<Long> nodeIds)
private void
readCommon(PrimitiveData current)
Read out the common attributes and put them into current OsmPrimitive.protected void
setParser(XMLStreamReader parser)
protected void
throwException(String msg)
protected void
throwException(String msg, Throwable th)
protected void
throwException(Throwable th)
-
Methods inherited from class org.openstreetmap.josm.io.AbstractReader
buildPrimitive, callPostProcessors, deregisterPostprocessor, doParseDataSet, getDataSet, getLong, parseAction, parseBounds, parseChangeset, parseChangeset, parseDownloadPolicy, parseId, parseLocked, parseNode, parseNode, parseRelation, parseRelationMember, parseRelationMember, parseTag, parseTimestamp, parseUploadPolicy, parseUser, parseUser, parseVersion, parseVersion, parseVersion, parseVisible, parseWay, prepareDataSet, processChangesetAfterParsing, processNodesAfterParsing, processRelationsAfterParsing, processWaysAfterParsing, registerPostprocessor
-
-
-
-
Field Detail
-
parser
protected XMLStreamReader parser
-
options
protected final Collection<OsmReader.Options> options
TheOsmReader.Options
to use when parsing the xml data
-
COMMON_XML_ATTRIBUTES
private static final Set<String> COMMON_XML_ATTRIBUTES
-
-
Constructor Detail
-
OsmReader
protected OsmReader()
constructor (for private and subclasses use only)
-
OsmReader
protected OsmReader(OsmReader.Options... options)
constructor (for private and subclasses use only)- Parameters:
options
- The options to use when reading data- Since:
- 16641
- See Also:
parseDataSet(InputStream, ProgressMonitor)
-
-
Method Detail
-
setParser
protected void setParser(XMLStreamReader parser)
-
throwException
protected void throwException(Throwable th) throws XMLStreamException
- Throws:
XMLStreamException
-
throwException
protected void throwException(String msg, Throwable th) throws XMLStreamException
- Throws:
XMLStreamException
-
throwException
protected void throwException(String msg) throws XMLStreamException
- Throws:
XMLStreamException
-
parse
protected void parse() throws XMLStreamException
- Throws:
XMLStreamException
-
parseRoot
protected void parseRoot() throws XMLStreamException
- Throws:
XMLStreamException
-
parseOsm
private void parseOsm() throws XMLStreamException
- Throws:
XMLStreamException
-
handleIllegalDataException
private void handleIllegalDataException(IllegalDataException e) throws XMLStreamException
- Throws:
XMLStreamException
-
parseRemark
private void parseRemark() throws XMLStreamException
- Throws:
XMLStreamException
-
parseBounds
private void parseBounds(String generator) throws XMLStreamException
- Throws:
XMLStreamException
-
parseNode
protected Node parseNode() throws XMLStreamException
- Throws:
XMLStreamException
-
parseNodeTags
private void parseNodeTags(NodeData n) throws IllegalDataException
- Throws:
IllegalDataException
-
parseWay
protected Way parseWay() throws XMLStreamException
- Throws:
XMLStreamException
-
parseWayNodesAndTags
private void parseWayNodesAndTags(WayData w, Collection<Long> nodeIds) throws IllegalDataException
- Throws:
IllegalDataException
-
parseWayNode
private long parseWayNode(WayData w) throws XMLStreamException
- Throws:
XMLStreamException
-
parseRelation
protected Relation parseRelation() throws XMLStreamException
- Throws:
XMLStreamException
-
parseRelationMembersAndTags
private void parseRelationMembersAndTags(RelationData r, Collection<RelationMemberData> members) throws IllegalDataException
- Throws:
IllegalDataException
-
parseRelationMember
private RelationMemberData parseRelationMember(RelationData r) throws XMLStreamException
- Throws:
XMLStreamException
-
parseChangeset
private void parseChangeset(Long uploadChangesetId) throws XMLStreamException
- Throws:
XMLStreamException
-
parseTag
private void parseTag(Tagged t) throws XMLStreamException
- Throws:
XMLStreamException
-
parseUnknown
protected void parseUnknown(boolean printWarning) throws XMLStreamException
- Throws:
XMLStreamException
-
parseUnknown
protected void parseUnknown() throws XMLStreamException
- Throws:
XMLStreamException
-
jumpToEnd
protected final void jumpToEnd(boolean printWarning) throws 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.- Parameters:
printWarning
- iftrue
, a warning message will be printed if an unknown element is met- Throws:
XMLStreamException
- if there is an error processing the underlying XML source
-
jumpToEnd
protected final void jumpToEnd() throws XMLStreamException
- Throws:
XMLStreamException
-
readCommon
private void readCommon(PrimitiveData current) throws IllegalDataException
Read out the common attributes and put them into current OsmPrimitive.- Parameters:
current
- primitive to update- Throws:
IllegalDataException
- if there is an error processing the underlying XML source
-
getLong
private long getLong(String name) throws XMLStreamException
- Throws:
XMLStreamException
-
doParseDataSet
protected DataSet doParseDataSet(InputStream source, ProgressMonitor progressMonitor) throws IllegalDataException
- Specified by:
doParseDataSet
in classAbstractReader
- Throws:
IllegalDataException
-
parseDataSet
public static DataSet parseDataSet(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
- if an error was found while parsing the data from the sourceIllegalArgumentException
- if source is null
-
parseDataSet
public static DataSet parseDataSet(InputStream source, ProgressMonitor progressMonitor, OsmReader.Options... options) 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 assumedoptions
- The options to use when parsing the dataset- Returns:
- the dataset with the parsed data
- Throws:
IllegalDataException
- if an error was found while parsing the data from the sourceIllegalArgumentException
- if source is null- Since:
- 16641
-
-