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 classOsmReader.OptionsOptions are used to change how the xml data is parsed.private static classOsmReader.OsmParsingCanceledExceptionException thrown after user cancellation.-
Nested classes/interfaces inherited from class org.openstreetmap.josm.io.AbstractReader
AbstractReader.BinaryParserWorker, AbstractReader.CommonReader, AbstractReader.NodeReader, AbstractReader.ParserWorker, AbstractReader.RelationReader, AbstractReader.WayReader
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.Set<java.lang.String>COMMON_XML_ATTRIBUTESprotected java.util.Collection<OsmReader.Options>optionsTheOsmReader.Optionsto use when parsing the xml dataprotected javax.xml.stream.XMLStreamReaderparser-
Fields inherited from class org.openstreetmap.josm.io.AbstractReader
cancel, ds, externalIdMap, relations, uploadChangeset, ways
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedOsmReader()constructor (for private and subclasses use only)protectedOsmReader(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 DataSetdoParseDataSet(java.io.InputStream source, ProgressMonitor progressMonitor)private longgetLong(java.lang.String name)private voidhandleIllegalDataException(IllegalDataException e)protected voidjumpToEnd()protected voidjumpToEnd(boolean printWarning)When cursor is at the start of an element, moves it to the end tag of that element.protected voidparse()private voidparseBounds(java.lang.String generator)private voidparseChangeset(java.lang.Long uploadChangesetId)static DataSetparseDataSet(java.io.InputStream source, ProgressMonitor progressMonitor)Parse the given input source and return the dataset.static DataSetparseDataSet(java.io.InputStream source, ProgressMonitor progressMonitor, OsmReader.Options... options)Parse the given input source and return the dataset.private voidparseError()protected NodeparseNode()private voidparseNodeTags(NodeData n)private voidparseOsm()protected RelationparseRelation()private RelationMemberDataparseRelationMember(RelationData r)private voidparseRelationMembersAndTags(RelationData r, java.util.Collection<RelationMemberData> members)private voidparseRemark()protected voidparseRoot()private voidparseTag(Tagged t)protected voidparseUnknown()protected voidparseUnknown(boolean printWarning)protected WayparseWay()private longparseWayNode(WayData w)private voidparseWayNodesAndTags(WayData w, java.util.Collection<java.lang.Long> nodeIds)private voidreadCommon(PrimitiveData current)Read out the common attributes and put them into current OsmPrimitive.protected voidsetParser(javax.xml.stream.XMLStreamReader parser)protected voidthrowException(java.lang.String msg)protected voidthrowException(java.lang.String msg, java.lang.Throwable th)protected voidthrowException(java.lang.Throwable th)-
Methods inherited from class org.openstreetmap.josm.io.AbstractReader
buildPrimitive, callPostProcessors, deregisterPostprocessor, doParseDataSet, 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 javax.xml.stream.XMLStreamReader parser
-
options
protected final java.util.Collection<OsmReader.Options> options
TheOsmReader.Optionsto use when parsing the xml data
-
COMMON_XML_ATTRIBUTES
private static final java.util.Set<java.lang.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(javax.xml.stream.XMLStreamReader parser)
-
throwException
protected void throwException(java.lang.Throwable th) throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
throwException
protected void throwException(java.lang.String msg, java.lang.Throwable th) throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
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
-
handleIllegalDataException
private void handleIllegalDataException(IllegalDataException e) throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
parseError
private void parseError() throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
parseRemark
private void parseRemark() 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
-
parseNodeTags
private void parseNodeTags(NodeData n) throws IllegalDataException
- Throws:
IllegalDataException
-
parseWay
protected Way parseWay() throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
parseWayNodesAndTags
private void parseWayNodesAndTags(WayData w, java.util.Collection<java.lang.Long> nodeIds) throws IllegalDataException
- Throws:
IllegalDataException
-
parseWayNode
private long parseWayNode(WayData 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
-
parseRelationMembersAndTags
private void parseRelationMembersAndTags(RelationData r, java.util.Collection<RelationMemberData> members) throws IllegalDataException
- Throws:
IllegalDataException
-
parseRelationMember
private RelationMemberData parseRelationMember(RelationData 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
protected final 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.- Parameters:
printWarning- iftrue, a warning message will be printed if an unknown element is met- Throws:
javax.xml.stream.XMLStreamException- if there is an error processing the underlying XML source
-
jumpToEnd
protected final void jumpToEnd() throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.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(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
- Specified by:
doParseDataSetin classAbstractReader- 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.INSTANCEis assumed- Returns:
- the dataset with the parsed data
- Throws:
IllegalDataException- if an error was found while parsing the data from the sourcejava.lang.IllegalArgumentException- if source is null
-
parseDataSet
public static DataSet parseDataSet(java.io.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.INSTANCEis 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 sourcejava.lang.IllegalArgumentException- if source is null- Since:
- 16641
-
-