Changeset 14641 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2019-01-05T00:26:34+01:00 (6 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/HelpAction.java
r14208 r14641 7 7 import java.awt.event.KeyEvent; 8 8 import java.io.IOException; 9 import java.io.InputStream;10 import java.net.URL;11 9 import java.util.ArrayList; 12 10 import java.util.Arrays; … … 15 13 import java.util.Objects; 16 14 import java.util.function.IntFunction; 17 import java.util.stream.Collectors;18 15 19 16 import javax.swing.AbstractAction; … … 21 18 import javax.swing.KeyStroke; 22 19 import javax.xml.parsers.ParserConfigurationException; 23 import javax.xml.xpath.XPath;24 import javax.xml.xpath.XPathConstants;25 20 import javax.xml.xpath.XPathExpressionException; 26 import javax.xml.xpath.XPathFactory;27 21 28 22 import org.openstreetmap.josm.data.osm.IRelation; 29 23 import org.openstreetmap.josm.gui.MainApplication; 30 24 import org.openstreetmap.josm.spi.preferences.Config; 31 import org.openstreetmap.josm.tools.HttpClient;32 25 import org.openstreetmap.josm.tools.ImageProvider; 33 26 import org.openstreetmap.josm.tools.LanguageInfo; 34 27 import org.openstreetmap.josm.tools.Logging; 28 import org.openstreetmap.josm.tools.Mediawiki; 35 29 import org.openstreetmap.josm.tools.OpenBrowser; 36 30 import org.openstreetmap.josm.tools.Utils; 37 import org.openstreetmap.josm.tools.XmlUtils;38 import org.w3c.dom.Document;39 import org.w3c.dom.Node;40 31 import org.xml.sax.SAXException; 41 32 … … 164 155 public static void displayHelp(final List<String> pages) { 165 156 try { 166 // find a page that actually exists in the wiki 167 // API documentation: https://wiki.openstreetmap.org/w/api.php?action=help&modules=query 168 final URL url = new URL(Config.getUrls().getOSMWiki() + "/w/api.php?action=query&format=xml&titles=" + pages.stream() 169 .map(Utils::encodeUrl) 170 .collect(Collectors.joining("|")) 171 ); 172 final HttpClient.Response conn = HttpClient.create(url).connect(); 173 final Document document; 174 try (InputStream content = conn.getContent()) { 175 document = XmlUtils.parseSafeDOM(content); 176 } 177 conn.disconnect(); 178 final XPath xPath = XPathFactory.newInstance().newXPath(); 179 for (String page : pages) { 180 String normalized = xPath.evaluate("/api/query/normalized/n[@from='" + page + "']/@to", document); 181 if (normalized == null || normalized.isEmpty()) { 182 normalized = page; 183 } 184 final Node node = (Node) xPath.evaluate("/api/query/pages/page[@title='" + normalized + "']", document, XPathConstants.NODE); 185 if (node != null 186 && node.getAttributes().getNamedItem("missing") == null 187 && node.getAttributes().getNamedItem("invalid") == null) { 188 OpenBrowser.displayUrl(Config.getUrls().getOSMWiki() + "/wiki/" + page); 189 break; 190 } 191 } 157 new Mediawiki(Config.getUrls().getOSMWiki()) 158 .findExistingPage(pages) 159 .ifPresent(page -> OpenBrowser.displayUrl(Config.getUrls().getOSMWiki() + "/wiki/" + page)); 192 160 } catch (IOException | ParserConfigurationException | XPathExpressionException | SAXException e1) { 193 161 Logging.error(e1);
Note:
See TracChangeset
for help on using the changeset viewer.