X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=tim%2Fprune%2Fgui%2Fmap%2FMapSource.java;h=35590a6e9a44964179050986d7ce6dc7c8475386;hp=c2311ae186ac89a077d265be2fba3b35973787b6;hb=f35b6d628f68e3b5ef19965ad8988d0dd1eb8efa;hpb=3745d70b1427bb8ac1a085e47cbdc566936784e1 diff --git a/tim/prune/gui/map/MapSource.java b/tim/prune/gui/map/MapSource.java index c2311ae..35590a6 100644 --- a/tim/prune/gui/map/MapSource.java +++ b/tim/prune/gui/map/MapSource.java @@ -69,23 +69,34 @@ public abstract class MapSource * @param inUrl url to check * @return validated url with correct prefix and trailing slash, or null */ - protected static String fixBaseUrl(String inUrl) + public static String fixBaseUrl(String inUrl) { if (inUrl == null || inUrl.equals("")) {return null;} - String url = inUrl; + String urlstr = inUrl; // check prefix try { - new URL(url); + new URL(urlstr); } catch (MalformedURLException e) { + // fail if protocol specified + if (urlstr.indexOf("://") >= 0) {return null;} // add the http protocol - url = "http://" + url; + urlstr = "http://" + urlstr; } // check trailing / - if (!url.endsWith("/")) { - url = url + "/"; + if (!urlstr.endsWith("/")) { + urlstr = urlstr + "/"; } - return url; + // Validate current url, return null if not ok + try { + URL url = new URL(urlstr); + // url host must contain a dot + if (url.getHost().indexOf('.') < 0) {return null;} + } + catch (MalformedURLException e) { + urlstr = null; + } + return urlstr; } /** @@ -114,11 +125,14 @@ public abstract class MapSource */ public String getSiteStrings() { - String s = ""; + StringBuilder sb = new StringBuilder(); for (int i=0; i