diff --git a/plugins/wikipedia/src/org/wikipedia/WikipediaApp.java b/plugins/wikipedia/src/org/wikipedia/WikipediaApp.java
index 77bc39b..ea8149a 100644
a
|
b
|
|
2 | 2 | package org.wikipedia; |
3 | 3 | |
4 | 4 | import java.io.IOException; |
| 5 | import java.io.InputStream; |
5 | 6 | import java.io.OutputStreamWriter; |
6 | 7 | import java.io.UnsupportedEncodingException; |
7 | 8 | import java.net.URL; |
… |
… |
public final class WikipediaApp {
|
45 | 46 | final String url = "http://toolserver.org/~kolossos/geoworld/marks.php?" |
46 | 47 | + "bbox=" + bbox + "&LANG=" + wikipediaLang; |
47 | 48 | System.out.println("Wikipedia: GET " + url); |
| 49 | return getEntriesFromCoordinates(new URL(url).openStream()); |
| 50 | } catch (Exception ex) { |
| 51 | throw new RuntimeException(ex); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | static List<WikipediaEntry> getEntriesFromCoordinates(InputStream in) { |
| 56 | try { |
48 | 57 | // parse XML document |
49 | 58 | final XPathExpression xpathPlacemark = XPathFactory.newInstance().newXPath().compile("//Placemark"); |
50 | 59 | final XPathExpression xpathName = XPathFactory.newInstance().newXPath().compile("name/text()"); |
51 | 60 | final XPathExpression xpathCoord = XPathFactory.newInstance().newXPath().compile("Point/coordinates/text()"); |
52 | 61 | final XPathExpression xpathDescr = XPathFactory.newInstance().newXPath().compile("description"); |
53 | | Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new URL(url).openStream()); |
| 62 | Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(in); |
54 | 63 | NodeList nodes = (NodeList) xpathPlacemark.evaluate(doc, XPathConstants.NODESET); |
55 | 64 | // construct WikipediaEntry for each XML element |
56 | 65 | List<WikipediaEntry> entries = new ArrayList<WikipediaEntry>(nodes.getLength()); |
… |
… |
public final class WikipediaApp {
|
60 | 69 | continue; |
61 | 70 | } |
62 | 71 | final String name = xpathName.evaluate(nodes.item(i)); |
63 | | final String descr = xpathDescr.evaluate(nodes.item(i)); |
| 72 | final String descr = xpathDescr.evaluate(nodes.item(i)).replace("%26amp%3B", "&"); |
64 | 73 | entries.add(new WikipediaEntry(name, descr, |
65 | 74 | new LatLon(Double.parseDouble(coord[1]), Double.parseDouble(coord[0])))); |
66 | 75 | } |
diff --git a/plugins/wikipedia/test/org/wikipedia/WikipediaAppTest.java b/plugins/wikipedia/test/org/wikipedia/WikipediaAppTest.java
index 1b049e5..da3b479 100644
a
|
b
|
import org.openstreetmap.josm.tools.Utils;
|
7 | 7 | import org.wikipedia.WikipediaApp.WikipediaEntry; |
8 | 8 | import org.wikipedia.WikipediaApp.WikipediaLangArticle; |
9 | 9 | |
| 10 | import java.io.ByteArrayInputStream; |
| 11 | import java.io.StringBufferInputStream; |
| 12 | import java.io.StringReader; |
10 | 13 | import java.util.Arrays; |
11 | 14 | import java.util.Collection; |
12 | 15 | import java.util.List; |
… |
… |
public class WikipediaAppTest {
|
125 | 128 | } |
126 | 129 | })); |
127 | 130 | } |
| 131 | |
| 132 | @Test |
| 133 | public void testTicket8491() throws Exception { |
| 134 | final String kml = "<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n" + |
| 135 | "<Document>\n" + |
| 136 | "<Placemark><name>Sternheim & Emanuel</name> <visibility>1</visibility> <description><![CDATA[ <a target=\"_blank\" href=\"//de.wikipedia.org/wiki/Sternheim%20%26amp%3B%20Emanuel\">de.Wikipedia</a><br><div style=\" padding-top: 0.5em; padding-left: 0.5em; width:190px;height:250px; border:10px;\" > <img alt=\"1886_Stammhaus_Sternheim_&_Emanuel_Große_Packhofstraße_44_Hannover.jpg\" src=\"//upload.wikimedia.org/wikipedia/commons/thumb/9/95/1886_Stammhaus_Sternheim_&_Emanuel_Große_Packhofstraße_44_Hannover.jpg/180px-1886_Stammhaus_Sternheim_&_Emanuel_Große_Packhofstraße_44_Hannover.jpg\"></a></div><br><small>Source: de<br> style: landmark </small>]]></description> <styleUrl>#landmark</styleUrl> <Point><coordinates>9.736904,52.373235,0</coordinates></Point></Placemark>\n" + |
| 137 | "</Document>\n" + |
| 138 | "</kml>\n"; |
| 139 | final List<WikipediaEntry> entries = WikipediaApp.getEntriesFromCoordinates(new ByteArrayInputStream(kml.getBytes(Utils.UTF_8))); |
| 140 | assertThat(entries.get(0).wikipediaArticle, is("Sternheim & Emanuel")); |
| 141 | } |
128 | 142 | } |