From fb021e84b3cf22651b3928f8b3a5f0272b9519c2 Mon Sep 17 00:00:00 2001 From: Martin Kurz Date: Tue, 8 Oct 2013 22:13:32 +0200 Subject: [PATCH] dc:date is now preferred on entries over pubDate (fixes #125) --- .../feed/synd/impl/ConverterForRSS093.java | 2 +- .../syndication/unittest/TestDublinCore.java | 30 +++++++++++++++++++ src/test/resources/dublinCoreTest.xml | 29 ++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/sun/syndication/unittest/TestDublinCore.java create mode 100644 src/test/resources/dublinCoreTest.xml diff --git a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS093.java b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS093.java index 1a0309f..2630cd6 100644 --- a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS093.java +++ b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS093.java @@ -37,7 +37,7 @@ public class ConverterForRSS093 extends ConverterForRSS092 { protected SyndEntry createSyndEntry(final Item item, final boolean preserveWireItem) { final SyndEntry syndEntry = super.createSyndEntry(item, preserveWireItem); final Date pubDate = item.getPubDate(); - if (pubDate != null) { + if (pubDate != null && syndEntry.getPublishedDate() == null) { syndEntry.setPublishedDate(pubDate); // c } return syndEntry; diff --git a/src/test/java/com/sun/syndication/unittest/TestDublinCore.java b/src/test/java/com/sun/syndication/unittest/TestDublinCore.java new file mode 100644 index 0000000..0510219 --- /dev/null +++ b/src/test/java/com/sun/syndication/unittest/TestDublinCore.java @@ -0,0 +1,30 @@ +/* ---------------------------------------------------------------------------- + * (c) Mobile IQ Ltd 2009. All Rights Reserved. + * ---------------------------------------------------------------------------- + */ +package com.sun.syndication.unittest; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; +import java.util.TimeZone; + +import com.sun.syndication.feed.module.DCModule; +import com.sun.syndication.feed.synd.SyndEntry; +import com.sun.syndication.feed.synd.SyndFeed; + +public class TestDublinCore extends FeedTest { + public TestDublinCore() { + super("dublinCoreTest.xml"); + } + + public void testDublinCoreDateIsPreferredWhenAvailableRatherThanRss20PubDate() throws Exception { + final SyndFeed feed = this.getCachedSyndFeed(); + final SyndEntry entry = (SyndEntry) feed.getEntries().get(0); + final DCModule dc = (DCModule) entry.getModule(DCModule.URI); + final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ENGLISH); + sdf.setTimeZone(TimeZone.getTimeZone("UTC")); + final Date expected = sdf.parse("2009-03-03T13:06:20Z"); + assertEquals(" element is returned as date, rather than .", expected, dc.getDate()); + } +} \ No newline at end of file diff --git a/src/test/resources/dublinCoreTest.xml b/src/test/resources/dublinCoreTest.xml new file mode 100644 index 0000000..ec56da1 --- /dev/null +++ b/src/test/resources/dublinCoreTest.xml @@ -0,0 +1,29 @@ + + + + Title + http://example.com/ + Some description + en-gb + Tue, 03 Mar 2009 13:06:20 GMT + 15 + + Title + http://image.example.com/rss.gif + http://example.com + + + item title + http://example.com/articles/2009/03/03/some-article + Article description + Tue, 03 Mar 2009 13:05:50 GMT + http://example.com/articles/2009/03/03/some-article + Alice Bob + Bob news + 2009-03-03T13:06:20Z + Article + 2009-03-03T13:06:20Z + + + \ No newline at end of file