source: josm/trunk/src/org/openstreetmap/josm/io/OsmReader.java@ 13434

Last change on this file since 13434 was 13434, checked in by Don-vip, 6 years ago

see #8039, see #10456 - support read-only data layers

  • Property svn:eol-style set to native
File size: 26.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.io.IOException;
7import java.io.InputStream;
8import java.io.InputStreamReader;
9import java.text.MessageFormat;
10import java.util.ArrayList;
11import java.util.Collection;
12import java.util.List;
13import java.util.Objects;
14import java.util.regex.Matcher;
15import java.util.regex.Pattern;
16
17import javax.xml.stream.Location;
18import javax.xml.stream.XMLInputFactory;
19import javax.xml.stream.XMLStreamConstants;
20import javax.xml.stream.XMLStreamException;
21import javax.xml.stream.XMLStreamReader;
22
23import org.openstreetmap.josm.data.Bounds;
24import org.openstreetmap.josm.data.DataSource;
25import org.openstreetmap.josm.data.coor.LatLon;
26import org.openstreetmap.josm.data.osm.AbstractPrimitive;
27import org.openstreetmap.josm.data.osm.Changeset;
28import org.openstreetmap.josm.data.osm.DataSet;
29import org.openstreetmap.josm.data.osm.DataSet.UploadPolicy;
30import org.openstreetmap.josm.data.osm.Node;
31import org.openstreetmap.josm.data.osm.NodeData;
32import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
33import org.openstreetmap.josm.data.osm.PrimitiveData;
34import org.openstreetmap.josm.data.osm.Relation;
35import org.openstreetmap.josm.data.osm.RelationData;
36import org.openstreetmap.josm.data.osm.RelationMemberData;
37import org.openstreetmap.josm.data.osm.Tagged;
38import org.openstreetmap.josm.data.osm.User;
39import org.openstreetmap.josm.data.osm.Way;
40import org.openstreetmap.josm.data.osm.WayData;
41import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
42import org.openstreetmap.josm.gui.progress.ProgressMonitor;
43import org.openstreetmap.josm.tools.CheckParameterUtil;
44import org.openstreetmap.josm.tools.Logging;
45import org.openstreetmap.josm.tools.UncheckedParseException;
46import org.openstreetmap.josm.tools.Utils;
47import org.openstreetmap.josm.tools.date.DateUtils;
48
49/**
50 * Parser for the Osm Api. Read from an input stream and construct a dataset out of it.
51 *
52 * For each xml element, there is a dedicated method.
53 * The XMLStreamReader cursor points to the start of the element, when the method is
54 * entered, and it must point to the end of the same element, when it is exited.
55 */
56public class OsmReader extends AbstractReader {
57
58 protected XMLStreamReader parser;
59
60 protected boolean cancel;
61
62 /** Used by plugins to register themselves as data postprocessors. */
63 private static volatile List<OsmServerReadPostprocessor> postprocessors;
64
65 /** Register a new postprocessor.
66 * @param pp postprocessor
67 * @see #deregisterPostprocessor
68 */
69 public static void registerPostprocessor(OsmServerReadPostprocessor pp) {
70 if (postprocessors == null) {
71 postprocessors = new ArrayList<>();
72 }
73 postprocessors.add(pp);
74 }
75
76 /**
77 * Deregister a postprocessor previously registered with {@link #registerPostprocessor}.
78 * @param pp postprocessor
79 * @see #registerPostprocessor
80 */
81 public static void deregisterPostprocessor(OsmServerReadPostprocessor pp) {
82 if (postprocessors != null) {
83 postprocessors.remove(pp);
84 }
85 }
86
87 /**
88 * constructor (for private and subclasses use only)
89 *
90 * @see #parseDataSet(InputStream, ProgressMonitor)
91 */
92 protected OsmReader() {
93 // Restricts visibility
94 }
95
96 protected void setParser(XMLStreamReader parser) {
97 this.parser = parser;
98 }
99
100 protected void throwException(String msg, Throwable th) throws XMLStreamException {
101 throw new XmlStreamParsingException(msg, parser.getLocation(), th);
102 }
103
104 protected void throwException(String msg) throws XMLStreamException {
105 throw new XmlStreamParsingException(msg, parser.getLocation());
106 }
107
108 protected void parse() throws XMLStreamException {
109 int event = parser.getEventType();
110 while (true) {
111 if (event == XMLStreamConstants.START_ELEMENT) {
112 parseRoot();
113 } else if (event == XMLStreamConstants.END_ELEMENT)
114 return;
115 if (parser.hasNext()) {
116 event = parser.next();
117 } else {
118 break;
119 }
120 }
121 parser.close();
122 }
123
124 protected void parseRoot() throws XMLStreamException {
125 if ("osm".equals(parser.getLocalName())) {
126 parseOsm();
127 } else {
128 parseUnknown();
129 }
130 }
131
132 private void parseOsm() throws XMLStreamException {
133 String v = parser.getAttributeValue(null, "version");
134 if (v == null) {
135 throwException(tr("Missing mandatory attribute ''{0}''.", "version"));
136 }
137 if (!"0.6".equals(v)) {
138 throwException(tr("Unsupported version: {0}", v));
139 }
140 ds.setVersion(v);
141 String upload = parser.getAttributeValue(null, "upload");
142 if (upload != null) {
143 try {
144 ds.setUploadPolicy(UploadPolicy.of(upload));
145 } catch (IllegalArgumentException e) {
146 throwException(MessageFormat.format("Illegal value for attribute ''upload''. Got ''{0}''.", upload), e);
147 }
148 }
149 if ("true".equalsIgnoreCase(parser.getAttributeValue(null, "read-only"))) {
150 ds.setReadOnly();
151 }
152 String generator = parser.getAttributeValue(null, "generator");
153 Long uploadChangesetId = null;
154 if (parser.getAttributeValue(null, "upload-changeset") != null) {
155 uploadChangesetId = getLong("upload-changeset");
156 }
157 while (true) {
158 int event = parser.next();
159
160 if (cancel) {
161 cancel = false;
162 throw new OsmParsingCanceledException(tr("Reading was canceled"), parser.getLocation());
163 }
164
165 if (event == XMLStreamConstants.START_ELEMENT) {
166 switch (parser.getLocalName()) {
167 case "bounds":
168 parseBounds(generator);
169 break;
170 case "node":
171 parseNode();
172 break;
173 case "way":
174 parseWay();
175 break;
176 case "relation":
177 parseRelation();
178 break;
179 case "changeset":
180 parseChangeset(uploadChangesetId);
181 break;
182 default:
183 parseUnknown();
184 }
185 } else if (event == XMLStreamConstants.END_ELEMENT) {
186 return;
187 }
188 }
189 }
190
191 private void parseBounds(String generator) throws XMLStreamException {
192 String minlon = parser.getAttributeValue(null, "minlon");
193 String minlat = parser.getAttributeValue(null, "minlat");
194 String maxlon = parser.getAttributeValue(null, "maxlon");
195 String maxlat = parser.getAttributeValue(null, "maxlat");
196 String origin = parser.getAttributeValue(null, "origin");
197 if (minlon != null && maxlon != null && minlat != null && maxlat != null) {
198 if (origin == null) {
199 origin = generator;
200 }
201 Bounds bounds = new Bounds(
202 Double.parseDouble(minlat), Double.parseDouble(minlon),
203 Double.parseDouble(maxlat), Double.parseDouble(maxlon));
204 if (bounds.isOutOfTheWorld()) {
205 Bounds copy = new Bounds(bounds);
206 bounds.normalize();
207 Logging.info("Bbox " + copy + " is out of the world, normalized to " + bounds);
208 }
209 DataSource src = new DataSource(bounds, origin);
210 ds.addDataSource(src);
211 } else {
212 throwException(tr("Missing mandatory attributes on element ''bounds''. " +
213 "Got minlon=''{0}'',minlat=''{1}'',maxlon=''{2}'',maxlat=''{3}'', origin=''{4}''.",
214 minlon, minlat, maxlon, maxlat, origin
215 ));
216 }
217 jumpToEnd();
218 }
219
220 protected Node parseNode() throws XMLStreamException {
221 NodeData nd = new NodeData();
222 String lat = parser.getAttributeValue(null, "lat");
223 String lon = parser.getAttributeValue(null, "lon");
224 LatLon ll = null;
225 if (lat != null && lon != null) {
226 try {
227 ll = new LatLon(Double.parseDouble(lat), Double.parseDouble(lon));
228 nd.setCoor(ll);
229 } catch (NumberFormatException e) {
230 Logging.trace(e);
231 }
232 }
233 readCommon(nd);
234 if (lat != null && lon != null && (ll == null || !ll.isValid())) {
235 throwException(tr("Illegal value for attributes ''lat'', ''lon'' on node with ID {0}. Got ''{1}'', ''{2}''.",
236 Long.toString(nd.getId()), lat, lon));
237 }
238 Node n = new Node(nd.getId(), nd.getVersion());
239 n.setVisible(nd.isVisible());
240 n.load(nd);
241 externalIdMap.put(nd.getPrimitiveId(), n);
242 while (true) {
243 int event = parser.next();
244 if (event == XMLStreamConstants.START_ELEMENT) {
245 if ("tag".equals(parser.getLocalName())) {
246 parseTag(n);
247 } else {
248 parseUnknown();
249 }
250 } else if (event == XMLStreamConstants.END_ELEMENT)
251 return n;
252 }
253 }
254
255 protected Way parseWay() throws XMLStreamException {
256 WayData wd = new WayData();
257 readCommon(wd);
258 Way w = new Way(wd.getId(), wd.getVersion());
259 w.setVisible(wd.isVisible());
260 w.load(wd);
261 externalIdMap.put(wd.getPrimitiveId(), w);
262
263 Collection<Long> nodeIds = new ArrayList<>();
264 while (true) {
265 int event = parser.next();
266 if (event == XMLStreamConstants.START_ELEMENT) {
267 switch (parser.getLocalName()) {
268 case "nd":
269 nodeIds.add(parseWayNode(w));
270 break;
271 case "tag":
272 parseTag(w);
273 break;
274 default:
275 parseUnknown();
276 }
277 } else if (event == XMLStreamConstants.END_ELEMENT) {
278 break;
279 }
280 }
281 if (w.isDeleted() && !nodeIds.isEmpty()) {
282 Logging.info(tr("Deleted way {0} contains nodes", Long.toString(w.getUniqueId())));
283 nodeIds = new ArrayList<>();
284 }
285 ways.put(wd.getUniqueId(), nodeIds);
286 return w;
287 }
288
289 private long parseWayNode(Way w) throws XMLStreamException {
290 if (parser.getAttributeValue(null, "ref") == null) {
291 throwException(
292 tr("Missing mandatory attribute ''{0}'' on <nd> of way {1}.", "ref", Long.toString(w.getUniqueId()))
293 );
294 }
295 long id = getLong("ref");
296 if (id == 0) {
297 throwException(
298 tr("Illegal value of attribute ''ref'' of element <nd>. Got {0}.", Long.toString(id))
299 );
300 }
301 jumpToEnd();
302 return id;
303 }
304
305 protected Relation parseRelation() throws XMLStreamException {
306 RelationData rd = new RelationData();
307 readCommon(rd);
308 Relation r = new Relation(rd.getId(), rd.getVersion());
309 r.setVisible(rd.isVisible());
310 r.load(rd);
311 externalIdMap.put(rd.getPrimitiveId(), r);
312
313 Collection<RelationMemberData> members = new ArrayList<>();
314 while (true) {
315 int event = parser.next();
316 if (event == XMLStreamConstants.START_ELEMENT) {
317 switch (parser.getLocalName()) {
318 case "member":
319 members.add(parseRelationMember(r));
320 break;
321 case "tag":
322 parseTag(r);
323 break;
324 default:
325 parseUnknown();
326 }
327 } else if (event == XMLStreamConstants.END_ELEMENT) {
328 break;
329 }
330 }
331 if (r.isDeleted() && !members.isEmpty()) {
332 Logging.info(tr("Deleted relation {0} contains members", Long.toString(r.getUniqueId())));
333 members = new ArrayList<>();
334 }
335 relations.put(rd.getUniqueId(), members);
336 return r;
337 }
338
339 private RelationMemberData parseRelationMember(Relation r) throws XMLStreamException {
340 OsmPrimitiveType type = null;
341 long id = 0;
342 String value = parser.getAttributeValue(null, "ref");
343 if (value == null) {
344 throwException(tr("Missing attribute ''ref'' on member in relation {0}.", Long.toString(r.getUniqueId())));
345 }
346 try {
347 id = Long.parseLong(value);
348 } catch (NumberFormatException e) {
349 throwException(tr("Illegal value for attribute ''ref'' on member in relation {0}. Got {1}", Long.toString(r.getUniqueId()),
350 value), e);
351 }
352 value = parser.getAttributeValue(null, "type");
353 if (value == null) {
354 throwException(tr("Missing attribute ''type'' on member {0} in relation {1}.", Long.toString(id), Long.toString(r.getUniqueId())));
355 }
356 try {
357 type = OsmPrimitiveType.fromApiTypeName(value);
358 } catch (IllegalArgumentException e) {
359 throwException(tr("Illegal value for attribute ''type'' on member {0} in relation {1}. Got {2}.",
360 Long.toString(id), Long.toString(r.getUniqueId()), value), e);
361 }
362 String role = parser.getAttributeValue(null, "role");
363
364 if (id == 0) {
365 throwException(tr("Incomplete <member> specification with ref=0"));
366 }
367 jumpToEnd();
368 return new RelationMemberData(role, type, id);
369 }
370
371 private void parseChangeset(Long uploadChangesetId) throws XMLStreamException {
372
373 Long id = null;
374 if (parser.getAttributeValue(null, "id") != null) {
375 id = getLong("id");
376 }
377 // Read changeset info if neither upload-changeset nor id are set, or if they are both set to the same value
378 if (Objects.equals(id, uploadChangesetId)) {
379 uploadChangeset = new Changeset(id != null ? id.intValue() : 0);
380 while (true) {
381 int event = parser.next();
382 if (event == XMLStreamConstants.START_ELEMENT) {
383 if ("tag".equals(parser.getLocalName())) {
384 parseTag(uploadChangeset);
385 } else {
386 parseUnknown();
387 }
388 } else if (event == XMLStreamConstants.END_ELEMENT)
389 return;
390 }
391 } else {
392 jumpToEnd(false);
393 }
394 }
395
396 private void parseTag(Tagged t) throws XMLStreamException {
397 String key = parser.getAttributeValue(null, "k");
398 String value = parser.getAttributeValue(null, "v");
399 if (key == null || value == null) {
400 throwException(tr("Missing key or value attribute in tag."));
401 } else if (Utils.isStripEmpty(key) && t instanceof AbstractPrimitive) {
402 // #14199: Empty keys as ignored by AbstractPrimitive#put, but it causes problems to fix existing data
403 // Drop the tag on import, but flag the primitive as modified
404 ((AbstractPrimitive) t).setModified(true);
405 } else {
406 t.put(key.intern(), value.intern());
407 }
408 jumpToEnd();
409 }
410
411 protected void parseUnknown(boolean printWarning) throws XMLStreamException {
412 final String element = parser.getLocalName();
413 if (printWarning && ("note".equals(element) || "meta".equals(element))) {
414 // we know that Overpass API returns those elements
415 Logging.debug(tr("Undefined element ''{0}'' found in input stream. Skipping.", element));
416 } else if (printWarning) {
417 Logging.info(tr("Undefined element ''{0}'' found in input stream. Skipping.", element));
418 }
419 while (true) {
420 int event = parser.next();
421 if (event == XMLStreamConstants.START_ELEMENT) {
422 parseUnknown(false); /* no more warning for inner elements */
423 } else if (event == XMLStreamConstants.END_ELEMENT)
424 return;
425 }
426 }
427
428 protected void parseUnknown() throws XMLStreamException {
429 parseUnknown(true);
430 }
431
432 /**
433 * When cursor is at the start of an element, moves it to the end tag of that element.
434 * Nested content is skipped.
435 *
436 * This is basically the same code as parseUnknown(), except for the warnings, which
437 * are displayed for inner elements and not at top level.
438 * @param printWarning if {@code true}, a warning message will be printed if an unknown element is met
439 * @throws XMLStreamException if there is an error processing the underlying XML source
440 */
441 private void jumpToEnd(boolean printWarning) throws XMLStreamException {
442 while (true) {
443 int event = parser.next();
444 if (event == XMLStreamConstants.START_ELEMENT) {
445 parseUnknown(printWarning);
446 } else if (event == XMLStreamConstants.END_ELEMENT)
447 return;
448 }
449 }
450
451 private void jumpToEnd() throws XMLStreamException {
452 jumpToEnd(true);
453 }
454
455 private User createUser(String uid, String name) throws XMLStreamException {
456 if (uid == null) {
457 if (name == null)
458 return null;
459 return User.createLocalUser(name);
460 }
461 try {
462 long id = Long.parseLong(uid);
463 return User.createOsmUser(id, name);
464 } catch (NumberFormatException e) {
465 throwException(MessageFormat.format("Illegal value for attribute ''uid''. Got ''{0}''.", uid), e);
466 }
467 return null;
468 }
469
470 /**
471 * Read out the common attributes and put them into current OsmPrimitive.
472 * @param current primitive to update
473 * @throws XMLStreamException if there is an error processing the underlying XML source
474 */
475 private void readCommon(PrimitiveData current) throws XMLStreamException {
476 current.setId(getLong("id"));
477 if (current.getUniqueId() == 0) {
478 throwException(tr("Illegal object with ID=0."));
479 }
480
481 String time = parser.getAttributeValue(null, "timestamp");
482 if (time != null && !time.isEmpty()) {
483 current.setRawTimestamp((int) (DateUtils.tsFromString(time)/1000));
484 }
485
486 String user = parser.getAttributeValue(null, "user");
487 String uid = parser.getAttributeValue(null, "uid");
488 current.setUser(createUser(uid, user));
489
490 String visible = parser.getAttributeValue(null, "visible");
491 if (visible != null) {
492 current.setVisible(Boolean.parseBoolean(visible));
493 }
494
495 String versionString = parser.getAttributeValue(null, "version");
496 int version = 0;
497 if (versionString != null) {
498 try {
499 version = Integer.parseInt(versionString);
500 } catch (NumberFormatException e) {
501 throwException(tr("Illegal value for attribute ''version'' on OSM primitive with ID {0}. Got {1}.",
502 Long.toString(current.getUniqueId()), versionString), e);
503 }
504 switch (ds.getVersion()) {
505 case "0.6":
506 if (version <= 0 && !current.isNew()) {
507 throwException(tr("Illegal value for attribute ''version'' on OSM primitive with ID {0}. Got {1}.",
508 Long.toString(current.getUniqueId()), versionString));
509 } else if (version < 0 && current.isNew()) {
510 Logging.warn(tr("Normalizing value of attribute ''version'' of element {0} to {2}, API version is ''{3}''. Got {1}.",
511 current.getUniqueId(), version, 0, "0.6"));
512 version = 0;
513 }
514 break;
515 default:
516 // should not happen. API version has been checked before
517 throwException(tr("Unknown or unsupported API version. Got {0}.", ds.getVersion()));
518 }
519 } else {
520 // version expected for OSM primitives with an id assigned by the server (id > 0), since API 0.6
521 if (!current.isNew() && ds.getVersion() != null && "0.6".equals(ds.getVersion())) {
522 throwException(tr("Missing attribute ''version'' on OSM primitive with ID {0}.", Long.toString(current.getUniqueId())));
523 }
524 }
525 current.setVersion(version);
526
527 String action = parser.getAttributeValue(null, "action");
528 if (action == null) {
529 // do nothing
530 } else if ("delete".equals(action)) {
531 current.setDeleted(true);
532 current.setModified(current.isVisible());
533 } else if ("modify".equals(action)) {
534 current.setModified(true);
535 }
536
537 String v = parser.getAttributeValue(null, "changeset");
538 if (v == null) {
539 current.setChangesetId(0);
540 } else {
541 try {
542 current.setChangesetId(Integer.parseInt(v));
543 } catch (IllegalArgumentException e) {
544 Logging.debug(e.getMessage());
545 if (current.isNew()) {
546 // for a new primitive we just log a warning
547 Logging.info(tr("Illegal value for attribute ''changeset'' on new object {1}. Got {0}. Resetting to 0.",
548 v, current.getUniqueId()));
549 current.setChangesetId(0);
550 } else {
551 // for an existing primitive this is a problem
552 throwException(tr("Illegal value for attribute ''changeset''. Got {0}.", v), e);
553 }
554 } catch (IllegalStateException e) {
555 // thrown for positive changeset id on new primitives
556 Logging.debug(e);
557 Logging.info(e.getMessage());
558 current.setChangesetId(0);
559 }
560 if (current.getChangesetId() <= 0) {
561 if (current.isNew()) {
562 // for a new primitive we just log a warning
563 Logging.info(tr("Illegal value for attribute ''changeset'' on new object {1}. Got {0}. Resetting to 0.",
564 v, current.getUniqueId()));
565 current.setChangesetId(0);
566 } else {
567 // for an existing primitive this is a problem
568 throwException(tr("Illegal value for attribute ''changeset''. Got {0}.", v));
569 }
570 }
571 }
572 }
573
574 private long getLong(String name) throws XMLStreamException {
575 String value = parser.getAttributeValue(null, name);
576 if (value == null) {
577 throwException(tr("Missing required attribute ''{0}''.", name));
578 }
579 try {
580 return Long.parseLong(value);
581 } catch (NumberFormatException e) {
582 throwException(tr("Illegal long value for attribute ''{0}''. Got ''{1}''.", name, value), e);
583 }
584 return 0; // should not happen
585 }
586
587 /**
588 * Exception thrown after user cancelation.
589 */
590 private static final class OsmParsingCanceledException extends XmlStreamParsingException implements ImportCancelException {
591 /**
592 * Constructs a new {@code OsmParsingCanceledException}.
593 * @param msg The error message
594 * @param location The parser location
595 */
596 OsmParsingCanceledException(String msg, Location location) {
597 super(msg, location);
598 }
599 }
600
601 @Override
602 protected DataSet doParseDataSet(InputStream source, ProgressMonitor progressMonitor) throws IllegalDataException {
603 if (progressMonitor == null) {
604 progressMonitor = NullProgressMonitor.INSTANCE;
605 }
606 ProgressMonitor.CancelListener cancelListener = () -> cancel = true;
607 progressMonitor.addCancelListener(cancelListener);
608 CheckParameterUtil.ensureParameterNotNull(source, "source");
609 try {
610 progressMonitor.beginTask(tr("Prepare OSM data...", 2));
611 progressMonitor.indeterminateSubTask(tr("Parsing OSM data..."));
612
613 try (InputStreamReader ir = UTFInputStreamReader.create(source)) {
614 XMLInputFactory factory = XMLInputFactory.newInstance();
615 // do not try to load external entities
616 factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE);
617 factory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
618 setParser(factory.createXMLStreamReader(ir));
619 parse();
620 }
621 progressMonitor.worked(1);
622
623 boolean readOnly = getDataSet().isReadOnly();
624
625 progressMonitor.indeterminateSubTask(tr("Preparing data set..."));
626 if (readOnly) {
627 getDataSet().unsetReadOnly();
628 }
629 prepareDataSet();
630 if (readOnly) {
631 getDataSet().setReadOnly();
632 }
633 progressMonitor.worked(1);
634
635 // iterate over registered postprocessors and give them each a chance
636 // to modify the dataset we have just loaded.
637 if (postprocessors != null) {
638 for (OsmServerReadPostprocessor pp : postprocessors) {
639 pp.postprocessDataSet(getDataSet(), progressMonitor);
640 }
641 }
642 // Make sure postprocessors did not change the read-only state
643 if (readOnly && !getDataSet().isReadOnly()) {
644 getDataSet().setReadOnly();
645 }
646 return getDataSet();
647 } catch (IllegalDataException e) {
648 throw e;
649 } catch (XmlStreamParsingException | UncheckedParseException e) {
650 throw new IllegalDataException(e.getMessage(), e);
651 } catch (XMLStreamException e) {
652 String msg = e.getMessage();
653 Pattern p = Pattern.compile("Message: (.+)");
654 Matcher m = p.matcher(msg);
655 if (m.find()) {
656 msg = m.group(1);
657 }
658 if (e.getLocation() != null)
659 throw new IllegalDataException(tr("Line {0} column {1}: ",
660 e.getLocation().getLineNumber(), e.getLocation().getColumnNumber()) + msg, e);
661 else
662 throw new IllegalDataException(msg, e);
663 } catch (IOException e) {
664 throw new IllegalDataException(e);
665 } finally {
666 progressMonitor.finishTask();
667 progressMonitor.removeCancelListener(cancelListener);
668 }
669 }
670
671 /**
672 * Parse the given input source and return the dataset.
673 *
674 * @param source the source input stream. Must not be null.
675 * @param progressMonitor the progress monitor. If null, {@link NullProgressMonitor#INSTANCE} is assumed
676 *
677 * @return the dataset with the parsed data
678 * @throws IllegalDataException if an error was found while parsing the data from the source
679 * @throws IllegalArgumentException if source is null
680 */
681 public static DataSet parseDataSet(InputStream source, ProgressMonitor progressMonitor) throws IllegalDataException {
682 return new OsmReader().doParseDataSet(source, progressMonitor);
683 }
684}
Note: See TracBrowser for help on using the repository browser.