From e9bb18b89b5753f091362ea4fa3edc7ee2744dc1 Mon Sep 17 00:00:00 2001 From: Martin Kurz Date: Mon, 7 Oct 2013 23:05:58 +0200 Subject: [PATCH] Added support for docs, managingEditor, webMaster and generator on RSS channel and comments on RSS items (fixes #162) --- .../sun/syndication/feed/synd/SyndEntry.java | 17 +++++ .../syndication/feed/synd/SyndEntryImpl.java | 17 +++++ .../sun/syndication/feed/synd/SyndFeed.java | 70 +++++++++++++++++++ .../syndication/feed/synd/SyndFeedImpl.java | 68 ++++++++++++++++++ .../synd/impl/ConverterForRSS091Userland.java | 11 ++- .../io/impl/RSS091UserlandParser.java | 4 +- .../unittest/issues/Isseue162Test.java | 66 +++++++++++++++++ 7 files changed, 250 insertions(+), 3 deletions(-) create mode 100644 src/test/java/com/sun/syndication/unittest/issues/Isseue162Test.java diff --git a/src/main/java/com/sun/syndication/feed/synd/SyndEntry.java b/src/main/java/com/sun/syndication/feed/synd/SyndEntry.java index 3ff631c..30de185 100644 --- a/src/main/java/com/sun/syndication/feed/synd/SyndEntry.java +++ b/src/main/java/com/sun/syndication/feed/synd/SyndEntry.java @@ -421,6 +421,23 @@ public interface SyndEntry extends Cloneable, CopyFrom, Extendable { */ public void setForeignMarkup(List foreignMarkup); + /** + * URL of a page for comments relating to the item. + * + * @since 2.0.0 + * @return comments URL or {@code null}. + * + */ + String getComments(); + + /** + * URL of a page for comments relating to the item. + * + * @since 2.0.0 + * @param comments URL + */ + void setComments(String comments); + /** * Creates a deep clone of the object. *

diff --git a/src/main/java/com/sun/syndication/feed/synd/SyndEntryImpl.java b/src/main/java/com/sun/syndication/feed/synd/SyndEntryImpl.java index acf631e..3b35618 100644 --- a/src/main/java/com/sun/syndication/feed/synd/SyndEntryImpl.java +++ b/src/main/java/com/sun/syndication/feed/synd/SyndEntryImpl.java @@ -51,6 +51,7 @@ public class SyndEntryImpl implements Serializable, SyndEntry { private final ObjectBean objBean; private String uri; private String link; + private String comments; private Date updatedDate; private SyndContent title; private SyndContent description; @@ -691,6 +692,22 @@ public class SyndEntryImpl implements Serializable, SyndEntry { this.foreignMarkup = foreignMarkup; } + /** + * {@inheritDoc} + */ + @Override + public String getComments() { + return comments; + } + + /** + * {@inheritDoc} + */ + @Override + public void setComments(String comments) { + this.comments = comments; + } + @Override public Object getWireEntry() { return wireEntry; diff --git a/src/main/java/com/sun/syndication/feed/synd/SyndFeed.java b/src/main/java/com/sun/syndication/feed/synd/SyndFeed.java index 11f0ad1..1669f17 100644 --- a/src/main/java/com/sun/syndication/feed/synd/SyndFeed.java +++ b/src/main/java/com/sun/syndication/feed/synd/SyndFeed.java @@ -572,6 +572,76 @@ public interface SyndFeed extends Cloneable, CopyFrom, Extendable { */ public void setForeignMarkup(List foreignMarkup); + /** + * This tag should contain a URL that references a description of the + * channel. + * + * @since 2.0.0 + * @return channel description URL or {@code null} + */ + String getDocs(); + + /** + * This tag should contain a URL that references a description of the + * channel. + * + * @since 2.0.0 + * @param channel description URL + */ + public void setDocs(String docs); + + /** + * A string indicating the program used to generate the channel. + * + * @since 2.0.0 + * @return string indicating the program or {@code null} + */ + String getGenerator(); + + /** + * A string indicating the program used to generate the channel. + * + * @since 2.0.0 + * @param string indicating the program + */ + public void setGenerator(String generator); + + /** + * The email address of the managing editor of the site, the person to + * contact for editorial inquiries. + * + * @since 2.0.0 + * @return email address of the managing editor or {@code null} + */ + String getManagingEditor(); + + /** + * The email address of the managing editor of the site, the person to + * contact for editorial inquiries. + * + * @since 2.0.0 + * @param managingEditor email address of the managing editor + */ + public void setManagingEditor(String managingEditor); + + /** + * The email address of the webmaster for the site, the person to contact if + * there are technical problems with the channel. + * + * @since 2.0.0 + * @return email address of the webmaster or {@code null} + */ + String getWebMaster(); + + /** + * The email address of the webmaster for the site, the person to contact if + * there are technical problems with the channel. + * + * @since 2.0.0 + * @param webMaster email address of the webmaster + */ + void setWebMaster(String webMaster); + /** * Creates a deep clone of the object. *

diff --git a/src/main/java/com/sun/syndication/feed/synd/SyndFeedImpl.java b/src/main/java/com/sun/syndication/feed/synd/SyndFeedImpl.java index 0cc66dd..4bb5a53 100644 --- a/src/main/java/com/sun/syndication/feed/synd/SyndFeedImpl.java +++ b/src/main/java/com/sun/syndication/feed/synd/SyndFeedImpl.java @@ -62,6 +62,10 @@ public class SyndFeedImpl implements Serializable, SyndFeed { private SyndContent description; private String feedType; private String link; + private String webMaster; + private String managingEditor; + private String docs; + private String generator; private List links; private SyndImage image; private List entries; @@ -929,4 +933,68 @@ public class SyndFeedImpl implements Serializable, SyndFeed { public boolean isPreservingWireFeed() { return preserveWireFeed; } + + /** + * {@inheritDoc} + */ + @Override + public String getDocs() { + return docs; + } + + /** + * {@inheritDoc} + */ + @Override + public void setDocs(String docs) { + this.docs = docs; + } + + /** + * {@inheritDoc} + */ + @Override + public String getGenerator() { + return generator; + } + + /** + * {@inheritDoc} + */ + @Override + public void setGenerator(String generator) { + this.generator = generator; + } + + /** + * {@inheritDoc} + */ + @Override + public String getManagingEditor() { + return managingEditor; + } + + /** + * {@inheritDoc} + */ + @Override + public void setManagingEditor(String managingEditor) { + this.managingEditor = managingEditor; + } + + /** + * {@inheritDoc} + */ + @Override + public String getWebMaster() { + return webMaster; + } + + /** + * {@inheritDoc} + */ + @Override + public void setWebMaster(String webMaster) { + this.webMaster = webMaster; + } } diff --git a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS091Userland.java b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS091Userland.java index b8942a6..31d8ad4 100644 --- a/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS091Userland.java +++ b/src/main/java/com/sun/syndication/feed/synd/impl/ConverterForRSS091Userland.java @@ -53,6 +53,10 @@ public class ConverterForRSS091Userland extends ConverterForRSS090 { super.copyInto(channel, syndFeed); syndFeed.setLanguage(channel.getLanguage()); // c syndFeed.setCopyright(channel.getCopyright()); // c + syndFeed.setDocs(channel.getDocs()); + syndFeed.setManagingEditor(channel.getManagingEditor()); + syndFeed.setWebMaster(channel.getWebMaster()); + syndFeed.setGenerator(channel.getGenerator()); final Date pubDate = channel.getPubDate(); @@ -101,7 +105,7 @@ public class ConverterForRSS091Userland extends ConverterForRSS090 { @Override protected Item createRSSItem(final SyndEntry sEntry) { final Item item = super.createRSSItem(sEntry); - + item.setComments(sEntry.getComments()); final SyndContent sContent = sEntry.getDescription(); if (sContent != null) { @@ -127,6 +131,10 @@ public class ConverterForRSS091Userland extends ConverterForRSS090 { channel.setLanguage(syndFeed.getLanguage()); // c channel.setCopyright(syndFeed.getCopyright()); // c channel.setPubDate(syndFeed.getPublishedDate()); // c + channel.setDocs(syndFeed.getDocs()); + channel.setManagingEditor(syndFeed.getManagingEditor()); + channel.setWebMaster(syndFeed.getWebMaster()); + channel.setGenerator(syndFeed.getGenerator()); if (syndFeed.getAuthors() != null && syndFeed.getAuthors().size() > 0) { final SyndPerson author = syndFeed.getAuthors().get(0); @@ -143,6 +151,7 @@ public class ConverterForRSS091Userland extends ConverterForRSS090 { protected SyndEntry createSyndEntry(final Item item, final boolean preserveWireItem) { final SyndEntry syndEntry = super.createSyndEntry(item, preserveWireItem); final Description desc = item.getDescription(); + syndEntry.setComments(item.getComments()); if (desc != null) { final SyndContent descContent = new SyndContentImpl(); diff --git a/src/main/java/com/sun/syndication/io/impl/RSS091UserlandParser.java b/src/main/java/com/sun/syndication/io/impl/RSS091UserlandParser.java index eac91c2..f0b9115 100644 --- a/src/main/java/com/sun/syndication/io/impl/RSS091UserlandParser.java +++ b/src/main/java/com/sun/syndication/io/impl/RSS091UserlandParser.java @@ -115,9 +115,9 @@ public class RSS091UserlandParser extends RSS090Parser { if (e != null) { channel.setDocs(e.getText()); } - e = eChannel.getChild("docs", getRSSNamespace()); + e = eChannel.getChild("generator", getRSSNamespace()); if (e != null) { - channel.setDocs(e.getText()); + channel.setGenerator(e.getText()); } e = eChannel.getChild("managingEditor", getRSSNamespace()); if (e != null) { diff --git a/src/test/java/com/sun/syndication/unittest/issues/Isseue162Test.java b/src/test/java/com/sun/syndication/unittest/issues/Isseue162Test.java new file mode 100644 index 0000000..8fb9577 --- /dev/null +++ b/src/test/java/com/sun/syndication/unittest/issues/Isseue162Test.java @@ -0,0 +1,66 @@ +package com.sun.syndication.unittest.issues; + +import java.util.List; + +import com.sun.syndication.feed.rss.Channel; +import com.sun.syndication.feed.rss.Item; +import com.sun.syndication.feed.synd.SyndEntry; +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.unittest.TestSyndFeedRSS20; + +/** + * Test for #161: No source element in RSS 2.0 items. + * @author Martin Kurz + * + */ +public class Isseue162Test extends TestSyndFeedRSS20 { + + public Isseue162Test() { + super("rss_2.0"); + } + + public void testWireFeed() throws Exception { + final Channel channel = ((Channel) this.getCachedWireFeed()); + assertProperty(channel.getDocs(), "channel.docs"); + assertProperty(channel.getGenerator(), "channel.generator"); + assertProperty(channel.getManagingEditor(), "channel.managingEditor"); + assertProperty(channel.getWebMaster(), "channel.webMaster"); + } + + public void testWireFeedItems() throws Exception { + final int count = ((Channel) this.getCachedWireFeed()).getItems().size(); + for (int i = 0; i < count; i++) { + testItem(i); + } + } + + protected void testWireFeedItem(final int i) throws Exception { + final List items = ((Channel) this.getCachedWireFeed()).getItems(); + final Item entry = items.get(i); + assertProperty(entry.getComments(), "channel.item[" + i + "].comments"); + } + + public void testSyndFeed() throws Exception { + final SyndFeed feed = this.getCachedSyndFeed(); + assertProperty(feed.getDocs(), "channel.docs"); + assertProperty(feed.getGenerator(), "channel.generator"); + assertProperty(feed.getManagingEditor(), "channel.managingEditor"); + assertProperty(feed.getWebMaster(), "channel.webMaster"); + } + + public void testSyndFeedItems() throws Exception { + final int count = this.getCachedSyndFeed().getEntries().size(); + for (int i = 0; i < count; i++) { + testItem(i); + } + } + + @Override + protected void testItem(final int i) throws Exception { + super.testItem(i); + final List items = this.getCachedSyndFeed().getEntries(); + final SyndEntry entry = items.get(i); + assertProperty(entry.getComments(), "channel.item[" + i + "].comments"); + } + +}