Ignore:
Timestamp:
2017-08-26T02:16:05+02:00 (8 years ago)
Author:
donvip
Message:

update to JOSM 12663

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/RelationHelpAction.java

    r32398 r33530  
    1515import org.openstreetmap.josm.Main;
    1616import org.openstreetmap.josm.data.osm.Relation;
     17import org.openstreetmap.josm.gui.MainApplication;
    1718import org.openstreetmap.josm.tools.ImageProvider;
    1819import org.openstreetmap.josm.tools.LanguageInfo;
     
    6162            uris.add(new URI(String.format("%sRelations", base)));
    6263
    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();
    7183                            conn.setConnectTimeout(5000);
    7284
    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");
    7591                                conn.disconnect();
    7692                            } else {
    77                                 int osize = conn.getContentLength();
     93                                System.out.println("INFO: browsing to " + u);
    7894                                conn.disconnect();
    7995
    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;
    10098                            }
    10199                        }
    102                     } catch (Exception e) {
    103                         e.printStackTrace();
    104100                    }
     101                } catch (Exception e1) {
     102                    e1.printStackTrace();
    105103                }
    106104            });
Note: See TracChangeset for help on using the changeset viewer.