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
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 ClassesModifier and TypeClassDescriptionstatic enumOptions are used to change how the xml data is parsed.private static final classException 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
FieldsModifier and TypeFieldDescriptionprotected final Collection<OsmReader.Options>TheOsmReader.Optionsto use when parsing the xml dataprotected XMLStreamReaderFields inherited from class org.openstreetmap.josm.io.AbstractReader
cancel, ds, externalIdMap, relations, uploadChangeset, ways -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedconstructor (for private and subclasses use only)protectedOsmReader(OsmReader.Options... options) constructor (for private and subclasses use only) -
Method Summary
Modifier and TypeMethodDescriptionprotected DataSetdoParseDataSet(InputStream source, ProgressMonitor progressMonitor) private longprivate voidprotected final voidprotected final 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(String generator) private voidparseChangeset(Long uploadChangesetId) static DataSetparseDataSet(InputStream source, ProgressMonitor progressMonitor) Parse the given input source and return the dataset.static DataSetparseDataSet(InputStream source, ProgressMonitor progressMonitor, OsmReader.Options... options) Parse the given input source and return the dataset.private voidprotected Nodeprivate voidprivate voidparseOsm()protected Relationprivate RelationMemberDataprivate voidprivate voidprotected voidprivate voidprotected voidprotected voidparseUnknown(boolean printWarning) protected WayparseWay()private longprivate voidparseWayNodesAndTags(WayData w, Collection<Long> nodeIds) private voidreadCommon(PrimitiveData current) Read out the common attributes and put them into current OsmPrimitive.protected voidsetParser(XMLStreamReader parser) protected voidthrowException(String msg) protected voidthrowException(String msg, Throwable th) protected voidMethods 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 Details
-
parser
-
options
TheOsmReader.Optionsto use when parsing the xml data -
COMMON_XML_ATTRIBUTES
-
-
Constructor Details
-
OsmReader
protected OsmReader()constructor (for private and subclasses use only) -
OsmReader
constructor (for private and subclasses use only)- Parameters:
options- The options to use when reading data- Since:
- 16641
- See Also:
-
-
Method Details
-
setParser
-
throwException
- Throws:
XMLStreamException
-
throwException
- Throws:
XMLStreamException
-
throwException
- Throws:
XMLStreamException
-
parse
- Throws:
XMLStreamException
-
parseRoot
- Throws:
XMLStreamException
-
parseOsm
- Throws:
XMLStreamException
-
handleIllegalDataException
- Throws:
XMLStreamException
-
parseError
- Throws:
XMLStreamException
-
parseRemark
- Throws:
XMLStreamException
-
parseBounds
- Throws:
XMLStreamException
-
parseNode
- Throws:
XMLStreamException
-
parseNodeTags
- Throws:
IllegalDataException
-
parseWay
- Throws:
XMLStreamException
-
parseWayNodesAndTags
- Throws:
IllegalDataException
-
parseWayNode
- Throws:
XMLStreamException
-
parseRelation
- Throws:
XMLStreamException
-
parseRelationMembersAndTags
private void parseRelationMembersAndTags(RelationData r, Collection<RelationMemberData> members) throws IllegalDataException - Throws:
IllegalDataException
-
parseRelationMember
- Throws:
XMLStreamException
-
parseChangeset
- Throws:
XMLStreamException
-
parseTag
- Throws:
XMLStreamException
-
parseUnknown
- Throws:
XMLStreamException
-
parseUnknown
- Throws:
XMLStreamException
-
jumpToEnd
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
- Throws:
XMLStreamException
-
readCommon
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
- Throws:
XMLStreamException
-
doParseDataSet
protected DataSet doParseDataSet(InputStream source, ProgressMonitor progressMonitor) throws IllegalDataException - Specified by:
doParseDataSetin 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.INSTANCEis 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.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 sourceIllegalArgumentException- if source is null- Since:
- 16641
-