Changeset 7466 in josm for trunk/src


Ignore:
Timestamp:
2014-08-30T12:58:39+02:00 (10 years ago)
Author:
Don-vip
Message:

fix #10441 - wrong parsing of changesets list in API URL test task + fix EDT violations

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/HelpAwareOptionPane.java

    r7005 r7466  
    211211     * @return the index of the selected option or {@link JOptionPane#CLOSED_OPTION}
    212212     */
    213     public static int showOptionDialog(Component parentComponent, Object msg, String title, int messageType, Icon icon, final ButtonSpec[] options, final ButtonSpec defaultOption, final String helpTopic)  {
     213    public static int showOptionDialog(Component parentComponent, Object msg, String title, int messageType,
     214            Icon icon, final ButtonSpec[] options, final ButtonSpec defaultOption, final String helpTopic)  {
    214215        final List<JButton> buttons = createOptionButtons(options, helpTopic);
    215216        if (helpTopic != null) {
     
    318319     * @see #showOptionDialog(Component, Object, String, int, Icon, ButtonSpec[], ButtonSpec, String)
    319320     */
    320     public static int showOptionDialog(Component parentComponent, Object msg, String title, int messageType,final String helpTopic)  {
    321         return showOptionDialog(parentComponent, msg, title, messageType, null,null,null, helpTopic);
     321    public static int showOptionDialog(Component parentComponent, Object msg, String title, int messageType, String helpTopic)  {
     322        return showOptionDialog(parentComponent, msg, title, messageType, null, null, null, helpTopic);
    322323    }
    323324
    324325    /**
    325326     * Run it in Event Dispatch Thread.
    326      * This version does not return anything, so it is more like showMessageDialog.
     327     * This version does not return anything, so it is more like {@code showMessageDialog}.
    327328     *
    328329     * It can be used, when you need to show a message dialog from a worker thread,
    329      * e.g. from PleaseWaitRunnable
     330     * e.g. from {@code PleaseWaitRunnable}.
     331     *
     332     * @param parentComponent the parent component
     333     * @param msg the message
     334     * @param title the title
     335     * @param messageType the message type (see {@link JOptionPane})
     336     * @param helpTopic the help topic. Can be null.
    330337     */
    331338    public static void showMessageDialogInEDT(final Component parentComponent, final Object msg, final String title, final int messageType, final String helpTopic)  {
  • trunk/src/org/openstreetmap/josm/gui/preferences/server/ApiUrlTestTask.java

    r7082 r7466  
    55
    66import java.awt.Component;
    7 import java.io.BufferedReader;
    87import java.io.IOException;
    9 import java.io.InputStreamReader;
    108import java.net.HttpURLConnection;
    119import java.net.MalformedURLException;
    1210import java.net.URL;
    13 import java.nio.charset.StandardCharsets;
    1411
    1512import javax.swing.JOptionPane;
     
    1916import org.openstreetmap.josm.gui.PleaseWaitRunnable;
    2017import org.openstreetmap.josm.gui.help.HelpUtil;
     18import org.openstreetmap.josm.io.IllegalDataException;
     19import org.openstreetmap.josm.io.OsmChangesetParser;
    2120import org.openstreetmap.josm.io.OsmTransferException;
    2221import org.openstreetmap.josm.tools.CheckParameterUtil;
     
    3332 * to "https://x.y.y/api/0/capabilities" or "https://x.y.y/a/capabilities" with valid capabilities. If we get
    3433 * valid capabilities with an URL we therefore can't be sure that the base URL is valid API URL.
    35  *
     34 * @since 2745
    3635 */
    37 public class ApiUrlTestTask extends PleaseWaitRunnable{
    38 
    39     private String url;
     36public class ApiUrlTestTask extends PleaseWaitRunnable {
     37
     38    private final String url;
    4039    private boolean canceled;
    4140    private boolean success;
    42     private Component parent;
     41    private final Component parent;
    4342    private HttpURLConnection connection;
    4443
    4544    /**
    46      * Creates the task
     45     * Constructs a new {@code ApiUrlTestTask}.
    4746     *
    4847     * @param parent the parent component relative to which the {@link PleaseWaitRunnable}-Dialog is displayed
     
    5857
    5958    protected void alertInvalidUrl(String url) {
    60         HelpAwareOptionPane.showOptionDialog(
     59        HelpAwareOptionPane.showMessageDialogInEDT(
    6160                parent,
    6261                tr("<html>"
     
    7372
    7473    protected void alertInvalidChangesetUrl(String url) {
    75         HelpAwareOptionPane.showOptionDialog(
     74        HelpAwareOptionPane.showMessageDialogInEDT(
    7675                parent,
    7776                tr("<html>"
     
    8988
    9089    protected void alertConnectionFailed() {
    91         HelpAwareOptionPane.showOptionDialog(
     90        HelpAwareOptionPane.showMessageDialogInEDT(
    9291                parent,
    9392                tr("<html>"
     
    105104
    106105    protected void alertInvalidServerResult(int retCode) {
    107         HelpAwareOptionPane.showOptionDialog(
     106        HelpAwareOptionPane.showMessageDialogInEDT(
    108107                parent,
    109108                tr("<html>"
     
    122121
    123122    protected void alertInvalidChangesetList() {
    124         HelpAwareOptionPane.showOptionDialog(
     123        HelpAwareOptionPane.showMessageDialogInEDT(
    125124                parent,
    126125                tr("<html>"
     
    194193                return;
    195194            }
    196             StringBuilder changesets = new StringBuilder();
    197             try (BufferedReader bin = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) {
    198                 String line;
    199                 while ((line = bin.readLine()) != null) {
    200                     changesets.append(line).append("\n");
     195
     196            try {
     197                OsmChangesetParser.parse(connection.getInputStream(), progressMonitor.createSubTaskMonitor(1, true));
     198            } catch (IllegalDataException e) {
     199                if (e.getCause() instanceof IOException) {
     200                    throw (IOException) e.getCause();
     201                } else {
     202                    Main.warn(e.getMessage());
     203                    alertInvalidChangesetList();
     204                    return;
    201205                }
    202             }
    203             if (! (changesets.toString().contains("<osm") && changesets.toString().contains("</osm>"))) {
    204                 // heuristic: if there isn't an opening and closing "<osm>" tag in the returned content,
    205                 // then we didn't get a list of changesets in return. Could be replaced by explicitly parsing
    206                 // the result but currently not worth the effort.
    207                 alertInvalidChangesetList();
    208                 return;
    209206            }
    210207            success = true;
Note: See TracChangeset for help on using the changeset viewer.