source: osm/applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreInterface.java@ 31646

Last change on this file since 31646 was 30859, checked in by donvip, 11 years ago

[josm_cadastre-fr] replace calls to System.out/err by calls to Main.info/warn/error

  • Property svn:eol-style set to native
File size: 25.9 KB
Line 
1// License: GPL. v2 and later. Copyright 2008-2009 by Pieren <pieren3@gmail.com> and others
2package cadastre_fr;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.GridBagLayout;
7import java.io.BufferedReader;
8import java.io.IOException;
9import java.io.InputStreamReader;
10import java.io.OutputStream;
11import java.net.HttpURLConnection;
12import java.net.MalformedURLException;
13import java.net.URL;
14import java.util.Date;
15import java.util.Vector;
16
17import javax.swing.JComboBox;
18import javax.swing.JDialog;
19import javax.swing.JOptionPane;
20import javax.swing.JPanel;
21
22import org.openstreetmap.josm.Main;
23import org.openstreetmap.josm.data.coor.EastNorth;
24import org.openstreetmap.josm.gui.layer.Layer;
25import org.openstreetmap.josm.tools.GBC;
26
27public class CadastreInterface {
28 public boolean downloadCanceled = false;
29 public HttpURLConnection urlConn = null;
30
31 private String cookie;
32 private String interfaceRef = null;
33 private String lastWMSLayerName = null;
34 private URL searchFormURL;
35 private Vector<String> listOfCommunes = new Vector<>();
36 private Vector<String> listOfTA = new Vector<>();
37 class PlanImage {
38 String name;
39 String ref;
40 PlanImage(String name, String ref) {
41 this.name = name;
42 this.ref = ref;
43 }
44 }
45 private Vector<PlanImage> listOfFeuilles = new Vector<>();
46 private long cookieTimestamp;
47
48 final String baseURL = "http://www.cadastre.gouv.fr";
49 final String cImageFormat = "Cette commune est au format ";
50 final String cCommuneListStart = "<select name=\"codeCommune\"";
51 final String cCommuneListEnd = "</select>";
52 final String c0ptionListStart = "<option value=\"";
53 final String cOptionListEnd = "</option>";
54 final String cBBoxCommunStart = "new GeoBox(";
55 final String cBBoxCommunEnd = ")";
56
57 final String cInterfaceVector = "afficherCarteCommune.do";
58 final String cInterfaceRasterTA = "afficherCarteTa.do";
59 final String cInterfaceRasterFeuille = "afficherCarteFeuille.do";
60 final String cImageLinkStart = "<a href=\"#\" class=\"raster\" onClick=\"popup('afficherCarteFeuille.do?f=";
61 final String cTAImageLinkStart = "<a href=\"#\" class=\"raster\" onClick=\"popup('afficherCarteTa.do?f=";
62 final String cImageNameStart = ">Feuille ";
63 final String cTAImageNameStart = "Tableau d'assemblage <strong>";
64
65 final static long cCookieExpiration = 30 * 60 * 1000; // 30 minutes expressed in milliseconds
66
67 final int cRetriesGetCookie = 10; // 10 times every 3 seconds means 30 seconds trying to get a cookie
68
69 public boolean retrieveInterface(WMSLayer wmsLayer) throws DuplicateLayerException, WMSException {
70 if (wmsLayer.getName().equals(""))
71 return false;
72 boolean isCookieExpired = isCookieExpired();
73 if (wmsLayer.getName().equals(lastWMSLayerName) && !isCookieExpired)
74 return true;
75 if (!wmsLayer.getName().equals(lastWMSLayerName))
76 interfaceRef = null;
77 // open the session with the French Cadastre web front end
78 downloadCanceled = false;
79 try {
80 if (cookie == null || isCookieExpired) {
81 getCookie();
82 interfaceRef = null;
83 }
84 if (cookie == null)
85 throw new WMSException(tr("Cannot open a new client session.\nServer in maintenance or temporary overloaded."));
86 if (interfaceRef == null) {
87 getInterface(wmsLayer);
88 this.lastWMSLayerName = wmsLayer.getName();
89 }
90 openInterface();
91 } catch (IOException e) {
92 JOptionPane.showMessageDialog(Main.parent,
93 tr("Town/city {0} not found or not available\n" +
94 "or action canceled", wmsLayer.getLocation()));
95 return false;
96 }
97 return true;
98 }
99
100 /**
101 *
102 * @return true if a cookie is delivered by WMS and false is WMS is not opening a client session
103 * (too many clients or in maintenance)
104 * @throws IOException
105 */
106 private void getCookie() throws IOException {
107 boolean cookied = false;
108 int retries = cRetriesGetCookie;
109 try {
110 searchFormURL = new URL(baseURL + "/scpc/accueil.do");
111 while (cookied == false && retries > 0) {
112 urlConn = (HttpURLConnection)searchFormURL.openConnection();
113 urlConn.setRequestProperty("Connection", "close");
114 urlConn.setRequestMethod("GET");
115 urlConn.connect();
116 if (urlConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
117 Main.info("GET "+searchFormURL);
118 BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
119 while(in.readLine() != null) {} // read the buffer otherwise we sent POST too early
120 String headerName=null;
121 for (int i=1; (headerName = urlConn.getHeaderFieldKey(i))!=null; i++) {
122 if (headerName.equals("Set-Cookie")) {
123 cookie = urlConn.getHeaderField(i);
124 cookie = cookie.substring(0, cookie.indexOf(";"));
125 cookieTimestamp = new Date().getTime();
126 Main.info("received cookie=" + cookie + " at " + new Date(cookieTimestamp));
127 cookied = true;
128 }
129 }
130 } else {
131 Main.warn("Request to home page failed. Http error:"+urlConn.getResponseCode()+". Try again "+retries+" times");
132 CadastrePlugin.safeSleep(3000);
133 retries --;
134 }
135 }
136 } catch (MalformedURLException e) {
137 throw new IOException("Illegal url.", e);
138 }
139 }
140
141 public void resetCookie() {
142 lastWMSLayerName = null;
143 cookie = null;
144 }
145
146 public boolean isCookieExpired() {
147 long now = new Date().getTime();
148 if ((now - cookieTimestamp) > cCookieExpiration) {
149 Main.info("cookie received at "+new Date(cookieTimestamp)+" expired (now is "+new Date(now)+")");
150 return true;
151 }
152 return false;
153 }
154
155 public void resetInterfaceRefIfNewLayer(String newWMSLayerName) {
156 if (!newWMSLayerName.equals(lastWMSLayerName)) {
157 interfaceRef = null;
158 cookie = null; // new since WMS server requires that we come back to the main form
159 }
160 }
161
162 public void setCookie() {
163 this.urlConn.setRequestProperty("Cookie", this.cookie);
164 }
165
166 public void setCookie(HttpURLConnection urlConn) {
167 urlConn.setRequestProperty("Cookie", this.cookie);
168 }
169
170 private void getInterface(WMSLayer wmsLayer) throws IOException, DuplicateLayerException {
171 // first attempt : search for given name without codeCommune
172 interfaceRef = postForm(wmsLayer, "");
173 // second attempt either from known codeCommune (e.g. from cache) or from ComboBox
174 if (interfaceRef == null) {
175 if (!wmsLayer.getCodeCommune().equals("")) {
176 // codeCommune is already known (from previous request or from cache on disk)
177 interfaceRef = postForm(wmsLayer, wmsLayer.getCodeCommune());
178 } else {
179 if (listOfCommunes.size() > 1) {
180 // commune unknown, prompt the list of communes from
181 // server and try with codeCommune
182 String selected = selectMunicipalityDialog(wmsLayer);
183 if (selected != null) {
184 String newCodeCommune = selected.substring(1, selected.indexOf(">")-2);
185 String newLocation = selected.substring(selected.indexOf(">")+1, selected.lastIndexOf(" - "));
186 wmsLayer.setCodeCommune(newCodeCommune);
187 wmsLayer.setLocation(newLocation);
188 Main.pref.put("cadastrewms.codeCommune", newCodeCommune);
189 Main.pref.put("cadastrewms.location", newLocation);
190 }
191 checkLayerDuplicates(wmsLayer);
192 interfaceRef = postForm(wmsLayer, wmsLayer.getCodeCommune());
193 }
194 if (listOfCommunes.size() == 1 && wmsLayer.isRaster()) {
195 // commune known but raster format. Select "Feuille" (non-georeferenced image) from list.
196 int res = selectFeuilleDialog();
197 if (res != -1) {
198 wmsLayer.setCodeCommune(listOfFeuilles.elementAt(res).name);
199 checkLayerDuplicates(wmsLayer);
200 interfaceRef = buildRasterFeuilleInterfaceRef(wmsLayer.getCodeCommune());
201 }
202 }
203 }
204 }
205
206 if (interfaceRef == null)
207 throw new IOException("Town/city " + wmsLayer.getLocation() + " not found.");
208 }
209
210 private void openInterface() throws IOException {
211 try {
212 // finally, open the interface on server side giving access to the wms server
213 String lines = null;
214 String ln = null;
215 URL interfaceURL = new URL(baseURL + "/scpc/"+interfaceRef);
216 urlConn = (HttpURLConnection)interfaceURL.openConnection();
217 urlConn.setRequestMethod("GET");
218 setCookie();
219 urlConn.connect();
220 if (urlConn.getResponseCode() != HttpURLConnection.HTTP_OK) {
221 throw new IOException("Cannot open Cadastre interface. GET response:"+urlConn.getResponseCode());
222 }
223 Main.info("GET "+interfaceURL);
224 BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
225 // read the buffer otherwise we sent POST too early
226 while ((ln = in.readLine()) != null) {
227 lines += ln;
228 }
229 if (Main.isDebugEnabled()) {
230 Main.debug(lines);
231 }
232 } catch (MalformedURLException e) {
233 throw (IOException) new IOException(
234 "CadastreGrabber: Illegal url.").initCause(e);
235 }
236 }
237
238 /**
239 * Post the form with the commune name and check the returned answer which is embedded
240 * in HTTP XML packets. This function doesn't use an XML parser yet but that would be a good idea
241 * for the next releases.
242 * Two possibilities :
243 * - either the commune name matches and we receive an URL starting with "afficherCarteCommune.do" or
244 * - we don't receive a single answer but a list of possible values. This answer looks like:
245 * <select name="codeCommune" class="long erreur" id="codeCommune">
246 * <option value="">Choisir</option>
247 * <option value="50061" >COLMARS - 04370</option>
248 * <option value="QK066" >COLMAR - 68000</option>
249 * </select>
250 * The returned string is the interface name used in further requests, e.g. "afficherCarteCommune.do?c=QP224"
251 * where QP224 is the code commune known by the WMS (or "afficherCarteTa.do?c=..." for raster images).
252 *
253 * @param location
254 * @param codeCommune
255 * @return retURL url to available code commune in the cadastre; "" if not found
256 * @throws IOException
257 */
258 private String postForm(WMSLayer wmsLayer, String codeCommune) throws IOException {
259 try {
260 String ln = null;
261 String lines = null;
262 listOfCommunes.clear();
263 listOfTA.clear();
264 // send a POST request with a city/town/village name
265 String content = "numerovoie=";
266 content += "&indiceRepetition=";
267 content += "&nomvoie=";
268 content += "&lieuDit=";
269 if (codeCommune == "") {
270 content += "&ville=" + new String(java.net.URLEncoder.encode(wmsLayer.getLocation(), "UTF-8"));
271 content += "&codePostal=";
272 } else {
273 content += "&codeCommune=" + codeCommune;
274 }
275 content += "&codeDepartement=";
276 content += wmsLayer.getDepartement();
277 content += "&nbResultatParPage=10";
278 content += "&x=0&y=0";
279 searchFormURL = new URL(baseURL + "/scpc/rechercherPlan.do");
280 urlConn = (HttpURLConnection)searchFormURL.openConnection();
281 urlConn.setRequestMethod("POST");
282 urlConn.setDoOutput(true);
283 urlConn.setDoInput(true);
284 setCookie();
285 try (OutputStream wr = urlConn.getOutputStream()) {
286 wr.write(content.getBytes());
287 Main.info("POST "+content);
288 wr.flush();
289 }
290 try (BufferedReader rd = new BufferedReader(new InputStreamReader(urlConn.getInputStream()))) {
291 while ((ln = rd.readLine()) != null) {
292 lines += ln;
293 }
294 }
295 urlConn.disconnect();
296 if (lines != null) {
297 if (lines.indexOf(cImageFormat) != -1) {
298 int i = lines.indexOf(cImageFormat);
299 int j = lines.indexOf(".", i);
300 wmsLayer.setRaster(lines.substring(i+cImageFormat.length(), j).equals("image"));
301 }
302 if (!wmsLayer.isRaster() && lines.indexOf(cInterfaceVector) != -1) { // "afficherCarteCommune.do"
303 // shall be something like: interfaceRef = "afficherCarteCommune.do?c=X2269";
304 lines = lines.substring(lines.indexOf(cInterfaceVector),lines.length());
305 lines = lines.substring(0, lines.indexOf("'"));
306 Main.info("interface ref.:"+lines);
307 return lines;
308 } else if (wmsLayer.isRaster() && lines.indexOf(cInterfaceRasterTA) != -1) { // "afficherCarteTa.do"
309 // list of values parsed in listOfFeuilles (list all non-georeferenced images)
310 lines = getFeuillesList();
311 if (!downloadCanceled) {
312 parseFeuillesList(lines);
313 if (listOfFeuilles.size() > 0) {
314 int res = selectFeuilleDialog();
315 if (res != -1) {
316 wmsLayer.setCodeCommune(listOfFeuilles.elementAt(res).name);
317 checkLayerDuplicates(wmsLayer);
318 interfaceRef = buildRasterFeuilleInterfaceRef(wmsLayer.getCodeCommune());
319 wmsLayer.setCodeCommune(listOfFeuilles.elementAt(res).ref);
320 lines = buildRasterFeuilleInterfaceRef(listOfFeuilles.elementAt(res).ref);
321 Main.info("interface ref.:"+lines);
322 return lines;
323 }
324 }
325 }
326 return null;
327 } else if (lines.indexOf(cCommuneListStart) != -1 && lines.indexOf(cCommuneListEnd) != -1) {
328 // list of values parsed in listOfCommunes
329 int i = lines.indexOf(cCommuneListStart);
330 int j = lines.indexOf(cCommuneListEnd, i);
331 parseCommuneList(lines.substring(i, j));
332 }
333 }
334 } catch (MalformedURLException e) {
335 throw (IOException) new IOException(
336 "Illegal url.").initCause(e);
337 } catch (Exception e){
338 e.printStackTrace();
339 }
340 return null;
341 }
342
343 private void parseCommuneList(String input) {
344 if (input.indexOf(c0ptionListStart) != -1) {
345 while (input.indexOf("<option value=\"") != -1) {
346 int i = input.indexOf(c0ptionListStart);
347 int j = input.indexOf(cOptionListEnd, i+c0ptionListStart.length());
348 int k = input.indexOf("\"", i+c0ptionListStart.length());
349 if (j != -1 && k > (i + c0ptionListStart.length())) {
350 String lov = new String(input.substring(i+c0ptionListStart.length()-1, j));
351 if (lov.indexOf(">") != -1) {
352 Main.info("parse "+lov);
353 listOfCommunes.add(lov);
354 } else
355 Main.error("unable to parse commune string:"+lov);
356 }
357 input = input.substring(j+cOptionListEnd.length());
358 }
359 }
360 }
361
362 private String getFeuillesList() {
363 // get all images in one html page
364 String ln = null;
365 String lines = null;
366 HttpURLConnection urlConn2 = null;
367 try {
368 URL getAllImagesURL = new URL(baseURL + "/scpc/listerFeuillesParcommune.do?keepVolatileSession=&offset=2000");
369 urlConn2 = (HttpURLConnection)getAllImagesURL.openConnection();
370 setCookie(urlConn2);
371 urlConn2.connect();
372 Main.info("GET "+getAllImagesURL);
373 try (BufferedReader rd = new BufferedReader(new InputStreamReader(urlConn2.getInputStream()))) {
374 while ((ln = rd.readLine()) != null) {
375 lines += ln;
376 }
377 }
378 urlConn2.disconnect();
379 } catch (IOException e) {
380 listOfFeuilles.clear();
381 Main.error(e);
382 }
383 return lines;
384 }
385
386 private void parseFeuillesList(String input) {
387 listOfFeuilles.clear();
388 // get "Tableau d'assemblage"
389 String inputTA = input;
390 if (Main.pref.getBoolean("cadastrewms.useTA", false)) {
391 while (inputTA.indexOf(cTAImageLinkStart) != -1) {
392 inputTA = inputTA.substring(inputTA.indexOf(cTAImageLinkStart) + cTAImageLinkStart.length());
393 String refTA = inputTA.substring(0, inputTA.indexOf("'"));
394 String nameTA = inputTA.substring(inputTA.indexOf(cTAImageNameStart) + cTAImageNameStart.length());
395 nameTA = nameTA.substring(0, nameTA.indexOf("<"));
396 listOfFeuilles.add(new PlanImage(nameTA, refTA));
397 }
398 }
399 // get "Feuilles"
400 while (input.indexOf(cImageLinkStart) != -1) {
401 input = input.substring(input.indexOf(cImageLinkStart)+cImageLinkStart.length());
402 String refFeuille = input.substring(0, input.indexOf("'"));
403 String nameFeuille = input.substring(
404 input.indexOf(cImageNameStart)+cImageNameStart.length(),
405 input.indexOf(" -"));
406 listOfFeuilles.add(new PlanImage(nameFeuille, refFeuille));
407 }
408 }
409
410 private String selectMunicipalityDialog(WMSLayer wmsLayer) {
411 JPanel p = new JPanel(new GridBagLayout());
412 String[] communeList = new String[listOfCommunes.size() + 1];
413 communeList[0] = tr("Choose from...");
414 for (int i = 0; i < listOfCommunes.size(); i++) {
415 communeList[i + 1] = listOfCommunes.elementAt(i).substring(listOfCommunes.elementAt(i).indexOf(">")+1);
416 }
417 JComboBox<String> inputCommuneList = new JComboBox<>(communeList);
418 p.add(inputCommuneList, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 0, 0, 0));
419 JOptionPane pane = new JOptionPane(p, JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null) {
420 private static final long serialVersionUID = 1L;
421 };
422 //pane.createDialog(Main.parent, tr("Select commune")).setVisible(true);
423 // this below is a temporary workaround to fix the "always on top" issue
424 JDialog dialog = pane.createDialog(Main.parent, tr("Select commune"));
425 CadastrePlugin.prepareDialog(dialog);
426 dialog.setVisible(true);
427 // till here
428 if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue()))
429 return null;
430 return listOfCommunes.elementAt(inputCommuneList.getSelectedIndex()-1);
431 }
432
433 private int selectFeuilleDialog() {
434 JPanel p = new JPanel(new GridBagLayout());
435 Vector<String> imageNames = new Vector<>();
436 for (PlanImage src : listOfFeuilles) {
437 imageNames.add(src.name);
438 }
439 JComboBox<String> inputFeuilleList = new JComboBox<>(imageNames);
440 p.add(inputFeuilleList, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 0, 0, 0));
441 JOptionPane pane = new JOptionPane(p, JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null);
442 //pane.createDialog(Main.parent, tr("Select Feuille")).setVisible(true);
443 // this below is a temporary workaround to fix the "always on top" issue
444 JDialog dialog = pane.createDialog(Main.parent, tr("Select Feuille"));
445 CadastrePlugin.prepareDialog(dialog);
446 dialog.setVisible(true);
447 // till here
448 if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue()))
449 return -1;
450 int result = inputFeuilleList.getSelectedIndex();
451 return result;
452 }
453
454 private String buildRasterFeuilleInterfaceRef(String codeCommune) {
455 return cInterfaceRasterFeuille + "?f=" + codeCommune;
456 }
457
458 /**
459 * Retrieve the bounding box size in pixels of the whole commune (point 0,0 at top, left corner)
460 * and store it in given wmsLayer
461 * In case of raster image, we also check in the same http request if the image is already georeferenced
462 * and store the result in the wmsLayer as well.
463 * @param wmsLayer the WMSLayer where the commune data and images are stored
464 * @throws IOException
465 */
466 public void retrieveCommuneBBox(WMSLayer wmsLayer) throws IOException {
467 if (interfaceRef == null)
468 return;
469 String ln = null;
470 String line = null;
471 // send GET opening normally the small window with the commune overview
472 String content = baseURL + "/scpc/" + interfaceRef;
473 content += "&dontSaveLastForward&keepVolatileSession=";
474 searchFormURL = new URL(content);
475 urlConn = (HttpURLConnection)searchFormURL.openConnection();
476 urlConn.setRequestMethod("GET");
477 setCookie();
478 urlConn.connect();
479 if (urlConn.getResponseCode() != HttpURLConnection.HTTP_OK) {
480 throw new IOException("Cannot get Cadastre response.");
481 }
482 Main.info("GET "+searchFormURL);
483 try (BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream()))) {
484 while ((ln = in.readLine()) != null) {
485 line += ln;
486 }
487 }
488 urlConn.disconnect();
489 parseBBoxCommune(wmsLayer, line);
490 if (wmsLayer.isRaster() && !wmsLayer.isAlreadyGeoreferenced()) {
491 parseGeoreferences(wmsLayer, line);
492 }
493 }
494
495 private void parseBBoxCommune(WMSLayer wmsLayer, String input) {
496 if (input.indexOf(cBBoxCommunStart) != -1) {
497 input = input.substring(input.indexOf(cBBoxCommunStart));
498 int i = input.indexOf(",");
499 double minx = Double.parseDouble(input.substring(cBBoxCommunStart.length(), i));
500 int j = input.indexOf(",", i+1);
501 double miny = Double.parseDouble(input.substring(i+1, j));
502 int k = input.indexOf(",", j+1);
503 double maxx = Double.parseDouble(input.substring(j+1, k));
504 int l = input.indexOf(cBBoxCommunEnd, k+1);
505 double maxy = Double.parseDouble(input.substring(k+1, l));
506 wmsLayer.setCommuneBBox( new EastNorthBound(new EastNorth(minx,miny), new EastNorth(maxx,maxy)));
507 }
508 }
509
510 private void parseGeoreferences(WMSLayer wmsLayer, String input) {
511 /* commented since cadastre WMS changes mid july 2013
512 * until new GeoBox coordinates parsing is solved */
513// if (input.lastIndexOf(cBBoxCommunStart) != -1) {
514// input = input.substring(input.lastIndexOf(cBBoxCommunStart));
515// input = input.substring(input.indexOf(cBBoxCommunEnd)+cBBoxCommunEnd.length());
516// int i = input.indexOf(",");
517// int j = input.indexOf(",", i+1);
518// String str = input.substring(i+1, j);
519// double unknown_yet = tryParseDouble(str);
520// int j_ = input.indexOf(",", j+1);
521// double angle = Double.parseDouble(input.substring(j+1, j_));
522// int k = input.indexOf(",", j_+1);
523// double scale_origin = Double.parseDouble(input.substring(j_+1, k));
524// int l = input.indexOf(",", k+1);
525// double dpi = Double.parseDouble(input.substring(k+1, l));
526// int m = input.indexOf(",", l+1);
527// double fX = Double.parseDouble(input.substring(l+1, m));
528// int n = input.indexOf(",", m+1);
529// double fY = Double.parseDouble(input.substring(m+1, n));
530// int o = input.indexOf(",", n+1);
531// double X0 = Double.parseDouble(input.substring(n+1, o));
532// int p = input.indexOf(",", o+1);
533// double Y0 = Double.parseDouble(input.substring(o+1, p));
534// if (X0 != 0.0 && Y0 != 0) {
535// wmsLayer.setAlreadyGeoreferenced(true);
536// wmsLayer.fX = fX;
537// wmsLayer.fY = fY;
538// wmsLayer.angle = angle;
539// wmsLayer.X0 = X0;
540// wmsLayer.Y0 = Y0;
541// }
542// Main.info("parse georef:"+unknown_yet+","+angle+","+scale_origin+","+dpi+","+fX+","+
543// fY+","+X0+","+Y0);
544// }
545 }
546
547 private void checkLayerDuplicates(WMSLayer wmsLayer) throws DuplicateLayerException {
548 if (Main.map != null) {
549 for (Layer l : Main.map.mapView.getAllLayers()) {
550 if (l instanceof WMSLayer && l.getName().equals(wmsLayer.getName()) && (l != wmsLayer)) {
551 Main.info("Try to grab into a new layer when "+wmsLayer.getName()+" is already opened.");
552 // remove the duplicated layer
553 Main.main.removeLayer(wmsLayer);
554 throw new DuplicateLayerException();
555 }
556 }
557 }
558 }
559
560 public void cancel() {
561 if (urlConn != null) {
562 urlConn.setConnectTimeout(1);
563 urlConn.setReadTimeout(1);
564 //urlConn.disconnect();
565 }
566 downloadCanceled = true;
567 lastWMSLayerName = null;
568 }
569
570}
Note: See TracBrowser for help on using the repository browser.