Changeset 12679 in josm for trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java
- Timestamp:
- 2017-08-27T23:42:54+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java
r12671 r12679 6 6 import java.io.IOException; 7 7 import java.net.URL; 8 import java.util.Arrays; 8 9 import java.util.Optional; 9 10 import java.util.concurrent.Future; … … 31 32 import org.openstreetmap.josm.io.BoundingBoxDownloader; 32 33 import org.openstreetmap.josm.io.OsmServerLocationReader; 34 import org.openstreetmap.josm.io.OsmServerLocationReader.GpxUrlPattern; 33 35 import org.openstreetmap.josm.io.OsmServerReader; 34 36 import org.openstreetmap.josm.io.OsmTransferException; … … 44 46 private GpxLayer gpxLayer; 45 47 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 55 48 protected String newLayerName; 56 49 57 50 @Override 58 51 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); 64 53 } 65 54 … … 81 70 public Future<?> loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor) { 82 71 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)) 85 74 .filter(Matcher::matches) 86 75 .map(m -> "https://www.openstreetmap.org/trace/" + m.group(2) + "/data") … … 89 78 return loadUrl(newLayer, mappedUrl.get(), progressMonitor); 90 79 } 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()))) { 94 82 downloadTask = new DownloadTask(newLayer, 95 83 new OsmServerLocationReader(url), progressMonitor); 96 84 // 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); 98 86 newLayerName = matcher.matches() ? matcher.group(1) : null; 99 87 // We need submit instead of execute so we can wait for it to finish and get the error … … 101 89 return MainApplication.worker.submit(downloadTask); 102 90 103 } else if (url.matches( PATTERN_TRACKPOINTS_BBOX)) {91 } else if (url.matches(GpxUrlPattern.TRACKPOINTS_BBOX.pattern())) { 104 92 String[] table = url.split("\\?|=|&"); 105 93 for (int i = 0; i < table.length; i++) { … … 224 212 return true; 225 213 } 226 227 /**228 * Determines if the given URL denotes an OSM gpx-related API call.229 * @param url The url to check230 * @return true if the url matches "Trace ID" API call or "Trackpoints bbox" API call, false otherwise231 * @see GpxData#fromServer232 * @since 5745233 */234 public static final boolean isFromServer(String url) {235 return url != null && (url.matches(PATTERN_TRACE_ID) || url.matches(PATTERN_TRACKPOINTS_BBOX));236 }237 214 }
Note:
See TracChangeset
for help on using the changeset viewer.