Changeset 15470 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2019-10-22T23:54:14+02:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/OsmReader.java
r14266 r15470 7 7 import java.util.Collection; 8 8 import java.util.Objects; 9 import java.util.Set; 10 import java.util.TreeSet; 9 11 import java.util.regex.Matcher; 10 12 import java.util.regex.Pattern; … … 40 42 protected XMLStreamReader parser; 41 43 44 protected boolean convertUnknownToTags; 45 46 private static final Set<String> COMMON_XML_ATTRIBUTES = new TreeSet<>(); 47 48 static { 49 COMMON_XML_ATTRIBUTES.add("id"); 50 COMMON_XML_ATTRIBUTES.add("timestamp"); 51 COMMON_XML_ATTRIBUTES.add("user"); 52 COMMON_XML_ATTRIBUTES.add("uid"); 53 COMMON_XML_ATTRIBUTES.add("visible"); 54 COMMON_XML_ATTRIBUTES.add("version"); 55 COMMON_XML_ATTRIBUTES.add("action"); 56 COMMON_XML_ATTRIBUTES.add("changeset"); 57 COMMON_XML_ATTRIBUTES.add("lat"); 58 COMMON_XML_ATTRIBUTES.add("lon"); 59 } 60 42 61 /** 43 62 * constructor (for private and subclasses use only) … … 46 65 */ 47 66 protected OsmReader() { 67 this(false); 68 } 69 70 /** 71 * constructor (for private and subclasses use only) 72 * @param convertUnknownToTags if true, keep unknown xml attributes as tags 73 * 74 * @see #parseDataSet(InputStream, ProgressMonitor) 75 * @since 15470 76 */ 77 protected OsmReader(boolean convertUnknownToTags) { 48 78 // Restricts visibility 79 this.convertUnknownToTags = convertUnknownToTags; 49 80 } 50 81 … … 394 425 parseAction(current, parser.getAttributeValue(null, "action")); 395 426 parseChangeset(current, parser.getAttributeValue(null, "changeset")); 427 428 if (convertUnknownToTags) { 429 for (int i = 0; i < parser.getAttributeCount(); i++) { 430 if (!COMMON_XML_ATTRIBUTES.contains(parser.getAttributeLocalName(i))) { 431 parseTag(current, parser.getAttributeLocalName(i), parser.getAttributeValue(i)); 432 } 433 } 434 } 396 435 } catch (UncheckedParseException | XMLStreamException e) { 397 436 throw new IllegalDataException(e); … … 458 497 */ 459 498 public static DataSet parseDataSet(InputStream source, ProgressMonitor progressMonitor) throws IllegalDataException { 460 return new OsmReader().doParseDataSet(source, progressMonitor); 499 return parseDataSet(source, progressMonitor, false); 500 } 501 502 /** 503 * Parse the given input source and return the dataset. 504 * 505 * @param source the source input stream. Must not be null. 506 * @param progressMonitor the progress monitor. If null, {@link NullProgressMonitor#INSTANCE} is assumed 507 * @param convertUnknownToTags true if unknown xml attributes should be kept as tags 508 * 509 * @return the dataset with the parsed data 510 * @throws IllegalDataException if an error was found while parsing the data from the source 511 * @throws IllegalArgumentException if source is null 512 * @since 15470 513 */ 514 public static DataSet parseDataSet(InputStream source, ProgressMonitor progressMonitor, boolean convertUnknownToTags) 515 throws IllegalDataException { 516 return new OsmReader(convertUnknownToTags).doParseDataSet(source, progressMonitor); 461 517 } 462 518 }
Note:
See TracChangeset
for help on using the changeset viewer.