Ticket #5464: PropertiesDialog.java.patch
| File PropertiesDialog.java.patch, 5.3 KB (added by , 15 years ago) |
|---|
-
src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
18 18 import java.awt.event.MouseAdapter; 19 19 import java.awt.event.MouseEvent; 20 20 import java.net.HttpURLConnection; 21 import java.net.ProxySelector; 21 22 import java.net.URI; 22 23 import java.net.URLEncoder; 23 24 import java.util.ArrayList; … … 1060 1061 try { 1061 1062 String base = new String(Main.pref.get("url.openstreetmap-wiki", "http://wiki.openstreetmap.org/wiki/")); 1062 1063 String l = LanguageInfo.getWikiLanguagePrefix(); 1063 List<URI> uris = new ArrayList<URI>();1064 final List<URI> uris = new ArrayList<URI>(); 1064 1065 int row; 1065 1066 if (propertyTable.getSelectedRowCount() == 1) { 1066 1067 row = propertyTable.getSelectedRow(); … … 1096 1097 uris.add(new URI(String.format("%sMap_Features", base))); 1097 1098 } 1098 1099 1099 // find a page that actually exists in the wiki 1100 HttpURLConnection conn; 1101 for(URI u : uris) { 1102 conn = (HttpURLConnection) u.toURL().openConnection(); 1100 Main.worker.execute(new Runnable(){ 1101 public void run() { 1102 try { 1103 // find a page that actually exists in the wiki 1104 HttpURLConnection conn; 1105 for(URI u : uris) { 1106 conn = (HttpURLConnection) u.toURL().openConnection(ProxySelector.getDefault().select(u).get(0)); 1103 1107 1104 if (conn.getResponseCode() != 200) {1105 System.out.println("INFO: " + u + " does not exist");1106 conn.disconnect();1107 } else {1108 int osize = conn.getContentLength();1109 conn.disconnect();1108 if (conn.getResponseCode() != 200) { 1109 System.out.println("INFO: " + u + " does not exist"); 1110 conn.disconnect(); 1111 } else { 1112 int osize = conn.getContentLength(); 1113 conn.disconnect(); 1110 1114 1111 conn = (HttpURLConnection) new URI(u.toString()1112 .replace("=", "%3D") /* do not URLencode whole string! */1113 .replaceFirst("/wiki/", "/w/index.php?redirect=no&title=")1114 ).toURL().openConnection();1115 conn = (HttpURLConnection) new URI(u.toString() 1116 .replace("=", "%3D") /* do not URLencode whole string! */ 1117 .replaceFirst("/wiki/", "/w/index.php?redirect=no&title=") 1118 ).toURL().openConnection(); 1115 1119 1116 /* redirect pages have different content length, but retrieving a "nonredirect"1117 * page using index.php and the direct-link method gives slightly different1118 * content lengths, so we have to be fuzzy.. (this is UGLY, recode if u know better)1119 */1120 if (Math.abs(conn.getContentLength()-osize) > 200) {1121 System.out.println("INFO: " + u + " is a mediawiki redirect");1122 conn.disconnect();1123 } else {1124 System.out.println("INFO: browsing to " + u);1125 conn.disconnect();1120 /* redirect pages have different content length, but retrieving a "nonredirect" 1121 * page using index.php and the direct-link method gives slightly different 1122 * content lengths, so we have to be fuzzy.. (this is UGLY, recode if u know better) 1123 */ 1124 if (Math.abs(conn.getContentLength()-osize) > 200) { 1125 System.out.println("INFO: " + u + " is a mediawiki redirect"); 1126 conn.disconnect(); 1127 } else { 1128 System.out.println("INFO: browsing to " + u); 1129 conn.disconnect(); 1126 1130 1127 OpenBrowser.displayUrl(u.toString()); 1128 break; 1131 OpenBrowser.displayUrl(u.toString()); 1132 break; 1133 } 1134 } 1135 } 1136 } catch (Exception e) { 1137 e.printStackTrace(); 1129 1138 } 1130 1139 } 1131 } 1140 }); 1132 1141 } catch (Exception e1) { 1133 1142 e1.printStackTrace(); 1134 1143 }
