fixed feed api servlet and and enhanced RSSReader class

pull/1/head
orbiter 11 years ago
parent d38c3c14d8
commit 252c525709

@ -1,6 +1,7 @@
import java.util.Date;
import java.util.List;
import net.yacy.cora.document.RSSFeed;
import net.yacy.cora.document.RSSMessage;
@ -60,7 +61,8 @@ public class feed {
if (feed == null || feed.isEmpty()) continue channelIteration;
RSSMessage message = feed.getChannel();
String description = message.getDescriptions().size() > 0 ? message.getDescriptions().get(0) : "";
List<String> descriptions = message.getDescriptions();
String description = descriptions.size() > 0 ? descriptions.get(0) : "";
if (message != null) {
prop.putXML("channel_title", message.getTitle());
prop.putXML("channel_description", description);
@ -72,6 +74,8 @@ public class feed {
// create RSS entry
prop.putXML("item_" + messageCount + "_title", channelName + ": " + message.getTitle());
descriptions = message.getDescriptions();
description = descriptions.size() > 0 ? descriptions.get(0) : "";
prop.putXML("item_" + messageCount + "_description", description);
prop.putXML("item_" + messageCount + "_link", message.getLink());
prop.put("item_" + messageCount + "_pubDate", message.getPubDate());

@ -105,28 +105,28 @@ public class RSSMessage implements Hit, Comparable<RSSMessage>, Comparator<RSSMe
public RSSMessage(final String title, final String description, final String link) {
this.map = new HashMap<String, String>();
this.map.put("title", title);
this.map.put("description", description);
this.map.put("link", link);
this.map.put("pubDate", ISO8601Formatter.FORMATTER.format());
this.map.put("guid", artificialGuidPrefix + Integer.toHexString((title + description + link).hashCode()));
if (title.length() > 0) this.map.put(Token.title.name(), title);
if (description.length() > 0) this.map.put(Token.description.name(), description);
if (link.length() > 0) this.map.put(Token.link.name(), link);
this.map.put(Token.pubDate.name(), ISO8601Formatter.FORMATTER.format());
this.map.put(Token.guid.name(), artificialGuidPrefix + Integer.toHexString((title + description + link).hashCode()));
}
public RSSMessage(final String title, final String description, final MultiProtocolURI link, final String guid) {
this.map = new HashMap<String, String>();
this.map.put("title", title);
this.map.put("description", description);
this.map.put("link", link.toNormalform(true));
this.map.put("pubDate", ISO8601Formatter.FORMATTER.format());
this.map.put("guid", guid);
if (title.length() > 0) this.map.put(Token.title.name(), title);
if (description.length() > 0) this.map.put(Token.description.name(), description);
this.map.put(Token.link.name(), link.toNormalform(true));
this.map.put(Token.pubDate.name(), ISO8601Formatter.FORMATTER.format());
if (guid.length() > 0) this.map.put(Token.guid.name(), guid);
}
public RSSMessage() {
this.map = new HashMap<String, String>();
}
public void setValue(final String name, final String value) {
this.map.put(name, value);
public void setValue(final Token token, final String value) {
if (value.length() > 0) this.map.put(token.name(), value);
}
@Override
@ -265,17 +265,17 @@ public class RSSMessage implements Hit, Comparable<RSSMessage>, Comparator<RSSMe
@Override
public void setAuthor(final String author) {
setValue("author", author);
setValue(Token.author, author);
}
@Override
public void setCategory(final String category) {
setValue("category", category);
setValue(Token.category, category);
}
@Override
public void setCopyright(final String copyright) {
setValue("copyright", copyright);
setValue(Token.copyright, copyright);
}
@Override
@ -283,52 +283,52 @@ public class RSSMessage implements Hit, Comparable<RSSMessage>, Comparator<RSSMe
final StringBuilder sb = new StringBuilder(tags.length * 10);
for (final String tag: tags) sb.append(tag).append(',');
if (sb.length() > 0) sb.setLength(sb.length() - 1);
setValue("subject", sb.toString());
setValue(Token.subject, sb.toString());
}
@Override
public void setDescription(final String description) {
setValue("description", description);
setValue(Token.description, description);
}
@Override
public void setDocs(final String docs) {
setValue("docs", docs);
setValue(Token.docs, docs);
}
@Override
public void setGuid(final String guid) {
setValue("guid", guid);
setValue(Token.guid, guid);
}
@Override
public void setLanguage(final String language) {
setValue("language", language);
setValue(Token.language, language);
}
@Override
public void setLink(final String link) {
setValue("link", link);
setValue(Token.link, link);
}
@Override
public void setPubDate(final Date pubdate) {
setValue("pubDate", ISO8601Formatter.FORMATTER.format(pubdate));
setValue(Token.pubDate, ISO8601Formatter.FORMATTER.format(pubdate));
}
@Override
public void setReferrer(final String referrer) {
setValue("referrer", referrer);
setValue(Token.referrer, referrer);
}
@Override
public void setSize(final long size) {
setValue("size", Long.toString(size));
setValue(Token.size, Long.toString(size));
}
@Override
public void setTitle(final String title) {
setValue("title", title);
setValue(Token.title, title);
}
public static String sizename(int size) {

@ -30,6 +30,8 @@ import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import net.yacy.cora.document.RSSMessage.Token;
import org.xml.sax.Attributes;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
@ -184,7 +186,7 @@ public class RSSReader extends DefaultHandler {
this.parsingItem = true;
} else if (this.parsingItem && this.type == Type.atom && "link".equals(tag) && (atts.getValue("type") == null || atts.getValue("type").startsWith("text"))) {
final String url = atts.getValue("href");
if (url != null && url.length() > 0) this.item.setValue("link", url);
if (url != null && url.length() > 0) this.item.setValue(Token.link, url);
} else if ("image".equals(tag) || (this.parsingItem && this.type == Type.atom && "link".equals(tag) && (atts.getValue("type") == null || atts.getValue("type").startsWith("image")))) {
this.parsingImage = true;
}
@ -208,11 +210,11 @@ public class RSSReader extends DefaultHandler {
} else if (this.parsingItem) {
final String value = this.buffer.toString().trim();
this.buffer.setLength(0);
if (RSSMessage.tags.contains(tag) && value.length() > 0) this.item.setValue(tag, value);
if (RSSMessage.tags.contains(tag) && value.length() > 0) this.item.setValue(Token.valueOf(tag), value);
} else if (this.parsingChannel) {
final String value = this.buffer.toString().trim();
this.buffer.setLength(0);
if (RSSMessage.tags.contains(tag)) this.item.setValue(tag, value);
if (RSSMessage.tags.contains(tag)) this.item.setValue(Token.valueOf(tag), value);
}
}

Loading…
Cancel
Save