Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

have RSSFeed.getChannel return empty message on missing channel element, a) required b) prevent NPE in rss servlets + add test

reger32a2e3a22a77
diff --git a/source/net/yacy/cora/document/feed/RSSFeed.java b/source/net/yacy/cora/document/feed/RSSFeed.java
index 552dce869..e7b5aba4c 100644
--- a/source/net/yacy/cora/document/feed/RSSFeed.java
+++ b/source/net/yacy/cora/document/feed/RSSFeed.java
@@ -36,7 +36,7 @@ public class RSSFeed implements Iterable<RSSMessage> {
public static final int DEFAULT_MAXSIZE = 10000;
// class variables
- private RSSMessage channel = null;
+ private RSSMessage channel = null; // single required element see http://www.rssboard.org/rss-profile#element-channel
private final Map<String, RSSMessage> messages; // a guid:Item map
private final int maxsize;
@@ -91,7 +91,15 @@ public class RSSFeed implements Iterable<RSSMessage> {
this.channel = channelItem;
}
+ /**
+ * Return Channel element
+ * (This element is required and must contain three child elements: description, link and title)
+ * see http://www.rssboard.org/rss-profile#element-channel
+ * @return RSSMessage with channel elements or empty RSSMessage
+ */
public RSSMessage getChannel() {
+ // This element is required and must contain three child elements: description, link and title.
+ if (this.channel==null) this.channel = new RSSMessage();
return this.channel;
}
diff --git a/source/net/yacy/cora/document/feed/RSSMessage.java b/source/net/yacy/cora/document/feed/RSSMessage.java
index 291897663..0d6738ca7 100644
--- a/source/net/yacy/cora/document/feed/RSSMessage.java
+++ b/source/net/yacy/cora/document/feed/RSSMessage.java
@@ -325,6 +325,10 @@ public class RSSMessage implements Hit, Comparable<RSSMessage>, Comparator<RSSMe
setValue(Token.description, description);
}
+ /**
+ * set a URL that points to the documentation for the format used in the RSS file.
+ * @param docs e.g. "http://www.rssboard.org/rss-specification"
+ */
@Override
public void setDocs(final String docs) {
setValue(Token.docs, docs);
diff --git a/test/java/net/yacy/cora/document/feed/RSSFeedTest.java b/test/java/net/yacy/cora/document/feed/RSSFeedTest.java
new file mode 100644
index 000000000..287e3de87
--- /dev/null
+++ b/test/java/net/yacy/cora/document/feed/RSSFeedTest.java
@@ -0,0 +1,22 @@
+package net.yacy.cora.document.feed;
+
+import java.io.IOException;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class RSSFeedTest {
+
+ /**
+ * Test of getChannel method, of class RSSFeed.
+ */
+ @Test
+ public void testGetChannel() throws IOException {
+ RSSFeed feed = new RSSFeed(Integer.MAX_VALUE);
+
+ // channel is required in RSS 2.0 and accessed in code w/o != null checks
+ RSSMessage channel = feed.getChannel();
+ assertNotNull(channel);
+
+ }
+
+}