Changeset 5497 in josm


Ignore:
Timestamp:
2012-09-03T18:56:02+02:00 (5 years ago)
Author:
bastiK
Message:

applied #7915 - Automatically discard some TIGER tags on upload (based on patch by ToeBee)

Location:
trunk/src/org/openstreetmap/josm
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/UploadAction.java

    r5266 r5497  
    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;
     
    5051     */
    5152    private static final LinkedList<UploadHook> uploadHooks = new LinkedList<UploadHook>();
     53    private static final LinkedList<UploadHook> lateUploadHooks = new LinkedList<UploadHook>();
    5254    static {
    5355        uploadHooks.add(new ValidateUploadHook());
     
    6163         */
    6264        uploadHooks.add(new RelationUploadOrderHook());
     65
     66        /**
     67         * Removes discardable tags like created_by on modified objects
     68         */
     69        lateUploadHooks.add(new DiscardTagsHook());
    6370    }
    6471
     
    6976     */
    7077    public static void registerUploadHook(UploadHook hook) {
     78        registerUploadHook(hook, false);
     79    }
     80
     81    /**
     82     * Registers an upload hook. Adds the hook at the first position of the upload hooks.
     83     *
     84     * @param hook the upload hook. Ignored if null.
     85     * @param late true, if the hook should be executed after the upload dialog
     86     * has been confirmed. Late upload hooks should in general succeed and not
     87     * abort the upload.
     88     */
     89    public static void registerUploadHook(UploadHook hook, boolean late) {
    7190        if(hook == null) return;
    72         if (!uploadHooks.contains(hook)) {
    73             uploadHooks.add(0,hook);
     91        if (late) {
     92            if (!lateUploadHooks.contains(hook)) {
     93                lateUploadHooks.add(0, hook);
     94            }
     95        } else {
     96            if (!uploadHooks.contains(hook)) {
     97                uploadHooks.add(0, hook);
     98            }
    7499        }
    75100    }
     
    84109        if (uploadHooks.contains(hook)) {
    85110            uploadHooks.remove(hook);
     111        }
     112        if (lateUploadHooks.contains(hook)) {
     113            lateUploadHooks.remove(hook);
    86114        }
    87115    }
     
    122150     * want to continue
    123151     */
    124     public static final boolean warnUploadDiscouraged(OsmDataLayer layer) {
     152    public static boolean warnUploadDiscouraged(OsmDataLayer layer) {
    125153        return GuiHelper.warnUser(tr("Upload discouraged"),
    126154                "<html>" +
     
    200228        dialog.rememberUserInput();
    201229
     230        for (UploadHook hook : lateUploadHooks) {
     231            if (!hook.checkUpload(apiData))
     232                return;
     233        }
     234
    202235        Main.worker.execute(
    203236                new UploadPrimitivesTask(
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r5442 r5497  
    609609     *----------------------------------*/
    610610
    611 
    612611    private static volatile Collection<String> uninteresting = null;
     612    private static volatile Collection<String> discardable = null;
     613   
    613614    /**
    614615     * Contains a list of "uninteresting" keys that do not make an object
     
    620621        if (uninteresting == null) {
    621622            uninteresting = Main.pref.getCollection("tags.uninteresting",
    622                     Arrays.asList(new String[]{"source", "source_ref", "source:", "note", "comment",
     623                    Arrays.asList("source", "source_ref", "source:", "note", "comment",
    623624                            "converted_by", "created_by", "watch", "watch:", "fixme", "FIXME",
    624                             "description", "attribution"}));
     625                            "description", "attribution"));
    625626        }
    626627        return uninteresting;
     628    }
     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     */
     634    public static Collection<String> getDiscardableKeys() {
     635        if(discardable == null) {
     636            discardable = Main.pref.getCollection("tags.discardable",
     637                    Arrays.asList("created_by",
     638                            "tiger:upload_uuid", "tiger:tlid", "tiger:source", "tiger:separated",
     639                            "geobase:datasetName", "geobase:uuid", "sub_sea:type",
     640                            "odbl", "odbl:note"));
     641        }
     642        return discardable;
    627643    }
    628644
  • trunk/src/org/openstreetmap/josm/io/OsmWriter.java

    r5326 r5497  
    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 + ">");
Note: See TracChangeset for help on using the changeset viewer.