Changeset 34086 in osm for applications/editors
- Timestamp:
- 2018-03-13T01:12:27+01:00 (7 years ago)
- Location:
- applications/editors/josm/plugins/reltoolbox
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/reltoolbox/build.xml
r33694 r34086 4 4 <property name="commit.message" value="RelToolbox: make natural sort for relation and find relation lists"/> 5 5 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 6 <property name="plugin.main.version" value="1 2840"/>6 <property name="plugin.main.version" value="13522"/> 7 7 8 8 <property name="plugin.author" value="Ilya Zverev"/> -
applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/RelationHelpAction.java
r33530 r34086 5 5 6 6 import java.awt.event.ActionEvent; 7 import java.net.HttpURLConnection;8 7 import java.net.URI; 9 import java.net.URLEncoder;10 import java.util.ArrayList;11 8 import java.util.List; 12 9 … … 16 13 import org.openstreetmap.josm.data.osm.Relation; 17 14 import org.openstreetmap.josm.gui.MainApplication; 15 import org.openstreetmap.josm.gui.dialogs.properties.HelpAction; 18 16 import org.openstreetmap.josm.tools.ImageProvider; 19 17 import org.openstreetmap.josm.tools.LanguageInfo; 20 import org.openstreetmap.josm.tools. OpenBrowser;18 import org.openstreetmap.josm.tools.Logging; 21 19 22 20 import relcontext.ChosenRelation; … … 24 22 25 23 public class RelationHelpAction extends AbstractAction implements ChosenRelationListener { 26 private ChosenRelation rel;24 private final ChosenRelation rel; 27 25 28 26 public RelationHelpAction(ChosenRelation rel) { 29 super();30 27 putValue(NAME, tr("Open relation wiki page")); 31 28 putValue(SHORT_DESCRIPTION, tr("Launch browser with wiki help for selected object")); … … 41 38 } 42 39 43 /**44 * Copypasted from {@link org.openstreetmap.josm.gui.dialogs.properties.PropertiesDialog.HelpAction}.45 */46 40 @Override 47 41 public void actionPerformed(ActionEvent e) { … … 51 45 String base = Main.pref.get("url.openstreetmap-wiki", "http://wiki.openstreetmap.org/wiki/"); 52 46 String lang = LanguageInfo.getWikiLanguagePrefix(); 53 final List<URI> uris = new ArrayList<>(); 54 String type = URLEncoder.encode(rel.get().get("type"), "UTF-8"); 55 56 if (type != null && !type.equals("")) { 57 uris.add(new URI(String.format("%s%sRelation:%s", base, lang, type))); 58 uris.add(new URI(String.format("%sRelation:%s", base, type))); 59 } 60 61 uris.add(new URI(String.format("%s%sRelations", base, lang))); 62 uris.add(new URI(String.format("%sRelations", base))); 63 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(); 83 conn.setConnectTimeout(5000); 84 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"); 91 conn.disconnect(); 92 } else { 93 System.out.println("INFO: browsing to " + u); 94 conn.disconnect(); 95 96 OpenBrowser.displayUrl(u.toString()); 97 break; 98 } 99 } 100 } 101 } catch (Exception e1) { 102 e1.printStackTrace(); 103 } 104 }); 47 final List<URI> uris = HelpAction.getRelationURIs(base, lang, rel.get()); 48 MainApplication.worker.execute(() -> HelpAction.displayHelp(uris)); 105 49 } catch (Exception e1) { 106 e1.printStackTrace();50 Logging.error(e1); 107 51 } 108 52 }
Note:
See TracChangeset
for help on using the changeset viewer.