Changeset 11073 in josm for trunk


Ignore:
Timestamp:
2016-10-02T22:12:40+02:00 (3 years ago)
Author:
simon04
Message:

see #13749 - Enhance supported URLs for downloading GPS data

Location:
trunk
Files:
2 edited

Legend:

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

    r10432 r11073  
    66import java.io.IOException;
    77import java.net.URL;
     8import java.util.Optional;
    89import java.util.concurrent.Future;
    910import java.util.regex.Matcher;
    1011import java.util.regex.Pattern;
     12import java.util.stream.Stream;
    1113
    1214import org.openstreetmap.josm.Main;
     
    3941
    4042    private static final String PATTERN_TRACE_ID = "https?://.*(osm|openstreetmap).org/trace/\\p{Digit}+/data";
     43    private static final String PATTERN_USER_TRACE_ID = "https?://.*(osm|openstreetmap).org/user/[^/]+/traces/(\\p{Digit}+)";
     44    private static final String PATTERN_EDIT_TRACE_ID = "https?://.*(osm|openstreetmap).org/edit/?\\?gpx=(\\p{Digit}+)";
    4145
    4246    private static final String PATTERN_TRACKPOINTS_BBOX = "https?://.*/api/0.6/trackpoints\\?bbox=.*,.*,.*,.*";
     
    4953    @Override
    5054    public String[] getPatterns() {
    51         return new String[] {PATTERN_EXTERNAL_GPX_FILE, PATTERN_EXTERNAL_GPX_SCRIPT, PATTERN_TRACE_ID, PATTERN_TRACKPOINTS_BBOX};
     55        return new String[] {
     56                PATTERN_EXTERNAL_GPX_FILE, PATTERN_EXTERNAL_GPX_SCRIPT,
     57                PATTERN_TRACE_ID, PATTERN_USER_TRACE_ID, PATTERN_EDIT_TRACE_ID,
     58                PATTERN_TRACKPOINTS_BBOX,
     59        };
    5260    }
    5361
     
    6977    public Future<?> loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor) {
    7078        CheckParameterUtil.ensureParameterNotNull(url, "url");
     79        final Optional<String> mappedUrl = Stream.of(PATTERN_USER_TRACE_ID, PATTERN_EDIT_TRACE_ID)
     80                .map(p -> Pattern.compile(p).matcher(url))
     81                .filter(Matcher::matches)
     82                .map(m -> "https://www.openstreetmap.org/trace/" + m.group(2) + "/data")
     83                .findFirst();
     84        if (mappedUrl.isPresent()) {
     85            return loadUrl(newLayer, mappedUrl.get(), progressMonitor);
     86        }
    7187        if (url.matches(PATTERN_TRACE_ID)
    7288         || url.matches(PATTERN_EXTERNAL_GPX_SCRIPT)
  • trunk/test/unit/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTaskTest.java

    r10945 r11073  
    4242        assertTrue(task.acceptsUrl("http://www.openstreetmap.org/trace/5000/data"));
    4343        assertTrue(task.acceptsUrl("http://www.trackmyjourney.co.uk/exportgpx.php?session=S6rZR2Bh6GwX1wpB0C&trk=79292"));
     44        assertTrue(task.acceptsUrl("https://www.openstreetmap.org/user/simon04/traces/750057"));
     45        assertTrue(task.acceptsUrl("https://www.openstreetmap.org/edit?gpx=750057"));
    4446        assertTrue(task.acceptsUrl(REMOTE_FILE));
    4547    }
Note: See TracChangeset for help on using the changeset viewer.