Changeset 10294 in josm for trunk/src


Ignore:
Timestamp:
2016-05-29T00:14:28+02:00 (8 years ago)
Author:
Don-vip
Message:

sonar - squid:S1848 - refactor URL checks

Location:
trunk/src/org/openstreetmap/josm
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/oauth/OAuthParameters.java

    r9355 r10294  
    22package org.openstreetmap.josm.data.oauth;
    33
    4 import java.net.MalformedURLException;
    5 import java.net.URL;
    64import java.util.Objects;
    75
    8 import oauth.signpost.OAuthConsumer;
    9 import oauth.signpost.OAuthProvider;
    106import org.openstreetmap.josm.Main;
    117import org.openstreetmap.josm.data.Preferences;
    128import org.openstreetmap.josm.io.OsmApi;
    139import org.openstreetmap.josm.tools.CheckParameterUtil;
     10import org.openstreetmap.josm.tools.Utils;
     11
     12import oauth.signpost.OAuthConsumer;
     13import oauth.signpost.OAuthProvider;
    1414
    1515/**
     
    5252        final String serverUrl;
    5353
    54         if (apiUrl != null) {
    55             // validate URL syntax
    56             try {
    57                 new URL(apiUrl);
    58             } catch (MalformedURLException e) {
    59                 apiUrl = null;
    60             }
     54        if (!Utils.isValidUrl(apiUrl)) {
     55            apiUrl = null;
    6156        }
    6257
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/query/UrlBasedQueryPanel.java

    r10179 r10294  
    134134        }
    135135        String path = url.getPath();
    136         String query = url.getQuery();
    137136        if (path == null || !path.endsWith("/changesets"))
    138137            return null;
    139138
    140139        try {
    141             return ChangesetQuery.buildFromUrlQuery(query);
     140            return ChangesetQuery.buildFromUrlQuery(url.getQuery());
    142141        } catch (ChangesetQueryUrlException e) {
    143142            Main.warn(e.getMessage());
  • trunk/src/org/openstreetmap/josm/gui/preferences/server/OsmApiUrlInputPanel.java

    r10217 r10294  
    1414import java.awt.event.ItemEvent;
    1515import java.awt.event.ItemListener;
    16 import java.net.MalformedURLException;
    17 import java.net.URL;
    1816import java.util.Arrays;
    1917
     
    258256            if (getComponent().getText().trim().isEmpty())
    259257                return false;
    260 
    261             try {
    262                 new URL(getComponent().getText().trim());
    263                 return true;
    264             } catch (MalformedURLException e) {
    265                 return false;
    266             }
     258            return Utils.isValidUrl(getComponent().getText().trim());
    267259        }
    268260
  • trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java

    r10212 r10294  
    1212import java.lang.reflect.Constructor;
    1313import java.lang.reflect.InvocationTargetException;
    14 import java.net.MalformedURLException;
    1514import java.net.URL;
    1615import java.text.MessageFormat;
     
    206205            s = attr.getValue("Plugin-Link");
    207206        }
    208         if (s != null) {
    209             try {
    210                 new URL(s);
    211             } catch (MalformedURLException e) {
    212                 Main.info(tr("Invalid URL ''{0}'' in plugin {1}", s, name));
    213                 s = null;
    214             }
     207        if (s != null && !Utils.isValidUrl(s)) {
     208            Main.info(tr("Invalid URL ''{0}'' in plugin {1}", s, name));
     209            s = null;
    215210        }
    216211        link = s;
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r10289 r10294  
    13241324
    13251325    /**
     1326     * Determines if the given URL is valid.
     1327     * @param url The URL to test
     1328     * @return {@code true} if the url is valid
     1329     * @since 10294
     1330     */
     1331    public static boolean isValidUrl(String url) {
     1332        try {
     1333            new URL(url);
     1334            return true;
     1335        } catch (MalformedURLException | NullPointerException e) {
     1336            return false;
     1337        }
     1338    }
     1339
     1340    /**
    13261341     * Creates a new {@link ThreadFactory} which creates threads with names according to {@code nameFormat}.
    13271342     * @param nameFormat a {@link String#format(String, Object...)} compatible name format; its first argument is a unique thread index
Note: See TracChangeset for help on using the changeset viewer.