Changeset 33530 in osm for applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/RelationHelpAction.java
- Timestamp:
- 2017-08-26T02:16:05+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/RelationHelpAction.java
r32398 r33530 15 15 import org.openstreetmap.josm.Main; 16 16 import org.openstreetmap.josm.data.osm.Relation; 17 import org.openstreetmap.josm.gui.MainApplication; 17 18 import org.openstreetmap.josm.tools.ImageProvider; 18 19 import org.openstreetmap.josm.tools.LanguageInfo; … … 61 62 uris.add(new URI(String.format("%sRelations", base))); 62 63 63 Main.worker.execute(new Runnable() { 64 @Override 65 public void run() { 66 try { 67 // find a page that actually exists in the wiki 68 HttpURLConnection conn; 69 for (URI u : uris) { 70 conn = (HttpURLConnection) u.toURL().openConnection(); 64 MainApplication.worker.execute(() -> { 65 try { 66 // find a page that actually exists in the wiki 67 HttpURLConnection conn; 68 for (URI u : uris) { 69 conn = (HttpURLConnection) u.toURL().openConnection(); 70 conn.setConnectTimeout(5000); 71 72 if (conn.getResponseCode() != 200) { 73 System.out.println("INFO: " + u + " does not exist"); 74 conn.disconnect(); 75 } else { 76 int osize = conn.getContentLength(); 77 conn.disconnect(); 78 79 conn = (HttpURLConnection) new URI(u.toString() 80 .replace("=", "%3D") /* do not URLencode whole string! */ 81 .replaceFirst("/wiki/", "/w/index.php?redirect=no&title=") 82 ).toURL().openConnection(); 71 83 conn.setConnectTimeout(5000); 72 84 73 if (conn.getResponseCode() != 200) { 74 System.out.println("INFO: " + u + " does not exist"); 85 /* redirect pages have different content length, but retrieving a "nonredirect" 86 * page using index.php and the direct-link method gives slightly different 87 * content lengths, so we have to be fuzzy.. (this is UGLY, recode if u know better) 88 */ 89 if (Math.abs(conn.getContentLength() - osize) > 200) { 90 System.out.println("INFO: " + u + " is a mediawiki redirect"); 75 91 conn.disconnect(); 76 92 } else { 77 int osize = conn.getContentLength();93 System.out.println("INFO: browsing to " + u); 78 94 conn.disconnect(); 79 95 80 conn = (HttpURLConnection) new URI(u.toString() 81 .replace("=", "%3D") /* do not URLencode whole string! */ 82 .replaceFirst("/wiki/", "/w/index.php?redirect=no&title=") 83 ).toURL().openConnection(); 84 conn.setConnectTimeout(5000); 85 86 /* redirect pages have different content length, but retrieving a "nonredirect" 87 * page using index.php and the direct-link method gives slightly different 88 * content lengths, so we have to be fuzzy.. (this is UGLY, recode if u know better) 89 */ 90 if (Math.abs(conn.getContentLength() - osize) > 200) { 91 System.out.println("INFO: " + u + " is a mediawiki redirect"); 92 conn.disconnect(); 93 } else { 94 System.out.println("INFO: browsing to " + u); 95 conn.disconnect(); 96 97 OpenBrowser.displayUrl(u.toString()); 98 break; 99 } 96 OpenBrowser.displayUrl(u.toString()); 97 break; 100 98 } 101 99 } 102 } catch (Exception e) {103 e.printStackTrace();104 100 } 101 } catch (Exception e1) { 102 e1.printStackTrace(); 105 103 } 106 104 });
Note:
See TracChangeset
for help on using the changeset viewer.
