source: josm/trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmIdTask.java@ 13632

Last change on this file since 13632 was 12634, checked in by Don-vip, 7 years ago

see #15182 - deprecate Main.worker, replace it by gui.MainApplication.worker + code refactoring to make sure only editor packages use it

  • Property svn:eol-style set to native
File size: 2.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions.downloadtasks;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.util.Collections;
7import java.util.concurrent.Future;
8import java.util.regex.Matcher;
9import java.util.regex.Pattern;
10
11import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
12import org.openstreetmap.josm.data.osm.PrimitiveId;
13import org.openstreetmap.josm.data.osm.SimplePrimitiveId;
14import org.openstreetmap.josm.gui.MainApplication;
15import org.openstreetmap.josm.gui.io.DownloadPrimitivesWithReferrersTask;
16import org.openstreetmap.josm.gui.progress.ProgressMonitor;
17
18/**
19 * Specialized task for downloading OSM objects by ID.
20 * <p>
21 * It handles one URL pattern: openstreetmap website URL with {@code /(node|way|relation)/<id>} argument.
22 * @since 8240
23 */
24public class DownloadOsmIdTask extends DownloadOsmTask {
25
26 private static final String URL_ID_PATTERN = "https?://www\\.(osm|openstreetmap)\\.org/(node|way|relation)/(\\p{Digit}+).*";
27
28 @Override
29 public String[] getPatterns() {
30 return new String[]{URL_ID_PATTERN};
31 }
32
33 @Override
34 public Future<?> loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor) {
35 final Matcher matcher = Pattern.compile(URL_ID_PATTERN).matcher(url);
36 if (matcher.matches()) {
37 final OsmPrimitiveType type = OsmPrimitiveType.from(matcher.group(2));
38 final long id = Long.parseLong(matcher.group(3));
39 final PrimitiveId primitiveId = new SimplePrimitiveId(id, type);
40 final DownloadPrimitivesWithReferrersTask downloadTask = new DownloadPrimitivesWithReferrersTask(
41 newLayer, Collections.singletonList(primitiveId), true, true, null, null);
42 return MainApplication.worker.submit(downloadTask);
43 } else {
44 throw new IllegalStateException("Failed to parse id from " + url);
45 }
46 }
47
48 @Override
49 public String getTitle() {
50 return tr("Download OSM object by ID");
51 }
52}
Note: See TracBrowser for help on using the repository browser.