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

Last change on this file since 12182 was 8624, checked in by bastiK, 9 years ago

add missing svn:eol-style=native

  • Property svn:eol-style set to native
File size: 1.8 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.Main;
12import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
13import org.openstreetmap.josm.data.osm.PrimitiveId;
14import org.openstreetmap.josm.data.osm.SimplePrimitiveId;
15import org.openstreetmap.josm.gui.io.DownloadPrimitivesWithReferrersTask;
16import org.openstreetmap.josm.gui.progress.ProgressMonitor;
17
18public class DownloadOsmIdTask extends DownloadOsmTask {
19
20 private static final String URL_ID_PATTERN = "https?://www\\.(osm|openstreetmap)\\.org/(node|way|relation)/(\\p{Digit}+).*";
21
22 @Override
23 public String[] getPatterns() {
24 return new String[]{URL_ID_PATTERN};
25 }
26
27 @Override
28 public Future<?> loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor) {
29 final Matcher matcher = Pattern.compile(URL_ID_PATTERN).matcher(url);
30 if (matcher.matches()) {
31 final OsmPrimitiveType type = OsmPrimitiveType.from(matcher.group(2));
32 final long id = Long.parseLong(matcher.group(3));
33 final PrimitiveId primitiveId = new SimplePrimitiveId(id, type);
34 final DownloadPrimitivesWithReferrersTask downloadTask = new DownloadPrimitivesWithReferrersTask(
35 newLayer, Collections.singletonList(primitiveId), true, true, null, null);
36 return Main.worker.submit(downloadTask);
37 } else {
38 throw new IllegalStateException("Failed to parse id from " + url);
39 }
40 }
41
42 @Override
43 public String getTitle() {
44 return tr("Download OSM object by ID");
45 }
46}
Note: See TracBrowser for help on using the repository browser.