Changeset 16328 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/remotecontrol/AddTagsDialog.java
r15319 r16328 11 11 import java.awt.event.KeyEvent; 12 12 import java.awt.event.MouseEvent; 13 import java.util.Arrays;14 13 import java.util.Collection; 15 14 import java.util.HashMap; … … 18 17 import java.util.Map.Entry; 19 18 import java.util.Set; 20 import java.util.stream.Collectors;21 19 22 20 import javax.swing.AbstractAction; … … 38 36 import org.openstreetmap.josm.gui.util.TableHelper; 39 37 import org.openstreetmap.josm.tools.GBC; 38 import org.openstreetmap.josm.tools.TextTagParser; 40 39 41 40 /** … … 293 292 * @since 15316 294 293 */ 295 public static String[][] parseUrlTagsToKeyValues(String urlSection) { 296 return Arrays.stream(urlSection.split("\\|")) 297 .map(String::trim) 298 .filter(tag -> !tag.isEmpty() && tag.contains("=")) 299 .map(tag -> tag.split("\\s*=\\s*", 2)) 300 .map(pair -> { 301 pair[1] = pair.length < 2 ? "" : pair[1]; 302 return pair; 303 }) 304 .collect(Collectors.toList()).toArray(new String[][] {}); 294 public static Map<String, String> parseUrlTagsToKeyValues(String urlSection) { 295 return TextTagParser.readTagsByRegexp(urlSection, "\\|", "(.*?)=(.*?)", false); 305 296 } 306 297 … … 313 304 */ 314 305 public static void addTags(String[][] keyValue, String sender, Collection<? extends OsmPrimitive> primitives) { 315 if (trustedSenders.contains(sender)) { 316 if (MainApplication.getLayerManager().getEditDataSet() != null) { 317 for (String[] row : keyValue) { 318 UndoRedoHandler.getInstance().add(new ChangePropertyCommand(primitives, row[0], row[1])); 319 } 320 } 321 } else { 322 new AddTagsDialog(keyValue, sender, primitives).showDialog(); 323 } 306 new AddTagsDialog(keyValue, sender, primitives).showDialog(); 324 307 } 325 308 } -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/LoadAndZoomHandler.java
r16324 r16328 269 269 DataSet ds = MainApplication.getLayerManager().getEditDataSet(); 270 270 if (ds != null) { 271 for (String[] key : AddTagsDialog.parseUrlTagsToKeyValues(args.get("changeset_tags"))) { 272 ds.addChangeSetTag(key[0], key[1]); 273 } 271 AddTagsDialog.parseUrlTagsToKeyValues(args.get("changeset_tags")).forEach(ds::addChangeSetTag); 274 272 } 275 273 }); -
trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/AddTagsDialogTest.java
r16327 r16328 4 4 import static org.junit.Assert.assertEquals; 5 5 6 import java.util. Arrays;6 import java.util.Map; 7 7 8 import org.junit.Rule; 8 9 import org.junit.Test; 10 import org.openstreetmap.josm.testutils.JOSMTestRules; 11 12 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 9 13 10 14 /** … … 12 16 */ 13 17 public class AddTagsDialogTest { 18 /** 19 * Setup test. 20 */ 21 @Rule 22 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 23 public JOSMTestRules test = new JOSMTestRules().preferences(); 14 24 15 25 /** … … 18 28 @Test 19 29 public void testParseUrlTagsToKeyValues() { 20 String[][] strings = AddTagsDialog.parseUrlTagsToKeyValues("wikipedia:de=Residenzschloss Dresden|name:en=Dresden Castle"); 21 assertEquals("[[wikipedia:de, Residenzschloss Dresden], [name:en, Dresden Castle]]", Arrays.deepToString(strings)); 30 Map<String, String> strings = AddTagsDialog.parseUrlTagsToKeyValues("wikipedia:de=Residenzschloss Dresden|name:en=Dresden Castle"); 31 assertEquals(2, strings.size()); 32 assertEquals("Residenzschloss Dresden", strings.get("wikipedia:de")); 33 assertEquals("Dresden Castle", strings.get("name:en")); 22 34 } 23 35 }
Note:
See TracChangeset
for help on using the changeset viewer.