- Timestamp:
- 2011-07-14T12:48:27+02:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 8 edited
-
data/imagery/ImageryInfo.java (modified) (14 diffs)
-
data/imagery/ImageryLayerInfo.java (modified) (4 diffs)
-
gui/layer/WMSLayer.java (modified) (8 diffs)
-
gui/preferences/AddWMSLayerPanel.java (modified) (2 diffs)
-
gui/preferences/ImageryPreference.java (modified) (3 diffs)
-
io/MirroredInputStream.java (modified) (3 diffs)
-
io/imagery/ImageryReader.java (added)
-
io/imagery/OsmosnimkiOffsetServer.java (modified) (2 diffs)
-
io/imagery/WMSGrabber.java (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java ¶
r4198 r4240 4 4 import java.util.ArrayList; 5 5 import java.util.Collection; 6 import java.util.Collections; 7 import java.util.List; 6 8 import java.util.regex.Matcher; 7 9 import java.util.regex.Pattern; … … 42 44 private String name; 43 45 private String url = null; 46 private boolean defaultEntry = false; 44 47 private String cookies = null; 45 48 private String eulaAcceptanceRequired= null; … … 50 53 private int defaultMinZoom = 0; 51 54 private Bounds bounds = null; 55 private List<String> serverProjections; 52 56 private String attributionText; 53 57 private String attributionImage; … … 55 59 private String termsOfUseURL; 56 60 61 public ImageryInfo() { 62 } 63 57 64 public ImageryInfo(String name) { 58 65 this.name=name; … … 61 68 public ImageryInfo(String name, String url) { 62 69 this.name=name; 63 setUrl(url); 70 setExtendedUrl(url); 64 71 } 65 72 66 73 public ImageryInfo(String name, String url, String eulaAcceptanceRequired) { 67 74 this.name=name; 68 setUrl(url); 75 setExtendedUrl(url); 69 76 this.eulaAcceptanceRequired = eulaAcceptanceRequired; 70 77 } … … 72 79 public ImageryInfo(String name, String url, String eulaAcceptanceRequired, String cookies) { 73 80 this.name=name; 74 setUrl(url); 81 setExtendedUrl(url); 75 82 this.cookies=cookies; 76 83 this.eulaAcceptanceRequired = eulaAcceptanceRequired; … … 79 86 public ImageryInfo(String name, String url, String cookies, double pixelPerDegree) { 80 87 this.name=name; 81 setUrl(url); 88 setExtendedUrl(url); 82 89 this.cookies=cookies; 83 90 this.pixelPerDegree=pixelPerDegree; … … 87 94 ArrayList<String> res = new ArrayList<String>(); 88 95 res.add(name); 89 res.add((url != null && !url.isEmpty()) ? get FullUrl() : null);96 res.add((url != null && !url.isEmpty()) ? getExtendedUrl() : null); 90 97 res.add(cookies); 91 98 if(imageryType == ImageryType.WMS || imageryType == ImageryType.HTML) { … … 106 113 this.name=array.get(0); 107 114 if(array.size() >= 2 && !array.get(1).isEmpty()) { 108 setUrl(array.get(1)); 115 setExtendedUrl(array.get(1)); 109 116 } 110 117 if(array.size() >= 3 && !array.get(2).isEmpty()) { … … 178 185 } 179 186 187 public void setDefaultMaxZoom(int defaultMaxZoom) { 188 this.defaultMaxZoom = defaultMaxZoom; 189 } 190 191 public void setDefaultMinZoom(int defaultMinZoom) { 192 this.defaultMinZoom = defaultMinZoom; 193 } 194 180 195 public void setMaxZoom(int maxZoom) { 181 196 this.maxZoom = maxZoom; … … 206 221 } 207 222 208 public void setUrl(String url) { 223 public void setExtendedUrl(String url) { 209 224 CheckParameterUtil.ensureParameterNotNull(url); 210 225 … … 244 259 } 245 260 261 public void setUrl(String url) { 262 this.url = url; 263 } 264 265 public boolean isDefaultEntry() { 266 return defaultEntry; 267 } 268 269 public void setDefaultEntry(boolean defaultEntry) { 270 this.defaultEntry = defaultEntry; 271 } 272 246 273 public String getCookies() { 247 274 return this.cookies; … … 264 291 } 265 292 266 public String getFullUrl() { 293 public void setEulaAcceptanceRequired(String eulaAcceptanceRequired) { 294 this.eulaAcceptanceRequired = eulaAcceptanceRequired; 295 } 296 297 /** 298 * Get the projections supported by the server. Only relevant for 299 * WMS-type ImageryInfo at the moment. 300 * @return null, if no projections have been specified; the list 301 * of supported projections otherwise. 302 */ 303 public List<String> getServerProjections() { 304 if (serverProjections == null) return null; 305 return Collections.unmodifiableList(serverProjections); 306 } 307 308 public void setServerProjections(Collection<String> serverProjections) { 309 this.serverProjections = new ArrayList<String>(serverProjections); 310 } 311 312 public String getExtendedUrl() { 267 313 return imageryType.getUrlString() + (defaultMaxZoom != 0 268 314 ? "["+(defaultMinZoom != 0 ? defaultMinZoom+",":"")+defaultMaxZoom+"]" : "") + ":" + url; … … 331 377 public ImageryType getImageryType() { 332 378 return imageryType; 379 } 380 381 public void setImageryType(ImageryType imageryType) { 382 this.imageryType = imageryType; 333 383 } 334 384 -
TabularUnified trunk/src/org/openstreetmap/josm/data/imagery/ImageryLayerInfo.java ¶
r4216 r4240 2 2 package org.openstreetmap.josm.data.imagery; 3 3 4 import static org.openstreetmap.josm.tools.I18n.tr;5 6 import java.io.BufferedReader;7 4 import java.io.IOException; 8 import java.io.InputStreamReader;9 import java.io.UnsupportedEncodingException;10 5 import java.util.ArrayList; 11 6 import java.util.Arrays; … … 16 11 17 12 import org.openstreetmap.josm.Main; 18 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType; 19 import org.openstreetmap.josm.data.Bounds; 13 import org.openstreetmap.josm.io.imagery.ImageryReader; 20 14 import org.openstreetmap.josm.io.MirroredInputStream; 15 import org.openstreetmap.josm.tools.Utils; 16 import org.xml.sax.SAXException; 21 17 22 18 public class ImageryLayerInfo { … … 65 61 public void loadDefaults(boolean clearCache) { 66 62 defaultLayers.clear(); 67 Collection<String> defaults = Main.pref.getCollection( 68 "imagery.layers.default", Collections.<String>emptySet()); 63 for (String source : Main.pref.getCollection("imagery.layers.sites", Arrays.asList(DEFAULT_LAYER_SITES))) { 64 if (clearCache) { 65 MirroredInputStream.cleanup(source); 66 } 67 MirroredInputStream stream = null; 68 try { 69 ImageryReader reader = new ImageryReader(source); 70 Collection<ImageryInfo> result = reader.parse(); 71 defaultLayers.addAll(result); 72 } catch (IOException ex) { 73 Utils.close(stream); 74 ex.printStackTrace(); 75 continue; 76 } catch (SAXException sex) { 77 Utils.close(stream); 78 sex.printStackTrace(); 79 continue; 80 } 81 } 82 while (defaultLayers.remove(null)) {} 83 84 Collection<String> defaults = Main.pref.getCollection("imagery.layers.default"); 69 85 ArrayList<String> defaultsSave = new ArrayList<String>(); 70 for(String source : Main.pref.getCollection("imagery.layers.sites", Arrays.asList(DEFAULT_LAYER_SITES))) 71 { 72 try 73 { 74 if (clearCache) { 75 MirroredInputStream.cleanup(source); 86 for (ImageryInfo def : defaultLayers) { 87 if (def.isDefaultEntry()) { 88 defaultsSave.add(def.getUrl()); 89 90 boolean isKnownDefault = false; 91 for (String url : defaults) { 92 if (isSimilar(url, def.getUrl())) { 93 isKnownDefault = true; 94 break; 95 } 76 96 } 77 MirroredInputStream s = new MirroredInputStream(source, -1); 78 try { 79 InputStreamReader r; 80 try 81 { 82 r = new InputStreamReader(s, "UTF-8"); 83 } 84 catch (UnsupportedEncodingException e) 85 { 86 r = new InputStreamReader(s); 87 } 88 BufferedReader reader = new BufferedReader(r); 89 String line; 90 while((line = reader.readLine()) != null) 91 { 92 String val[] = line.split(";"); 93 if(!line.startsWith("#") && val.length >= 3) { 94 boolean force = "true".equals(val[0]); 95 String name = tr(val[1]); 96 String url = val[2]; 97 String eulaAcceptanceRequired = null; 98 99 if (val.length >= 4 && !val[3].isEmpty()) { 100 // 4th parameter optional for license agreement (EULA) 101 eulaAcceptanceRequired = val[3]; 102 } 103 104 ImageryInfo info = new ImageryInfo(name, url, eulaAcceptanceRequired); 105 106 if (val.length >= 5 && !val[4].isEmpty()) { 107 // 5th parameter optional for bounds 108 try { 109 info.setBounds(new Bounds(val[4], ",")); 110 } catch (IllegalArgumentException e) { 111 Main.warn(e.toString()); 112 } 113 } 114 if (val.length >= 6 && !val[5].isEmpty()) { 115 info.setAttributionText(val[5]); 116 } 117 if (val.length >= 7 && !val[6].isEmpty()) { 118 info.setAttributionLinkURL(val[6]); 119 } 120 if (val.length >= 8 && !val[7].isEmpty()) { 121 info.setTermsOfUseURL(val[7]); 122 } 123 if (val.length >= 9 && !val[8].isEmpty()) { 124 info.setAttributionImage(val[8]); 125 } 126 127 defaultLayers.add(info); 128 129 if (force) { 130 defaultsSave.add(url); 131 if (!defaults.contains(url)) { 132 for (ImageryInfo i : layers) { 133 if ((i.getImageryType() == ImageryType.WMS && url.equals(i.getUrl())) 134 || url.equals(i.getFullUrl())) { 135 force = false; 136 } 137 } 138 if (force) { 139 add(new ImageryInfo(name, url)); 140 } 141 } 142 } 97 boolean isInUserList = false; 98 if (!isKnownDefault) { 99 for (ImageryInfo i : layers) { 100 if (isSimilar(def.getUrl(), i.getUrl())) { 101 isInUserList = true; 102 break; 143 103 } 144 104 } 145 } finally {146 s.close();147 105 } 148 }149 catch (IOException e)150 {106 if (!isKnownDefault && !isInUserList) { 107 add(new ImageryInfo(def)); 108 } 151 109 } 152 110 } … … 155 113 Main.pref.putCollection("imagery.layers.default", defaultsSave.size() > 0 156 114 ? defaultsSave : defaults); 115 } 116 117 // some additional checks to respect extended URLs in preferences (legacy workaround) 118 private boolean isSimilar(String a, String b) { 119 return Utils.equal(a, b) || (a != null && b != null && !"".equals(a) && !"".equals(b) && (a.contains(b) || b.contains(a))); 157 120 } 158 121 -
TabularUnified trunk/src/org/openstreetmap/josm/gui/layer/WMSLayer.java ¶
r4184 r4240 108 108 private int workingThreadCount; 109 109 private boolean canceled; 110 private ArrayList<String> serverProjections = null;110 private List<String> serverProjections = null; 111 111 112 112 /** set to true if this layer uses an invalid base url */ … … 121 121 public WMSLayer(ImageryInfo info) { 122 122 super(info); 123 serverProjections = info.getServerProjections(); 123 124 mv = Main.map.mapView; 124 125 setBackgroundLayer(true); /* set global background variable */ … … 143 144 144 145 if(info.getUrl() != null) { 145 serverProjections = WMSGrabber.getServerProjections(info.getUrl(), true); 146 if (serverProjections == null) { 147 serverProjections = WMSGrabber.getServerProjections(info.getUrl(), true); 148 } 146 149 startGrabberThreads(); 147 150 if(info.getImageryType() == ImageryType.WMS && !ImageryInfo.isUrlWithPatterns(info.getUrl())) { … … 310 313 */ 311 314 public int getBaseImageWidth() { 312 int overlap = (PROP_OVERLAP.get()?PROP_OVERLAP_EAST.get() * imageSize / 100:0);315 int overlap = PROP_OVERLAP.get() ? (PROP_OVERLAP_EAST.get() * imageSize / 100) : 0; 313 316 return imageSize + overlap; 314 317 } … … 319 322 */ 320 323 public int getBaseImageHeight() { 321 int overlap = (PROP_OVERLAP.get()?PROP_OVERLAP_NORTH.get() * imageSize / 100:0);324 int overlap = PROP_OVERLAP.get() ? (PROP_OVERLAP_NORTH.get() * imageSize / 100) : 0; 322 325 return imageSize + overlap; 323 326 } … … 696 699 oos.writeDouble(info.getPixelPerDegree()); 697 700 oos.writeObject(info.getName()); 698 oos.writeObject(info.get FullUrl());701 oos.writeObject(info.getExtendedUrl()); 699 702 oos.writeObject(images); 700 703 oos.close(); … … 735 738 info.setPixelPerDegree(ois.readDouble()); 736 739 doSetName((String)ois.readObject()); 737 info.setUrl((String) ois.readObject()); 740 info.setExtendedUrl((String) ois.readObject()); 738 741 images = (GeorefImage[][])ois.readObject(); 739 742 ois.close(); … … 914 917 } 915 918 919 /** 920 * Get the list of projections supported by the WMS server corresponding to this layer. 921 * @return The list of projections, if known. An empty list otherwise. 922 */ 923 public List<String> getServerProjections() { 924 if (serverProjections == null) 925 return Collections.emptyList(); 926 else 927 return Collections.unmodifiableList(serverProjections); 928 } 929 916 930 @Override 917 931 public boolean isProjectionSupported(Projection proj) { -
TabularUnified trunk/src/org/openstreetmap/josm/gui/preferences/AddWMSLayerPanel.java ¶
r4188 r4240 323 323 String incomingData; 324 324 try { 325 System.out.println("GET "+getCapabilitiesUrl.toString()); 325 326 URLConnection openConnection = getCapabilitiesUrl.openConnection(); 326 327 InputStream inputStream = openConnection.getInputStream(); … … 341 342 Document document; 342 343 try { 344 //System.out.println("WMS capabilities:\n"+incomingData+"\n"); 343 345 DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); 344 346 builderFactory.setValidating(false); -
TabularUnified trunk/src/org/openstreetmap/josm/gui/preferences/ImageryPreference.java ¶
r4216 r4240 593 593 return info.getName(); 594 594 case 1: 595 return info.get FullUrl();595 return info.getExtendedUrl(); 596 596 case 2: 597 597 return (info.getImageryType() == ImageryType.WMS || info.getImageryType() == ImageryType.HTML) ? … … 611 611 break; 612 612 case 1: 613 info.setUrl((String)o); 613 info.setExtendedUrl((String)o); 614 614 break; 615 615 case 2: … … 660 660 return info.getName(); 661 661 case 1: 662 return info.get FullUrl();662 return info.getExtendedUrl(); 663 663 } 664 664 return null; -
TabularUnified trunk/src/org/openstreetmap/josm/io/MirroredInputStream.java ¶
r4172 r4240 29 29 InputStream fs = null; 30 30 File file = null; 31 32 public final static long DEFAULT_MAXTIME = -1l; 31 33 32 34 public MirroredInputStream(String name) throws IOException { 33 this(name, null, -1L);35 this(name, null, DEFAULT_MAXTIME); 34 36 } 35 37 … … 39 41 40 42 public MirroredInputStream(String name, String destDir) throws IOException { 41 this(name, destDir, -1L);43 this(name, destDir, DEFAULT_MAXTIME); 42 44 } 43 45 … … 193 195 file = null; 194 196 else { 195 if (maxTime <= 0) { 197 if ( maxTime == DEFAULT_MAXTIME 198 || maxTime <= 0 // arbitrary value <= 0 is deprecated 199 ) { 196 200 maxTime = Main.pref.getInteger("mirror.maxtime", 7*24*60*60); 197 201 } -
TabularUnified trunk/src/org/openstreetmap/josm/io/imagery/OsmosnimkiOffsetServer.java ¶
r4126 r4240 26 26 public boolean isLayerSupported(ImageryInfo info) { 27 27 try { 28 URL url = new URL(this.url + "action=CheckAvailability&id=" + URLEncoder.encode(info.get FullUrl(), "UTF-8"));28 URL url = new URL(this.url + "action=CheckAvailability&id=" + URLEncoder.encode(info.getUrl(), "UTF-8")); 29 29 System.out.println(tr("Querying offset availability: {0}", url)); 30 30 final BufferedReader rdr = new BufferedReader(new InputStreamReader(url.openConnection().getInputStream(), "UTF-8")); … … 42 42 LatLon ll = Main.getProjection().eastNorth2latlon(en); 43 43 try { 44 URL url = new URL(this.url + "action=GetOffsetForPoint&lat=" + ll.lat() + "&lon=" + ll.lon() + "&id=" + URLEncoder.encode(info.get FullUrl(), "UTF-8"));44 URL url = new URL(this.url + "action=GetOffsetForPoint&lat=" + ll.lat() + "&lon=" + ll.lon() + "&id=" + URLEncoder.encode(info.getUrl(), "UTF-8")); 45 45 System.out.println(tr("Querying offset: {0}", url.toString())); 46 46 final BufferedReader rdr = new BufferedReader(new InputStreamReader(url.openConnection().getInputStream(), "UTF-8")); -
TabularUnified trunk/src/org/openstreetmap/josm/io/imagery/WMSGrabber.java ¶
r4228 r4240 19 19 import java.text.NumberFormat; 20 20 import java.util.ArrayList; 21 import java.util.List; 21 22 import java.util.Map.Entry; 22 23 import java.util.Locale; … … 47 48 protected String baseURL; 48 49 private final boolean urlWithPatterns; 50 private List<String> serverProjections; 49 51 private Map<String, String> props = new HashMap<String, String>(); 50 52 … … 52 54 super(mv, layer); 53 55 this.baseURL = layer.getInfo().getUrl(); 56 this.serverProjections = layer.getServerProjections(); 54 57 /* URL containing placeholders? */ 55 58 urlWithPatterns = ImageryInfo.isUrlWithPatterns(baseURL); … … 139 142 } else { 140 143 str += "bbox=" + bbox 141 + srs 142 + "&width=" + wi + "&height=" + ht; 144 + srs 145 + "&width=" + wi + "&height=" + ht; 143 146 if (!(baseURL.endsWith("&") || baseURL.endsWith("?"))) { 144 147 System.out.println(tr("Warning: The base URL ''{0}'' for a WMS service doesn't have a trailing '&' or a trailing '?'.", baseURL));
Note:
See TracChangeset
for help on using the changeset viewer.
