Changeset 3592 in josm for trunk/src/org
- Timestamp:
- 2010-10-05T20:34:31+02:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
r3529 r3592 1059 1059 public void actionPerformed(ActionEvent e) { 1060 1060 try { 1061 String base = new String(Main.pref.get("url.openstreetmap-wiki", "http://wiki.openstreetmap.org/wiki/"));1062 String l = LanguageInfo.getWikiLanguagePrefix();1063 List<URI> uris = new ArrayList<URI>();1061 String base = Main.pref.get("url.openstreetmap-wiki", "http://wiki.openstreetmap.org/wiki/"); 1062 String lang = LanguageInfo.getWikiLanguagePrefix(); 1063 final List<URI> uris = new ArrayList<URI>(); 1064 1064 int row; 1065 1065 if (propertyTable.getSelectedRowCount() == 1) { 1066 1066 row = propertyTable.getSelectedRow(); 1067 1067 String key = URLEncoder.encode(propertyData.getValueAt(row, 0).toString(), "UTF-8"); 1068 @SuppressWarnings("unchecked")1069 1068 String val = URLEncoder.encode( 1070 1069 ((Map<String,Integer>)propertyData.getValueAt(row, 1)) … … 1072 1071 ); 1073 1072 1074 uris.add(new URI(String.format("%s%sTag:%s=%s", base, l , key, val)));1073 uris.add(new URI(String.format("%s%sTag:%s=%s", base, lang, key, val))); 1075 1074 uris.add(new URI(String.format("%sTag:%s=%s", base, key, val))); 1076 uris.add(new URI(String.format("%s%sKey:%s", base, l , key)));1075 uris.add(new URI(String.format("%s%sKey:%s", base, lang, key))); 1077 1076 uris.add(new URI(String.format("%sKey:%s", base, key))); 1078 uris.add(new URI(String.format("%s%sMap_Features", base, l )));1077 uris.add(new URI(String.format("%s%sMap_Features", base, lang))); 1079 1078 uris.add(new URI(String.format("%sMap_Features", base))); 1080 1079 } else if (membershipTable.getSelectedRowCount() == 1) { … … 1085 1084 1086 1085 if (type != null && !type.equals("")) { 1087 uris.add(new URI(String.format("%s%sRelation:%s", base, l , type)));1086 uris.add(new URI(String.format("%s%sRelation:%s", base, lang, type))); 1088 1087 uris.add(new URI(String.format("%sRelation:%s", base, type))); 1089 1088 } 1090 1089 1091 uris.add(new URI(String.format("%s%sRelations", base, l )));1090 uris.add(new URI(String.format("%s%sRelations", base, lang))); 1092 1091 uris.add(new URI(String.format("%sRelations", base))); 1093 1092 } else { 1094 1093 // give the generic help page, if more than one element is selected 1095 uris.add(new URI(String.format("%s%sMap_Features", base, l )));1094 uris.add(new URI(String.format("%s%sMap_Features", base, lang))); 1096 1095 uris.add(new URI(String.format("%sMap_Features", base))); 1097 1096 } 1098 1097 1099 // find a page that actually exists in the wiki 1100 HttpURLConnection conn; 1101 for(URI u : uris) { 1102 conn = (HttpURLConnection) u.toURL().openConnection(); 1103 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(); 1110 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 1116 /* redirect pages have different content length, but retrieving a "nonredirect" 1117 * page using index.php and the direct-link method gives slightly different 1118 * 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(); 1126 1127 OpenBrowser.displayUrl(u.toString()); 1128 break; 1098 Main.worker.execute(new Runnable(){ 1099 public void run() { 1100 try { 1101 // find a page that actually exists in the wiki 1102 HttpURLConnection conn; 1103 for (URI u : uris) { 1104 conn = (HttpURLConnection) u.toURL().openConnection(); 1105 conn.setConnectTimeout(5000); 1106 1107 if (conn.getResponseCode() != 200) { 1108 System.out.println("INFO: " + u + " does not exist"); 1109 conn.disconnect(); 1110 } else { 1111 int osize = conn.getContentLength(); 1112 conn.disconnect(); 1113 1114 conn = (HttpURLConnection) new URI(u.toString() 1115 .replace("=", "%3D") /* do not URLencode whole string! */ 1116 .replaceFirst("/wiki/", "/w/index.php?redirect=no&title=") 1117 ).toURL().openConnection(); 1118 conn.setConnectTimeout(5000); 1119 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(); 1130 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();
Note:
See TracChangeset
for help on using the changeset viewer.