Changeset 9856 in josm for trunk/src


Ignore:
Timestamp:
2016-02-23T13:29:54+01:00 (9 years ago)
Author:
simon04
Message:

fix #12547 see #12469 - Fix Overpass API "Build query" for Java 7

File:
1 edited

Legend:

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

    r9850 r9856  
    33
    44import java.io.IOException;
    5 import java.io.InputStreamReader;
    65import java.io.Reader;
    7 import java.nio.charset.StandardCharsets;
    8 import java.util.HashMap;
    96
    107import javax.script.Invocable;
     
    1411
    1512import org.openstreetmap.josm.Main;
     13import org.openstreetmap.josm.io.CachedFile;
    1614
    1715/**
     
    4038
    4139    private OverpassTurboQueryWizard() {
    42         try (final Reader reader = new InputStreamReader(
    43                 getClass().getResourceAsStream("/data/overpass-wizard.js"), StandardCharsets.UTF_8)) {
     40
     41        try (final CachedFile file = new CachedFile("resource://data/overpass-wizard.js");
     42             final Reader reader = file.getContentReader()) {
    4443            engine.eval("var console = {error: " + Main.class.getCanonicalName() + ".warn};");
    4544            engine.eval("var global = {};");
    4645            engine.eval(reader);
     46            engine.eval("var overpassWizard = function(query) {" +
     47                    "  return global.overpassWizard(query, {" +
     48                    "    comment: false," +
     49                    "    outputFormat: 'xml'," +
     50                    "    outputMode: 'recursive_meta'" +
     51                    "  });" +
     52                    "}");
    4753        } catch (ScriptException | IOException ex) {
    4854            throw new RuntimeException("Failed to initialize OverpassTurboQueryWizard", ex);
     
    5864    public String constructQuery(String search) throws UncheckedParseException {
    5965        try {
    60             final Object result = ((Invocable) engine).invokeMethod(engine.get("global"),
    61                     "overpassWizard", search, new HashMap<String, Object>() { {
    62                         put("comment", false);
    63                         put("outputFormat", "xml");
    64                         put("outputMode", "recursive_meta");
    65                     } }
    66             );
     66            final Object result = ((Invocable) engine).invokeFunction("overpassWizard", search);
    6767            if (Boolean.FALSE.equals(result)) {
    6868                throw new UncheckedParseException();
Note: See TracChangeset for help on using the changeset viewer.