Changeset 5175 in josm for trunk/src


Ignore:
Timestamp:
2012-04-11T18:34:04+02:00 (8 years ago)
Author:
Don-vip
Message:

fix #7581 - gpx tracks download limited only to osm.org server

File:
1 edited

Legend:

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

    r5108 r5175  
    66import java.io.IOException;
    77import java.util.concurrent.Future;
     8import java.util.regex.Matcher;
     9import java.util.regex.Pattern;
    810
    911import org.openstreetmap.josm.Main;
     
    3133    private static final String PATTERN_TRACKPOINTS_BBOX = "http://.*/api/0.6/trackpoints\\?bbox=.*,.*,.*,.*";
    3234
     35    private static final String PATTERN_EXTERNAL_GPX_SCRIPT = "http://.*exportgpx.*";
     36    private static final String PATTERN_EXTERNAL_GPX_FILE = "http://.*/(.*\\.gpx)";
     37
     38    protected String newLayerName = null;
     39
    3340    public Future<?> download(boolean newLayer, Bounds downloadArea, ProgressMonitor progressMonitor) {
    3441        downloadTask = new DownloadTask(newLayer,
     
    4047
    4148    public Future<?> loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor) {
    42         if (url != null && url.matches(PATTERN_TRACE_ID)) {
     49        if (url != null && (url.matches(PATTERN_TRACE_ID) || url.matches(PATTERN_EXTERNAL_GPX_SCRIPT) || url.matches(PATTERN_EXTERNAL_GPX_FILE))) {
    4350            downloadTask = new DownloadTask(newLayer,
    4451                    new OsmServerLocationReader(url), progressMonitor);
     52            // Extract .gpx filename from URL to set the new layer name
     53            Matcher matcher = Pattern.compile(PATTERN_EXTERNAL_GPX_FILE).matcher(url);
     54            newLayerName = matcher.matches() ? matcher.group(1) : null;
    4555            // We need submit instead of execute so we can wait for it to finish and get the error
    4656            // message if necessary. If no one calls getErrorMessage() it just behaves like execute.
     
    6272    @Override
    6373    public boolean acceptsUrl(String url) {
    64         return url != null && (url.matches(PATTERN_TRACE_ID) || url.matches(PATTERN_TRACKPOINTS_BBOX));
     74        return url != null && (url.matches(PATTERN_TRACE_ID) || url.matches(PATTERN_TRACKPOINTS_BBOX)
     75                || url.matches(PATTERN_EXTERNAL_GPX_SCRIPT) || url.matches(PATTERN_EXTERNAL_GPX_FILE));
    6576    }
    6677
     
    103114            if (rawData == null)
    104115                return;
    105             String name = tr("Downloaded GPX Data");
     116            String name = newLayerName != null ? newLayerName : tr("Downloaded GPX Data");
    106117            GpxLayer layer = new GpxLayer(rawData, name);
    107118            Layer x = findMergeLayer();
Note: See TracChangeset for help on using the changeset viewer.