@Override
 protected String buildRequestString(final OsmPrimitiveType type, Set<Long> idPackage) {
   final Utils.Function<Long, Object> toOverpassExpression =
       new Utils.Function<Long, Object>() {
         @Override
         public Object apply(Long x) {
           return type.getAPIName() + "(" + x + ");>;";
         }
       };
   final String query =
       "(" + Utils.join("", Utils.transform(idPackage, toOverpassExpression)) + ");out meta;";
   return "interpreter?data=" + Utils.encodeUrl(query);
 }
Esempio n. 2
0
    @Override
    protected void realRun() throws SAXException, IOException, OsmTransferException {
      String urlString = useserver.url + Utils.encodeUrl(searchExpression);

      try {
        getProgressMonitor().indeterminateSubTask(tr("Querying name server ..."));
        URL url = new URL(urlString);
        synchronized (this) {
          connection = HttpClient.create(url);
          connection.connect();
        }
        try (Reader reader = connection.getResponse().getContentReader()) {
          InputSource inputSource = new InputSource(reader);
          NameFinderResultParser parser = new NameFinderResultParser();
          Utils.parseSafeSAX(inputSource, parser);
          this.data = parser.getResult();
        }
      } catch (SAXParseException e) {
        if (!canceled) {
          // Nominatim sometimes returns garbage, see #5934, #10643
          Main.warn(tr("Error occured with query ''{0}'': ''{1}''", urlString, e.getMessage()));
          GuiHelper.runInEDTAndWait(
              new Runnable() {
                @Override
                public void run() {
                  HelpAwareOptionPane.showOptionDialog(
                      Main.parent,
                      tr("Name server returned invalid data. Please try again."),
                      tr("Bad response"),
                      JOptionPane.WARNING_MESSAGE,
                      null);
                }
              });
        }
      } catch (Exception e) {
        if (!canceled) {
          OsmTransferException ex = new OsmTransferException(e);
          ex.setUrl(urlString);
          lastException = ex;
        }
      }
    }