Fixes #2 (NFE when parsing an invalid point value)

This commit is contained in:
Patrick Gotthard 2014-04-18 21:39:58 +02:00
parent cd7a73d521
commit 8757d20686
4 changed files with 55 additions and 13 deletions

View file

@ -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);
}
}
}

View file

@ -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());

View file

@ -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);
}
}

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
<channel>
<item>
<georss:point> -</georss:point>
</item>
</channel>
</rss>