Changeset 35322 in osm
- Timestamp:
- 2020-02-15T15:55:39+01:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/TemplatedTMSTileSource.java
r35321 r35322 52 52 private static final Pattern PATTERN_API_KEY = Pattern.compile("\\{apiKey\\}"); 53 53 private static final Pattern PATTERN_PARAM = Pattern.compile("\\{((?:\\d+-)?z(?:oom)?(:?[+-]\\d+)?|x|y|!y|-y|switch:([^}]+))\\}"); 54 55 /** 56 * Pattern used only for compatibility with older JOSM clients. To remove end of 2020, with an update of JOSM wiki 57 * @deprecated to remove end of 2020 58 */ 59 @Deprecated 60 private static final Pattern PATTERN_API_KEY_COMPATIBILITY = Pattern.compile("_apiKey_"); 54 61 // CHECKSTYLE.ON: SingleSpaceSeparator 55 62 … … 71 78 } 72 79 73 private void replacePattern(Pattern p, BiConsumer<Matcher, StringBuffer> replaceAction) { 74 StringBuffer output = new StringBuffer(); 75 Matcher m = p.matcher(baseUrl); 76 while (m.find()) { 77 replaceAction.accept(m, output); 80 private void replacePattern(BiConsumer<Matcher, StringBuffer> replaceAction, Pattern... patterns) { 81 for (Pattern p : patterns) { 82 StringBuffer output = new StringBuffer(); 83 Matcher m = p.matcher(baseUrl); 84 while (m.find()) { 85 replaceAction.accept(m, output); 86 } 87 m.appendTail(output); 88 baseUrl = output.toString(); 78 89 } 79 m.appendTail(output);80 baseUrl = output.toString();81 90 } 82 91 … … 89 98 } 90 99 // Capturing group pattern on header values 91 replacePattern( PATTERN_HEADER,(matcher, output) -> {100 replacePattern((matcher, output) -> { 92 101 headers.put(matcher.group(1), matcher.group(2)); 93 102 matcher.appendReplacement(output, ""); 94 } );103 }, PATTERN_HEADER); 95 104 // Capturing group pattern on API key values 96 replacePattern(PATTERN_API_KEY, (matcher, output) -> { 97 try { 98 matcher.appendReplacement(output, FeatureAdapter.retrieveApiKey(imageryId)); 99 } catch (IOException e) { 100 throw new IllegalArgumentException(e); 101 } 102 }); 105 if (imageryId != null) { 106 replacePattern((matcher, output) -> { 107 try { 108 matcher.appendReplacement(output, FeatureAdapter.retrieveApiKey(imageryId)); 109 } catch (IOException e) { 110 throw new IllegalArgumentException(e); 111 } 112 }, PATTERN_API_KEY, PATTERN_API_KEY_COMPATIBILITY); 113 } 103 114 // Capturing group pattern on zoom values 104 115 m = PATTERN_ZOOM.matcher(baseUrl);
Note:
See TracChangeset
for help on using the changeset viewer.