diff --git a/src/main/java/org/rometools/feed/module/yahooweather/io/WeatherModuleGenerator.java b/src/main/java/org/rometools/feed/module/yahooweather/io/WeatherModuleGenerator.java index 6d7201d..ce56033 100644 --- a/src/main/java/org/rometools/feed/module/yahooweather/io/WeatherModuleGenerator.java +++ b/src/main/java/org/rometools/feed/module/yahooweather/io/WeatherModuleGenerator.java @@ -39,6 +39,7 @@ package org.rometools.feed.module.yahooweather.io; import java.text.SimpleDateFormat; import java.util.HashSet; +import java.util.Locale; import java.util.Set; import org.jdom2.Element; @@ -58,11 +59,11 @@ import com.sun.syndication.io.ModuleGenerator; */ public class WeatherModuleGenerator implements ModuleGenerator { private static final Namespace NS = Namespace.getNamespace("yweather", YWeatherModule.URI); - private static final SimpleDateFormat TIME_ONLY = new SimpleDateFormat("h:mm a"); - private static final SimpleDateFormat LONG_DATE = new SimpleDateFormat("EEE, d MMM yyyy h:mm a zzz"); - private static final SimpleDateFormat SHORT_DATE = new SimpleDateFormat("d MMM yyyy"); + private static final SimpleDateFormat TIME_ONLY = new SimpleDateFormat("h:mm a", Locale.US); + private static final SimpleDateFormat LONG_DATE = new SimpleDateFormat("EEE, d MMM yyyy h:mm a zzz", Locale.US); + private static final SimpleDateFormat SHORT_DATE = new SimpleDateFormat("d MMM yyyy", Locale.US); - /** Creates a new instance of SlashModuleGenerator */ + /** Creates a new instance of SlashModuleGenerator. */ public WeatherModuleGenerator() { } diff --git a/src/main/java/org/rometools/feed/module/yahooweather/io/WeatherModuleParser.java b/src/main/java/org/rometools/feed/module/yahooweather/io/WeatherModuleParser.java index 9efa1b9..890e358 100644 --- a/src/main/java/org/rometools/feed/module/yahooweather/io/WeatherModuleParser.java +++ b/src/main/java/org/rometools/feed/module/yahooweather/io/WeatherModuleParser.java @@ -69,12 +69,7 @@ import com.sun.syndication.io.ModuleParser; * @author Robert "kebernet" Cooper */ public class WeatherModuleParser implements ModuleParser { - private static final Logger LOG = LoggerFactory.getLogger(WeatherModuleParser.class); - - private static final SimpleDateFormat TIME_ONLY = new SimpleDateFormat("h:mm a"); - private static final SimpleDateFormat LONG_DATE = new SimpleDateFormat("EEE, d MMM yyyy h:mm a zzz"); - private static final SimpleDateFormat SHORT_DATE = new SimpleDateFormat("d MMM yyyy"); private static final Namespace NS = Namespace.getNamespace(YWeatherModule.URI); @Override @@ -129,8 +124,9 @@ public class WeatherModuleParser implements ModuleParser { if (astronomy != null) { try { - final Astronomy a = new Astronomy(TIME_ONLY.parse(astronomy.getAttributeValue("sunrise").replaceAll("am", "AM").replaceAll("pm", "PM")), - TIME_ONLY.parse(astronomy.getAttributeValue("sunset").replaceAll("am", "AM").replaceAll("pm", "PM"))); + final SimpleDateFormat timeFormat = new SimpleDateFormat("h:mm a", locale); + final Astronomy a = new Astronomy(timeFormat.parse(astronomy.getAttributeValue("sunrise").replaceAll("am", "AM").replaceAll("pm", "PM")), + timeFormat.parse(astronomy.getAttributeValue("sunset").replaceAll("am", "AM").replaceAll("pm", "PM"))); module.setAstronomy(a); } catch (final ParseException pe) { LOG.warn("ParseException processing tag.", pe); @@ -141,8 +137,9 @@ public class WeatherModuleParser implements ModuleParser { if (condition != null) { try { + final SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, d MMM yyyy h:mm a zzz", locale); final Condition c = new Condition(condition.getAttributeValue("text"), ConditionCode.fromCode(Integer.parseInt(condition - .getAttributeValue("code"))), Integer.parseInt(condition.getAttributeValue("temp")), LONG_DATE.parse(condition + .getAttributeValue("code"))), Integer.parseInt(condition.getAttributeValue("temp")), dateFormat.parse(condition .getAttributeValue("date").replaceAll("pm", "PM").replaceAll("am", "AM"))); module.setCondition(c); } catch (final NumberFormatException nfe) { @@ -158,11 +155,12 @@ public class WeatherModuleParser implements ModuleParser { final Forecast[] f = new Forecast[forecasts.size()]; int i = 0; + final SimpleDateFormat dateFormat = new SimpleDateFormat("d MMM yyyy", locale); for (final Iterator it = forecasts.iterator(); it.hasNext(); i++) { final Element forecast = it.next(); try { - f[i] = new Forecast(forecast.getAttributeValue("day"), SHORT_DATE.parse(forecast.getAttributeValue("date")), Integer.parseInt(forecast + f[i] = new Forecast(forecast.getAttributeValue("day"), dateFormat.parse(forecast.getAttributeValue("date")), Integer.parseInt(forecast .getAttributeValue("low")), Integer.parseInt(forecast.getAttributeValue("high")), forecast.getAttributeValue("text"), ConditionCode.fromCode(Integer.parseInt(forecast.getAttributeValue("code")))); } catch (final NumberFormatException nfe) { diff --git a/src/main/resources/rome.properties b/src/main/resources/rome.properties index edf3956..a35ae97 100644 --- a/src/main/resources/rome.properties +++ b/src/main/resources/rome.properties @@ -11,8 +11,8 @@ rss_2.0.feed.ModuleParser.classes=org.rometools.feed.module.cc.io.ModuleParserRS org.rometools.feed.module.mediarss.io.MediaModuleParser \ org.rometools.feed.module.itunes.io.ITunesParserOldNamespace \ org.rometools.feed.module.mediarss.io.AlternateMediaModuleParser \ - org.rometools.feed.module.sle.io.ModuleParser - + org.rometools.feed.module.sle.io.ModuleParser \ + org.rometools.feed.module.yahooweather.io.WeatherModuleParser rss_1.0.feed.ModuleParser.classes=org.rometools.feed.module.cc.io.ModuleParserRSS1 \ org.rometools.feed.module.content.io.ContentModuleParser @@ -45,7 +45,8 @@ rss_2.0.item.ModuleParser.classes=org.rometools.feed.module.cc.io.ModuleParserRS org.rometools.feed.module.photocast.io.Parser \ org.rometools.feed.module.itunes.io.ITunesParserOldNamespace \ org.rometools.feed.module.mediarss.io.AlternateMediaModuleParser \ - org.rometools.feed.module.sle.io.ItemParser + org.rometools.feed.module.sle.io.ItemParser \ + org.rometools.feed.module.yahooweather.io.WeatherModuleParser rss_1.0.item.ModuleParser.classes=org.rometools.feed.module.cc.io.ModuleParserRSS1 \ org.rometools.feed.module.base.io.GoogleBaseParser \ @@ -83,7 +84,8 @@ rss_2.0.feed.ModuleGenerator.classes=org.rometools.feed.module.cc.io.CCModuleGen org.rometools.feed.module.georss.W3CGeoGenerator \ org.rometools.feed.module.photocast.io.Generator \ org.rometools.feed.module.mediarss.io.MediaModuleGenerator \ - org.rometools.feed.module.sle.io.ModuleGenerator + org.rometools.feed.module.sle.io.ModuleGenerator \ + org.rometools.feed.module.yahooweather.io.WeatherModuleGenerator rss_1.0.feed.ModuleGenerator.classes=org.rometools.feed.module.content.io.ContentModuleGenerator @@ -111,7 +113,8 @@ rss_2.0.item.ModuleGenerator.classes=org.rometools.feed.module.cc.io.CCModuleGen org.rometools.feed.module.georss.SimpleGenerator \ org.rometools.feed.module.georss.W3CGeoGenerator \ org.rometools.feed.module.photocast.io.Generator \ - org.rometools.feed.module.mediarss.io.MediaModuleGenerator + org.rometools.feed.module.mediarss.io.MediaModuleGenerator \ + org.rometools.feed.module.yahooweather.io.WeatherModuleGenerator rss_1.0.item.ModuleGenerator.classes=org.rometools.feed.module.base.io.GoogleBaseGenerator \ org.rometools.feed.module.content.io.ContentModuleGenerator \ diff --git a/src/test/java/org/rometools/feed/module/yahooweather/io/WeatherGeneratorTest.java b/src/test/java/org/rometools/feed/module/yahooweather/io/WeatherGeneratorTest.java index 7eec15d..036c3a0 100644 --- a/src/test/java/org/rometools/feed/module/yahooweather/io/WeatherGeneratorTest.java +++ b/src/test/java/org/rometools/feed/module/yahooweather/io/WeatherGeneratorTest.java @@ -24,23 +24,31 @@ import com.sun.syndication.io.SyndFeedInput; import com.sun.syndication.io.SyndFeedOutput; /** - * + * * @author Robert "kebernet" Cooper */ public class WeatherGeneratorTest extends AbstractTestCase { private static final Logger LOG = LoggerFactory.getLogger(WeatherGeneratorTest.class); + /** + * @param testName name of the test + */ public WeatherGeneratorTest(final String testName) { super(testName); } + /** + * @return test suite + */ public static Test suite() { return new TestSuite(WeatherGeneratorTest.class); } /** * Test of generate method, of class com.totsp.xml.syndication.base.io.SlashGenerator. + * + * @throws Exception on error */ public void testGenerate() throws Exception { LOG.debug("testGenerate"); @@ -56,18 +64,15 @@ public class WeatherGeneratorTest extends AbstractTestCase { final SyndFeed feed = input.build(testFiles[h]); output.output(feed, new File("target/" + testFiles[h].getName())); final SyndFeed feed2 = input.build(new File("target/" + testFiles[h].getName())); - { - final YWeatherModule weather = (YWeatherModule) feed.getModule(YWeatherModule.URI); - final YWeatherModule weather2 = (YWeatherModule) feed2.getModule(YWeatherModule.URI); - Assert.assertEquals(testFiles[h].getName(), weather, weather2); - - } + final YWeatherModule weather = (YWeatherModule) feed.getModule(YWeatherModule.URI); + final YWeatherModule weather2 = (YWeatherModule) feed2.getModule(YWeatherModule.URI); + Assert.assertEquals(testFiles[h].getName(), weather, weather2); for (int i = 0; i < feed.getEntries().size(); i++) { final SyndEntry entry = feed.getEntries().get(i); final SyndEntry entry2 = feed2.getEntries().get(i); - final YWeatherModule weather = (YWeatherModule) entry.getModule(YWeatherModule.URI); - final YWeatherModule weather2 = (YWeatherModule) entry2.getModule(YWeatherModule.URI); - Assert.assertEquals(testFiles[h].getName(), weather, weather2); + final YWeatherModule weatherEntry = (YWeatherModule) entry.getModule(YWeatherModule.URI); + final YWeatherModule weatherEntry2 = (YWeatherModule) entry2.getModule(YWeatherModule.URI); + assertEquals(testFiles[h].getName(), weatherEntry, weatherEntry2); } } diff --git a/src/test/resources/xml/yweather.xml b/src/test/resources/xml/yweather.xml new file mode 100644 index 0000000..c1f55e8 --- /dev/null +++ b/src/test/resources/xml/yweather.xml @@ -0,0 +1,65 @@ + + + + + + Yahoo! Weather - Milano/Linate, IT + http://us.rd.yahoo.com/dailynews/rss/weather/Milano/Linate__IT/*http://weather.yahoo.com/forecast/ITXX0090_f.html + Yahoo! Weather for Milano/Linate, IT + en-us + Sun, 20 Apr 2014 8:19 pm CEST + 60 + + + + + + + Yahoo! Weather + 142 + 18 + http://weather.yahoo.com + http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif + + + Conditions for Milano/Linate, IT at 8:19 pm CEST + 45.43 + 9.28 + http://us.rd.yahoo.com/dailynews/rss/weather/Milano/Linate__IT/*http://weather.yahoo.com/forecast/ITXX0090_f.html + Sun, 20 Apr 2014 8:19 pm CEST + +
+Current Conditions:
+Mostly Cloudy, 59 F
+
Forecast:
+Sun - Rain. High: 65 Low: 52
+Mon - Light Rain. High: 61 Low: 50
+Tue - PM Showers. High: 69 Low: 49
+Wed - Sunny. High: 74 Low: 50
+Thu - Mostly Sunny. High: 76 Low: 52
+
+Full Forecast at Yahoo! Weather

+(provided by The Weather Channel)
+]]>
+ + + + + + ITXX0090_2014_04_24_7_00_CEST +
+
+
+ +