Ticket #7915: discard_tags.patch

File discard_tags.patch, 4.8 KB (added by ToeBee, 5 years ago)

Alright let's try this on for size. Implemented as an upload hook instead.

  • src/org/openstreetmap/josm/actions/UploadAction.java

     
    1313
    1414import org.openstreetmap.josm.Main;
    1515import org.openstreetmap.josm.actions.upload.ApiPreconditionCheckerHook;
     16import org.openstreetmap.josm.actions.upload.DiscardTagsHook;
    1617import org.openstreetmap.josm.actions.upload.RelationUploadOrderHook;
    1718import org.openstreetmap.josm.actions.upload.UploadHook;
    1819import org.openstreetmap.josm.actions.upload.ValidateUploadHook;
     
    6061         * Adjusts the upload order of new relations
    6162         */
    6263        uploadHooks.add(new RelationUploadOrderHook());
     64
     65        /**
     66         * Removes discardable tags like created_by on modified objects
     67         */
     68        uploadHooks.add(new DiscardTagsHook());
    6369    }
    6470
    6571    /**
  • src/org/openstreetmap/josm/actions/upload/DiscardTagsHook.java

     
     1// License: GPL. For details, see LICENSE file.
     2package org.openstreetmap.josm.actions.upload;
     3
     4import java.util.AbstractMap;
     5import java.util.Collection;
     6import java.util.HashMap;
     7import java.util.List;
     8
     9import org.openstreetmap.josm.Main;
     10import org.openstreetmap.josm.command.ChangePropertyCommand;
     11import org.openstreetmap.josm.data.APIDataSet;
     12import org.openstreetmap.josm.data.osm.OsmPrimitive;
     13
     14/**
     15 * Removes discardable tags such as created_by from all modified objects before upload
     16 */
     17public 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

     
    610610
    611611
    612612    private static volatile Collection<String> uninteresting = null;
     613    private static volatile Collection<String> discardable = null;
    613614    /**
    614615     * Contains a list of "uninteresting" keys that do not make an object
    615616     * "tagged".  Entries that end with ':' are causing a whole namespace to be considered
     
    627628    }
    628629
    629630    /**
     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    /**
    630646     * Returns true if key is considered "uninteresting".
    631647     */
    632648    public static boolean isUninterestingKey(String key) {
  • src/org/openstreetmap/josm/io/OsmWriter.java

     
    218218            List<Entry<String, String>> entries = new ArrayList<Entry<String,String>>(osm.getKeys().entrySet());
    219219            Collections.sort(entries, byKeyComparator);
    220220            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())+ "' />");
    225223            }
    226224            out.println("  </" + tagname + ">");
    227225        } else if (tagOpen) {