Changeset 14357 in josm


Ignore:
Timestamp:
2018-10-23T00:52:11+02:00 (3 weeks ago)
Author:
Don-vip
Message:

detect Overpass API links in load location/remote control. Needed to detect query timeout from Overpass Turbo remote control links

File:
1 edited

Legend:

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

    r14350 r14357  
    55
    66import java.io.IOException;
     7import java.net.MalformedURLException;
    78import java.net.URL;
    89import java.util.ArrayList;
     
    4243import org.openstreetmap.josm.io.OsmTransferCanceledException;
    4344import org.openstreetmap.josm.io.OsmTransferException;
     45import org.openstreetmap.josm.io.OverpassDownloadReader;
    4446import org.openstreetmap.josm.tools.Logging;
    4547import org.openstreetmap.josm.tools.Utils;
     
    5961    /** This allows subclasses to ignore this warning */
    6062    protected boolean warnAboutEmptyArea = true;
     63
     64    protected static final String OVERPASS_INTERPRETER_DATA = "interpreter?data=";
    6165
    6266    @Override
     
    149153    public Future<?> loadUrl(DownloadParams settings, String url, ProgressMonitor progressMonitor) {
    150154        String newUrl = modifyUrlBeforeLoad(url);
    151         downloadTask = new DownloadTask(settings,
    152                 new OsmServerLocationReader(newUrl),
    153                 progressMonitor);
     155        downloadTask = new DownloadTask(settings, getOsmServerReader(newUrl), progressMonitor);
    154156        currentBounds = null;
    155157        // Extract .osm filename from URL to set the new layer name
    156158        extractOsmFilename(settings, "https?://.*/(.*\\.osm)", newUrl);
    157159        return MainApplication.worker.submit(downloadTask);
     160    }
     161
     162    protected OsmServerReader getOsmServerReader(String url) {
     163        try {
     164            String host = new URL(url).getHost();
     165            for (String knownOverpassServer : OverpassDownloadReader.OVERPASS_SERVER_HISTORY.get()) {
     166                if (host.equals(new URL(knownOverpassServer).getHost())) {
     167                    int index = url.indexOf(OVERPASS_INTERPRETER_DATA);
     168                    if (index > 0) {
     169                        return new OverpassDownloadReader(new Bounds(LatLon.ZERO), knownOverpassServer,
     170                                Utils.decodeUrl(url.substring(index + OVERPASS_INTERPRETER_DATA.length())));
     171                    }
     172                }
     173            }
     174        } catch (MalformedURLException e) {
     175            Logging.error(e);
     176        }
     177        return new OsmServerLocationReader(url);
    158178    }
    159179
Note: See TracChangeset for help on using the changeset viewer.