Changeset 16018 in josm for trunk/scripts


Ignore:
Timestamp:
2020-03-03T22:49:50+01:00 (5 years ago)
Author:
Don-vip
Message:

see #18845 - fix epsg and taginfo goals

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/scripts/TagInfoExtract.java

    r16006 r16018  
    2424import java.util.Optional;
    2525import java.util.Set;
     26import java.util.regex.Matcher;
     27import java.util.regex.Pattern;
    2628import java.util.stream.Collectors;
    2729
     
    206208         */
    207209        private String findImageUrl(String path) {
    208             final Path f = baseDir.resolve("images").resolve(path);
     210            final Path f = baseDir.resolve("resources").resolve("images").resolve(path);
    209211            if (Files.exists(f)) {
    210212                return "https://josm.openstreetmap.de/export/" + josmSvnRevision + "/josm/trunk/resources/images/" + path;
     
    379381         */
    380382        private abstract class Checker {
     383            private final Pattern reservedChars = Pattern.compile("[<>:\"|\\?\\*]");
     384
    381385            Checker(Tag tag) {
    382386                this.tag = tag;
     
    417421                renderer.getSettings(false);
    418422                element.paintPrimitive(osm, MapPaintSettings.INSTANCE, renderer, false, false, false);
    419                 final String imageName = type + "_" + tag + ".png";
     423                final String imageName = type + "_" + normalize(tag.toString()) + ".png";
    420424                try (OutputStream out = Files.newOutputStream(options.imageDir.resolve(imageName))) {
    421425                    ImageIO.write(img, "png", out);
     
    425429                final String baseUrl = options.imageUrlPrefix != null ? options.imageUrlPrefix : options.imageDir.toString();
    426430                return baseUrl + "/" + imageName;
     431            }
     432
     433            /**
     434             * Normalizes tag so that it can used as a filename on all platforms, including Windows.
     435             * @param tag OSM tag, that can contain illegal path characters
     436             * @return OSM tag with all illegal path characters replaced by underscore ('_')
     437             */
     438            String normalize(String tag) {
     439                Matcher m = reservedChars.matcher(tag);
     440                return m.find() ? m.replaceAll("_") : tag;
    427441            }
    428442
Note: See TracChangeset for help on using the changeset viewer.