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

Last change on this file since 4153 was 3974, checked in by bastiK, 13 years ago

see #6088 - ImageryInfo.url is null (added additional check)

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