Changeset 19267 in osm for applications/editors/josm/plugins/cadastre-fr/src
- Timestamp:
- 2010-01-04T00:33:04+01:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreInterface.java
r19078 r19267 12 12 import java.net.MalformedURLException; 13 13 import java.net.URL; 14 import java.util.Date; 14 15 import java.util.Vector; 15 16 … … 43 44 } 44 45 private Vector<PlanImage> listOfFeuilles = new Vector<PlanImage>(); 46 private long cookieTimestamp; 45 47 46 48 final String baseURL = "http://www.cadastre.gouv.fr"; … … 51 53 final String cOptionListEnd = "</option>"; 52 54 final String cBBoxCommunStart = "new GeoBox("; 53 final String cBBoxCommunEnd = ")"; 55 final String cBBoxCommunEnd = ")"; 54 56 55 57 final String cInterfaceVector = "afficherCarteCommune.do"; … … 58 60 final String cImageLinkStart = "title=\"image\"><a href=\"#\" onClick=\"popup('afficherCarteFeuille.do?f="; 59 61 final String cImageNameStart = ">Feuille "; 62 63 final static long cCookieExpiration = 30 * 60 * 1000; // 30 minutes expressed in milliseconds 64 65 final int cRetriesGetCookie = 10; // 10 times every 3 seconds means 30 seconds trying to get a cookie 60 66 61 67 public boolean retrieveInterface(WMSLayer wmsLayer) throws DuplicateLayerException { 62 68 if (wmsLayer.getName().equals("")) 63 69 return false; 70 if (wmsLayer.getName().equals(lastWMSLayerName)) 71 return true; 64 72 // open the session with the French Cadastre web front end 65 73 downloadCancelled = false; 66 74 try { 67 if (cookie == null || !wmsLayer.getName().equals(lastWMSLayerName)) {75 if (cookie == null || isCookieExpired()) 68 76 getCookie(); 69 getInterface(wmsLayer); 70 this.lastWMSLayerName = wmsLayer.getName(); 77 if (cookie != null && interfaceRef == null) { 78 getInterface(wmsLayer); 79 this.lastWMSLayerName = wmsLayer.getName(); 80 } else { 81 JOptionPane.showMessageDialog(Main.parent, 82 tr("Cannot open a new client session.\nServer in maintenance or temporary overloaded.")); 83 return false; 71 84 } 72 85 openInterface(); 73 86 } catch (IOException e) { 74 /*JOptionPane.showMessageDialog(Main.parent,87 JOptionPane.showMessageDialog(Main.parent, 75 88 tr("Town/city {0} not found or not available\n" + 76 "or action canceled", wmsLayer.getLocation()));*/ 77 JOptionPane pane = new JOptionPane( 78 tr("Town/city {0} not found or not available\n" + 79 "or action canceled", wmsLayer.getLocation()), 80 JOptionPane.INFORMATION_MESSAGE); 81 // this below is a temporary workaround to fix the "always on top" issue 82 JDialog dialog = pane.createDialog(Main.parent, tr("Select commune")); 83 CadastrePlugin.prepareDialog(dialog); 84 dialog.setVisible(true); 85 // till here 89 "or action canceled", wmsLayer.getLocation())); 86 90 return false; 87 91 } … … 89 93 } 90 94 95 /** 96 * 97 * @return true if a cookie is delivered by WMS and false is WMS is not opening a client session 98 * (too many clients or in maintenance) 99 * @throws IOException 100 */ 91 101 private void getCookie() throws IOException { 102 boolean cookied = false; 103 int retries = cRetriesGetCookie; 92 104 try { 93 // first, get the cookie from Cadastre to allow next downloads94 105 searchFormURL = new URL(baseURL + "/scpc/accueil.do"); 95 urlConn = (HttpURLConnection)searchFormURL.openConnection(); 96 urlConn.setRequestMethod("GET"); 97 urlConn.connect(); 98 if (urlConn.getResponseCode() != HttpURLConnection.HTTP_OK) { 99 throw new IOException("Cannot get Cadastre cookie."); 100 } 101 System.out.println("GET "+searchFormURL); 102 BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream())); 103 while(in.readLine() != null) {} // read the buffer otherwise we sent POST too early 104 String headerName=null; 105 for (int i=1; (headerName = urlConn.getHeaderFieldKey(i))!=null; i++) { 106 if (headerName.equals("Set-Cookie")) { 107 cookie = urlConn.getHeaderField(i); 108 cookie = cookie.substring(0, cookie.indexOf(";")); 109 System.out.println("Cookie="+cookie); 106 while (cookied == false && retries > 0) { 107 urlConn = (HttpURLConnection)searchFormURL.openConnection(); 108 urlConn.setRequestMethod("GET"); 109 urlConn.connect(); 110 if (urlConn.getResponseCode() == HttpURLConnection.HTTP_OK) { 111 System.out.println("GET "+searchFormURL); 112 BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream())); 113 while(in.readLine() != null) {} // read the buffer otherwise we sent POST too early 114 String headerName=null; 115 for (int i=1; (headerName = urlConn.getHeaderFieldKey(i))!=null; i++) { 116 if (headerName.equals("Set-Cookie")) { 117 cookie = urlConn.getHeaderField(i); 118 cookie = cookie.substring(0, cookie.indexOf(";")); 119 cookieTimestamp = new Date().getTime(); 120 System.out.println("received cookie=" + cookie + " at " + new Date(cookieTimestamp)); 121 cookied = true; 122 } 123 } 124 } else { 125 System.out.println("Request to home page failed. Http error:"+urlConn.getResponseCode()+". Try again "+retries+" times"); 126 CadastrePlugin.safeSleep(3000); 127 retries --; 110 128 } 111 129 } … … 118 136 public void resetCookie() { 119 137 lastWMSLayerName = null; 120 } 121 122 public void resetCookieIfNewLayer(String newWMSLayerName) { 138 cookie = null; 139 } 140 141 public boolean isCookieExpired() { 142 long now = new Date().getTime(); 143 if ((now - cookieTimestamp) > cCookieExpiration) { 144 System.out.println("cookie received at "+new Date(cookieTimestamp)+" expired (now is "+new Date(now)+")"); 145 return true; 146 } 147 return false; 148 } 149 150 public void resetInterfaceRefIfNewLayer(String newWMSLayerName) { 123 151 if (!newWMSLayerName.equals(lastWMSLayerName)) { 124 resetCookie();152 interfaceRef = null; 125 153 } 126 154 } … … 154 182 int res = selectFeuilleDialog(); 155 183 if (res != -1) { 156 // TODO157 184 wmsLayer.setCodeCommune(listOfFeuilles.elementAt(res).name); 158 185 checkLayerDuplicates(wmsLayer); -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastrePlugin.java
r19078 r19267 87 87 * - removed autosourcing of empty new nodes 88 88 * 1.6 28-Nov-2009 - Fix minor issues if Grab is called without layer (possible since projection rework) 89 * 1.7 12-Dec-2009 - Change URL's changes for cookie and downgrade imgs resolution due to WMS changes 89 * 1.7 12-Dec-2009 - Change URL's changes for cookie and downgrade imgs resolution due to WMS changes 90 * 1.8 xxx - filter the mouse button 1 during georeferencing 91 * - possibility to modify the auto-sourcing text just before upload 92 * - retry if getting a new cookie failed (10 times during 30 seconds) 93 * - cookie expiration automatically detected and renewed (after 30 minutes) 94 * - proper WMS layer cleanup at destruction (workaround for memory leak) 90 95 */ 91 96 public class CadastrePlugin extends Plugin { 92 static String VERSION = "1. 7";97 static String VERSION = "1.8"; 93 98 94 99 static JMenu cadastreJMenu; … … 122 127 */ 123 128 public CadastrePlugin() throws Exception { 124 System.out.println("Pluging \"cadastre-fr\" started...");129 System.out.println("Pluging cadastre-fr v"+VERSION+" started..."); 125 130 if (Main.pref.get("cadastrewms.cacheDir").equals("")) 126 131 cacheDir = Main.pref.getPreferencesDir()+"plugins/cadastrewms/"; -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionGrabPlanImage.java
r18544 r19267 124 124 else 125 125 mouseClickedTime = System.currentTimeMillis(); 126 if (e.getButton() != MouseEvent.BUTTON1) 127 return; 126 128 countMouseClicked++; 127 129 EastNorth ea = Main.proj.latlon2eastNorth(Main.map.mapView.getLatLon(e.getX(), e.getY())); -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionNewLocation.java
r18838 r19267 39 39 String codeDepartement = ""; 40 40 String codeCommune = ""; 41 boolean resetCookie = false;41 boolean changeInterface = false; 42 42 JLabel labelSectionNewLocation = new JLabel(tr("Add a new layer")); 43 43 JPanel p = new JPanel(new GridBagLayout()); … … 66 66 if (!inputTown.getText().equals("")) { 67 67 location = inputTown.getText().toUpperCase(); 68 resetCookie = true;68 changeInterface = true; 69 69 Main.pref.put("cadastrewms.location", location); 70 70 Main.pref.put("cadastrewms.codeCommune", codeCommune); … … 89 89 } else if (existingLayers != null && existingLayers.size() > 0 && Main.map.mapView.getActiveLayer() instanceof WMSLayer) { 90 90 wmsLayer = (WMSLayer)Main.map.mapView.getActiveLayer(); 91 resetCookie = true;91 changeInterface = true; 92 92 } 93 93 94 if ( resetCookie)95 CadastrePlugin.cadastreGrabber.getWmsInterface().reset CookieIfNewLayer(wmsLayer.getName());94 if (changeInterface) 95 CadastrePlugin.cadastreGrabber.getWmsInterface().resetInterfaceRefIfNewLayer(wmsLayer.getName()); 96 96 return wmsLayer; 97 97 } -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java
r19149 r19267 88 88 } 89 89 90 public void destroy() { 91 super.destroy(); 92 images = null; 93 dividedBbox = null; 94 System.out.println("Layer "+location+" destroyed"); 95 } 96 90 97 private static String buildName(String location, String codeCommune) { 91 98 String ret = new String(location.toUpperCase());
Note:
See TracChangeset
for help on using the changeset viewer.