source: josm/trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java@ 3961

Last change on this file since 3961 was 3934, checked in by framm, 13 years ago

Changed the way in which JOSM handles imagery layer blacklisting. Instead
of a hard-coded list of Google URLs, we now parse the server's
/api/capabilities response which is expected to look like this:

<osm version="0.6" generator="OpenStreetMap server">

<api>

<version minimum="0.6" maximum="0.6"/>
<area maximum="0.25"/>
<tracepoints per_page="5000"/>
<waynodes maximum="2000"/>
<changesets maximum_elements="50000"/>
<timeout seconds="300"/>

</api>
<policy>

<imagery>

<blacklist regex=".*\.google\.com/.*"/>
<blacklist regex=".*209\.85\.2\d\d.*"/>
<blacklist regex=".*209\.85\.1[3-9]\d.*"/>
<blacklist regex=".*209\.85\.12[89].*"/>

</imagery>

</policy>

</osm>

JOSM will now try to establish an API connection when started, so that
it knows about blacklisted layers. It will also re-read the list when
the URL is changed in the preferences, and if any prohibited layers are
active they will be removed.

For an interim period, JOSM still uses the four regular expressions
listed above whenever the server API URL is *.openstreetmap.org and
the API does not send any blacklist entries. It is expected that the
API will soon return proper blacklist entries.

Things that could be improved:

  1. Establish a general listener system where components can register

their interest in a change of the configured OSM server. Currently
we have to plug through to the gui layer (Main.main.mapView) from
the base comms layer (OsmApi) which is ugly.

  1. Establish a new class of blacklist which works by IP number and not

just regular expression, so that you can say "any host name that resolves
to this IP is blacklisted".

  1. Track all layers that were used in editing a data set, and refuse

uploading if the upload URL bans any of these layers.

  • Property svn:eol-style set to native
File size: 6.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.imagery;
3
4import java.util.ArrayList;
5import java.util.Collection;
6
7import org.openstreetmap.josm.io.OsmApi;
8
9/**
10 * Class that stores info about an image background layer.
11 *
12 * @author Frederik Ramm <frederik@remote.org>
13 */
14public class ImageryInfo implements Comparable<ImageryInfo> {
15
16 public enum ImageryType {
17 WMS("wms"),
18 TMS("tms"),
19 HTML("html"),
20 BING("bing"),
21 SCANEX("scanex");
22
23 private String urlString;
24 ImageryType(String urlString) {
25 this.urlString = urlString;
26 }
27 public String getUrlString() {
28 return urlString;
29 }
30 }
31
32 String name;
33 String url = null;
34 String cookies = null;
35 public final String eulaAcceptanceRequired;
36 ImageryType imageryType = ImageryType.WMS;
37 double pixelPerDegree = 0.0;
38 int maxZoom = 0;
39
40 public ImageryInfo(String name) {
41 this.name=name;
42 this.eulaAcceptanceRequired = null;
43 }
44
45 public ImageryInfo(String name, String url) {
46 this.name=name;
47 setUrl(url);
48 this.eulaAcceptanceRequired = null;
49 }
50
51 public ImageryInfo(String name, String url, String eulaAcceptanceRequired) {
52 this.name=name;
53 setUrl(url);
54 this.eulaAcceptanceRequired = eulaAcceptanceRequired;
55 }
56
57 public ImageryInfo(String name, String url, String eulaAcceptanceRequired, String cookies) {
58 this.name=name;
59 setUrl(url);
60 this.cookies=cookies;
61 this.eulaAcceptanceRequired = eulaAcceptanceRequired;
62 }
63
64 public ImageryInfo(String name, String url, String cookies, double pixelPerDegree) {
65 this.name=name;
66 setUrl(url);
67 this.cookies=cookies;
68 this.pixelPerDegree=pixelPerDegree;
69 this.eulaAcceptanceRequired = null;
70 }
71
72 public ArrayList<String> getInfoArray() {
73 String e2 = null;
74 String e3 = null;
75 String e4 = null;
76 if(url != null && !url.isEmpty()) {
77 e2 = getFullUrl();
78 }
79 if(cookies != null && !cookies.isEmpty()) {
80 e3 = cookies;
81 }
82 if(imageryType == ImageryType.WMS || imageryType == ImageryType.HTML) {
83 if(pixelPerDegree != 0.0) {
84 e4 = String.valueOf(pixelPerDegree);
85 }
86 } else {
87 if(maxZoom != 0) {
88 e4 = String.valueOf(maxZoom);
89 }
90 }
91 if(e4 != null && e3 == null) {
92 e3 = "";
93 }
94 if(e3 != null && e2 == null) {
95 e2 = "";
96 }
97
98 ArrayList<String> res = new ArrayList<String>();
99 res.add(name);
100 if(e2 != null) {
101 res.add(e2);
102 }
103 if(e3 != null) {
104 res.add(e3);
105 }
106 if(e4 != null) {
107 res.add(e4);
108 }
109 return res;
110 }
111
112 public ImageryInfo(Collection<String> list) {
113 ArrayList<String> array = new ArrayList<String>(list);
114 this.name=array.get(0);
115 if(array.size() >= 2) {
116 setUrl(array.get(1));
117 }
118 if(array.size() >= 3) {
119 this.cookies=array.get(2);
120 }
121 if(array.size() >= 4) {
122 if (imageryType == ImageryType.WMS || imageryType == ImageryType.HTML) {
123 this.pixelPerDegree=Double.valueOf(array.get(3));
124 } else {
125 this.maxZoom=Integer.valueOf(array.get(3));
126 }
127 }
128 this.eulaAcceptanceRequired = null;
129 }
130
131 public ImageryInfo(ImageryInfo i) {
132 this.name=i.name;
133 this.url=i.url;
134 this.cookies=i.cookies;
135 this.imageryType=i.imageryType;
136 this.pixelPerDegree=i.pixelPerDegree;
137 this.eulaAcceptanceRequired = null;
138 }
139
140 @Override
141 public int compareTo(ImageryInfo in)
142 {
143 int i = name.compareTo(in.name);
144 if(i == 0) {
145 i = url.compareTo(in.url);
146 }
147 if(i == 0) {
148 i = Double.compare(pixelPerDegree, in.pixelPerDegree);
149 }
150 return i;
151 }
152
153 public boolean equalsBaseValues(ImageryInfo in)
154 {
155 return url.equals(in.url);
156 }
157
158 public void setPixelPerDegree(double ppd) {
159 this.pixelPerDegree = ppd;
160 }
161
162 public void setMaxZoom(int maxZoom) {
163 this.maxZoom = maxZoom;
164 }
165
166 public void setUrl(String url) {
167
168 for (ImageryType type : ImageryType.values()) {
169 if (url.startsWith(type.getUrlString() + ":")) {
170 this.url = url.substring(type.getUrlString().length() + 1);
171 this.imageryType = type;
172 return;
173 }
174 }
175
176 // Default imagery type is WMS
177 this.url = url;
178 this.imageryType = ImageryType.WMS;
179 }
180
181 public String getName() {
182 return this.name;
183 }
184
185 public void setName(String name) {
186 this.name = name;
187 }
188
189 public String getUrl() {
190 return this.url;
191 }
192
193 public String getCookies() {
194 return this.cookies;
195 }
196
197 public double getPixelPerDegree() {
198 return this.pixelPerDegree;
199 }
200
201 public int getMaxZoom() {
202 return this.maxZoom;
203 }
204
205 public String getFullUrl() {
206 return imageryType.getUrlString() + ":" + url;
207 }
208
209 public String getToolbarName()
210 {
211 String res = name;
212 if(pixelPerDegree != 0.0) {
213 res += "#PPD="+pixelPerDegree;
214 }
215 return res;
216 }
217
218 public String getMenuName()
219 {
220 String res = name;
221 if(pixelPerDegree != 0.0) {
222 res += " ("+pixelPerDegree+")";
223 } else if(maxZoom != 0) {
224 res += " (z"+maxZoom+")";
225 }
226 return res;
227 }
228
229 public ImageryType getImageryType() {
230 return imageryType;
231 }
232
233 public static boolean isUrlWithPatterns(String url) {
234 return url != null && url.contains("{") && url.contains("}");
235 }
236
237 /**
238 * Returns true if this layer's URL is matched by one of the regular
239 * expressions kept by the current OsmApi instance.
240 */
241 public boolean isBlacklisted() {
242 return OsmApi.getOsmApi().getCapabilities().isOnImageryBlacklist(this.url);
243 }
244}
Note: See TracBrowser for help on using the repository browser.