Changeset 18380 in josm for trunk/src/org
- Timestamp:
- 2022-02-15T18:12:49+01:00 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/imagery/ImageryPatterns.java
r18378 r18380 9 9 import java.util.Map; 10 10 import java.util.Objects; 11 import java.util.Optional; 11 12 import java.util.regex.Matcher; 12 13 import java.util.regex.Pattern; 13 14 14 15 import org.openstreetmap.gui.jmapviewer.FeatureAdapter; 16 import org.openstreetmap.josm.spi.preferences.Config; 15 17 16 18 /** … … 94 96 if (id != null && url != null) { 95 97 final Matcher matcher = PATTERN_API_KEY.matcher(url); 96 if (matcher. matches()) {98 if (matcher.find()) { 97 99 try { 98 final String apiKey = FeatureAdapter.retrieveApiKey(id); 99 return matcher.replaceAll(apiKey); 100 } catch (IOException | NullPointerException e) { 100 return Optional.ofNullable(FeatureAdapter.retrieveApiKey(id)) 101 .map(matcher::replaceAll) 102 /* None of the configured API key sites had an API key for the id. */ 103 .orElseThrow(() -> { 104 // Give a more complete error message so that users can fix the problem without 105 // opening a bug report. Hopefully. 106 final String message; 107 if (Config.getPref().getKeySet().contains("apikey.sites")) { 108 message = tr("Advanced preference ''{0}'' is not default. Please consider resetting it.", "apikey.sites"); 109 } else { 110 message = tr("API key for imagery with id={0} may not be available.", id); 111 } 112 return new IOException(message); 113 }); 114 } catch (IOException e) { 101 115 // Match rough behavior in JMapViewer TemplatedTMSTileSource, but with better error message. 102 throw new IllegalArgumentException(tr("Could not retrieve API key for imagery with id={0}. Cannot add layer.", id), e); 116 throw new IllegalArgumentException(tr("Could not retrieve API key for imagery with id={0}. Cannot add layer.\n{1}", 117 id, e.getMessage()), e); 103 118 } 104 119 }
Note:
See TracChangeset
for help on using the changeset viewer.