Ignore:
Timestamp:
2020-08-03T20:23:44+02:00 (4 years ago)
Author:
simon04
Message:

fix #19620 - Tag2Link: allow to customize sources

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/Tag2Link.java

    r16780 r16834  
    2323
    2424import org.openstreetmap.josm.data.osm.OsmUtils;
     25import org.openstreetmap.josm.data.preferences.ListProperty;
     26import org.openstreetmap.josm.io.CachedFile;
    2527
    2628/**
     
    5456            .collect(Collectors.joining("|"));
    5557
     58    static final ListProperty PREF_SOURCE = new ListProperty("tag2link.source",
     59            Collections.singletonList("resource://META-INF/resources/webjars/tag2link/2020.7.15/index.json"));
     60
    5661    private Tag2Link() {
    5762        // private constructor for utility class
     
    7782        try {
    7883            wikidataRules.clear();
    79             initializeFromResources();
     84            for (String source : PREF_SOURCE.get()) {
     85                initializeFromResources(new CachedFile(source));
     86            }
    8087        } catch (Exception e) {
    8188            Logging.error("Failed to initialize tag2link rules");
     
    8794     * Initializes the tag2link rules from the resources.
    8895     *
     96     * @param resource the source
    8997     * @throws IOException in case of I/O error
    9098     */
    91     private static void initializeFromResources() throws IOException {
    92         final String resource = "META-INF/resources/webjars/tag2link/2020.7.15/index.json";
     99    private static void initializeFromResources(CachedFile resource) throws IOException {
    93100        final JsonArray rules;
    94         try (InputStream inputStream = Tag2Link.class.getClassLoader().getResourceAsStream(resource);
     101        try (InputStream inputStream = resource.getInputStream();
    95102             JsonReader jsonReader = Json.createReader(inputStream)) {
    96103            rules = jsonReader.readArray();
Note: See TracChangeset for help on using the changeset viewer.