Changeset 8240 in josm for trunk


Ignore:
Timestamp:
2015-04-20T00:15:43+02:00 (4 years ago)
Author:
simon04
Message:

Open Location: enable loading of nodes/ways/relations/changesets from OSM website URL

Up to now, only corresponding API URLs have been supported.

Location:
trunk/src/org/openstreetmap/josm/actions
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/OpenLocationAction.java

    r8203 r8240  
    3131import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmChangeTask;
    3232import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmCompressedTask;
     33import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmIdTask;
    3334import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask;
    3435import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmUrlTask;
     
    6869        addDownloadTaskClass(DownloadOsmChangeTask.class);
    6970        addDownloadTaskClass(DownloadOsmUrlTask.class);
     71        addDownloadTaskClass(DownloadOsmIdTask.class);
    7072        addDownloadTaskClass(DownloadOsmCompressedTask.class);
    7173        addDownloadTaskClass(DownloadOsmChangeCompressedTask.class);
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadNotesUrlIdTask.java

    r8195 r8240  
    1717    public Future<?> loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor) {
    1818        final Matcher matcher = Pattern.compile(URL_ID_PATTERN).matcher(url);
    19         final long id;
    20         try {
    21             matcher.matches();
     19        if (matcher.matches()) {
    2220            return download(newLayer, Long.parseLong(matcher.group(2)), null);
    23         } catch (RuntimeException ex) {
     21        } else {
    2422            throw new IllegalStateException("Failed to parse note id from " + url);
    2523        }
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmChangeTask.java

    r7937 r8240  
    1010import java.util.Map;
    1111import java.util.concurrent.Future;
     12import java.util.regex.Matcher;
     13import java.util.regex.Pattern;
    1214
    1315import org.openstreetmap.josm.Main;
     
    3234import org.openstreetmap.josm.gui.history.HistoryLoadTask;
    3335import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     36import org.openstreetmap.josm.io.OsmApi;
    3437import org.openstreetmap.josm.io.OsmServerLocationReader;
    3538import org.openstreetmap.josm.io.OsmServerReader;
     
    4245public class DownloadOsmChangeTask extends DownloadOsmTask {
    4346
     47    private static final String OSM_WEBSITE_PATTERN = "https?://www\\.(osm|openstreetmap)\\.org/changeset/(\\p{Digit}+).*";
     48
    4449    @Override
    4550    public String[] getPatterns() {
    4651        return new String[]{"https?://.*/api/0.6/changeset/\\p{Digit}+/download", // OSM API 0.6 changesets
     52            OSM_WEBSITE_PATTERN, // OSM changesets
    4753            "https?://.*/.*\\.osc" // Remote .osc files
    4854        };
     
    6167
    6268    @Override
    63     public Future<?> loadUrl(boolean new_layer, String url,
    64             ProgressMonitor progressMonitor) {
    65         downloadTask = new DownloadTask(new_layer,
    66                 new OsmServerLocationReader(url),
    67                 progressMonitor);
     69    public Future<?> loadUrl(boolean new_layer, String url, ProgressMonitor progressMonitor) {
     70        final Matcher matcher = Pattern.compile(OSM_WEBSITE_PATTERN).matcher(url);
     71        if (matcher.matches()) {
     72            url = OsmApi.getOsmApi().getBaseUrl() + "changeset/" + Long.parseLong(matcher.group(2)) + "/download";
     73        }
     74        downloadTask = new DownloadTask(new_layer, new OsmServerLocationReader(url), progressMonitor);
    6875        // Extract .osc filename from URL to set the new layer name
    6976        extractOsmFilename("https?://.*/(.*\\.osc)", url);
Note: See TracChangeset for help on using the changeset viewer.