added toString() methods to feed classes which makes it possible to

export full rss feed files out of the RSSFeed class
pull/1/head
Michael Peter Christen 10 years ago
parent 568c991405
commit 8b522687e0

@ -36,10 +36,33 @@ public class RSSFeed implements Iterable<RSSMessage> {
public static final int DEFAULT_MAXSIZE = 10000;
// class variables
private RSSMessage channel;
private RSSMessage channel = null;
private final Map<String, RSSMessage> messages; // a guid:Item map
private final int maxsize;
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
sb.append("<rss version=\"2.0\"\n");
sb.append(" xmlns:opensearch=\"http://a9.com/-/spec/opensearch/1.1/\"\n");
sb.append(" xmlns:atom=\"http://www.w3.org/2005/Atom\"\n");
sb.append(">\n");
sb.append("<channel>\n");
if (this.channel != null) sb.append(this.channel.toString(false));
sb.append("<opensearch:startIndex>0</opensearch:startIndex>\n");
sb.append("<opensearch:itemsPerPage>" + this.size() + "</opensearch:itemsPerPage>\n");
sb.append("<opensearch:totalResults>" + this.size() + "</opensearch:totalResults>\n");
for (RSSMessage item: messages.values()) {
sb.append(item.toString());
}
sb.append("</channel>\n");
sb.append("</rss>\n");
return sb.toString();
}
public RSSFeed(final int maxsize) {
this.messages = Collections.synchronizedMap(new LinkedHashMap<String, RSSMessage>());
this.channel = null;

@ -273,7 +273,19 @@ public class RSSMessage implements Hit, Comparable<RSSMessage>, Comparator<RSSMe
@Override
public String toString() {
return this.map.toString();
return this.toString(true);
}
public String toString(boolean withItemTag) {
StringBuilder sb = new StringBuilder();
if (withItemTag) sb.append("<item>\n");
if (this.map.containsKey(Token.title.name())) sb.append("<title>").append(this.map.get(Token.title.name())).append("</title>\n");
if (this.map.containsKey(Token.link.name())) sb.append("<link>").append(this.map.get(Token.link.name())).append("</link>\n");
if (this.map.containsKey(Token.description.name())) sb.append("<description>").append(this.map.get(Token.description.name())).append("</description>\n");
if (this.map.containsKey(Token.pubDate.name())) sb.append("<pubDate>").append(this.map.get(Token.pubDate.name())).append("</pubDate>\n");
if (this.map.containsKey(Token.guid.name())) sb.append("<guid isPermaLink=\"false\">").append(this.map.get(Token.guid.name())).append("</guid>\n");
if (withItemTag) sb.append("</item>\n");
return sb.toString();
}
@Override

Loading…
Cancel
Save