Changeset 16641 in josm for trunk/src/org/openstreetmap/josm
- Timestamp:
- 2020-06-14T19:35:04+02:00 (4 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java
r15820 r16641 735 735 "created_by", 736 736 "converted_by", 737 "current_id", 737 738 "geobase:datasetName", 738 739 "geobase:uuid", -
trunk/src/org/openstreetmap/josm/io/OsmReader.java
r15470 r16641 5 5 6 6 import java.io.InputStream; 7 import java.util.Arrays; 7 8 import java.util.Collection; 9 import java.util.Collections; 8 10 import java.util.Objects; 9 11 import java.util.Set; … … 40 42 public class OsmReader extends AbstractReader { 41 43 44 /** 45 * Options are used to change how the xml data is parsed. 46 * For example, {@link Options#CONVERT_UNKNOWN_TO_TAGS} is used to convert unknown XML attributes to a tag for the object. 47 * @since 16641 48 */ 49 public enum Options { 50 /** 51 * Convert unknown XML attributes to tags 52 */ 53 CONVERT_UNKNOWN_TO_TAGS, 54 /** 55 * Save the original id of an object (currently stored in `current_id`) 56 */ 57 SAVE_ORIGINAL_ID 58 } 59 42 60 protected XMLStreamReader parser; 43 61 44 protected boolean convertUnknownToTags; 62 /** The {@link OsmReader.Options} to use when parsing the xml data */ 63 protected final Collection<Options> options; 45 64 46 65 private static final Set<String> COMMON_XML_ATTRIBUTES = new TreeSet<>(); … … 65 84 */ 66 85 protected OsmReader() { 67 this( false);86 this((Options) null); 68 87 } 69 88 70 89 /** 71 90 * constructor (for private and subclasses use only) 72 * @param convertUnknownToTags if true, keep unknown xml attributes as tags91 * @param options The options to use when reading data 73 92 * 74 93 * @see #parseDataSet(InputStream, ProgressMonitor) 75 * @since 1 547076 */ 77 protected OsmReader( boolean convertUnknownToTags) {94 * @since 16641 95 */ 96 protected OsmReader(Options... options) { 78 97 // Restricts visibility 79 this. convertUnknownToTags = convertUnknownToTags;98 this.options = options == null ? Collections.emptyList() : Arrays.asList(options); 80 99 } 81 100 … … 426 445 parseChangeset(current, parser.getAttributeValue(null, "changeset")); 427 446 428 if (convertUnknownToTags) { 447 if (options.contains(Options.SAVE_ORIGINAL_ID)) { 448 parseTag(current, "current_id", Long.toString(getLong("id"))); 449 } 450 if (options.contains(Options.CONVERT_UNKNOWN_TO_TAGS)) { 429 451 for (int i = 0; i < parser.getAttributeCount(); i++) { 430 452 if (!COMMON_XML_ATTRIBUTES.contains(parser.getAttributeLocalName(i))) { … … 497 519 */ 498 520 public static DataSet parseDataSet(InputStream source, ProgressMonitor progressMonitor) throws IllegalDataException { 499 return parseDataSet(source, progressMonitor, false);521 return parseDataSet(source, progressMonitor, (Options) null); 500 522 } 501 523 … … 505 527 * @param source the source input stream. Must not be null. 506 528 * @param progressMonitor the progress monitor. If null, {@link NullProgressMonitor#INSTANCE} is assumed 507 * @param convertUnknownToTags true if unknown xml attributes should be kept as tags529 * @param options The options to use when parsing the dataset 508 530 * 509 531 * @return the dataset with the parsed data 510 532 * @throws IllegalDataException if an error was found while parsing the data from the source 511 533 * @throws IllegalArgumentException if source is null 512 * @since 1 5470513 */ 514 public static DataSet parseDataSet(InputStream source, ProgressMonitor progressMonitor, boolean convertUnknownToTags)534 * @since 16641 535 */ 536 public static DataSet parseDataSet(InputStream source, ProgressMonitor progressMonitor, Options... options) 515 537 throws IllegalDataException { 516 return new OsmReader( convertUnknownToTags).doParseDataSet(source, progressMonitor);538 return new OsmReader(options).doParseDataSet(source, progressMonitor); 517 539 } 518 540 }
Note:
See TracChangeset
for help on using the changeset viewer.