Ticket #17459: add-reverter-core-hacks.patch
File add-reverter-core-hacks.patch, 9.0 KB (added by , 6 years ago) |
---|
-
src/org/openstreetmap/josm/data/osm/ChangesetDataSet.java
15 15 * A ChangesetDataSet holds the content of a changeset. 16 16 */ 17 17 public class ChangesetDataSet { 18 private final boolean useEarliestVersion; 18 19 19 20 /** 21 * Constructs a new {@code ChangesetDataSet} 22 * For primitives which appear with different versions the last version is kept. 23 */ 24 public ChangesetDataSet() { 25 this.useEarliestVersion = false; 26 } 27 28 /** 29 * Constructs a new {@code ChangesetDataSet} 30 * @param useEarliestVersion if true, keep the first version of a primitive, else the last version is kept. 31 */ 32 public ChangesetDataSet(boolean useEarliestVersion) { 33 this.useEarliestVersion = useEarliestVersion; 34 } 35 36 /** 20 37 * Type of primitive modification. 21 38 */ 22 39 public enum ChangesetModificationType { … … 60 77 public void put(HistoryOsmPrimitive primitive, ChangesetModificationType cmt) { 61 78 CheckParameterUtil.ensureParameterNotNull(primitive, "primitive"); 62 79 CheckParameterUtil.ensureParameterNotNull(cmt, "cmt"); 63 primitives.put(primitive.getPrimitiveId(), primitive); 64 modificationTypes.put(primitive.getPrimitiveId(), cmt); 80 if (!useEarliestVersion || !primitives.containsKey(primitive)) { 81 primitives.put(primitive.getPrimitiveId(), primitive); 82 modificationTypes.put(primitive.getPrimitiveId(), cmt); 83 } 65 84 } 66 85 67 86 /** -
src/org/openstreetmap/josm/io/AbstractParser.java
28 28 /** the current primitive to be read */ 29 29 protected HistoryOsmPrimitive currentPrimitive; 30 30 protected Locator locator; 31 /** if true, replace user information in input by anonymous user */ 32 protected boolean useAnonymousUser; 31 33 32 34 @Override 33 35 public void setDocumentLocator(Locator locator) { … … 111 113 long changesetId = changeset != null ? changeset : 0L; 112 114 boolean visible = getMandatoryAttributeBoolean(atts, "visible"); 113 115 114 Long uid = getAttributeLong(atts, "uid"); 115 String userStr = atts.getValue("user"); 116 User user; 117 if (userStr != null) { 118 if (uid != null) { 119 user = User.createOsmUser(uid, userStr); 120 user.setPreferredName(userStr); 121 } else { 122 user = User.createLocalUser(userStr); 116 User user = null; 117 if (!useAnonymousUser) { 118 Long uid = getAttributeLong(atts, "uid"); 119 String userStr = atts.getValue("user"); 120 if (userStr != null) { 121 if (uid != null) { 122 user = User.createOsmUser(uid, userStr); 123 user.setPreferredName(userStr); 124 } else { 125 user = User.createLocalUser(userStr); 126 } 123 127 } 124 } else { 128 } 129 if (user == null) { 125 130 user = User.getAnonymous(); 126 131 } 127 132 -
src/org/openstreetmap/josm/io/OsmChangesetContentParser.java
31 31 public class OsmChangesetContentParser { 32 32 33 33 private final InputSource source; 34 private final ChangesetDataSet data = new ChangesetDataSet();34 private final ChangesetDataSet data; 35 35 36 36 private class Parser extends AbstractParser { 37 Parser(boolean useAnonymousUser) { 38 this.useAnonymousUser = useAnonymousUser; 39 } 37 40 38 41 /** the current change modification type */ 39 42 private ChangesetDataSet.ChangesetModificationType currentModificationType; … … 115 118 } 116 119 117 120 /** 121 * Constructs a new {@code OsmChangesetContentParser} which keeps the oldest version if 122 * multiple versions of a primitive appear in one changeset. 123 * 124 * @param source the input stream with the changeset content as XML document. Must not be null. 125 * @throws IllegalArgumentException if source is {@code null}. 126 */ 127 public OsmChangesetContentParser(InputStream source) { 128 this(source, false); 129 } 130 131 /** 118 132 * Constructs a new {@code OsmChangesetContentParser}. 119 133 * 120 134 * @param source the input stream with the changeset content as XML document. Must not be null. 135 * @param useEarliestVersion if true, keep the first version of a primitive, else the last version is kept. 121 136 * @throws IllegalArgumentException if source is {@code null}. 137 * @since xxx 122 138 */ 123 @SuppressWarnings("resource") 124 public OsmChangesetContentParser(InputStream source) { 139 public OsmChangesetContentParser(InputStream source, boolean useEarliestVersion) { 125 140 CheckParameterUtil.ensureParameterNotNull(source, "source"); 126 141 this.source = new InputSource(new InputStreamReader(source, StandardCharsets.UTF_8)); 142 data = new ChangesetDataSet(useEarliestVersion); 127 143 } 128 144 129 145 /** … … 135 151 public OsmChangesetContentParser(String source) { 136 152 CheckParameterUtil.ensureParameterNotNull(source, "source"); 137 153 this.source = new InputSource(new StringReader(source)); 154 data = new ChangesetDataSet(); 138 155 } 139 156 140 157 /** … … 146 163 * exceptions. 147 164 */ 148 165 public ChangesetDataSet parse(ProgressMonitor progressMonitor) throws XmlParsingException { 166 return parse(progressMonitor, false); 167 } 168 169 /** 170 * Parses the content. 171 * 172 * @param progressMonitor the progress monitor. Set to {@link NullProgressMonitor#INSTANCE} if null 173 * @param useAnonymousUser if true, replace all user information with the anonymous user 174 * @return the parsed data 175 * @throws XmlParsingException if something went wrong. Check for chained 176 * exceptions. 177 */ 178 public ChangesetDataSet parse(ProgressMonitor progressMonitor, boolean useAnonymousUser) throws XmlParsingException { 149 179 if (progressMonitor == null) { 150 180 progressMonitor = NullProgressMonitor.INSTANCE; 151 181 } … … 152 182 try { 153 183 progressMonitor.beginTask(""); 154 184 progressMonitor.indeterminateSubTask(tr("Parsing changeset content ...")); 155 XmlUtils.parseSafeSAX(source, new Parser( ));185 XmlUtils.parseSafeSAX(source, new Parser(useAnonymousUser)); 156 186 } catch (XmlParsingException e) { 157 187 throw e; 158 188 } catch (ParserConfigurationException | SAXException | IOException e) { … … 171 201 * exceptions. 172 202 */ 173 203 public ChangesetDataSet parse() throws XmlParsingException { 174 return parse(null );204 return parse(null, false); 175 205 } 176 206 } -
src/org/openstreetmap/josm/io/OsmServerChangesetReader.java
26 26 * 27 27 */ 28 28 public class OsmServerChangesetReader extends OsmServerReader { 29 final boolean useAnonymousUser; 30 final boolean useEarliestVersion; 29 31 32 30 33 /** 34 * Constructs a new {@code OsmServerChangesetReader} with default settings. 35 */ 36 public OsmServerChangesetReader() { 37 this(false, false); 38 } 39 40 /** 41 * Constructs a new {@code OsmServerChangesetReader} 42 * @param useAnonymousUser if true, replace all user information with the anonymous user 43 * @param useEarliestVersion if true, keep the first version of a primitive, else the last version is kept. 44 * @since xxx 45 */ 46 public OsmServerChangesetReader(boolean useAnonymousUser, boolean useEarliestVersion) { 47 super(); 48 this.useAnonymousUser = useAnonymousUser; 49 this.useEarliestVersion = useEarliestVersion; 50 } 51 52 /** 31 53 * don't use - not implemented! 32 54 */ 33 55 @Override … … 197 219 if (in == null) 198 220 return null; 199 221 monitor.setCustomText(tr("Downloading content for changeset {0} ...", id)); 200 OsmChangesetContentParser parser = new OsmChangesetContentParser(in );201 result = parser.parse(monitor.createSubTaskMonitor(1, true) );222 OsmChangesetContentParser parser = new OsmChangesetContentParser(in, useEarliestVersion); 223 result = parser.parse(monitor.createSubTaskMonitor(1, true), useAnonymousUser); 202 224 } catch (IOException e) { 203 225 Logging.warn(e); 204 226 }