Ticket #18258: 18258.patch

File 18258.patch, 3.3 KB (added by taylor.smock, 6 years ago)

Implementation of (2) (no unit tests)

  • src/org/openstreetmap/josm/io/OsmReader.java

     
    4242    protected XMLStreamReader parser;
    4343
    4444    protected boolean convertUnknownToTags;
     45    protected boolean saveOriginalId;
    4546
    4647    private static final Set<String> COMMON_XML_ATTRIBUTES = new TreeSet<>();
    4748
     
    6465     * @see #parseDataSet(InputStream, ProgressMonitor)
    6566     */
    6667    protected OsmReader() {
    67         this(false);
     68        this(false, false);
    6869    }
    6970
    7071    /**
     
    7576     * @since 15470
    7677     */
    7778    protected OsmReader(boolean convertUnknownToTags) {
     79        this(convertUnknownToTags, false);
    7880        // Restricts visibility
     81    }
     82    /**
     83     * constructor (for private and subclasses use only)
     84     * @param convertUnknownToTags if true, keep unknown xml attributes as tags
     85     * @param saveOriginalId if true, save the original id in a "current_id" tag
     86     *
     87     * @see #parseDataSet(InputStream, ProgressMonitor)
     88     * @since xxx
     89     */
     90    protected OsmReader(boolean convertUnknownToTags, boolean saveOriginalId) {
     91        // Restricts visibility
    7992        this.convertUnknownToTags = convertUnknownToTags;
    8093    }
    8194
     
    432445                    }
    433446                }
    434447            }
     448            if (saveOriginalId) {
     449                parseTag(current, "current_id", Long.toString(getLong("id")));
     450            }
    435451        } catch (UncheckedParseException | XMLStreamException e) {
    436452            throw new IllegalDataException(e);
    437453        }
     
    496512     * @throws IllegalArgumentException if source is null
    497513     */
    498514    public static DataSet parseDataSet(InputStream source, ProgressMonitor progressMonitor) throws IllegalDataException {
    499         return parseDataSet(source, progressMonitor, false);
     515        return parseDataSet(source, progressMonitor, false, false);
    500516    }
    501517
    502518    /**
     
    513529     */
    514530    public static DataSet parseDataSet(InputStream source, ProgressMonitor progressMonitor, boolean convertUnknownToTags)
    515531            throws IllegalDataException {
    516         return new OsmReader(convertUnknownToTags).doParseDataSet(source, progressMonitor);
     532        return parseDataSet(source, progressMonitor, convertUnknownToTags, false);
    517533    }
     534   
     535    /**
     536     * Parse the given input source and return the dataset.
     537     *
     538     * @param source the source input stream. Must not be null.
     539     * @param progressMonitor the progress monitor. If null, {@link NullProgressMonitor#INSTANCE} is assumed
     540     * @param convertUnknownToTags true if unknown xml attributes should be kept as tags
     541     * @param saveOriginalId if true, keep the original id (as a tag, "current_id")
     542     *
     543     * @return the dataset with the parsed data
     544     * @throws IllegalDataException if an error was found while parsing the data from the source
     545     * @throws IllegalArgumentException if source is null
     546     * @since xxx
     547     */
     548    public static DataSet parseDataSet(InputStream source, ProgressMonitor progressMonitor, boolean convertUnknownToTags, boolean saveOriginalId)
     549            throws IllegalDataException {
     550        return new OsmReader(convertUnknownToTags, saveOriginalId).doParseDataSet(source, progressMonitor);
     551    }
    518552}