Esempio n. 1
0
 private static boolean confirmEulaAcceptance(PreferenceTabbedPane gui, String eulaUrl) {
   URL url = null;
   try {
     url = new URL(eulaUrl.replaceAll("\\{lang\\}", LanguageInfo.getWikiLanguagePrefix()));
     JosmEditorPane htmlPane = null;
     try {
       htmlPane = new JosmEditorPane(url);
     } catch (IOException e1) {
       Main.trace(e1);
       // give a second chance with a default Locale 'en'
       try {
         url = new URL(eulaUrl.replaceAll("\\{lang\\}", ""));
         htmlPane = new JosmEditorPane(url);
       } catch (IOException e2) {
         Main.debug(e2);
         JOptionPane.showMessageDialog(gui, tr("EULA license URL not available: {0}", eulaUrl));
         return false;
       }
     }
     Box box = Box.createVerticalBox();
     htmlPane.setEditable(false);
     JScrollPane scrollPane = new JScrollPane(htmlPane);
     scrollPane.setPreferredSize(new Dimension(400, 400));
     box.add(scrollPane);
     int option =
         JOptionPane.showConfirmDialog(
             Main.parent,
             box,
             tr("Please abort if you are not sure"),
             JOptionPane.YES_NO_OPTION,
             JOptionPane.WARNING_MESSAGE);
     if (option == JOptionPane.YES_OPTION) return true;
   } catch (MalformedURLException e2) {
     JOptionPane.showMessageDialog(gui, tr("Malformed URL for the EULA licence: {0}", eulaUrl));
   }
   return false;
 }
    @Override
    protected void realRun() throws SAXException, IOException, OsmTransferException {
      LinkedList<StyleSourceInfo> styles = new LinkedList<StyleSourceInfo>();
      String lang = LanguageInfo.getLanguageCodeXML();
      try {
        MirroredInputStream stream = new MirroredInputStream(url);
        InputStreamReader r;
        try {
          r = new InputStreamReader(stream, "UTF-8");
        } catch (UnsupportedEncodingException e) {
          r = new InputStreamReader(stream);
        }
        BufferedReader reader = new BufferedReader(r);

        String line;
        StyleSourceInfo last = null;

        while ((line = reader.readLine()) != null && !canceled) {
          if (line.trim().equals("")) {
            continue; // skip empty lines
          }
          if (line.startsWith("\t")) {
            Matcher m = Pattern.compile("^\t([^:]+): *(.+)$").matcher(line);
            if (!m.matches()) {
              System.err.println(
                  tr(
                      "Warning: illegal format of entry in style list ''{0}''. Got ''{1}''",
                      url, line));
              continue;
            }
            if (last != null) {
              String key = m.group(1);
              String value = m.group(2);
              if ("author".equals(key) && last.author == null) {
                last.author = value;
              } else if ("version".equals(key)) {
                last.version = value;
              } else if ("link".equals(key) && last.link == null) {
                last.link = value;
              } else if ("description".equals(key) && last.description == null) {
                last.description = value;
              } else if ("shortdescription".equals(key) && last.shortdescription == null) {
                last.shortdescription = value;
              } else if ((lang + "author").equals(key)) {
                last.author = value;
              } else if ((lang + "link").equals(key)) {
                last.link = value;
              } else if ((lang + "description").equals(key)) {
                last.description = value;
              } else if ((lang + "shortdescription").equals(key)) {
                last.shortdescription = value;
              }
            }
          } else {
            last = null;
            Matcher m = Pattern.compile("^(.+);(.+)$").matcher(line);
            if (m.matches()) {
              styles.add(last = new StyleSourceInfo(m.group(1), m.group(2)));
            } else {
              System.err.println(
                  tr(
                      "Warning: illegal format of entry in style list ''{0}''. Got ''{1}''",
                      url, line));
            }
          }
        }
      } catch (Exception e) {
        if (canceled)
          // ignore the exception and return
          return;
        warn(e);
        return;
      }
      availableStylesModel.setStyleSources(styles);
    }