Changeset 35322 in osm


Ignore:
Timestamp:
2020-02-15T15:55:39+01:00 (5 years ago)
Author:
donvip
Message:

see #josm18440 - define a pattern used only for compatibility with older JOSM clients. To remove end of 2020, with an update of JOSM wiki

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/TemplatedTMSTileSource.java

    r35321 r35322  
    5252    private static final Pattern PATTERN_API_KEY = Pattern.compile("\\{apiKey\\}");
    5353    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_");
    5461    // CHECKSTYLE.ON: SingleSpaceSeparator
    5562
     
    7178    }
    7279
    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();
    7889        }
    79         m.appendTail(output);
    80         baseUrl = output.toString();
    8190    }
    8291
     
    8998        }
    9099        // Capturing group pattern on header values
    91         replacePattern(PATTERN_HEADER, (matcher, output) -> {
     100        replacePattern((matcher, output) -> {
    92101            headers.put(matcher.group(1), matcher.group(2));
    93102            matcher.appendReplacement(output, "");
    94         });
     103        }, PATTERN_HEADER);
    95104        // 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        }
    103114        // Capturing group pattern on zoom values
    104115        m = PATTERN_ZOOM.matcher(baseUrl);
Note: See TracChangeset for help on using the changeset viewer.