Changeset 32670 in osm for applications/editors/josm/plugins
- Timestamp:
- 2016-07-17T19:01:53+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/wikipedia
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/wikipedia/src/org/wikipedia/WikidataItemSearchDialog.java
r32634 r32670 11 11 import java.util.Collection; 12 12 import java.util.Collections; 13 import java.util.HashSet;14 13 import java.util.List; 15 14 import java.util.Locale; 16 15 import java.util.TreeSet; 17 import java.util.concurrent.Executors;18 16 import java.util.concurrent.TimeUnit; 19 17 … … 31 29 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionListItem; 32 30 import org.openstreetmap.josm.gui.util.GuiHelper; 33 import org.openstreetmap.josm.gui.widgets.SearchTextResultListPanel;34 31 import org.openstreetmap.josm.tools.GBC; 35 32 import org.openstreetmap.josm.tools.Predicate; … … 120 117 } 121 118 122 private static class Selector extends SearchTextResultListPanel<WikipediaApp.WikidataEntry> { 123 124 final Debouncer debouncer = new Debouncer( 125 Executors.newSingleThreadScheduledExecutor(Utils.newThreadFactory("wikidata-search-%d", Thread.NORM_PRIORITY))); 119 private static class Selector extends WikiSearchTextResultListPanel<WikipediaApp.WikidataEntry> { 126 120 127 121 Selector() { … … 135 129 } 136 130 }); 137 }138 139 public WikipediaApp.WikidataEntry getSelectedItem() {140 final WikipediaApp.WikidataEntry selected = lsResult.getSelectedValue();141 if (selected != null) {142 return selected;143 } else if (!lsResultModel.isEmpty()) {144 return lsResultModel.getElementAt(0);145 } else {146 return null;147 }148 131 } 149 132 -
applications/editors/josm/plugins/wikipedia/src/org/wikipedia/WikipediaApp.java
r32654 r32670 264 264 } 265 265 return r; 266 } catch (Exception ex) { 267 throw new RuntimeException(ex); 268 } 269 } 270 271 static List<String> getCategoriesForPrefix(final String wikipediaLang, final String prefix) { 272 try { 273 final String url = getSiteUrl(wikipediaLang) + "/w/api.php" 274 + "?action=query" 275 + "&list=prefixsearch" 276 + "&format=xml" 277 + "&psnamespace=14" 278 + "&pslimit=50" 279 + "&pssearch=" + Utils.encodeUrl(prefix); 280 // parse XML document 281 try (final InputStream in = HttpClient.create(new URL(url)).setReasonForRequest("Wikipedia").connect().getContent()) { 282 final Document doc = DOCUMENT_BUILDER.parse(in); 283 final NodeList nodes = (NodeList) X_PATH.compile("//ps/@title").evaluate(doc, XPathConstants.NODESET); 284 final List<String> categories = new ArrayList<>(nodes.getLength()); 285 for (int i = 0; i < nodes.getLength(); i++) { 286 final Node node = nodes.item(i); 287 final String value = node.getNodeValue(); 288 categories.add(value.contains(":") ? value.split(":", 2)[1] : value); 289 } 290 return categories; 291 } 266 292 } catch (Exception ex) { 267 293 throw new RuntimeException(ex); -
applications/editors/josm/plugins/wikipedia/src/org/wikipedia/WikipediaToggleDialog.java
r32625 r32670 205 205 @Override 206 206 public void actionPerformed(ActionEvent e) { 207 final String category = JOptionPane.showInputDialog( 208 Main.parent, 209 tr("Enter the Wikipedia category")); 207 final WikipediaCategorySearchDialog categorySearchDialog = WikipediaCategorySearchDialog.getInstance(); 208 categorySearchDialog.showDialog(); 209 if (categorySearchDialog.getValue() != 1) { 210 return; 211 } 212 final String category = categorySearchDialog.getCategory(); 210 213 if (category == null) { 211 214 return; -
applications/editors/josm/plugins/wikipedia/test/unit/org/wikipedia/WikipediaAppTest.java
r32626 r32670 6 6 import org.openstreetmap.josm.data.coor.LatLon; 7 7 import org.openstreetmap.josm.tools.Predicate; 8 import org.openstreetmap.josm.tools.Predicates; 8 9 import org.openstreetmap.josm.tools.Utils; 9 10 import org.wikipedia.WikipediaApp.WikipediaEntry; … … 214 215 assertThat(entry3.getWiwosmStatus(), is(false)); 215 216 } 217 218 @Test 219 public void testCategoriesForPrefix() throws Exception { 220 final List<String> categories = WikipediaApp.getCategoriesForPrefix("de", "Gemeinde in Öster"); 221 assertTrue(Utils.exists(categories, Predicates.equalTo("Gemeinde in Österreich"))); 222 } 216 223 }
Note:
See TracChangeset
for help on using the changeset viewer.