Changeset 15646 in josm for trunk/src/org/openstreetmap/josm/actions
- Timestamp:
- 2020-01-06T20:05:34+01:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java
r14761 r15646 16 16 import org.openstreetmap.josm.data.Bounds.ParseMethod; 17 17 import org.openstreetmap.josm.data.ProjectionBounds; 18 import org.openstreetmap.josm.data.gpx.GpxConstants; 18 19 import org.openstreetmap.josm.data.gpx.GpxData; 19 20 import org.openstreetmap.josm.gui.MainApplication; … … 34 35 import org.openstreetmap.josm.spi.preferences.Config; 35 36 import org.openstreetmap.josm.tools.CheckParameterUtil; 37 import org.openstreetmap.josm.tools.Utils; 36 38 import org.xml.sax.SAXException; 37 39 … … 44 46 private GpxLayer gpxLayer; 45 47 46 protected String newLayerName;48 protected String url; 47 49 48 50 @Override … … 68 70 public Future<?> loadUrl(DownloadParams settings, String url, ProgressMonitor progressMonitor) { 69 71 CheckParameterUtil.ensureParameterNotNull(url, "url"); 72 this.url = url; 70 73 final Optional<String> mappedUrl = Stream.of(GpxUrlPattern.USER_TRACE_ID, GpxUrlPattern.EDIT_TRACE_ID) 71 74 .map(p -> Pattern.compile(p.pattern()).matcher(url)) … … 81 84 downloadTask = new DownloadTask(settings, 82 85 new OsmServerLocationReader(url), progressMonitor); 83 // Extract .gpx filename from URL to set the new layer name84 Matcher matcher = Pattern.compile(GpxUrlPattern.EXTERNAL_GPX_FILE.pattern()).matcher(url);85 newLayerName = matcher.matches() ? matcher.group(1) : null;86 86 // We need submit instead of execute so we can wait for it to finish and get the error 87 87 // message if necessary. If no one calls getErrorMessage() it just behaves like execute. … … 139 139 if (rawData == null) 140 140 return; 141 String name = newLayerName!= null ? newLayerName : tr("Downloaded GPX Data");141 String name = getLayerName(); 142 142 143 143 GpxImporterData layers = GpxImporter.loadLayers(rawData, reader.isGpxParsedProperly(), name, … … 149 149 150 150 layers.getPostLayerTask().run(); 151 } 152 153 private String getLayerName() { 154 // Extract .gpx filename from URL to set the new layer name 155 final Matcher matcher = Pattern.compile(GpxUrlPattern.EXTERNAL_GPX_FILE.pattern()).matcher(url); 156 final String newLayerName = matcher.matches() ? matcher.group(1) : null; 157 final String metadataName = rawData != null ? rawData.getString(GpxConstants.META_NAME) : null; 158 final String defaultName = tr("Downloaded GPX Data"); 159 160 if (Config.getPref().getBoolean("gpx.prefermetadataname", false)) { 161 return Utils.firstNotEmptyString(defaultName, metadataName, newLayerName); 162 } else { 163 return Utils.firstNotEmptyString(defaultName, newLayerName, metadataName); 164 } 151 165 } 152 166
Note:
See TracChangeset
for help on using the changeset viewer.