have RSSFeed.getChannel return empty message on missing channel element,

a) required b) prevent NPE in rss servlets
+ add test
pull/77/head
reger 9 years ago
parent fedb9f8151
commit 32a2e3a22a

@ -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;
}

@ -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);

@ -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);
}
}
Loading…
Cancel
Save