Changeset 31857 in osm for applications/editors/josm/plugins/wikipedia/src/org
- Timestamp:
- 2015-12-25T20:03:27+01:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/wikipedia/src/org/wikipedia
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/wikipedia/src/org/wikipedia/WikipediaApp.java
r31852 r31857 29 29 import org.openstreetmap.josm.data.osm.OsmPrimitive; 30 30 import org.openstreetmap.josm.data.osm.Tag; 31 import org.openstreetmap.josm.tools.CheckParameterUtil; 31 32 import org.openstreetmap.josm.tools.Predicate; 32 33 import org.openstreetmap.josm.tools.Utils; … … 37 38 38 39 public final class WikipediaApp { 40 41 public static Pattern WIKIDATA_PATTERN = Pattern.compile("Q\\d+"); 39 42 40 43 private WikipediaApp() { … … 201 204 } 202 205 206 static String getLabelForWikidata(String wikidataId, String preferredLanguage) { 207 try { 208 CheckParameterUtil.ensureThat(WIKIDATA_PATTERN.matcher(wikidataId).matches(), "Invalid Wikidata ID given"); 209 final String url = "https://www.wikidata.org/w/api.php" + 210 "?action=wbgetentities" + 211 "&props=labels" + 212 "&ids=" + wikidataId + 213 "&languages=" + preferredLanguage + 214 "&languagefallback=en" + 215 "&format=xml"; 216 Main.info("Wikipedia: GET " + url); 217 try (final InputStream in = Utils.openURL(new URL(url))) { 218 final Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(in); 219 final Node label = (Node) XPathFactory.newInstance().newXPath().compile("//label").evaluate(xml, XPathConstants.NODE); 220 if (label == null) { 221 return null; 222 } else { 223 return (String) XPathFactory.newInstance().newXPath().compile("./@value").evaluate(label, XPathConstants.STRING); 224 } 225 } 226 } catch (Exception ex) { 227 throw new RuntimeException(ex); 228 } 229 } 230 203 231 static Collection<WikipediaLangArticle> getInterwikiArticles(String wikipediaLang, String article) { 204 232 try { -
applications/editors/josm/plugins/wikipedia/src/org/wikipedia/WikipediaPlugin.java
r31852 r31857 21 21 if (newFrame != null) { 22 22 newFrame.addToggleDialog(new WikipediaToggleDialog()); 23 newFrame.propertiesDialog.addCustomPropertiesCellRenderer(new WikidataTagCellRenderer()); 23 24 } 24 25 }
Note:
See TracChangeset
for help on using the changeset viewer.