Changeset 15784 in josm for trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java
- Timestamp:
- 2020-01-27T02:35:43+01:00 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java
r15652 r15784 6 6 import java.io.IOException; 7 7 import java.net.URL; 8 import java.util. Arrays;8 import java.util.Objects; 9 9 import java.util.Optional; 10 10 import java.util.concurrent.Future; 11 11 import java.util.regex.Matcher; 12 import java.util.regex.Pattern;13 12 import java.util.stream.Stream; 14 13 … … 30 29 import org.openstreetmap.josm.io.BoundingBoxDownloader; 31 30 import org.openstreetmap.josm.io.OsmServerLocationReader; 32 import org.openstreetmap.josm.io.OsmServerLocationReader.GpxUrlPattern;33 31 import org.openstreetmap.josm.io.OsmServerReader; 34 32 import org.openstreetmap.josm.io.OsmTransferException; 33 import org.openstreetmap.josm.io.UrlPatterns.GpxUrlPattern; 35 34 import org.openstreetmap.josm.spi.preferences.Config; 36 import org.openstreetmap.josm.tools.CheckParameterUtil;37 35 import org.openstreetmap.josm.tools.Utils; 38 36 import org.xml.sax.SAXException; … … 50 48 @Override 51 49 public String[] getPatterns() { 52 return Arrays.stream(GpxUrlPattern.values()).map(GpxUrlPattern::pattern).toArray(String[]::new);50 return patterns(GpxUrlPattern.class); 53 51 } 54 52 … … 69 67 @Override 70 68 public Future<?> loadUrl(DownloadParams settings, String url, ProgressMonitor progressMonitor) { 71 CheckParameterUtil.ensureParameterNotNull(url, "url"); 72 this.url = url; 69 this.url = Objects.requireNonNull(url); 73 70 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)) 75 72 .filter(Matcher::matches) 76 73 .map(m -> "https://www.openstreetmap.org/trace/" + m.group(2) + "/data") … … 81 78 if (Stream.of(GpxUrlPattern.TRACE_ID, GpxUrlPattern.EXTERNAL_GPX_SCRIPT, 82 79 GpxUrlPattern.EXTERNAL_GPX_FILE, GpxUrlPattern.TASKING_MANAGER) 83 .anyMatch(p -> url.matches(p.pattern()))) {80 .anyMatch(p -> p.matches(url))) { 84 81 downloadTask = new DownloadTask(settings, 85 82 new OsmServerLocationReader(url), progressMonitor); … … 88 85 return MainApplication.worker.submit(downloadTask); 89 86 90 } else if ( url.matches(GpxUrlPattern.TRACKPOINTS_BBOX.pattern())) {87 } else if (GpxUrlPattern.TRACKPOINTS_BBOX.matches(url)) { 91 88 String[] table = url.split("\\?|=|&"); 92 89 for (int i = 0; i < table.length; i++) { … … 153 150 private String getLayerName() { 154 151 // 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; 156 153 final String newLayerName = matcher != null && matcher.matches() ? matcher.group(1) : null; 157 154 final String metadataName = rawData != null ? rawData.getString(GpxConstants.META_NAME) : null;
Note:
See TracChangeset
for help on using the changeset viewer.