Changeset 5175 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2012-04-11T18:34:04+02:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java
r5108 r5175 6 6 import java.io.IOException; 7 7 import java.util.concurrent.Future; 8 import java.util.regex.Matcher; 9 import java.util.regex.Pattern; 8 10 9 11 import org.openstreetmap.josm.Main; … … 31 33 private static final String PATTERN_TRACKPOINTS_BBOX = "http://.*/api/0.6/trackpoints\\?bbox=.*,.*,.*,.*"; 32 34 35 private static final String PATTERN_EXTERNAL_GPX_SCRIPT = "http://.*exportgpx.*"; 36 private static final String PATTERN_EXTERNAL_GPX_FILE = "http://.*/(.*\\.gpx)"; 37 38 protected String newLayerName = null; 39 33 40 public Future<?> download(boolean newLayer, Bounds downloadArea, ProgressMonitor progressMonitor) { 34 41 downloadTask = new DownloadTask(newLayer, … … 40 47 41 48 public Future<?> loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor) { 42 if (url != null && url.matches(PATTERN_TRACE_ID)) {49 if (url != null && (url.matches(PATTERN_TRACE_ID) || url.matches(PATTERN_EXTERNAL_GPX_SCRIPT) || url.matches(PATTERN_EXTERNAL_GPX_FILE))) { 43 50 downloadTask = new DownloadTask(newLayer, 44 51 new OsmServerLocationReader(url), progressMonitor); 52 // Extract .gpx filename from URL to set the new layer name 53 Matcher matcher = Pattern.compile(PATTERN_EXTERNAL_GPX_FILE).matcher(url); 54 newLayerName = matcher.matches() ? matcher.group(1) : null; 45 55 // We need submit instead of execute so we can wait for it to finish and get the error 46 56 // message if necessary. If no one calls getErrorMessage() it just behaves like execute. … … 62 72 @Override 63 73 public boolean acceptsUrl(String url) { 64 return url != null && (url.matches(PATTERN_TRACE_ID) || url.matches(PATTERN_TRACKPOINTS_BBOX)); 74 return url != null && (url.matches(PATTERN_TRACE_ID) || url.matches(PATTERN_TRACKPOINTS_BBOX) 75 || url.matches(PATTERN_EXTERNAL_GPX_SCRIPT) || url.matches(PATTERN_EXTERNAL_GPX_FILE)); 65 76 } 66 77 … … 103 114 if (rawData == null) 104 115 return; 105 String name = tr("Downloaded GPX Data");116 String name = newLayerName != null ? newLayerName : tr("Downloaded GPX Data"); 106 117 GpxLayer layer = new GpxLayer(rawData, name); 107 118 Layer x = findMergeLayer();
Note:
See TracChangeset
for help on using the changeset viewer.