Changeset 32611 in osm for applications/editors/josm/plugins
- Timestamp:
- 2016-07-08T19:58:24+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/wikipedia/src/org/wikipedia/WikipediaApp.java
r32610 r32611 84 84 final XPathExpression xpathLon = X_PATH.compile("@lon"); 85 85 try (final InputStream in = HttpClient.create(new URL(url)).setReasonForRequest("Wikipedia").connect().getContent()) { 86 Document doc = DOCUMENT_BUILDER.parse(in);87 NodeList nodes = (NodeList) xpathPlacemark.evaluate(doc, XPathConstants.NODESET);88 // construct WikipediaEntry for each XML element89 List<WikipediaEntry> entries = new ArrayList<>(nodes.getLength());86 final Document doc = DOCUMENT_BUILDER.parse(in); 87 final NodeList nodes = (NodeList) xpathPlacemark.evaluate(doc, XPathConstants.NODESET); 88 final List<String> names = new ArrayList<>(nodes.getLength()); 89 final List<WikipediaEntry> entries = new ArrayList<>(nodes.getLength()); 90 90 for (int i = 0; i < nodes.getLength(); i++) { 91 91 final Node node = nodes.item(i); 92 92 final String name = xpathName.evaluate(node); 93 names.add(name); 93 94 final LatLon latLon = new LatLon(( 94 95 (double) xpathLat.evaluate(node, XPathConstants.NUMBER)), 95 96 (double) xpathLon.evaluate(node, XPathConstants.NUMBER)); 96 97 if ("wikidata".equals(wikipediaLang)) { 97 entries.add(new WikidataEntry(name, latLon, getLabelForWikidata(name, Locale.getDefault())));98 entries.add(new WikidataEntry(name, latLon, null)); 98 99 } else { 99 100 entries.add(new WikipediaEntry(name, wikipediaLang, name, latLon … … 101 102 } 102 103 } 103 return entries; 104 if ("wikidata".equals(wikipediaLang)) { 105 final Map<String, String> labels = getLabelForWikidata(names, Locale.getDefault()); 106 final List<WikipediaEntry> entriesWithLabel = new ArrayList<>(nodes.getLength()); 107 for (WikipediaEntry entry : entries) { 108 entriesWithLabel.add(new WikidataEntry(entry.wikipediaArticle, entry.coordinate, labels.get(entry.wikipediaArticle))); 109 } 110 return entriesWithLabel; 111 } else { 112 return entries; 113 } 104 114 } 105 115 } catch (Exception ex) {
Note:
See TracChangeset
for help on using the changeset viewer.