Changeset 32829 in osm for applications/editors/josm/plugins/wikipedia
- Timestamp:
- 2016-08-18T07:21:04+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/wikipedia
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/wikipedia/src/org/wikipedia/WikidataTagCellRenderer.java
r32749 r32829 24 24 public class WikidataTagCellRenderer extends DefaultTableCellRenderer { 25 25 26 privatefinal Map<String, CompletableFuture<String>> labelCache = new ConcurrentHashMap<>();26 final Map<String, CompletableFuture<String>> labelCache = new ConcurrentHashMap<>(); 27 27 28 28 @Override -
applications/editors/josm/plugins/wikipedia/src/org/wikipedia/WikipediaApp.java
r32719 r32829 43 43 44 44 public static final Pattern WIKIDATA_PATTERN = Pattern.compile("Q\\d+"); 45 private static final DocumentBuilder DOCUMENT_BUILDER = newDocumentBuilder();46 45 private static final XPath X_PATH = XPath.getInstance(); 47 46 … … 76 75 // parse XML document 77 76 try (final InputStream in = HttpClient.create(new URL(url)).setReasonForRequest("Wikipedia").connect().getContent()) { 78 final Document doc = DOCUMENT_BUILDER.parse(in);77 final Document doc = newDocumentBuilder().parse(in); 79 78 final List<WikipediaEntry> entries = X_PATH.evaluateNodes("//gs", doc).stream() 80 79 .map(node -> { … … 110 109 "&format=xml"; 111 110 try (final InputStream in = HttpClient.create(new URL(url)).setReasonForRequest("Wikipedia").connect().getContent()) { 112 final Document xml = DOCUMENT_BUILDER.parse(in);111 final Document xml = newDocumentBuilder().parse(in); 113 112 final List<WikidataEntry> r = X_PATH.evaluateNodes("//entity", xml).stream() 114 113 .map(node -> new WikidataEntry(X_PATH.evaluateString("@id", node), null, null, null)) … … 213 212 final Map<String, String> r = new TreeMap<>(); 214 213 try (final InputStream in = HttpClient.create(new URL(url)).setReasonForRequest("Wikipedia").connect().getContent()) { 215 final Document xml = DOCUMENT_BUILDER.parse(in);214 final Document xml = newDocumentBuilder().parse(in); 216 215 X_PATH.evaluateNodes("//entity", xml).forEach(node -> { 217 216 final String wikidata = X_PATH.evaluateString("./@id", node); … … 237 236 // parse XML document 238 237 try (final InputStream in = HttpClient.create(new URL(url)).setReasonForRequest("Wikipedia").connect().getContent()) { 239 final Document doc = DOCUMENT_BUILDER.parse(in);238 final Document doc = newDocumentBuilder().parse(in); 240 239 return X_PATH.evaluateNodes("//ps/@title", doc).stream() 241 240 .map(Node::getNodeValue) … … 281 280 final List<WikidataEntry> r = new ArrayList<>(entries.size()); 282 281 try (final InputStream in = HttpClient.create(new URL(url)).setReasonForRequest("Wikipedia").connect().getContent()) { 283 final Document xml = DOCUMENT_BUILDER.parse(in);282 final Document xml = newDocumentBuilder().parse(in); 284 283 for (final WikipediaEntry entry : entries) { 285 284 final Node entity = X_PATH.evaluateNode("//entity[@id='" + entry.wikipediaArticle + "']", xml); 285 if (entity == null) { 286 continue; 287 } 286 288 r.add(new WikidataEntry( 287 289 entry.wikipediaArticle, … … 317 319 "&format=xml"; 318 320 try (final InputStream in = HttpClient.create(new URL(url)).setReasonForRequest("Wikipedia").connect().getContent()) { 319 final Document xml = DOCUMENT_BUILDER.parse(in);321 final Document xml = newDocumentBuilder().parse(in); 320 322 return X_PATH.evaluateNodes("//ll", xml).stream() 321 323 .map(node -> { … … 338 340 "&format=xml"; 339 341 try (final InputStream in = HttpClient.create(new URL(url)).setReasonForRequest("Wikipedia").connect().getContent()) { 340 final Document xml = DOCUMENT_BUILDER.parse(in);342 final Document xml = newDocumentBuilder().parse(in); 341 343 final Node node = X_PATH.evaluateNode("//coordinates/co", xml); 342 344 if (node == null) { -
applications/editors/josm/plugins/wikipedia/test/unit/org/wikipedia/WikidataTagCellRendererTest.java
r32744 r32829 27 27 final WikidataTagCellRenderer renderer = new WikidataTagCellRenderer(); 28 28 renderer.renderValues(ids, new JTable(), new JLabel()); 29 Main.worker.submit(new Runnable() { 30 @Override 31 public void run() { 32 } 33 }).get(); // wait for labels to be fetched 29 for (String id : ids) { 30 // wait for labels to be fetched 31 renderer.labelCache.get(id).get(); 32 } 34 33 final JLabel label = renderer.renderValues(ids, new JTable(), new JLabel()); 35 34 assertNotNull(label);
Note:
See TracChangeset
for help on using the changeset viewer.