Changeset 32211 in osm for applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreInterface.java
- Timestamp:
- 2016-06-01T00:55:28+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreInterface.java
r32205 r32211 12 12 import java.net.MalformedURLException; 13 13 import java.net.URL; 14 import java.nio.charset.StandardCharsets; 15 import java.util.ArrayList; 14 16 import java.util.Date; 15 import java.util. Vector;17 import java.util.List; 16 18 17 19 import javax.swing.JComboBox; … … 26 28 27 29 public class CadastreInterface { 28 public boolean downloadCanceled = false;29 public HttpURLConnection urlConn = null;30 public boolean downloadCanceled; 31 public HttpURLConnection urlConn; 30 32 31 33 private String cookie; 32 private String interfaceRef = null;33 private String lastWMSLayerName = null;34 private String interfaceRef; 35 private String lastWMSLayerName; 34 36 private URL searchFormURL; 35 private Vector<String> listOfCommunes = newVector<>();36 private Vector<String> listOfTA = newVector<>();37 class PlanImage { 37 private List<String> listOfCommunes = new ArrayList<>(); 38 private List<String> listOfTA = new ArrayList<>(); 39 static class PlanImage { 38 40 String name; 39 41 String ref; … … 43 45 } 44 46 } 45 private Vector<PlanImage> listOfFeuilles = newVector<>();47 private List<PlanImage> listOfFeuilles = new ArrayList<>(); 46 48 private long cookieTimestamp; 47 49 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 finalstaticlong cCookieExpiration= 30 * 60 * 1000; // 30 minutes expressed in milliseconds66 67 final int cRetriesGetCookie= 10; // 10 times every 3 seconds means 30 seconds trying to get a cookie50 static final String BASE_URL = "http://www.cadastre.gouv.fr"; 51 static final String C_IMAGE_FORMAT = "Cette commune est au format "; 52 static final String C_COMMUNE_LIST_START = "<select name=\"codeCommune\""; 53 static final String C_COMMUNE_LIST_END = "</select>"; 54 static final String C_OPTION_LIST_START = "<option value=\""; 55 static final String C_OPTION_LIST_END = "</option>"; 56 static final String C_BBOX_COMMUN_START = "new GeoBox("; 57 static final String C_BBOX_COMMUN_END = ")"; 58 59 static final String C_INTERFACE_VECTOR = "afficherCarteCommune.do"; 60 static final String C_INTERFACE_RASTER_TA = "afficherCarteTa.do"; 61 static final String C_INTERFACE_RASTER_FEUILLE = "afficherCarteFeuille.do"; 62 static final String C_IMAGE_LINK_START = "<a href=\"#\" class=\"raster\" onClick=\"popup('afficherCarteFeuille.do?f="; 63 static final String C_TA_IMAGE_LINK_START = "<a href=\"#\" class=\"raster\" onClick=\"popup('afficherCarteTa.do?f="; 64 static final String C_IMAGE_NAME_START = ">Feuille "; 65 static final String C_TA_IMAGE_NAME_START = "Tableau d'assemblage <strong>"; 66 67 static final long COOKIE_EXPIRATION = 30 * 60 * 1000L; // 30 minutes expressed in milliseconds 68 69 static final int RETRIES_GET_COOKIE = 10; // 10 times every 3 seconds means 30 seconds trying to get a cookie 68 70 69 71 public boolean retrieveInterface(WMSLayer wmsLayer) throws DuplicateLayerException, WMSException { 70 if (wmsLayer.getName(). equals(""))72 if (wmsLayer.getName().isEmpty()) 71 73 return false; 72 74 boolean isCookieExpired = isCookieExpired(); … … 90 92 openInterface(); 91 93 } catch (IOException e) { 94 Main.error(e); 92 95 JOptionPane.showMessageDialog(Main.parent, 93 96 tr("Town/city {0} not found or not available\n" + … … 105 108 */ 106 109 private void getCookie() throws IOException { 107 boolean sucess = false; 108 int retries = cRetriesGetCookie;110 boolean success = false; 111 int retries = RETRIES_GET_COOKIE; 109 112 try { 110 searchFormURL = new URL( baseURL + "/scpc/accueil.do");111 while ( sucess == false&& retries > 0) {113 searchFormURL = new URL(BASE_URL + "/scpc/accueil.do"); 114 while (!success && retries > 0) { 112 115 urlConn = (HttpURLConnection)searchFormURL.openConnection(); 113 116 urlConn.setRequestProperty("Connection", "close"); … … 116 119 if (urlConn.getResponseCode() == HttpURLConnection.HTTP_OK) { 117 120 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 sucess = true; 121 BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream(), StandardCharsets.UTF_8)); 122 while(in.readLine() != null) { 123 // read the buffer otherwise we sent POST too early 124 } 125 success = true; 121 126 String headerName; 122 127 for (int i=1; (headerName = urlConn.getHeaderFieldKey(i))!=null; i++) { … … 155 160 public boolean isCookieExpired() { 156 161 long now = new Date().getTime(); 157 if ((now - cookieTimestamp) > cCookieExpiration) {162 if ((now - cookieTimestamp) > COOKIE_EXPIRATION) { 158 163 Main.info("cookie received at "+new Date(cookieTimestamp)+" expired (now is "+new Date(now)+")"); 159 164 return true; … … 182 187 // second attempt either from known codeCommune (e.g. from cache) or from ComboBox 183 188 if (interfaceRef == null) { 184 if (!wmsLayer.getCodeCommune(). equals("")) {189 if (!wmsLayer.getCodeCommune().isEmpty()) { 185 190 // codeCommune is already known (from previous request or from cache on disk) 186 191 interfaceRef = postForm(wmsLayer, wmsLayer.getCodeCommune()); 187 192 } else { 188 193 if (listOfCommunes.size() > 1) { 189 // commune unknown, prompt the list of communes from 190 // server and try with codeCommune 191 String selected = selectMunicipalityDialog(wmsLayer); 194 // commune unknown, prompt the list of communes from server and try with codeCommune 195 String selected = selectMunicipalityDialog(); 192 196 if (selected != null) { 193 String newCodeCommune = selected.substring(1, selected.indexOf( ">")-2);194 String newLocation = selected.substring(selected.indexOf( ">")+1, selected.lastIndexOf(" - "));197 String newCodeCommune = selected.substring(1, selected.indexOf('>') - 2); 198 String newLocation = selected.substring(selected.indexOf('>') + 1, selected.lastIndexOf(" - ")); 195 199 wmsLayer.setCodeCommune(newCodeCommune); 196 200 wmsLayer.setLocation(newLocation); … … 205 209 int res = selectFeuilleDialog(); 206 210 if (res != -1) { 207 wmsLayer.setCodeCommune(listOfFeuilles. elementAt(res).name);211 wmsLayer.setCodeCommune(listOfFeuilles.get(res).name); 208 212 checkLayerDuplicates(wmsLayer); 209 213 interfaceRef = buildRasterFeuilleInterfaceRef(wmsLayer.getCodeCommune()); … … 220 224 try { 221 225 // finally, open the interface on server side giving access to the wms server 222 String lines = null; 223 String ln = null; 224 URL interfaceURL = new URL(baseURL + "/scpc/"+interfaceRef); 226 URL interfaceURL = new URL(BASE_URL + "/scpc/"+interfaceRef); 225 227 urlConn = (HttpURLConnection)interfaceURL.openConnection(); 226 228 urlConn.setRequestMethod("GET"); … … 231 233 } 232 234 Main.info("GET "+interfaceURL); 233 BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream())); 235 BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream(), StandardCharsets.UTF_8)); 234 236 // read the buffer otherwise we sent POST too early 237 StringBuilder lines = new StringBuilder(); 238 String ln; 235 239 while ((ln = in.readLine()) != null) { 236 lines += ln; 240 if (Main.isDebugEnabled()) { 241 lines.append(ln); 242 } 237 243 } 238 244 if (Main.isDebugEnabled()) { 239 Main.debug(lines); 245 Main.debug(lines.toString()); 240 246 } 241 247 } catch (MalformedURLException e) { … … 267 273 private String postForm(WMSLayer wmsLayer, String codeCommune) throws IOException { 268 274 try { 269 String ln = null;270 String lines = null;271 275 listOfCommunes.clear(); 272 276 listOfTA.clear(); … … 276 280 content += "&nomvoie="; 277 281 content += "&lieuDit="; 278 if (codeCommune == "") {279 content += "&ville=" + new String(java.net.URLEncoder.encode(wmsLayer.getLocation(), "UTF-8"));282 if (codeCommune.isEmpty()) { 283 content += "&ville=" + java.net.URLEncoder.encode(wmsLayer.getLocation(), "UTF-8"); 280 284 content += "&codePostal="; 281 285 } else { … … 286 290 content += "&nbResultatParPage=10"; 287 291 content += "&x=0&y=0"; 288 searchFormURL = new URL( baseURL + "/scpc/rechercherPlan.do");292 searchFormURL = new URL(BASE_URL + "/scpc/rechercherPlan.do"); 289 293 urlConn = (HttpURLConnection)searchFormURL.openConnection(); 290 294 urlConn.setRequestMethod("POST"); … … 293 297 setCookie(); 294 298 try (OutputStream wr = urlConn.getOutputStream()) { 295 wr.write(content.getBytes()); 299 wr.write(content.getBytes(StandardCharsets.UTF_8)); 296 300 Main.info("POST "+content); 297 301 wr.flush(); 298 302 } 299 try (BufferedReader rd = new BufferedReader(new InputStreamReader(urlConn.getInputStream()))) { 303 String ln; 304 StringBuilder sb = new StringBuilder(); 305 try (BufferedReader rd = new BufferedReader(new InputStreamReader(urlConn.getInputStream(), StandardCharsets.UTF_8))) { 300 306 while ((ln = rd.readLine()) != null) { 301 lines += ln; 302 } 303 } 307 sb.append(ln); 308 } 309 } 310 String lines = sb.toString(); 304 311 urlConn.disconnect(); 305 312 if (lines != null) { 306 if (lines.indexOf( cImageFormat) != -1) {307 int i = lines.indexOf( cImageFormat);308 int j = lines.indexOf( ".", i);309 wmsLayer.setRaster(lines.substring(i+ cImageFormat.length(), j).equals("image"));310 } 311 if (!wmsLayer.isRaster() && lines.indexOf( cInterfaceVector) != -1) { // "afficherCarteCommune.do"313 if (lines.indexOf(C_IMAGE_FORMAT) != -1) { 314 int i = lines.indexOf(C_IMAGE_FORMAT); 315 int j = lines.indexOf('.', i); 316 wmsLayer.setRaster("image".equals(lines.substring(i+C_IMAGE_FORMAT.length(), j))); 317 } 318 if (!wmsLayer.isRaster() && lines.indexOf(C_INTERFACE_VECTOR) != -1) { // "afficherCarteCommune.do" 312 319 // shall be something like: interfaceRef = "afficherCarteCommune.do?c=X2269"; 313 lines = lines.substring(lines.indexOf( cInterfaceVector),lines.length());314 lines = lines.substring(0, lines.indexOf( "'"));320 lines = lines.substring(lines.indexOf(C_INTERFACE_VECTOR),lines.length()); 321 lines = lines.substring(0, lines.indexOf('\'')); 315 322 Main.info("interface ref.:"+lines); 316 323 return lines; 317 } else if (wmsLayer.isRaster() && lines.indexOf( cInterfaceRasterTA) != -1) { // "afficherCarteTa.do"324 } else if (wmsLayer.isRaster() && lines.indexOf(C_INTERFACE_RASTER_TA) != -1) { // "afficherCarteTa.do" 318 325 // list of values parsed in listOfFeuilles (list all non-georeferenced images) 319 326 lines = getFeuillesList(); 320 327 if (!downloadCanceled) { 321 328 parseFeuillesList(lines); 322 if (listOfFeuilles. size() > 0) {329 if (!listOfFeuilles.isEmpty()) { 323 330 int res = selectFeuilleDialog(); 324 331 if (res != -1) { 325 wmsLayer.setCodeCommune(listOfFeuilles. elementAt(res).name);332 wmsLayer.setCodeCommune(listOfFeuilles.get(res).name); 326 333 checkLayerDuplicates(wmsLayer); 327 334 interfaceRef = buildRasterFeuilleInterfaceRef(wmsLayer.getCodeCommune()); 328 wmsLayer.setCodeCommune(listOfFeuilles. elementAt(res).ref);329 lines = buildRasterFeuilleInterfaceRef(listOfFeuilles. elementAt(res).ref);335 wmsLayer.setCodeCommune(listOfFeuilles.get(res).ref); 336 lines = buildRasterFeuilleInterfaceRef(listOfFeuilles.get(res).ref); 330 337 Main.info("interface ref.:"+lines); 331 338 return lines; … … 334 341 } 335 342 return null; 336 } else if (lines.indexOf( cCommuneListStart) != -1 && lines.indexOf(cCommuneListEnd) != -1) {343 } else if (lines.indexOf(C_COMMUNE_LIST_START) != -1 && lines.indexOf(C_COMMUNE_LIST_END) != -1) { 337 344 // list of values parsed in listOfCommunes 338 int i = lines.indexOf( cCommuneListStart);339 int j = lines.indexOf( cCommuneListEnd, i);345 int i = lines.indexOf(C_COMMUNE_LIST_START); 346 int j = lines.indexOf(C_COMMUNE_LIST_END, i); 340 347 parseCommuneList(lines.substring(i, j)); 341 348 } 342 349 } 343 350 } catch (MalformedURLException e) { 344 throw (IOException) new IOException( 345 "Illegal url.").initCause(e); 346 } catch (Exception e){ 347 e.printStackTrace(); 351 throw (IOException) new IOException("Illegal url.").initCause(e); 352 } catch (DuplicateLayerException e){ 353 Main.error(e); 348 354 } 349 355 return null; … … 351 357 352 358 private void parseCommuneList(String input) { 353 if (input.indexOf( c0ptionListStart) != -1) {359 if (input.indexOf(C_OPTION_LIST_START) != -1) { 354 360 while (input.indexOf("<option value=\"") != -1) { 355 int i = input.indexOf( c0ptionListStart);356 int j = input.indexOf( cOptionListEnd, i+c0ptionListStart.length());357 int k = input.indexOf( "\"", i+c0ptionListStart.length());358 if (j != -1 && k > (i + c0ptionListStart.length())) {359 String lov = new String(input.substring(i+c0ptionListStart.length()-1, j));360 if (lov.indexOf( ">") != -1) {361 int i = input.indexOf(C_OPTION_LIST_START); 362 int j = input.indexOf(C_OPTION_LIST_END, i+C_OPTION_LIST_START.length()); 363 int k = input.indexOf('"', i+C_OPTION_LIST_START.length()); 364 if (j != -1 && k > (i + C_OPTION_LIST_START.length())) { 365 String lov = input.substring(i+C_OPTION_LIST_START.length()-1, j); 366 if (lov.indexOf('>') != -1) { 361 367 Main.info("parse "+lov); 362 368 listOfCommunes.add(lov); … … 364 370 Main.error("unable to parse commune string:"+lov); 365 371 } 366 input = input.substring(j+ cOptionListEnd.length());372 input = input.substring(j+C_OPTION_LIST_END.length()); 367 373 } 368 374 } … … 372 378 // get all images in one html page 373 379 String ln = null; 374 String lines = n ull;380 StringBuilder lines = new StringBuilder(); 375 381 HttpURLConnection urlConn2 = null; 376 382 try { 377 URL getAllImagesURL = new URL( baseURL + "/scpc/listerFeuillesParcommune.do?keepVolatileSession=&offset=2000");383 URL getAllImagesURL = new URL(BASE_URL + "/scpc/listerFeuillesParcommune.do?keepVolatileSession=&offset=2000"); 378 384 urlConn2 = (HttpURLConnection)getAllImagesURL.openConnection(); 379 385 setCookie(urlConn2); 380 386 urlConn2.connect(); 381 387 Main.info("GET "+getAllImagesURL); 382 try (BufferedReader rd = new BufferedReader(new InputStreamReader(urlConn2.getInputStream()))) { 388 try (BufferedReader rd = new BufferedReader(new InputStreamReader(urlConn2.getInputStream(), StandardCharsets.UTF_8))) { 383 389 while ((ln = rd.readLine()) != null) { 384 lines += ln;390 lines.append(ln); 385 391 } 386 392 } … … 390 396 Main.error(e); 391 397 } 392 return lines; 398 return lines.toString(); 393 399 } 394 400 … … 398 404 String inputTA = input; 399 405 if (Main.pref.getBoolean("cadastrewms.useTA", false)) { 400 while (inputTA.indexOf( cTAImageLinkStart) != -1) {401 inputTA = inputTA.substring(inputTA.indexOf( cTAImageLinkStart) + cTAImageLinkStart.length());402 String refTA = inputTA.substring(0, inputTA.indexOf( "'"));403 String nameTA = inputTA.substring(inputTA.indexOf( cTAImageNameStart) + cTAImageNameStart.length());404 nameTA = nameTA.substring(0, nameTA.indexOf( "<"));406 while (inputTA.indexOf(C_TA_IMAGE_LINK_START) != -1) { 407 inputTA = inputTA.substring(inputTA.indexOf(C_TA_IMAGE_LINK_START) + C_TA_IMAGE_LINK_START.length()); 408 String refTA = inputTA.substring(0, inputTA.indexOf('\'')); 409 String nameTA = inputTA.substring(inputTA.indexOf(C_TA_IMAGE_NAME_START) + C_TA_IMAGE_NAME_START.length()); 410 nameTA = nameTA.substring(0, nameTA.indexOf('<')); 405 411 listOfFeuilles.add(new PlanImage(nameTA, refTA)); 406 412 } 407 413 } 408 414 // get "Feuilles" 409 while (input.indexOf( cImageLinkStart) != -1) {410 input = input.substring(input.indexOf( cImageLinkStart)+cImageLinkStart.length());411 String refFeuille = input.substring(0, input.indexOf( "'"));415 while (input.indexOf(C_IMAGE_LINK_START) != -1) { 416 input = input.substring(input.indexOf(C_IMAGE_LINK_START)+C_IMAGE_LINK_START.length()); 417 String refFeuille = input.substring(0, input.indexOf('\'')); 412 418 String nameFeuille = input.substring( 413 input.indexOf( cImageNameStart)+cImageNameStart.length(),419 input.indexOf(C_IMAGE_NAME_START)+C_IMAGE_NAME_START.length(), 414 420 input.indexOf(" -")); 415 421 listOfFeuilles.add(new PlanImage(nameFeuille, refFeuille)); … … 417 423 } 418 424 419 private String selectMunicipalityDialog( WMSLayer wmsLayer) {425 private String selectMunicipalityDialog() { 420 426 JPanel p = new JPanel(new GridBagLayout()); 421 427 String[] communeList = new String[listOfCommunes.size() + 1]; 422 428 communeList[0] = tr("Choose from..."); 423 429 for (int i = 0; i < listOfCommunes.size(); i++) { 424 communeList[i + 1] = listOfCommunes. elementAt(i).substring(listOfCommunes.elementAt(i).indexOf(">")+1);430 communeList[i + 1] = listOfCommunes.get(i).substring(listOfCommunes.get(i).indexOf('>')+1); 425 431 } 426 432 JComboBox<String> inputCommuneList = new JComboBox<>(communeList); 427 433 p.add(inputCommuneList, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 0, 0, 0)); 428 434 JOptionPane pane = new JOptionPane(p, JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null); 429 //pane.createDialog(Main.parent, tr("Select commune")).setVisible(true);430 435 // this below is a temporary workaround to fix the "always on top" issue 431 436 JDialog dialog = pane.createDialog(Main.parent, tr("Select commune")); … … 435 440 if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue())) 436 441 return null; 437 return listOfCommunes. elementAt(inputCommuneList.getSelectedIndex()-1);442 return listOfCommunes.get(inputCommuneList.getSelectedIndex()-1); 438 443 } 439 444 440 445 private int selectFeuilleDialog() { 441 446 JPanel p = new JPanel(new GridBagLayout()); 442 Vector<String> imageNames = newVector<>();447 List<String> imageNames = new ArrayList<>(); 443 448 for (PlanImage src : listOfFeuilles) { 444 449 imageNames.add(src.name); 445 450 } 446 JComboBox<String> inputFeuilleList = new JComboBox<>(imageNames); 451 JComboBox<String> inputFeuilleList = new JComboBox<>(imageNames.toArray(new String[]{})); 447 452 p.add(inputFeuilleList, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 0, 0, 0)); 448 453 JOptionPane pane = new JOptionPane(p, JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null); 449 //pane.createDialog(Main.parent, tr("Select Feuille")).setVisible(true);450 454 // this below is a temporary workaround to fix the "always on top" issue 451 455 JDialog dialog = pane.createDialog(Main.parent, tr("Select Feuille")); … … 455 459 if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue())) 456 460 return -1; 457 int result = inputFeuilleList.getSelectedIndex(); 458 return result; 459 } 460 461 private String buildRasterFeuilleInterfaceRef(String codeCommune) { 462 return cInterfaceRasterFeuille + "?f=" + codeCommune; 461 return inputFeuilleList.getSelectedIndex(); 462 } 463 464 private static String buildRasterFeuilleInterfaceRef(String codeCommune) { 465 return C_INTERFACE_RASTER_FEUILLE + "?f=" + codeCommune; 463 466 } 464 467 … … 474 477 if (interfaceRef == null) 475 478 return; 476 String ln = null;477 String line = null;478 479 // send GET opening normally the small window with the commune overview 479 String content = baseURL + "/scpc/" + interfaceRef;480 String content = BASE_URL + "/scpc/" + interfaceRef; 480 481 content += "&dontSaveLastForward&keepVolatileSession="; 481 482 searchFormURL = new URL(content); … … 488 489 } 489 490 Main.info("GET "+searchFormURL); 490 try (BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream()))) { 491 String ln; 492 StringBuilder sb = new StringBuilder(); 493 try (BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream(), StandardCharsets.UTF_8))) { 491 494 while ((ln = in.readLine()) != null) { 492 line += ln;495 sb.append(ln); 493 496 } 494 497 } 495 498 urlConn.disconnect(); 499 String line = sb.toString(); 496 500 parseBBoxCommune(wmsLayer, line); 497 501 if (wmsLayer.isRaster() && !wmsLayer.isAlreadyGeoreferenced()) { … … 500 504 } 501 505 502 private void parseBBoxCommune(WMSLayer wmsLayer, String input) { 503 if (input.indexOf( cBBoxCommunStart) != -1) {504 input = input.substring(input.indexOf( cBBoxCommunStart));505 int i = input.indexOf( ",");506 double minx = Double.parseDouble(input.substring( cBBoxCommunStart.length(), i));507 int j = input.indexOf( ",", i+1);506 private static void parseBBoxCommune(WMSLayer wmsLayer, String input) { 507 if (input.indexOf(C_BBOX_COMMUN_START) != -1) { 508 input = input.substring(input.indexOf(C_BBOX_COMMUN_START)); 509 int i = input.indexOf(','); 510 double minx = Double.parseDouble(input.substring(C_BBOX_COMMUN_START.length(), i)); 511 int j = input.indexOf(',', i+1); 508 512 double miny = Double.parseDouble(input.substring(i+1, j)); 509 int k = input.indexOf( ",", j+1);513 int k = input.indexOf(',', j+1); 510 514 double maxx = Double.parseDouble(input.substring(j+1, k)); 511 int l = input.indexOf( cBBoxCommunEnd, k+1);515 int l = input.indexOf(C_BBOX_COMMUN_END, k+1); 512 516 double maxy = Double.parseDouble(input.substring(k+1, l)); 513 517 wmsLayer.setCommuneBBox( new EastNorthBound(new EastNorth(minx,miny), new EastNorth(maxx,maxy))); … … 515 519 } 516 520 517 private void parseGeoreferences(WMSLayer wmsLayer, String input) { 521 private static void parseGeoreferences(WMSLayer wmsLayer, String input) { 518 522 /* commented since cadastre WMS changes mid july 2013 519 523 * until new GeoBox coordinates parsing is solved */ … … 547 551 // wmsLayer.Y0 = Y0; 548 552 // } 549 // Main.info("parse georef:"+unknown_yet+","+angle+","+scale_origin+","+dpi+","+fX+","+ 550 // fY+","+X0+","+Y0); 553 // Main.info("parse georef:"+unknown_yet+","+angle+","+scale_origin+","+dpi+","+fX+","+fY+","+X0+","+Y0); 551 554 // } 552 555 } 553 556 554 private void checkLayerDuplicates(WMSLayer wmsLayer) throws DuplicateLayerException { 557 private static void checkLayerDuplicates(WMSLayer wmsLayer) throws DuplicateLayerException { 555 558 if (Main.map != null) { 556 559 for (Layer l : Main.map.mapView.getAllLayers()) { 557 if (l instanceof WMSLayer && l.getName().equals(wmsLayer.getName()) && ( l !=wmsLayer)) {560 if (l instanceof WMSLayer && l.getName().equals(wmsLayer.getName()) && (!l.equals(wmsLayer))) { 558 561 Main.info("Try to grab into a new layer when "+wmsLayer.getName()+" is already opened."); 559 562 // remove the duplicated layer … … 569 572 urlConn.setConnectTimeout(1); 570 573 urlConn.setReadTimeout(1); 571 //urlConn.disconnect();572 574 } 573 575 downloadCanceled = true;
Note:
See TracChangeset
for help on using the changeset viewer.
