Ignore:
Timestamp:
2020-01-27T02:35:43+01:00 (4 years ago)
Author:
Don-vip
Message:

see #18613 - rework download tasks / URL patterns

File:
1 edited

Legend:

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

    r15652 r15784  
    66import java.io.IOException;
    77import java.net.URL;
    8 import java.util.Arrays;
     8import java.util.Objects;
    99import java.util.Optional;
    1010import java.util.concurrent.Future;
    1111import java.util.regex.Matcher;
    12 import java.util.regex.Pattern;
    1312import java.util.stream.Stream;
    1413
     
    3029import org.openstreetmap.josm.io.BoundingBoxDownloader;
    3130import org.openstreetmap.josm.io.OsmServerLocationReader;
    32 import org.openstreetmap.josm.io.OsmServerLocationReader.GpxUrlPattern;
    3331import org.openstreetmap.josm.io.OsmServerReader;
    3432import org.openstreetmap.josm.io.OsmTransferException;
     33import org.openstreetmap.josm.io.UrlPatterns.GpxUrlPattern;
    3534import org.openstreetmap.josm.spi.preferences.Config;
    36 import org.openstreetmap.josm.tools.CheckParameterUtil;
    3735import org.openstreetmap.josm.tools.Utils;
    3836import org.xml.sax.SAXException;
     
    5048    @Override
    5149    public String[] getPatterns() {
    52         return Arrays.stream(GpxUrlPattern.values()).map(GpxUrlPattern::pattern).toArray(String[]::new);
     50        return patterns(GpxUrlPattern.class);
    5351    }
    5452
     
    6967    @Override
    7068    public Future<?> loadUrl(DownloadParams settings, String url, ProgressMonitor progressMonitor) {
    71         CheckParameterUtil.ensureParameterNotNull(url, "url");
    72         this.url = url;
     69        this.url = Objects.requireNonNull(url);
    7370        final Optional<String> mappedUrl = Stream.of(GpxUrlPattern.USER_TRACE_ID, GpxUrlPattern.EDIT_TRACE_ID)
    74                 .map(p -> Pattern.compile(p.pattern()).matcher(url))
     71                .map(p -> p.matcher(url))
    7572                .filter(Matcher::matches)
    7673                .map(m -> "https://www.openstreetmap.org/trace/" + m.group(2) + "/data")
     
    8178        if (Stream.of(GpxUrlPattern.TRACE_ID, GpxUrlPattern.EXTERNAL_GPX_SCRIPT,
    8279                      GpxUrlPattern.EXTERNAL_GPX_FILE, GpxUrlPattern.TASKING_MANAGER)
    83                 .anyMatch(p -> url.matches(p.pattern()))) {
     80                .anyMatch(p -> p.matches(url))) {
    8481            downloadTask = new DownloadTask(settings,
    8582                    new OsmServerLocationReader(url), progressMonitor);
     
    8885            return MainApplication.worker.submit(downloadTask);
    8986
    90         } else if (url.matches(GpxUrlPattern.TRACKPOINTS_BBOX.pattern())) {
     87        } else if (GpxUrlPattern.TRACKPOINTS_BBOX.matches(url)) {
    9188            String[] table = url.split("\\?|=|&");
    9289            for (int i = 0; i < table.length; i++) {
     
    153150        private String getLayerName() {
    154151            // Extract .gpx filename from URL to set the new layer name
    155             final Matcher matcher = url != null ? Pattern.compile(GpxUrlPattern.EXTERNAL_GPX_FILE.pattern()).matcher(url) : null;
     152            final Matcher matcher = url != null ? GpxUrlPattern.EXTERNAL_GPX_FILE.matcher(url) : null;
    156153            final String newLayerName = matcher != null && matcher.matches() ? matcher.group(1) : null;
    157154            final String metadataName = rawData != null ? rawData.getString(GpxConstants.META_NAME) : null;
Note: See TracChangeset for help on using the changeset viewer.