diff --git a/src/main/java/org/rometools/feed/module/georss/SimpleParser.java b/src/main/java/org/rometools/feed/module/georss/SimpleParser.java index 9741fa7..9053a49 100644 --- a/src/main/java/org/rometools/feed/module/georss/SimpleParser.java +++ b/src/main/java/org/rometools/feed/module/georss/SimpleParser.java @@ -27,6 +27,7 @@ import org.rometools.feed.module.georss.geometries.Polygon; import org.rometools.feed.module.georss.geometries.Position; import org.rometools.feed.module.georss.geometries.PositionList; +import com.rometools.utils.Doubles; import com.rometools.utils.Strings; import com.sun.syndication.feed.module.Module; import com.sun.syndication.io.ModuleParser; @@ -87,15 +88,24 @@ public class SimpleParser implements ModuleParser { if (coordinates != null) { final String[] coord = coordinates.split(" "); - final double latitude = Double.parseDouble(coord[0]); - final double longitude = Double.parseDouble(coord[1]); - final Position pos = new Position(latitude, longitude); + if (coord.length == 2) { - final Point point = new Point(pos); + final Double latitude = Doubles.parse(coord[0]); + final Double longitude = Doubles.parse(coord[1]); - geoRSSModule = new SimpleModuleImpl(); - geoRSSModule.setGeometry(point); + if (latitude != null && longitude != null) { + + final Position pos = new Position(latitude, longitude); + + final Point point = new Point(pos); + + geoRSSModule = new SimpleModuleImpl(); + geoRSSModule.setGeometry(point); + + } + + } } diff --git a/src/test/java/org/rometools/feed/module/base/io/GoogleBaseParserTest.java b/src/test/java/org/rometools/feed/module/base/io/GoogleBaseParserTest.java index de0acdb..45c5c57 100644 --- a/src/test/java/org/rometools/feed/module/base/io/GoogleBaseParserTest.java +++ b/src/test/java/org/rometools/feed/module/base/io/GoogleBaseParserTest.java @@ -299,7 +299,7 @@ public class GoogleBaseParserTest extends AbstractTestCase { this.assertEquals("Industriy", new String[] { "Internet" }, module.getJobIndustries()); Assert.assertEquals("Employer", "Google, Inc", module.getEmployer()); this.assertEquals("Job Function", new String[] { "Google Coordinator" }, module.getJobFunctions()); - LOG.debug("{}", module.getJobTypes()); + LOG.debug("{}", new Object[] { module.getJobTypes() }); this.assertEquals("Job Type", new String[] { "full-time" }, module.getJobTypes()); Assert.assertEquals("Currency", CurrencyEnumeration.USD, module.getCurrency()); Assert.assertEquals("Salary", new Float(40000), module.getSalary()); diff --git a/src/test/java/org/rometools/feed/module/georss/GeoRSSModuleTest.java b/src/test/java/org/rometools/feed/module/georss/GeoRSSModuleTest.java index 1cc9988..67bb14f 100644 --- a/src/test/java/org/rometools/feed/module/georss/GeoRSSModuleTest.java +++ b/src/test/java/org/rometools/feed/module/georss/GeoRSSModuleTest.java @@ -19,14 +19,14 @@ package org.rometools.feed.module.georss; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; +import java.io.IOException; import java.io.InputStream; import java.io.StringWriter; import java.util.ArrayList; import java.util.Date; import java.util.List; -import junit.framework.TestCase; - +import org.rometools.feed.module.AbstractTestCase; import org.rometools.feed.module.georss.geometries.LineString; import org.rometools.feed.module.georss.geometries.Position; import org.rometools.feed.module.georss.geometries.PositionList; @@ -37,21 +37,26 @@ import com.sun.syndication.feed.synd.SyndEntry; import com.sun.syndication.feed.synd.SyndEntryImpl; import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.feed.synd.SyndFeedImpl; +import com.sun.syndication.io.FeedException; import com.sun.syndication.io.SyndFeedInput; import com.sun.syndication.io.SyndFeedOutput; import com.sun.syndication.io.XmlReader; /** * tests for geo-rss module. - * + * */ -public class GeoRSSModuleTest extends TestCase { +public class GeoRSSModuleTest extends AbstractTestCase { + + public GeoRSSModuleTest(final String testName) { + super(testName); + } private static final double DELTA = 0.00001; /** * compares expected lat/lng values with acutal values read from feed. - * + * * @param fileName a file in the src/data directory * @param expectedLat array of expected latitude values * @param expectedLng array of expected longitude values @@ -63,7 +68,7 @@ public class GeoRSSModuleTest extends TestCase { /** * test expected latitude and longitude values in items of test file. - * + * * @param in testfeed * @param expectedLat expected latitude values * @param expectedLng expected longitude values @@ -258,4 +263,23 @@ public class GeoRSSModuleTest extends TestCase { } } + /** + * Tests whether a feed with invalid point values can be parsed + * (https://github.com/rometools/rome-modules/issues/02). + * + * @throws IOException if file not found or not accessible + * @throws FeedException when the feed can't be parsed + * + */ + public void testParseInvalidPointValue() throws IOException, FeedException { + // only tests whether file can be parsed (there should be no exception) + getSyndFeed("org/rometools/feed/module/georss/issue-02.xml"); + } + + private SyndFeed getSyndFeed(final String filePath) throws IOException, FeedException { + final String fullPath = getTestFile(filePath); + final File file = new File(fullPath); + return new SyndFeedInput().build(file); + } + } diff --git a/src/test/resources/org/rometools/feed/module/georss/issue-02.xml b/src/test/resources/org/rometools/feed/module/georss/issue-02.xml new file mode 100644 index 0000000..50761f3 --- /dev/null +++ b/src/test/resources/org/rometools/feed/module/georss/issue-02.xml @@ -0,0 +1,8 @@ + + + + + - + + + \ No newline at end of file