Changeset 15784 in josm


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

see #18613 - rework download tasks / URL patterns

Location:
trunk
Files:
3 added
2 deleted
11 edited

Legend:

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

    r14397 r15784  
    2525import java.util.regex.Matcher;
    2626import java.util.regex.Pattern;
    27 import java.util.regex.PatternSyntaxException;
    2827
    2928import javax.swing.JOptionPane;
     
    3938import org.openstreetmap.josm.gui.io.importexport.AllFormatsImporter;
    4039import org.openstreetmap.josm.gui.io.importexport.FileImporter;
     40import org.openstreetmap.josm.gui.util.GuiHelper;
    4141import org.openstreetmap.josm.gui.widgets.AbstractFileChooser;
    4242import org.openstreetmap.josm.io.OsmTransferException;
     
    331331                            }
    332332                        }
    333                     } catch (IOException | PatternSyntaxException | IllegalStateException | IndexOutOfBoundsException e) {
     333                    } catch (IOException | RuntimeException | LinkageError e) {
    334334                        Logging.error(e);
     335                        GuiHelper.runInEDT(
     336                                () -> new Notification(Utils.getRootCause(e).getMessage()).setIcon(JOptionPane.ERROR_MESSAGE).show());
    335337                    }
    336338                }
  • trunk/src/org/openstreetmap/josm/actions/OpenLocationAction.java

    r15441 r15784  
    2828import org.openstreetmap.josm.actions.downloadtasks.DownloadNotesUrlBoundsTask;
    2929import org.openstreetmap.josm.actions.downloadtasks.DownloadNotesUrlIdTask;
    30 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmChangeCompressedTask;
    3130import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmChangeTask;
    32 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmCompressedTask;
    3331import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmIdTask;
    3432import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask;
     
    9795        addDownloadTaskClass(DownloadOsmUrlTask.class);
    9896        addDownloadTaskClass(DownloadOsmIdTask.class);
    99         addDownloadTaskClass(DownloadOsmCompressedTask.class);
    100         addDownloadTaskClass(DownloadOsmChangeCompressedTask.class);
    10197        addDownloadTaskClass(DownloadSessionTask.class);
    10298        addDownloadTaskClass(DownloadNotesUrlBoundsTask.class);
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/AbstractDownloadTask.java

    r13261 r15784  
    33
    44import java.util.ArrayList;
     5import java.util.Arrays;
    56import java.util.List;
    67
    78import org.openstreetmap.josm.data.ProjectionBounds;
     9import org.openstreetmap.josm.io.UrlPattern;
    810import org.openstreetmap.josm.io.XmlWriter;
    911
     
    5759    public void setFailed(boolean failed) {
    5860        this.failed = failed;
     61    }
     62
     63    protected static <T extends Enum<T> & UrlPattern> String[] patterns(Class<T> urlPatternEnum) {
     64        // Do not use a method reference until we switch to Java 11, as we face JDK-8141508 with Java 8
     65        return Arrays.stream(urlPatternEnum.getEnumConstants()).map(/* JDK-8141508 */ t -> t.pattern()).toArray(String[]::new);
    5966    }
    6067
     
    116123     */
    117124    public boolean acceptsUrl(String url) {
    118         if (url == null)
    119             return false;
    120         for (String p: getPatterns()) {
    121             if (url.matches(p)) {
    122                 return true;
    123             }
    124         }
    125         return false;
     125        return url != null && Arrays.stream(getPatterns()).anyMatch(url::matches);
    126126    }
    127127
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGeoJsonTask.java

    r15622 r15784  
    1212import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1313import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     14import org.openstreetmap.josm.io.Compression;
    1415import org.openstreetmap.josm.io.GeoJSONServerReader;
     16import org.openstreetmap.josm.io.UrlPatterns.GeoJsonUrlPattern;
    1517import org.openstreetmap.josm.tools.Utils;
    1618
     
    2224public class DownloadGeoJsonTask extends DownloadOsmTask {
    2325
    24     private static final String PATTERN_COMPRESS = "https?://.*/(.*\\.(json|geojson)(\\.(gz|xz|bz2?|zip))?)";
    25     private static final String PATTERN_FORMAT_GEOJSON = "https?://.*format=geojson.*";
    26 
    2726    @Override
    2827    public String[] getPatterns() {
    29         return new String[]{PATTERN_COMPRESS, PATTERN_FORMAT_GEOJSON};
     28        return patterns(GeoJsonUrlPattern.class);
    3029    }
    3130
     
    5150
    5251        InternalDownloadTask(DownloadParams settings, String url, ProgressMonitor progressMonitor) {
    53             super(settings, new GeoJSONServerReader(url), progressMonitor);
     52            super(settings, new GeoJSONServerReader(url), progressMonitor, true, Compression.byExtension(url));
    5453            this.url = url;
    5554        }
  • 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;
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadNotesTask.java

    r15358 r15784  
    77import java.io.IOException;
    88import java.net.URL;
    9 import java.util.Arrays;
    109import java.util.List;
    1110import java.util.concurrent.Future;
     
    2928import org.openstreetmap.josm.io.OsmApi;
    3029import org.openstreetmap.josm.io.OsmServerLocationReader;
    31 import org.openstreetmap.josm.io.OsmServerLocationReader.NoteUrlPattern;
    3230import org.openstreetmap.josm.io.OsmServerReader;
    3331import org.openstreetmap.josm.io.OsmTransferException;
     32import org.openstreetmap.josm.io.UrlPatterns.NoteUrlPattern;
    3433import org.openstreetmap.josm.tools.Logging;
    3534import org.xml.sax.SAXException;
     
    107106    @Override
    108107    public String[] getPatterns() {
    109         return Arrays.stream(NoteUrlPattern.values()).map(NoteUrlPattern::pattern).toArray(String[]::new);
     108        return patterns(NoteUrlPattern.class);
    110109    }
    111110
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmChangeTask.java

    r14763 r15784  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.util.Arrays;
    67import java.util.Date;
    78import java.util.HashMap;
     
    1213import java.util.concurrent.RejectedExecutionException;
    1314import java.util.regex.Matcher;
    14 import java.util.regex.Pattern;
    1515
    1616import org.openstreetmap.josm.data.Bounds;
     
    3434import org.openstreetmap.josm.gui.history.HistoryLoadTask;
    3535import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     36import org.openstreetmap.josm.io.Compression;
    3637import org.openstreetmap.josm.io.OsmApi;
    3738import org.openstreetmap.josm.io.OsmServerLocationReader;
    3839import org.openstreetmap.josm.io.OsmServerReader;
    3940import org.openstreetmap.josm.io.OsmTransferException;
     41import org.openstreetmap.josm.io.UrlPatterns.OsmChangeUrlPattern;
    4042import org.openstreetmap.josm.tools.Logging;
    4143
     
    4648public class DownloadOsmChangeTask extends DownloadOsmTask {
    4749
    48     private static final String OSM_WEBSITE_PATTERN = "https?://www\\.(osm|openstreetmap)\\.org/changeset/(\\p{Digit}+).*";
    49 
    5050    @Override
    5151    public String[] getPatterns() {
    52         return new String[]{"https?://.*/api/0.6/changeset/\\p{Digit}+/download", // OSM API 0.6 changesets
    53             OSM_WEBSITE_PATTERN, // OSM changesets
    54             "https?://.*/.*\\.osc" // Remote .osc files
    55         };
     52        return patterns(OsmChangeUrlPattern.class);
    5653    }
    5754
     
    6764
    6865    @Override
    69     public Future<?> loadUrl(DownloadParams settings, String url, ProgressMonitor progressMonitor) {
    70         final Matcher matcher = Pattern.compile(OSM_WEBSITE_PATTERN).matcher(url);
     66    public Future<?> loadUrl(DownloadParams settings, final String url, ProgressMonitor progressMonitor) {
     67        OsmChangeUrlPattern urlPattern = Arrays.stream(OsmChangeUrlPattern.values()).filter(p -> p.matches(url)).findFirst()
     68                .orElseThrow(() -> new IllegalArgumentException("URL does not match any OSM URL pattern: " + url));
     69        String newUrl = url;
     70        final Matcher matcher = OsmChangeUrlPattern.OSM_WEBSITE.matcher(url);
    7171        if (matcher.matches()) {
    72             url = OsmApi.getOsmApi().getBaseUrl() + "changeset/" + Long.parseLong(matcher.group(2)) + "/download";
    73         }
    74         downloadTask = new DownloadTask(settings, new OsmServerLocationReader(url), progressMonitor);
     72            newUrl = OsmApi.getOsmApi().getBaseUrl() + "changeset/" + Long.parseLong(matcher.group(2)) + "/download";
     73        }
     74        downloadTask = new DownloadTask(settings, new OsmServerLocationReader(newUrl), progressMonitor, true,
     75                Compression.byExtension(newUrl));
    7576        // Extract .osc filename from URL to set the new layer name
    76         extractOsmFilename(settings, "https?://.*/(.*\\.osc)", url);
     77        extractOsmFilename(settings, urlPattern.pattern(), newUrl);
    7778        return MainApplication.worker.submit(downloadTask);
    7879    }
     
    8889         * @param reader OSM data reader
    8990         * @param progressMonitor progress monitor
     91         * @param zoomAfterDownload If true, the map view will zoom to download area after download
     92         * @param compression compression to use
    9093         */
    91         public DownloadTask(DownloadParams settings, OsmServerReader reader, ProgressMonitor progressMonitor) {
    92             super(settings, reader, progressMonitor);
     94        public DownloadTask(DownloadParams settings, OsmServerReader reader, ProgressMonitor progressMonitor,
     95                boolean zoomAfterDownload, Compression compression) {
     96            super(settings, reader, progressMonitor, zoomAfterDownload, compression);
    9397        }
    9498
    9599        @Override
    96100        protected DataSet parseDataSet() throws OsmTransferException {
    97             return reader.parseOsmChange(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false));
     101            return reader.parseOsmChange(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false),
     102                    compression);
    98103        }
    99104
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java

    r15447 r15784  
    3838import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    3939import org.openstreetmap.josm.io.BoundingBoxDownloader;
     40import org.openstreetmap.josm.io.Compression;
    4041import org.openstreetmap.josm.io.OsmServerLocationReader;
    41 import org.openstreetmap.josm.io.OsmServerLocationReader.OsmUrlPattern;
    4242import org.openstreetmap.josm.io.OsmServerReader;
    4343import org.openstreetmap.josm.io.OsmTransferCanceledException;
    4444import org.openstreetmap.josm.io.OsmTransferException;
    4545import org.openstreetmap.josm.io.OverpassDownloadReader;
     46import org.openstreetmap.josm.io.UrlPatterns.OsmUrlPattern;
    4647import org.openstreetmap.josm.tools.Logging;
    4748import org.openstreetmap.josm.tools.Utils;
     
    7273    public String[] getPatterns() {
    7374        if (this.getClass() == DownloadOsmTask.class) {
    74             return Arrays.stream(OsmUrlPattern.values()).map(OsmUrlPattern::pattern).toArray(String[]::new);
     75            return patterns(OsmUrlPattern.class);
    7576        } else {
    7677            return super.getPatterns();
     
    158159    public Future<?> loadUrl(DownloadParams settings, String url, ProgressMonitor progressMonitor) {
    159160        String newUrl = modifyUrlBeforeLoad(url);
    160         downloadTask = new DownloadTask(settings, getOsmServerReader(newUrl), progressMonitor);
     161        OsmUrlPattern urlPattern = Arrays.stream(OsmUrlPattern.values()).filter(p -> p.matches(newUrl)).findFirst()
     162                .orElseThrow(() -> new IllegalArgumentException("URL does not match any OSM URL pattern: " + newUrl));
     163        downloadTask = new DownloadTask(settings, getOsmServerReader(newUrl), progressMonitor, true, Compression.byExtension(newUrl));
    161164        currentBounds = null;
    162165        // Extract .osm filename from URL to set the new layer name
    163         extractOsmFilename(settings, "https?://.*/(.*\\.osm)", newUrl);
     166        extractOsmFilename(settings, urlPattern.pattern(), newUrl);
    164167        return MainApplication.worker.submit(downloadTask);
    165168    }
     
    413416    protected class DownloadTask extends AbstractInternalTask {
    414417        protected final OsmServerReader reader;
     418        protected final Compression compression;
    415419
    416420        /**
     
    434438         */
    435439        public DownloadTask(DownloadParams settings, OsmServerReader reader, ProgressMonitor progressMonitor, boolean zoomAfterDownload) {
     440            this(settings, reader, progressMonitor, zoomAfterDownload, Compression.NONE);
     441        }
     442
     443        /**
     444         * Constructs a new {@code DownloadTask}.
     445         * @param settings download settings
     446         * @param reader OSM data reader
     447         * @param progressMonitor progress monitor
     448         * @param zoomAfterDownload If true, the map view will zoom to download area after download
     449         * @param compression compression to use
     450         * @since 15784
     451         */
     452        public DownloadTask(DownloadParams settings, OsmServerReader reader, ProgressMonitor progressMonitor, boolean zoomAfterDownload,
     453                Compression compression) {
    436454            super(settings, tr("Downloading data"), progressMonitor, false, zoomAfterDownload);
    437             this.reader = reader;
     455            this.reader = Objects.requireNonNull(reader);
     456            this.compression = compression;
    438457        }
    439458
    440459        protected DataSet parseDataSet() throws OsmTransferException {
    441             return reader.parseOsm(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false));
     460            ProgressMonitor subTaskMonitor = progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false);
     461            // Don't call parseOsm signature with compression if not needed, too many implementations to update before to avoid side effects
     462            return compression != null && compression != Compression.NONE ?
     463                    reader.parseOsm(subTaskMonitor, compression) : reader.parseOsm(subTaskMonitor);
    442464        }
    443465
     
    500522    @Override
    501523    public String getConfirmationMessage(URL url) {
    502         if (url != null) {
    503             String urlString = url.toExternalForm();
    504             if (urlString.matches(OsmUrlPattern.OSM_API_URL.pattern())) {
    505                 // TODO: proper i18n after stabilization
    506                 Collection<String> items = new ArrayList<>();
    507                 items.add(tr("OSM Server URL:") + ' ' + url.getHost());
    508                 items.add(tr("Command")+": "+url.getPath());
    509                 if (url.getQuery() != null) {
    510                     items.add(tr("Request details: {0}", url.getQuery().replaceAll(",\\s*", ", ")));
    511                 }
    512                 return Utils.joinAsHtmlUnorderedList(items);
    513             }
    514             // TODO: other APIs
     524        if (OsmUrlPattern.OSM_API_URL.matches(url)) {
     525            Collection<String> items = new ArrayList<>();
     526            items.add(tr("OSM Server URL:") + ' ' + url.getHost());
     527            items.add(tr("Command")+": "+url.getPath());
     528            if (url.getQuery() != null) {
     529                items.add(tr("Request details: {0}", url.getQuery().replaceAll(",\\s*", ", ")));
     530            }
     531            return Utils.joinAsHtmlUnorderedList(items);
    515532        }
    516533        return null;
  • trunk/src/org/openstreetmap/josm/io/GeoJSONServerReader.java

    r15452 r15784  
    55
    66import java.io.IOException;
    7 import java.util.Objects;
     7import java.io.InputStream;
    88
    99import org.openstreetmap.josm.data.osm.DataSet;
    10 import org.openstreetmap.josm.gui.io.importexport.GeoJSONImporter;
    1110import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     11import org.xml.sax.SAXException;
    1212
    1313/**
     
    1616 * @since 15424
    1717 */
    18 public class GeoJSONServerReader extends OsmServerReader {
    19 
    20     private final String url;
     18public class GeoJSONServerReader extends OsmServerLocationReader {
    2119
    2220    /**
     
    2523     */
    2624    public GeoJSONServerReader(String url) {
    27         this.url = Objects.requireNonNull(url);
     25        super(url);
     26    }
     27
     28    protected class GeoJsonParser extends Parser<DataSet> {
     29        protected GeoJsonParser(ProgressMonitor progressMonitor, Compression compression) {
     30            super(progressMonitor, compression);
     31        }
     32
     33        @Override
     34        public DataSet parse() throws OsmTransferException, IllegalDataException, IOException, SAXException {
     35            in = getInputStreamRaw(url, progressMonitor.createSubTaskMonitor(9, false));
     36            if (in == null)
     37                return null;
     38            progressMonitor.subTask(tr("Downloading OSM data..."));
     39            InputStream uncompressedInputStream = compression.getUncompressedInputStream(in); // NOPMD
     40            ProgressMonitor subTaskMonitor = progressMonitor.createSubTaskMonitor(1, false);
     41            return GeoJSONReader.parseDataSet(uncompressedInputStream, subTaskMonitor);
     42        }
    2843    }
    2944
    3045    @Override
    3146    public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException {
    32         try {
    33             progressMonitor.beginTask(tr("Contacting Server..."), 10);
    34             return new GeoJSONImporter().parseDataSet(url);
    35         } catch (IOException | IllegalDataException e) {
    36             throw new OsmTransferException(e);
    37         } finally {
    38             progressMonitor.finishTask();
    39         }
     47        return parseOsm(progressMonitor, Compression.NONE);
     48    }
     49
     50    @Override
     51    public DataSet parseOsm(ProgressMonitor progressMonitor, Compression compression) throws OsmTransferException {
     52        return doParse(new GeoJsonParser(progressMonitor, compression), progressMonitor);
    4053    }
    4154}
  • trunk/src/org/openstreetmap/josm/io/OsmServerLocationReader.java

    r15631 r15784  
    1313import org.openstreetmap.josm.data.osm.DataSet;
    1414import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     15import org.openstreetmap.josm.io.UrlPatterns.GpxUrlPattern;
    1516import org.openstreetmap.josm.tools.Utils;
    1617import org.xml.sax.SAXException;
     
    2122 */
    2223public class OsmServerLocationReader extends OsmServerReader {
    23 
    24     // CHECKSTYLE.OFF: MethodParamPad
    25     // CHECKSTYLE.OFF: SingleSpaceSeparator
    26 
    27     /**
    28      * Patterns for OSM data download URLs.
    29      * @since 12679
    30      */
    31     public enum OsmUrlPattern {
    32         OSM_API_URL           ("https?://.*/api/0.6/(map|nodes?|ways?|relations?|\\*).*"),
    33         OVERPASS_API_URL      ("https?://.*/interpreter\\?data=.*"),
    34         OVERPASS_API_XAPI_URL ("https?://.*/xapi(\\?.*\\[@meta\\]|_meta\\?).*"),
    35         EXTERNAL_OSM_FILE     ("https?://.*/.*\\.osm");
    36 
    37         private final String urlPattern;
    38 
    39         OsmUrlPattern(String urlPattern) {
    40             this.urlPattern = urlPattern;
    41         }
    42 
    43         /**
    44          * Returns the URL pattern.
    45          * @return the URL pattern
    46          */
    47         public String pattern() {
    48             return urlPattern;
    49         }
    50     }
    51 
    52     /**
    53      * Patterns for GPX download URLs.
    54      * @since 12679
    55      */
    56     public enum GpxUrlPattern {
    57         TRACE_ID     ("https?://.*(osm|openstreetmap).org/trace/\\p{Digit}+/data"),
    58         USER_TRACE_ID("https?://.*(osm|openstreetmap).org/user/[^/]+/traces/(\\p{Digit}+)"),
    59         EDIT_TRACE_ID("https?://.*(osm|openstreetmap).org/edit/?\\?gpx=(\\p{Digit}+)(#.*)?"),
    60 
    61         TRACKPOINTS_BBOX("https?://.*/api/0.6/trackpoints\\?bbox=.*,.*,.*,.*"),
    62         TASKING_MANAGER("https?://.*/api/v\\p{Digit}+/projects?/\\p{Digit}+/(tasks_as_gpx?.*|tasks/queries/gpx/\\?tasks=.*)"),
    63 
    64         /** External GPX script */
    65         EXTERNAL_GPX_SCRIPT("https?://.*exportgpx.*"),
    66         /** External GPX file */
    67         EXTERNAL_GPX_FILE  ("https?://.*/(.*\\.gpx)");
    68 
    69         private final String urlPattern;
    70 
    71         GpxUrlPattern(String urlPattern) {
    72             this.urlPattern = urlPattern;
    73         }
    74 
    75         /**
    76          * Returns the URL pattern.
    77          * @return the URL pattern
    78          */
    79         public String pattern() {
    80             return urlPattern;
    81         }
    82     }
    83 
    84     /**
    85      * Patterns for Note download URLs.
    86      * @since 12679
    87      */
    88     public enum NoteUrlPattern {
    89         /** URL of OSM API Notes endpoint */
    90         API_URL  ("https?://.*/api/0.6/notes.*"),
    91         /** URL of OSM API Notes compressed dump file */
    92         DUMP_FILE("https?://.*/(.*\\.osn(\\.(gz|xz|bz2?|zip))?)");
    93 
    94         private final String urlPattern;
    95 
    96         NoteUrlPattern(String urlPattern) {
    97             this.urlPattern = urlPattern;
    98         }
    99 
    100         /**
    101          * Returns the URL pattern.
    102          * @return the URL pattern
    103          */
    104         public String pattern() {
    105             return urlPattern;
    106         }
    107     }
    108 
    109     // CHECKSTYLE.ON: SingleSpaceSeparator
    110     // CHECKSTYLE.ON: MethodParamPad
    11124
    11225    protected final String url;
     
    250163            gpxParsedProperly = reader.parse(false);
    251164            GpxData result = reader.getGpxData();
    252             result.fromServer = isGpxFromServer(url);
     165            result.fromServer = GpxUrlPattern.isGpxFromServer(url);
    253166            return result;
    254167        }
     
    272185        }
    273186    }
    274 
    275     /**
    276      * Determines if the given URL denotes an OSM gpx-related API call.
    277      * @param url The url to check
    278      * @return true if the url matches "Trace ID" API call or "Trackpoints bbox" API call, false otherwise
    279      * @see GpxData#fromServer
    280      * @since 12679
    281      */
    282     public static final boolean isGpxFromServer(String url) {
    283         return url != null && (url.matches(GpxUrlPattern.TRACE_ID.pattern()) || url.matches(GpxUrlPattern.TRACKPOINTS_BBOX.pattern()));
    284     }
    285187}
  • trunk/src/org/openstreetmap/josm/io/OsmServerReader.java

    r14216 r15784  
    261261     */
    262262    public DataSet parseOsm(ProgressMonitor progressMonitor, Compression compression) throws OsmTransferException {
    263         return null;
     263        throw new UnsupportedOperationException();
    264264    }
    265265
     
    283283     */
    284284    public DataSet parseOsmChange(ProgressMonitor progressMonitor, Compression compression) throws OsmTransferException {
    285         return null;
     285        throw new UnsupportedOperationException();
    286286    }
    287287
     
    305305     */
    306306    public GpxData parseRawGps(ProgressMonitor progressMonitor, Compression compression) throws OsmTransferException {
    307         return null;
     307        throw new UnsupportedOperationException();
    308308    }
    309309
     
    372372     */
    373373    public List<Note> parseRawNotes(ProgressMonitor progressMonitor, Compression compression) throws OsmTransferException {
    374         return null;
     374        throw new UnsupportedOperationException();
    375375    }
    376376
Note: See TracChangeset for help on using the changeset viewer.