dc:date is now preferred on entries over pubDate (fixes #125)
This commit is contained in:
parent
9ebfafee0c
commit
fb021e84b3
3 changed files with 60 additions and 1 deletions
|
@ -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;
|
||||
|
|
|
@ -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("<dc:date/> element is returned as date, rather than <pubDate/>.", expected, dc.getDate());
|
||||
}
|
||||
}
|
29
src/test/resources/dublinCoreTest.xml
Normal file
29
src/test/resources/dublinCoreTest.xml
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"
|
||||
version="2.0">
|
||||
<channel>
|
||||
<title>Title</title>
|
||||
<link>http://example.com/</link>
|
||||
<description>Some description</description>
|
||||
<language>en-gb</language>
|
||||
<lastBuildDate>Tue, 03 Mar 2009 13:06:20 GMT</lastBuildDate>
|
||||
<ttl>15</ttl>
|
||||
<image>
|
||||
<title>Title</title>
|
||||
<url>http://image.example.com/rss.gif</url>
|
||||
<link>http://example.com</link>
|
||||
</image>
|
||||
<item>
|
||||
<title>item title</title>
|
||||
<link>http://example.com/articles/2009/03/03/some-article</link>
|
||||
<description>Article description</description>
|
||||
<pubDate>Tue, 03 Mar 2009 13:05:50 GMT</pubDate>
|
||||
<guid>http://example.com/articles/2009/03/03/some-article</guid>
|
||||
<dc:creator>Alice Bob</dc:creator>
|
||||
<dc:subject>Bob news</dc:subject>
|
||||
<dc:date>2009-03-03T13:06:20Z</dc:date>
|
||||
<dc:type>Article</dc:type>
|
||||
<atom:updated>2009-03-03T13:06:20Z</atom:updated>
|
||||
</item>
|
||||
</channel>
|
||||
</rss>
|
Loading…
Reference in a new issue