diff --git a/src/org/openstreetmap/josm/data/imagery/ImageryPatterns.java b/src/org/openstreetmap/josm/data/imagery/ImageryPatterns.java
index 30d0e99e0b..bcc6893462 100644
|
a
|
b
|
package org.openstreetmap.josm.data.imagery;
|
| 4 | 4 | import static org.openstreetmap.josm.tools.I18n.marktr; |
| 5 | 5 | import static org.openstreetmap.josm.tools.I18n.tr; |
| 6 | 6 | |
| | 7 | import java.io.IOException; |
| 7 | 8 | import java.util.Arrays; |
| 8 | 9 | import java.util.Map; |
| 9 | 10 | import java.util.Objects; |
| 10 | 11 | import java.util.regex.Matcher; |
| 11 | 12 | import java.util.regex.Pattern; |
| 12 | 13 | |
| | 14 | import org.openstreetmap.gui.jmapviewer.FeatureAdapter; |
| | 15 | |
| 13 | 16 | /** |
| 14 | 17 | * Patterns that can be replaced in imagery URLs. |
| 15 | 18 | * @since 17578 |
| … |
… |
public final class ImageryPatterns {
|
| 29 | 32 | static final Pattern PATTERN_HEIGHT = Pattern.compile("\\{height\\}"); |
| 30 | 33 | static final Pattern PATTERN_TIME = Pattern.compile("\\{time\\}"); // Sentinel-2 |
| 31 | 34 | static final Pattern PATTERN_PARAM = Pattern.compile("\\{([^}]+)\\}"); |
| | 35 | /** |
| | 36 | * The api key pattern is used to allow us to quickly switch apikeys. This is functionally the same as the pattern |
| | 37 | * in {@link org.openstreetmap.gui.jmapviewer.tilesources.TemplatedTMSTileSource}. |
| | 38 | */ |
| | 39 | static final Pattern PATTERN_API_KEY = Pattern.compile("\\{apikey}"); |
| 32 | 40 | // CHECKSTYLE.ON: SingleSpaceSeparator |
| 33 | 41 | |
| 34 | 42 | private static final Pattern[] ALL_WMS_PATTERNS = { |
| 35 | 43 | PATTERN_HEADER, PATTERN_PROJ, PATTERN_WKID, PATTERN_BBOX, |
| 36 | 44 | PATTERN_W, PATTERN_S, PATTERN_E, PATTERN_N, |
| 37 | | PATTERN_WIDTH, PATTERN_HEIGHT, PATTERN_TIME |
| | 45 | PATTERN_WIDTH, PATTERN_HEIGHT, PATTERN_TIME, |
| | 46 | PATTERN_API_KEY |
| 38 | 47 | }; |
| 39 | 48 | |
| 40 | 49 | private static final Pattern[] ALL_WMTS_PATTERNS = { |
| 41 | | PATTERN_HEADER |
| | 50 | PATTERN_HEADER, PATTERN_API_KEY |
| 42 | 51 | }; |
| 43 | 52 | |
| 44 | 53 | private ImageryPatterns() { |
| … |
… |
public final class ImageryPatterns {
|
| 74 | 83 | matcher.appendTail(output); |
| 75 | 84 | return output.toString(); |
| 76 | 85 | } |
| | 86 | |
| | 87 | /** |
| | 88 | * Handle the {@link #PATTERN_API_KEY} replacement |
| | 89 | * @param id The id of the info |
| | 90 | * @param url The templated url |
| | 91 | * @return The templated url with {@link #PATTERN_API_KEY} replaced |
| | 92 | */ |
| | 93 | static String handleApiKeyTemplate(final String id, final String url) { |
| | 94 | if (id != null && url != null) { |
| | 95 | try { |
| | 96 | final String apiKey = FeatureAdapter.retrieveApiKey(id); |
| | 97 | return PATTERN_API_KEY.matcher(url).replaceAll(apiKey); |
| | 98 | } catch (IOException | NullPointerException e) { |
| | 99 | // Match behavior in JMapViewer TemplatedTMSTileSource |
| | 100 | throw new IllegalArgumentException(e); |
| | 101 | } |
| | 102 | } |
| | 103 | return url; |
| | 104 | } |
| 77 | 105 | } |
diff --git a/src/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSource.java b/src/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSource.java
index e2803b993b..ba00497521 100644
|
a
|
b
|
public class TemplatedWMSTileSource extends AbstractWMSTileSource implements Tem
|
| 44 | 44 | this.serverProjections = new TreeSet<>(info.getServerProjections()); |
| 45 | 45 | this.headers.putAll(info.getCustomHttpHeaders()); |
| 46 | 46 | this.date = info.getDate(); |
| 47 | | this.baseUrl = ImageryPatterns.handleHeaderTemplate(baseUrl, headers); |
| | 47 | this.baseUrl = ImageryPatterns.handleApiKeyTemplate(info.getId(), ImageryPatterns.handleHeaderTemplate(baseUrl, headers)); |
| 48 | 48 | initProjection(); |
| 49 | 49 | // Bounding box coordinates have to be switched for WMS 1.3.0 EPSG:4326. |
| 50 | 50 | // |
diff --git a/src/org/openstreetmap/josm/data/imagery/WMTSTileSource.java b/src/org/openstreetmap/josm/data/imagery/WMTSTileSource.java
index 5ab3a3a358..11c743e4ba 100644
|
a
|
b
|
public class WMTSTileSource extends AbstractTMSTileSource implements TemplatedTi
|
| 360 | 360 | super(info); |
| 361 | 361 | CheckParameterUtil.ensureThat(info.getDefaultLayers().size() < 2, "At most 1 default layer for WMTS is supported"); |
| 362 | 362 | this.headers.putAll(info.getCustomHttpHeaders()); |
| 363 | | this.baseUrl = GetCapabilitiesParseHelper.normalizeCapabilitiesUrl(ImageryPatterns.handleHeaderTemplate(info.getUrl(), headers)); |
| | 363 | this.baseUrl = GetCapabilitiesParseHelper.normalizeCapabilitiesUrl( |
| | 364 | ImageryPatterns.handleApiKeyTemplate(info.getId(), ImageryPatterns.handleHeaderTemplate(info.getUrl(), headers))); |
| 364 | 365 | WMTSCapabilities capabilities = getCapabilities(baseUrl, headers); |
| 365 | 366 | this.layers = capabilities.getLayers(); |
| 366 | 367 | this.baseUrl = capabilities.getBaseUrl(); |