Ticket #7915: discard_tags.patch
File discard_tags.patch, 4.8 KB (added by , 12 years ago) |
---|
-
src/org/openstreetmap/josm/actions/UploadAction.java
13 13 14 14 import org.openstreetmap.josm.Main; 15 15 import org.openstreetmap.josm.actions.upload.ApiPreconditionCheckerHook; 16 import org.openstreetmap.josm.actions.upload.DiscardTagsHook; 16 17 import org.openstreetmap.josm.actions.upload.RelationUploadOrderHook; 17 18 import org.openstreetmap.josm.actions.upload.UploadHook; 18 19 import org.openstreetmap.josm.actions.upload.ValidateUploadHook; … … 60 61 * Adjusts the upload order of new relations 61 62 */ 62 63 uploadHooks.add(new RelationUploadOrderHook()); 64 65 /** 66 * Removes discardable tags like created_by on modified objects 67 */ 68 uploadHooks.add(new DiscardTagsHook()); 63 69 } 64 70 65 71 /** -
src/org/openstreetmap/josm/actions/upload/DiscardTagsHook.java
1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.actions.upload; 3 4 import java.util.AbstractMap; 5 import java.util.Collection; 6 import java.util.HashMap; 7 import java.util.List; 8 9 import org.openstreetmap.josm.Main; 10 import org.openstreetmap.josm.command.ChangePropertyCommand; 11 import org.openstreetmap.josm.data.APIDataSet; 12 import org.openstreetmap.josm.data.osm.OsmPrimitive; 13 14 /** 15 * Removes discardable tags such as created_by from all modified objects before upload 16 */ 17 public class DiscardTagsHook implements UploadHook { 18 19 public boolean checkUpload(APIDataSet apiDataSet) { 20 List<OsmPrimitive> objectsToUpload = apiDataSet.getPrimitives(); 21 22 Collection<String> discardableKeys = OsmPrimitive.getDiscardableKeys(); 23 AbstractMap<String, String> foo = new HashMap<String, String>(); 24 for (String string : discardableKeys) { 25 foo.put(string, null); 26 } 27 28 ChangePropertyCommand removeKeys = new ChangePropertyCommand(objectsToUpload, foo); 29 Main.main.undoRedo.add(removeKeys); 30 31 return true; 32 } 33 34 } -
src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
610 610 611 611 612 612 private static volatile Collection<String> uninteresting = null; 613 private static volatile Collection<String> discardable = null; 613 614 /** 614 615 * Contains a list of "uninteresting" keys that do not make an object 615 616 * "tagged". Entries that end with ':' are causing a whole namespace to be considered … … 627 628 } 628 629 629 630 /** 631 * Returns a list of keys which have been deemed uninteresting to the point 632 * that they can be silently removed from data which is being edited. 633 * The first example of this is the "created_by" tag on map objects. 634 */ 635 public static Collection<String> getDiscardableKeys() { 636 if(discardable == null) { 637 discardable = Main.pref.getCollection("tags.discardable", 638 Arrays.asList(new String[]{"created_by", 639 "tiger:upload_uuid", "tiger:tlid", "tiger:source", "tiger:separated", 640 "geobase:datasetName", "geobase:uuid", "geobase:datasetName", "sub_sea:type"})); 641 } 642 return discardable; 643 } 644 645 /** 630 646 * Returns true if key is considered "uninteresting". 631 647 */ 632 648 public static boolean isUninterestingKey(String key) { -
src/org/openstreetmap/josm/io/OsmWriter.java
218 218 List<Entry<String, String>> entries = new ArrayList<Entry<String,String>>(osm.getKeys().entrySet()); 219 219 Collections.sort(entries, byKeyComparator); 220 220 for (Entry<String, String> e : entries) { 221 if ((osm instanceof Changeset) || !("created_by".equals(e.getKey()))) { 222 out.println(" <tag k='"+ XmlWriter.encode(e.getKey()) + 223 "' v='"+XmlWriter.encode(e.getValue())+ "' />"); 224 } 221 out.println(" <tag k='"+ XmlWriter.encode(e.getKey()) + 222 "' v='"+XmlWriter.encode(e.getValue())+ "' />"); 225 223 } 226 224 out.println(" </" + tagname + ">"); 227 225 } else if (tagOpen) {