Ignore:
Timestamp:
2017-08-27T23:42:54+02:00 (7 years ago)
Author:
Don-vip
Message:

see #15182 - make actions.downloadtasks.Download*Task depend on io.OsmServerLocationReader, not the opposite

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

Legend:

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

    r12671 r12679  
    66import java.io.IOException;
    77import java.net.URL;
     8import java.util.Arrays;
    89import java.util.Optional;
    910import java.util.concurrent.Future;
     
    3132import org.openstreetmap.josm.io.BoundingBoxDownloader;
    3233import org.openstreetmap.josm.io.OsmServerLocationReader;
     34import org.openstreetmap.josm.io.OsmServerLocationReader.GpxUrlPattern;
    3335import org.openstreetmap.josm.io.OsmServerReader;
    3436import org.openstreetmap.josm.io.OsmTransferException;
     
    4446    private GpxLayer gpxLayer;
    4547
    46     private static final String PATTERN_TRACE_ID = "https?://.*(osm|openstreetmap).org/trace/\\p{Digit}+/data";
    47     private static final String PATTERN_USER_TRACE_ID = "https?://.*(osm|openstreetmap).org/user/[^/]+/traces/(\\p{Digit}+)";
    48     private static final String PATTERN_EDIT_TRACE_ID = "https?://.*(osm|openstreetmap).org/edit/?\\?gpx=(\\p{Digit}+)(#.*)?";
    49 
    50     private static final String PATTERN_TRACKPOINTS_BBOX = "https?://.*/api/0.6/trackpoints\\?bbox=.*,.*,.*,.*";
    51 
    52     private static final String PATTERN_EXTERNAL_GPX_SCRIPT = "https?://.*exportgpx.*";
    53     private static final String PATTERN_EXTERNAL_GPX_FILE = "https?://.*/(.*\\.gpx)";
    54 
    5548    protected String newLayerName;
    5649
    5750    @Override
    5851    public String[] getPatterns() {
    59         return new String[] {
    60                 PATTERN_EXTERNAL_GPX_FILE, PATTERN_EXTERNAL_GPX_SCRIPT,
    61                 PATTERN_TRACE_ID, PATTERN_USER_TRACE_ID, PATTERN_EDIT_TRACE_ID,
    62                 PATTERN_TRACKPOINTS_BBOX,
    63         };
     52        return Arrays.stream(GpxUrlPattern.values()).map(GpxUrlPattern::pattern).toArray(String[]::new);
    6453    }
    6554
     
    8170    public Future<?> loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor) {
    8271        CheckParameterUtil.ensureParameterNotNull(url, "url");
    83         final Optional<String> mappedUrl = Stream.of(PATTERN_USER_TRACE_ID, PATTERN_EDIT_TRACE_ID)
    84                 .map(p -> Pattern.compile(p).matcher(url))
     72        final Optional<String> mappedUrl = Stream.of(GpxUrlPattern.USER_TRACE_ID, GpxUrlPattern.EDIT_TRACE_ID)
     73                .map(p -> Pattern.compile(p.pattern()).matcher(url))
    8574                .filter(Matcher::matches)
    8675                .map(m -> "https://www.openstreetmap.org/trace/" + m.group(2) + "/data")
     
    8978            return loadUrl(newLayer, mappedUrl.get(), progressMonitor);
    9079        }
    91         if (url.matches(PATTERN_TRACE_ID)
    92          || url.matches(PATTERN_EXTERNAL_GPX_SCRIPT)
    93          || url.matches(PATTERN_EXTERNAL_GPX_FILE)) {
     80        if (Stream.of(GpxUrlPattern.TRACE_ID, GpxUrlPattern.EXTERNAL_GPX_SCRIPT, GpxUrlPattern.EXTERNAL_GPX_FILE)
     81                .anyMatch(p -> url.matches(p.pattern()))) {
    9482            downloadTask = new DownloadTask(newLayer,
    9583                    new OsmServerLocationReader(url), progressMonitor);
    9684            // Extract .gpx filename from URL to set the new layer name
    97             Matcher matcher = Pattern.compile(PATTERN_EXTERNAL_GPX_FILE).matcher(url);
     85            Matcher matcher = Pattern.compile(GpxUrlPattern.EXTERNAL_GPX_FILE.pattern()).matcher(url);
    9886            newLayerName = matcher.matches() ? matcher.group(1) : null;
    9987            // We need submit instead of execute so we can wait for it to finish and get the error
     
    10189            return MainApplication.worker.submit(downloadTask);
    10290
    103         } else if (url.matches(PATTERN_TRACKPOINTS_BBOX)) {
     91        } else if (url.matches(GpxUrlPattern.TRACKPOINTS_BBOX.pattern())) {
    10492            String[] table = url.split("\\?|=|&");
    10593            for (int i = 0; i < table.length; i++) {
     
    224212        return true;
    225213    }
    226 
    227     /**
    228      * Determines if the given URL denotes an OSM gpx-related API call.
    229      * @param url The url to check
    230      * @return true if the url matches "Trace ID" API call or "Trackpoints bbox" API call, false otherwise
    231      * @see GpxData#fromServer
    232      * @since 5745
    233      */
    234     public static final boolean isFromServer(String url) {
    235         return url != null && (url.matches(PATTERN_TRACE_ID) || url.matches(PATTERN_TRACKPOINTS_BBOX));
    236     }
    237214}
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadNotesTask.java

    r12636 r12679  
    77import java.io.IOException;
    88import java.net.URL;
     9import java.util.Arrays;
    910import java.util.List;
    1011import java.util.concurrent.Future;
     
    2829import org.openstreetmap.josm.io.OsmApi;
    2930import org.openstreetmap.josm.io.OsmServerLocationReader;
     31import org.openstreetmap.josm.io.OsmServerLocationReader.NoteUrlPattern;
    3032import org.openstreetmap.josm.io.OsmServerReader;
    3133import org.openstreetmap.josm.io.OsmTransferException;
     
    4143public class DownloadNotesTask extends AbstractDownloadTask<NoteData> {
    4244
    43     private static final String PATTERN_API_URL = "https?://.*/api/0.6/notes.*";
    44     private static final String PATTERN_DUMP_FILE = "https?://.*/(.*\\.osn(.bz2)?)";
    4545    /** Property defining the number of notes to be downloaded */
    4646    public static final IntegerProperty DOWNLOAD_LIMIT = new IntegerProperty("osm.notes.downloadLimit", 1000);
     
    9898    @Override
    9999    public String[] getPatterns() {
    100         return new String[] {PATTERN_API_URL, PATTERN_DUMP_FILE};
     100        return Arrays.stream(NoteUrlPattern.values()).map(NoteUrlPattern::pattern).toArray(String[]::new);
    101101    }
    102102
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java

    r12636 r12679  
    77import java.net.URL;
    88import java.util.ArrayList;
     9import java.util.Arrays;
    910import java.util.Collection;
    1011import java.util.Collections;
     
    3536import org.openstreetmap.josm.io.BoundingBoxDownloader;
    3637import org.openstreetmap.josm.io.OsmServerLocationReader;
     38import org.openstreetmap.josm.io.OsmServerLocationReader.OsmUrlPattern;
    3739import org.openstreetmap.josm.io.OsmServerReader;
    3840import org.openstreetmap.josm.io.OsmTransferCanceledException;
     
    4850public class DownloadOsmTask extends AbstractDownloadTask<DataSet> {
    4951
    50     // CHECKSTYLE.OFF: SingleSpaceSeparator
    51     protected static final String PATTERN_OSM_API_URL           = "https?://.*/api/0.6/(map|nodes?|ways?|relations?|\\*).*";
    52     protected static final String PATTERN_OVERPASS_API_URL      = "https?://.*/interpreter\\?data=.*";
    53     protected static final String PATTERN_OVERPASS_API_XAPI_URL = "https?://.*/xapi(\\?.*\\[@meta\\]|_meta\\?).*";
    54     protected static final String PATTERN_EXTERNAL_OSM_FILE     = "https?://.*/.*\\.osm";
    55     // CHECKSTYLE.ON: SingleSpaceSeparator
    56 
    5752    protected Bounds currentBounds;
    5853    protected DownloadTask downloadTask;
     
    6661    public String[] getPatterns() {
    6762        if (this.getClass() == DownloadOsmTask.class) {
    68             return new String[]{PATTERN_OSM_API_URL, PATTERN_OVERPASS_API_URL,
    69                 PATTERN_OVERPASS_API_XAPI_URL, PATTERN_EXTERNAL_OSM_FILE};
     63            return Arrays.stream(OsmUrlPattern.values()).map(OsmUrlPattern::pattern).toArray(String[]::new);
    7064        } else {
    7165            return super.getPatterns();
     
    408402        if (url != null) {
    409403            String urlString = url.toExternalForm();
    410             if (urlString.matches(PATTERN_OSM_API_URL)) {
     404            if (urlString.matches(OsmUrlPattern.OSM_API_URL.pattern())) {
    411405                // TODO: proper i18n after stabilization
    412406                Collection<String> items = new ArrayList<>();
Note: See TracChangeset for help on using the changeset viewer.