|
Last change
on this file since 8195 was 8195, checked in by simon04, 11 years ago |
|
see #9907 - Make "Open Location" capable of downloading notes
If more than one download task is suitable, ask the user which tasks to perform.
|
|
File size:
1.2 KB
|
| Line | |
|---|
| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package org.openstreetmap.josm.actions.downloadtasks;
|
|---|
| 3 |
|
|---|
| 4 | import org.openstreetmap.josm.gui.progress.ProgressMonitor;
|
|---|
| 5 |
|
|---|
| 6 | import java.util.concurrent.Future;
|
|---|
| 7 | import java.util.regex.Matcher;
|
|---|
| 8 | import java.util.regex.Pattern;
|
|---|
| 9 |
|
|---|
| 10 | import static org.openstreetmap.josm.tools.I18n.tr;
|
|---|
| 11 |
|
|---|
| 12 | public class DownloadNotesUrlIdTask extends DownloadNotesTask {
|
|---|
| 13 |
|
|---|
| 14 | private final String URL_ID_PATTERN = "https?://www\\.(osm|openstreetmap)\\.org/note/(\\p{Digit}+).*";
|
|---|
| 15 |
|
|---|
| 16 | @Override
|
|---|
| 17 | public Future<?> loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor) {
|
|---|
| 18 | final Matcher matcher = Pattern.compile(URL_ID_PATTERN).matcher(url);
|
|---|
| 19 | final long id;
|
|---|
| 20 | try {
|
|---|
| 21 | matcher.matches();
|
|---|
| 22 | return download(newLayer, Long.parseLong(matcher.group(2)), null);
|
|---|
| 23 | } catch (RuntimeException ex) {
|
|---|
| 24 | throw new IllegalStateException("Failed to parse note id from " + url);
|
|---|
| 25 | }
|
|---|
| 26 | }
|
|---|
| 27 |
|
|---|
| 28 | @Override
|
|---|
| 29 | public String[] getPatterns() {
|
|---|
| 30 | return new String[]{URL_ID_PATTERN};
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | public boolean acceptsUrl(String url) {
|
|---|
| 34 | return super.acceptsUrl(url);
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | @Override
|
|---|
| 38 | public String getTitle() {
|
|---|
| 39 | return tr("Download OSM Note by ID");
|
|---|
| 40 | }
|
|---|
| 41 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.