Fixing extra whitespace in GeoRSS (#315)
I fixed issue where more than one space in "<georss:point>" elements caused parsing to fail. Although most implementations of GeoRSS use one space between the coordinates, the specification technically allows for more than one whitespace character. See http://www.georss.org/simple.html for details.
This commit is contained in:
parent
48cccfb5a9
commit
b87f3293fe
4 changed files with 46 additions and 7 deletions
|
@ -51,7 +51,7 @@ public class GMLParser implements ModuleParser {
|
||||||
|
|
||||||
private static PositionList parsePosList(final Element element) {
|
private static PositionList parsePosList(final Element element) {
|
||||||
final String coordinates = element.getText();
|
final String coordinates = element.getText();
|
||||||
final String[] coord = Strings.trimToEmpty(coordinates).split(" ");
|
final String[] coord = Strings.trimToEmpty(coordinates).split("\\s+");
|
||||||
final PositionList posList = new PositionList();
|
final PositionList posList = new PositionList();
|
||||||
for (int i = 0; i < coord.length; i += 2) {
|
for (int i = 0; i < coord.length; i += 2) {
|
||||||
posList.add(Double.parseDouble(coord[i]), Double.parseDouble(coord[i + 1]));
|
posList.add(Double.parseDouble(coord[i]), Double.parseDouble(coord[i + 1]));
|
||||||
|
@ -71,7 +71,7 @@ public class GMLParser implements ModuleParser {
|
||||||
if (posElement != null) {
|
if (posElement != null) {
|
||||||
geoRSSModule = new GMLModuleImpl();
|
geoRSSModule = new GMLModuleImpl();
|
||||||
final String coordinates = posElement.getText();
|
final String coordinates = posElement.getText();
|
||||||
final String[] coord = Strings.trimToEmpty(coordinates).split(" ");
|
final String[] coord = Strings.trimToEmpty(coordinates).split("\\s+");
|
||||||
final Position pos = new Position(Double.parseDouble(coord[0]), Double.parseDouble(coord[1]));
|
final Position pos = new Position(Double.parseDouble(coord[0]), Double.parseDouble(coord[1]));
|
||||||
geoRSSModule.setGeometry(new Point(pos));
|
geoRSSModule.setGeometry(new Point(pos));
|
||||||
}
|
}
|
||||||
|
@ -129,9 +129,9 @@ public class GMLParser implements ModuleParser {
|
||||||
if (lowerElement != null && upperElement != null) {
|
if (lowerElement != null && upperElement != null) {
|
||||||
geoRSSModule = new GMLModuleImpl();
|
geoRSSModule = new GMLModuleImpl();
|
||||||
final String lowerCoordinates = lowerElement.getText();
|
final String lowerCoordinates = lowerElement.getText();
|
||||||
final String[] lowerCoord = Strings.trimToEmpty(lowerCoordinates).split(" ");
|
final String[] lowerCoord = Strings.trimToEmpty(lowerCoordinates).split("\\s+");
|
||||||
final String upperCoordinates = upperElement.getText();
|
final String upperCoordinates = upperElement.getText();
|
||||||
final String[] upperCoord = Strings.trimToEmpty(upperCoordinates).split(" ");
|
final String[] upperCoord = Strings.trimToEmpty(upperCoordinates).split("\\s+");
|
||||||
final Envelope envelope = new Envelope(Double.parseDouble(lowerCoord[0]), Double.parseDouble(lowerCoord[1]), Double.parseDouble(upperCoord[0]),
|
final Envelope envelope = new Envelope(Double.parseDouble(lowerCoord[0]), Double.parseDouble(lowerCoord[1]), Double.parseDouble(upperCoord[0]),
|
||||||
Double.parseDouble(upperCoord[1]));
|
Double.parseDouble(upperCoord[1]));
|
||||||
geoRSSModule.setGeometry(envelope);
|
geoRSSModule.setGeometry(envelope);
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class SimpleParser implements ModuleParser {
|
||||||
if (coordinates != null) {
|
if (coordinates != null) {
|
||||||
|
|
||||||
posList = new PositionList();
|
posList = new PositionList();
|
||||||
final String[] coord = coordinates.split(" ");
|
final String[] coord = coordinates.split("\\s+");
|
||||||
for (int i = 0; i < coord.length; i += 2) {
|
for (int i = 0; i < coord.length; i += 2) {
|
||||||
final double latitude = Double.parseDouble(coord[i]);
|
final double latitude = Double.parseDouble(coord[i]);
|
||||||
final double longitude = Double.parseDouble(coord[i + 1]);
|
final double longitude = Double.parseDouble(coord[i + 1]);
|
||||||
|
@ -83,7 +83,7 @@ public class SimpleParser implements ModuleParser {
|
||||||
final String coordinates = Strings.trimToNull(pointElement.getText());
|
final String coordinates = Strings.trimToNull(pointElement.getText());
|
||||||
if (coordinates != null) {
|
if (coordinates != null) {
|
||||||
|
|
||||||
final String[] coord = coordinates.split(" ");
|
final String[] coord = coordinates.split("\\s+");
|
||||||
|
|
||||||
if (coord.length == 2) {
|
if (coord.length == 2) {
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ public class SimpleParser implements ModuleParser {
|
||||||
final String coordinates = Strings.trimToNull(boxElement.getText());
|
final String coordinates = Strings.trimToNull(boxElement.getText());
|
||||||
if (coordinates != null) {
|
if (coordinates != null) {
|
||||||
|
|
||||||
final String[] coord = coordinates.split(" ");
|
final String[] coord = coordinates.split("\\s+");
|
||||||
final double bottom = Double.parseDouble(coord[0]);
|
final double bottom = Double.parseDouble(coord[0]);
|
||||||
final double left = Double.parseDouble(coord[1]);
|
final double left = Double.parseDouble(coord[1]);
|
||||||
final double top = Double.parseDouble(coord[2]);
|
final double top = Double.parseDouble(coord[2]);
|
||||||
|
|
|
@ -279,6 +279,13 @@ public class GeoRSSModuleTest extends AbstractTestCase {
|
||||||
getSyndFeed("org/rometools/feed/module/georss/issue-02.xml");
|
getSyndFeed("org/rometools/feed/module/georss/issue-02.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testDoubleSpacePointValue() throws Exception {
|
||||||
|
final Double[] lat = { 31.7666667, 31.7666667, 31.7666667 };
|
||||||
|
final Double[] lng = { 35.2333333, 35.2333333, 35.2333333 };
|
||||||
|
|
||||||
|
assertTestFile("georss-double-space-issue.xml", lat, lng);
|
||||||
|
}
|
||||||
|
|
||||||
private SyndFeed getSyndFeed(final String filePath) throws IOException, FeedException {
|
private SyndFeed getSyndFeed(final String filePath) throws IOException, FeedException {
|
||||||
final String fullPath = getTestFile(filePath);
|
final String fullPath = getTestFile(filePath);
|
||||||
final File file = new File(fullPath);
|
final File file = new File(fullPath);
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<rss version="2.0" xmlns:georss="http://www.georss.org/georss">
|
||||||
|
<channel>
|
||||||
|
<title>GeoNames.org recent changes</title>
|
||||||
|
<link>http://www.geonames.org/recent-changes.html</link>
|
||||||
|
<description>50 most recent modifications</description>
|
||||||
|
<item>
|
||||||
|
<title>Jerusalem</title>
|
||||||
|
<link>http://www.geonames.org/maps/geonameId=281184</link>
|
||||||
|
<guid>http://www.geonames.org/maps/geonameId=281184&revision=80</guid>
|
||||||
|
<description>delete name :la,Hierusalem </description>
|
||||||
|
<pubDate>Mon, 03 Apr 2006 10:35:16 +0200</pubDate>
|
||||||
|
<georss:point>31.7666667 35.2333333</georss:point>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<title>Jerusalem</title>
|
||||||
|
<link>http://www.geonames.org/maps/geonameId=281184</link>
|
||||||
|
<guid>http://www.geonames.org/maps/geonameId=281184&revision=72</guid>
|
||||||
|
<description>add name :he,Ir Ha-Qodesh</description>
|
||||||
|
<pubDate>Mon, 03 Apr 2006 10:32:24 +0200</pubDate>
|
||||||
|
<georss:point>31.7666667 35.2333333</georss:point>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<title>Jerusalem</title>
|
||||||
|
<link>http://www.geonames.org/maps/geonameId=281184</link>
|
||||||
|
<guid>http://www.geonames.org/maps/geonameId=281184&revision=31</guid>
|
||||||
|
<description>update name :grc,Μωριας</description>
|
||||||
|
<pubDate>Mon, 03 Apr 2006 10:17:41 +0200</pubDate>
|
||||||
|
<georss:point>31.7666667 35.2333333</georss:point>
|
||||||
|
</item>
|
||||||
|
</channel>
|
||||||
|
</rss>
|
Loading…
Reference in a new issue