Ticket #18038: 18038.2.patch

File 18038.2.patch, 4.1 KB (added by taylor.smock, 5 years ago)

Code deduplication (new function parseUrlTagsToKeyValues)

  • src/org/openstreetmap/josm/io/remotecontrol/AddTagsDialog.java

     
    280280    public static void addTags(final Map<String, String> args, final String sender, final Collection<? extends OsmPrimitive> primitives) {
    281281        if (args.containsKey("addtags")) {
    282282            GuiHelper.executeByMainWorkerInEDT(() -> {
    283                 Set<String> tagSet = new LinkedHashSet<>(); // preserve order, see #15704
    284                 for (String tag1 : args.get("addtags").split("\\|")) {
    285                     if (!tag1.trim().isEmpty() && tag1.contains("=")) {
    286                         tagSet.add(tag1.trim());
    287                     }
    288                 }
    289                 if (!tagSet.isEmpty()) {
    290                     String[][] keyValue = new String[tagSet.size()][2];
    291                     int i = 0;
    292                     for (String tag2 : tagSet) {
    293                         // support a  =   b===c as "a"="b===c"
    294                         String[] pair = tag2.split("\\s*=\\s*", 2);
    295                         keyValue[i][0] = pair[0];
    296                         keyValue[i][1] = pair.length < 2 ? "" : pair[1];
    297                         i++;
    298                     }
    299                     addTags(keyValue, sender, primitives);
    300                 }
     283                addTags(parseUrlTagsToKeyValues(args.get("addtags")), sender, primitives);
    301284            });
    302285        }
    303286    }
    304287
    305288    /**
     289     * Convert a argument from a url to a series of tags
     290     * @param urlSection A url section that looks like {@code tag1=value1|tag2=value2}
     291     * @return An 2d array in the format of {@code [key][value]}
     292     * @since xxx
     293     */
     294    public static String[][] parseUrlTagsToKeyValues(String urlSection) {
     295        Set<String> tagSet = new LinkedHashSet<>();// preserve order, see #15704
     296        String[][] keyValue = new String[][] {};
     297        for (String tag : urlSection.split("\\|")) {
     298            if (!tag.trim().isEmpty() && tag.contains("=")) {
     299                tagSet.add(tag.trim());
     300            }
     301        }
     302        if (!tagSet.isEmpty()) {
     303            keyValue = new String[tagSet.size()][2];
     304            int i = 0;
     305            for (String tag : tagSet) {
     306                // support a  =   b===c as "a"="b===c"
     307                String[] pair = tag.split("\\s*=\\s*", 2);
     308                keyValue[i][0] = pair[0];
     309                keyValue[i][1] = pair.length < 2 ? "" : pair[1];
     310                i++;
     311            }
     312        }
     313        return keyValue;
     314    }
     315
     316    /**
    306317     * Ask user and add the tags he confirm.
    307318     * @param keyValue is a table or {{tag1,val1},{tag2,val2},...}
    308319     * @param sender is a string for skipping confirmations. Use empty string for always confirmed adding.
  • src/org/openstreetmap/josm/io/remotecontrol/handler/LoadAndZoomHandler.java

     
    224224            zoom(Collections.<OsmPrimitive>emptySet(), bbox);
    225225        }
    226226
     227        // This comes before the other changeset tags, so that they can be overridden
     228        if (args.containsKey("changeset_tags")) {
     229            MainApplication.worker.submit(() -> {
     230                DataSet ds = MainApplication.getLayerManager().getEditDataSet();
     231                if (ds != null) {
     232                    String[][] newChangesetTags = AddTagsDialog.parseUrlTagsToKeyValues(args.get("changeset_tags"));
     233                    for (String[] key : newChangesetTags) {
     234                        ds.addChangeSetTag(key[0], key[1]);
     235                    }
     236                }
     237            });
     238        }
     239
    227240        // add changeset tags after download if necessary
    228241        if (args.containsKey("changeset_comment") || args.containsKey("changeset_source") || args.containsKey("changeset_hashtags")) {
    229242            MainApplication.worker.submit(() -> {