Ticket #5464: PropertiesDialog.java.patch

File PropertiesDialog.java.patch, 5.3 KB (added by cmuelle8, 15 years ago)

see #5465

  • src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

     
    1818import java.awt.event.MouseAdapter;
    1919import java.awt.event.MouseEvent;
    2020import java.net.HttpURLConnection;
     21import java.net.ProxySelector;
    2122import java.net.URI;
    2223import java.net.URLEncoder;
    2324import java.util.ArrayList;
     
    10601061            try {
    10611062                String base = new String(Main.pref.get("url.openstreetmap-wiki", "http://wiki.openstreetmap.org/wiki/"));
    10621063                String l = LanguageInfo.getWikiLanguagePrefix();
    1063                 List<URI> uris = new ArrayList<URI>();
     1064                final List<URI> uris = new ArrayList<URI>();
    10641065                int row;
    10651066                if (propertyTable.getSelectedRowCount() == 1) {
    10661067                    row = propertyTable.getSelectedRow();
     
    10961097                    uris.add(new URI(String.format("%sMap_Features", base)));
    10971098                }
    10981099
    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));
    11031107
    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();
    11101114
    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();
    11151119
    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();
     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();
    11261130
    1127                             OpenBrowser.displayUrl(u.toString());
    1128                             break;
     1131                                        OpenBrowser.displayUrl(u.toString());
     1132                                        break;
     1133                                    }
     1134                                }
     1135                            }
     1136                        } catch (Exception e) {
     1137                            e.printStackTrace();
    11291138                        }
    11301139                    }
    1131                 }
     1140                });
    11321141            } catch (Exception e1) {
    11331142                e1.printStackTrace();
    11341143            }