Changeset 13028 in josm


Ignore:
Timestamp:
2017-10-21T14:07:26+02:00 (4 weeks ago)
Author:
Don-vip
Message:

fix #15464 - Allow plugins to modify the changeset tags before upload (patch by rorym)

Location:
trunk/src/org/openstreetmap/josm/actions
Files:
2 edited

Legend:

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

    r12636 r13028  
    99import java.util.LinkedList;
    1010import java.util.List;
     11import java.util.Map;
    1112
    1213import javax.swing.JOptionPane;
     
    2122import org.openstreetmap.josm.data.APIDataSet;
    2223import org.openstreetmap.josm.data.conflict.ConflictCollection;
     24import org.openstreetmap.josm.data.osm.Changeset;
    2325import org.openstreetmap.josm.gui.HelpAwareOptionPane;
    2426import org.openstreetmap.josm.gui.MainApplication;
     
    246248        }
    247249
     250        // Any hooks want to change the changeset tags?
     251        Changeset cs = UploadDialog.getUploadDialog().getChangeset();
     252        Map<String, String> changesetTags = cs.getKeys();
     253        for (UploadHook hook : UPLOAD_HOOKS) {
     254            hook.modifyChangesetTags(changesetTags);
     255        }
     256        for (UploadHook hook : LATE_UPLOAD_HOOKS) {
     257            hook.modifyChangesetTags(changesetTags);
     258        }
     259
    248260        MainApplication.worker.execute(
    249261                new UploadPrimitivesTask(
     
    251263                        layer,
    252264                        apiData,
    253                         UploadDialog.getUploadDialog().getChangeset()
     265                        cs
    254266                )
    255267        );
  • trunk/src/org/openstreetmap/josm/actions/upload/UploadHook.java

    r12581 r13028  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.actions.upload;
     3
     4import java.util.Map;
    35
    46import org.openstreetmap.josm.data.APIDataSet;
    57
    68/**
    7  * A check right before the upload. The UploadHook may modify the uploaded data
    8  * silently, it may display a warning message to the user or prevent the upload
    9  * altogether.
     9 * Change, or block, the upload.
     10 *
     11 * The UploadHook may modify the uploaded data silently, it may display a
     12 * warning message to the user or prevent the upload altogether.
     13 *
     14 * The tags of the changeset can also be changed with modifyChangesetTags method.
    1015 */
    11 @FunctionalInterface
    1216public interface UploadHook {
    1317
    1418    /**
    15      * Checks the upload.
    16      * @param apiDataSet the data to upload
    17      * @return {@code true} if upload is possible
     19     * Check, and/or change, the data to be uploaded.
     20     * Default implementation is to approve the upload.
     21     * @param apiDataSet the data to upload, modify this to change the data.
     22     * @return {@code true} if upload is possible, {@code false} to block the upload.
    1823     */
    19     boolean checkUpload(APIDataSet apiDataSet);
     24    default boolean checkUpload(APIDataSet apiDataSet) {
     25        return true;
     26    }
     27
     28    /**
     29     * Modify the changeset tags (in place) before upload.
     30     * Default implementation is to do no changes.
     31     * @param tags The current tags to change
     32     * @since 13028
     33     */
     34    default void modifyChangesetTags(Map<String, String> tags) {
     35    }
    2036}
Note: See TracChangeset for help on using the changeset viewer.