X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Fgui%2Fmap%2FMapSource.java;h=c4e294665e128def7d1fcbfb048cb516624d5d00;hb=2d8cb72e84d5cc1089ce77baf1e34ea3ea2f8465;hp=e3ac2ed2227a1825d01526c87800c3abdd9819d4;hpb=f1b92378a792131ac8fb33a869405851d5b2d1f7;p=GpsPrune.git diff --git a/tim/prune/gui/map/MapSource.java b/tim/prune/gui/map/MapSource.java index e3ac2ed..c4e2946 100644 --- a/tim/prune/gui/map/MapSource.java +++ b/tim/prune/gui/map/MapSource.java @@ -2,6 +2,8 @@ package tim.prune.gui.map; import java.net.MalformedURLException; import java.net.URL; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * Class to represent any map source, whether an OsmMapSource @@ -14,6 +16,9 @@ public abstract class MapSource /** File extensions */ protected String[] _extensions = null; + /** Regular expression for catching server wildcards */ + protected static final Pattern WILD_PATTERN = Pattern.compile("^(.*)\\[(.*)\\](.*)$"); + /** * @return the number of layers used in this source @@ -79,11 +84,20 @@ public abstract class MapSource { if (inUrl == null || inUrl.equals("")) {return null;} String urlstr = inUrl; + boolean urlOk = false; + // check prefix - try { - new URL(urlstr); + try + { + urlOk = new URL(urlstr.replace('[', 'w').replace(']', 'w')).toString() != null; } - catch (MalformedURLException e) { + catch (MalformedURLException e) + { + urlOk = false; + } + + if (!urlOk) + { // fail if protocol specified if (urlstr.indexOf("://") >= 0) {return null;} // add the http protocol @@ -94,8 +108,9 @@ public abstract class MapSource urlstr = urlstr + "/"; } // Validate current url, return null if not ok - try { - URL url = new URL(urlstr); + try + { + URL url = new URL(urlstr.replace('[', 'w').replace(']', 'w')); // url host must contain a dot if (url.getHost().indexOf('.') < 0) {return null;} } @@ -118,6 +133,17 @@ public abstract class MapSource int idx = url.indexOf("://"); if (idx >= 0) {url = url.substring(idx + 3);} if (url.startsWith("www.")) {url = url.substring(4);} + // Strip out any "[.*]" as well + if (url.indexOf('[') >= 0) + { + Matcher matcher = WILD_PATTERN.matcher(url); + if (matcher.matches()) { + url = matcher.group(1) + matcher.group(3); + if (url.length() > 1 && url.charAt(0) == '.') { + url = url.substring(1); + } + } + } return url; }