Changeset 33682 in osm for applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap
- Timestamp:
- 2017-09-29T21:28:46+02:00 (7 years ago)
- Location:
- applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/CadastreInterface.java
r33640 r33682 43 43 private HttpURLConnection urlConn; 44 44 45 private String csrfToken; 45 46 private String cookie; 46 47 private String interfaceRef; … … 72 73 static final String C_INTERFACE_VECTOR = "afficherCarteCommune.do"; 73 74 static final String C_INTERFACE_RASTER_TA = "afficherCarteTa.do"; 74 static final String C_INTERFACE_RASTER_FEUILLE = "afficherCarteFeuille.do ";75 static final String C_IMAGE_LINK_START = "<a href=\"#\" class=\"raster\" onClick=\"popup(' afficherCarteFeuille.do?f=";76 static final String C_TA_IMAGE_LINK_START = "<a href=\"#\" class=\"raster\" onClick=\"popup('afficherCarteTa.do? f=";75 static final String C_INTERFACE_RASTER_FEUILLE = "afficherCarteFeuille.do?CSRF_TOKEN="; 76 static final String C_IMAGE_LINK_START = "<a href=\"#\" class=\"raster\" onClick=\"popup('" + C_INTERFACE_RASTER_FEUILLE; 77 static final String C_TA_IMAGE_LINK_START = "<a href=\"#\" class=\"raster\" onClick=\"popup('afficherCarteTa.do?CSRF_TOKEN="; 77 78 static final String C_IMAGE_NAME_START = ">Feuille "; 78 79 static final String C_TA_IMAGE_NAME_START = "Tableau d'assemblage <strong>"; 80 81 static final String C_CSRF_TOKEN = "CSRF_TOKEN="; 82 static final String C_F = "&f="; 79 83 80 84 static final long COOKIE_EXPIRATION = 30 * 60 * 1000L; // 30 minutes expressed in milliseconds … … 100 104 throw new WMSException(tr("Cannot open a new client session.\nServer in maintenance or temporary overloaded.")); 101 105 if (interfaceRef == null) { 102 103 106 getInterface(wmsLayer); 107 this.lastWMSLayerName = wmsLayer.getName(); 104 108 } 105 109 openInterface(); … … 237 241 wmsLayer.setCodeCommune(listOfFeuilles.get(res).name); 238 242 checkLayerDuplicates(wmsLayer); 239 interfaceRef = buildRasterFeuilleInterfaceRef(wmsLayer.getCodeCommune() );243 interfaceRef = buildRasterFeuilleInterfaceRef(wmsLayer.getCodeCommune(), csrfToken); 240 244 } 241 245 } … … 334 338 urlConn.disconnect(); 335 339 if (lines != null) { 336 if (lines.indexOf(C_IMAGE_FORMAT) != -1) { 337 int i = lines.indexOf(C_IMAGE_FORMAT); 338 int j = lines.indexOf('.', i); 339 wmsLayer.setRaster("image".equals(lines.substring(i+C_IMAGE_FORMAT.length(), j))); 340 } 341 if (!wmsLayer.isRaster() && lines.indexOf(C_INTERFACE_VECTOR) != -1) { // "afficherCarteCommune.do" 340 int i = lines.indexOf(C_IMAGE_FORMAT); 341 if (i > -1) { 342 wmsLayer.setRaster("image".equals(lines.substring(i+C_IMAGE_FORMAT.length(), lines.indexOf('.', i)))); 343 } 344 csrfToken = null; 345 i = lines.indexOf(C_CSRF_TOKEN); 346 if (i > -1) { 347 csrfToken = lines.substring(i+C_CSRF_TOKEN.length(), Math.min(lines.indexOf('"', i), lines.indexOf('&', i))); 348 } 349 i = lines.indexOf(C_INTERFACE_VECTOR); 350 if (!wmsLayer.isRaster() && i != -1) { // "afficherCarteCommune.do" 342 351 // shall be something like: interfaceRef = "afficherCarteCommune.do?c=X2269"; 343 lines = lines.substring( lines.indexOf(C_INTERFACE_VECTOR), lines.length());352 lines = lines.substring(i, lines.length()); 344 353 lines = lines.substring(0, lines.indexOf('\'')); 345 354 lines = Entities.unescape(lines); … … 348 357 } else if (wmsLayer.isRaster() && lines.indexOf(C_INTERFACE_RASTER_TA) != -1) { // "afficherCarteTa.do" 349 358 // list of values parsed in listOfFeuilles (list all non-georeferenced images) 350 lines = getFeuillesList( );359 lines = getFeuillesList(csrfToken); 351 360 if (!downloadCanceled) { 352 parseFeuillesList(lines );361 parseFeuillesList(lines, csrfToken); 353 362 if (!listOfFeuilles.isEmpty()) { 354 363 int res = selectFeuilleDialog(); … … 356 365 wmsLayer.setCodeCommune(listOfFeuilles.get(res).name); 357 366 checkLayerDuplicates(wmsLayer); 358 interfaceRef = buildRasterFeuilleInterfaceRef(wmsLayer.getCodeCommune() );367 interfaceRef = buildRasterFeuilleInterfaceRef(wmsLayer.getCodeCommune(), csrfToken); 359 368 wmsLayer.setCodeCommune(listOfFeuilles.get(res).ref); 360 lines = buildRasterFeuilleInterfaceRef(listOfFeuilles.get(res).ref );369 lines = buildRasterFeuilleInterfaceRef(listOfFeuilles.get(res).ref, csrfToken); 361 370 lines = Entities.unescape(lines); 362 371 Logging.info("interface ref.:"+lines); … … 368 377 } else if (lines.indexOf(C_COMMUNE_LIST_START) != -1 && lines.indexOf(C_COMMUNE_LIST_END) != -1) { 369 378 // list of values parsed in listOfCommunes 370 int i = lines.indexOf(C_COMMUNE_LIST_START); 371 int j = lines.indexOf(C_COMMUNE_LIST_END, i); 372 parseCommuneList(lines.substring(i, j)); 379 i = lines.indexOf(C_COMMUNE_LIST_START); 380 parseCommuneList(lines.substring(i, lines.indexOf(C_COMMUNE_LIST_END, i))); 373 381 } 374 382 } … … 400 408 } 401 409 402 private String getFeuillesList( ) {410 private String getFeuillesList(String csrfToken) { 403 411 // get all images in one html page 404 412 String ln = null; … … 406 414 HttpURLConnection urlConn2 = null; 407 415 try { 408 URL getAllImagesURL = new URL(BASE_URL + "/scpc/listerFeuillesParcommune.do?keepVolatileSession=&offset=2000"); 416 URL getAllImagesURL = new URL(BASE_URL + "/scpc/listerFeuillesParcommune.do?CSRF_TOKEN=" + 417 csrfToken + "&keepVolatileSession=&offset=2000"); 409 418 urlConn2 = (HttpURLConnection) getAllImagesURL.openConnection(); 410 419 setCookie(urlConn2); … … 424 433 } 425 434 426 private void parseFeuillesList(String input ) {435 private void parseFeuillesList(String input, String csrfToken) { 427 436 listOfFeuilles.clear(); 428 437 // get "Tableau d'assemblage" … … 430 439 if (Main.pref.getBoolean("cadastrewms.useTA", false)) { 431 440 while (inputTA.indexOf(C_TA_IMAGE_LINK_START) != -1) { 432 inputTA = inputTA.substring(inputTA.indexOf(C_TA_IMAGE_LINK_START) + C_TA_IMAGE_LINK_START.length()); 441 inputTA = inputTA.substring(inputTA.indexOf(C_TA_IMAGE_LINK_START) + C_TA_IMAGE_LINK_START.length() 442 + csrfToken.length() + C_F.length()); 433 443 String refTA = inputTA.substring(0, inputTA.indexOf('\'')); 434 444 String nameTA = inputTA.substring(inputTA.indexOf(C_TA_IMAGE_NAME_START) + C_TA_IMAGE_NAME_START.length()); … … 439 449 // get "Feuilles" 440 450 while (input.indexOf(C_IMAGE_LINK_START) != -1) { 441 input = input.substring(input.indexOf(C_IMAGE_LINK_START)+C_IMAGE_LINK_START.length()); 451 input = input.substring(input.indexOf(C_IMAGE_LINK_START)+C_IMAGE_LINK_START.length() 452 + csrfToken.length() + C_F.length()); 442 453 String refFeuille = input.substring(0, input.indexOf('\'')); 443 454 String nameFeuille = input.substring( … … 449 460 450 461 private String selectMunicipalityDialog() { 451 JPanel p = new JPanel(new GridBagLayout()); 452 String[] communeList = new String[listOfCommunes.size() + 1]; 453 communeList[0] = tr("Choose from..."); 454 for (int i = 0; i < listOfCommunes.size(); i++) { 455 communeList[i + 1] = listOfCommunes.get(i).substring(listOfCommunes.get(i).indexOf('>')+1); 456 } 457 JComboBox<String> inputCommuneList = new JComboBox<>(communeList); 458 p.add(inputCommuneList, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 0, 0, 0)); 459 JOptionPane pane = new JOptionPane(p, JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null); 460 // this below is a temporary workaround to fix the "always on top" issue 461 JDialog dialog = pane.createDialog(Main.parent, tr("Select commune")); 462 CadastrePlugin.prepareDialog(dialog); 463 dialog.setVisible(true); 464 // till here 465 if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue())) 466 return null; 467 return listOfCommunes.get(inputCommuneList.getSelectedIndex()-1); 462 return GuiHelper.runInEDTAndWaitAndReturn(() -> { 463 JPanel p = new JPanel(new GridBagLayout()); 464 String[] communeList = new String[listOfCommunes.size() + 1]; 465 communeList[0] = tr("Choose from..."); 466 for (int i = 0; i < listOfCommunes.size(); i++) { 467 communeList[i + 1] = listOfCommunes.get(i).substring(listOfCommunes.get(i).indexOf('>')+1); 468 } 469 JComboBox<String> inputCommuneList = new JComboBox<>(communeList); 470 p.add(inputCommuneList, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 0, 0, 0)); 471 JOptionPane pane = new JOptionPane(p, JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null); 472 // this below is a temporary workaround to fix the "always on top" issue 473 JDialog dialog = pane.createDialog(Main.parent, tr("Select commune")); 474 CadastrePlugin.prepareDialog(dialog); 475 dialog.setVisible(true); 476 // till here 477 if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue())) 478 return null; 479 return listOfCommunes.get(inputCommuneList.getSelectedIndex()-1); 480 }); 468 481 } 469 482 470 483 private int selectFeuilleDialog() { 471 JPanel p = new JPanel(new GridBagLayout()); 472 List<String> imageNames = new ArrayList<>(); 473 for (PlanImage src : listOfFeuilles) { 474 imageNames.add(src.name); 475 } 476 JComboBox<String> inputFeuilleList = new JComboBox<>(imageNames.toArray(new String[]{})); 477 p.add(inputFeuilleList, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 0, 0, 0)); 478 JOptionPane pane = new JOptionPane(p, JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null); 479 // this below is a temporary workaround to fix the "always on top" issue 480 JDialog dialog = pane.createDialog(Main.parent, tr("Select Feuille")); 481 CadastrePlugin.prepareDialog(dialog); 482 dialog.setVisible(true); 483 // till here 484 if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue())) 485 return -1; 486 return inputFeuilleList.getSelectedIndex(); 487 } 488 489 private static String buildRasterFeuilleInterfaceRef(String codeCommune) { 490 return C_INTERFACE_RASTER_FEUILLE + "?f=" + codeCommune; 484 return GuiHelper.runInEDTAndWaitAndReturn(() -> { 485 JPanel p = new JPanel(new GridBagLayout()); 486 List<String> imageNames = new ArrayList<>(); 487 for (PlanImage src : listOfFeuilles) { 488 imageNames.add(src.name); 489 } 490 JComboBox<String> inputFeuilleList = new JComboBox<>(imageNames.toArray(new String[]{})); 491 p.add(inputFeuilleList, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 0, 0, 0)); 492 JOptionPane pane = new JOptionPane(p, JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null); 493 // this below is a temporary workaround to fix the "always on top" issue 494 JDialog dialog = pane.createDialog(Main.parent, tr("Select Feuille")); 495 CadastrePlugin.prepareDialog(dialog); 496 dialog.setVisible(true); 497 // till here 498 if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue())) 499 return -1; 500 return inputFeuilleList.getSelectedIndex(); 501 }); 502 } 503 504 private static String buildRasterFeuilleInterfaceRef(String codeCommune, String csrfToken) { 505 return C_INTERFACE_RASTER_FEUILLE + csrfToken + "&f=" + codeCommune; 491 506 } 492 507 … … 497 512 * and store the result in the wmsLayer as well. 498 513 * @param wmsLayer the WMSLayer where the commune data and images are stored 514 * @throws IOException if any I/O error occurs 499 515 */ 500 516 public void retrieveCommuneBBox(WMSLayer wmsLayer) throws IOException { -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/DownloadWMSVectorImage.java
r33640 r33682 13 13 import org.openstreetmap.josm.gui.MapView; 14 14 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 15 import org.openstreetmap.josm.gui.util.GuiHelper; 15 16 import org.openstreetmap.josm.tools.Logging; 16 17 … … 44 45 if (wmsLayer.isRaster()) { 45 46 // set raster image commune bounding box based on current view (before adjustment) 46 JOptionPane.showMessageDialog(Main.parent, 47 tr("This commune is not vectorized.\nPlease use the other menu entry to georeference a \"Plan image\"")); 47 GuiHelper.runInEDT(() -> 48 JOptionPane.showMessageDialog(Main.parent, 49 tr("This commune is not vectorized.\nPlease use the other menu entry to georeference a \"Plan image\""))); 48 50 MainApplication.getLayerManager().removeLayer(wmsLayer); 49 51 wmsLayer = null; -
applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/RasterImageGeoreferencer.java
r33640 r33682 19 19 import org.openstreetmap.josm.data.coor.EastNorth; 20 20 import org.openstreetmap.josm.gui.MainApplication; 21 import org.openstreetmap.josm.gui.util.GuiHelper; 21 22 import org.openstreetmap.josm.tools.GBC; 22 23 import org.openstreetmap.josm.tools.Logging; … … 46 47 } 47 48 48 49 /** 49 50 * 51 * @param wmsLayer WMS layer 50 52 * @return false if all operations are canceled 51 53 */ … … 57 59 mouseClickedTime = System.currentTimeMillis(); 58 60 Object[] options = {"OK", "Cancel"}; 59 int ret = JOptionPane.showOptionDialog(null,61 int ret = GuiHelper.runInEDTAndWaitAndReturn(() -> JOptionPane.showOptionDialog(null, 60 62 tr("Click first corner for image cropping\n(two points required)"), 61 63 tr("Image cropping"), 62 64 JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, 63 null, options, options[0]) ;65 null, options, options[0])); 64 66 if (ret == JOptionPane.OK_OPTION) { 65 67 mouseClickedTime = System.currentTimeMillis(); … … 70 72 } 71 73 72 73 *74 75 74 /** 75 * @param wmsLayer WMS layer 76 * @return false if all operations are canceled 77 */ 76 78 public boolean startGeoreferencing(WMSLayer wmsLayer) { 77 79 this.wmsLayer = wmsLayer;
Note:
See TracChangeset
for help on using the changeset viewer.