- Timestamp:
- 2020-01-27T22:40:13+01:00 (5 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/actions/downloadtasks
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmChangeTask.java
r15784 r15789 10 10 import java.util.Map; 11 11 import java.util.Map.Entry; 12 import java.util.Optional; 12 13 import java.util.concurrent.Future; 13 14 import java.util.concurrent.RejectedExecutionException; … … 65 66 @Override 66 67 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)); 68 Optional<OsmChangeUrlPattern> urlPattern = Arrays.stream(OsmChangeUrlPattern.values()).filter(p -> p.matches(url)).findFirst(); 69 69 String newUrl = url; 70 70 final Matcher matcher = OsmChangeUrlPattern.OSM_WEBSITE.matcher(url); … … 75 75 Compression.byExtension(newUrl)); 76 76 // Extract .osc filename from URL to set the new layer name 77 extractOsmFilename(settings, urlPattern. pattern(), newUrl);77 extractOsmFilename(settings, urlPattern.orElse(OsmChangeUrlPattern.EXTERNAL_OSC_FILE).pattern(), newUrl); 78 78 return MainApplication.worker.submit(downloadTask); 79 79 } -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java
r15784 r15789 159 159 public Future<?> loadUrl(DownloadParams settings, String url, ProgressMonitor progressMonitor) { 160 160 String newUrl = modifyUrlBeforeLoad(url); 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)); 161 Optional<OsmUrlPattern> urlPattern = Arrays.stream(OsmUrlPattern.values()).filter(p -> p.matches(newUrl)).findFirst(); 163 162 downloadTask = new DownloadTask(settings, getOsmServerReader(newUrl), progressMonitor, true, Compression.byExtension(newUrl)); 164 163 currentBounds = null; 165 164 // Extract .osm filename from URL to set the new layer name 166 extractOsmFilename(settings, urlPattern. pattern(), newUrl);165 extractOsmFilename(settings, urlPattern.orElse(OsmUrlPattern.EXTERNAL_OSM_FILE).pattern(), newUrl); 167 166 return MainApplication.worker.submit(downloadTask); 168 167 } … … 190 189 if (newLayerName == null || newLayerName.isEmpty()) { 191 190 Matcher matcher = Pattern.compile(pattern).matcher(url); 192 newLayerName = matcher.matches() ? matcher.group(1) : null;191 newLayerName = matcher.matches() && matcher.groupCount() > 0 ? matcher.group(1) : null; 193 192 } 194 193 }
Note:
See TracChangeset
for help on using the changeset viewer.