Changeset 33076 in osm for applications/editors/josm/plugins
- Timestamp:
- 2016-11-18T20:00:52+01:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/wikipedia/src/org/wikipedia/WikipediaApp.java
r33075 r33076 70 70 } 71 71 72 private static HttpClient.Response connect(String url) throws IOException { 73 final HttpClient.Response response = HttpClient.create(new URL(url)).setReasonForRequest("Wikipedia").connect(); 74 if (response.getResponseCode() != 200) { 75 throw new IOException("Server responded with HTTP " + response.getResponseCode()); 76 } 77 return response; 78 } 79 72 80 public List<WikipediaEntry> getEntriesFromCoordinates(LatLon min, LatLon max) { 73 81 try { … … 80 88 + "&gsbbox=" + max.lat() + "|" + min.lon() + "|" + min.lat() + "|" + max.lon(); 81 89 // parse XML document 82 try (final InputStream in = HttpClient.create(new URL(url)).setReasonForRequest("Wikipedia").connect().getContent()) {90 try (final InputStream in = connect(url).getContent()) { 83 91 final Document doc = newDocumentBuilder().parse(in); 84 92 final List<WikipediaEntry> entries = X_PATH.evaluateNodes("//gs", doc).stream() … … 114 122 "&limit=50" + 115 123 "&format=xml"; 116 try (final InputStream in = HttpClient.create(new URL(url)).setReasonForRequest("Wikipedia").connect().getContent()) {124 try (final InputStream in = connect(url).getContent()) { 117 125 final Document xml = newDocumentBuilder().parse(in); 118 126 final List<WikidataEntry> r = X_PATH.evaluateNodes("//entity", xml).stream() … … 133 141 + "&cat=" + Utils.encodeUrl(category); 134 142 135 try (final BufferedReader reader = HttpClient.create(new URL(url)).setReasonForRequest("Wikipedia") 136 .connect().getContentReader()) { 143 try (final BufferedReader reader = connect(url).getContentReader()) { 137 144 return reader.lines() 138 145 .map(line -> new WikipediaEntry(wikipediaLang, line.trim().replace("_", " "))) … … 239 246 "&titles=" + articles.stream().map(Utils::encodeUrl).collect(Collectors.joining("|")); 240 247 final Map<String, String> r = new TreeMap<>(); 241 try (final InputStream in = HttpClient.create(new URL(url)).setReasonForRequest("Wikipedia").connect().getContent()) {248 try (final InputStream in = connect(url).getContent()) { 242 249 final Document xml = newDocumentBuilder().parse(in); 243 250 X_PATH.evaluateNodes("//entity", xml).forEach(node -> { … … 265 272 + "&pssearch=" + Utils.encodeUrl(prefix); 266 273 // parse XML document 267 try (final InputStream in = HttpClient.create(new URL(url)).setReasonForRequest("Wikipedia").connect().getContent()) {274 try (final InputStream in = connect(url).getContent()) { 268 275 final Document doc = newDocumentBuilder().parse(in); 269 276 return X_PATH.evaluateNodes("//ps/@title", doc).stream() … … 309 316 languages.add(null); 310 317 final List<WikidataEntry> r = new ArrayList<>(entries.size()); 311 try (final InputStream in = HttpClient.create(new URL(url)).setReasonForRequest("Wikipedia").connect().getContent()) {318 try (final InputStream in = connect(url).getContent()) { 312 319 final Document xml = newDocumentBuilder().parse(in); 313 320 for (final WikipediaEntry entry : entries) { … … 348 355 "&lllimit=500" + 349 356 "&format=xml"; 350 try (final InputStream in = HttpClient.create(new URL(url)).setReasonForRequest("Wikipedia").connect().getContent()) {357 try (final InputStream in = connect(url).getContent()) { 351 358 final Document xml = newDocumentBuilder().parse(in); 352 359 return X_PATH.evaluateNodes("//ll", xml).stream() … … 369 376 "&titles=" + Utils.encodeUrl(article) + 370 377 "&format=xml"; 371 try (final InputStream in = HttpClient.create(new URL(url)).setReasonForRequest("Wikipedia").connect().getContent()) {378 try (final InputStream in = connect(url).getContent()) { 372 379 final Document xml = newDocumentBuilder().parse(in); 373 380 final Node node = X_PATH.evaluateNode("//coordinates/co", xml);
Note:
See TracChangeset
for help on using the changeset viewer.