make sure dates are in an acceptable interval

This commit is contained in:
Athou
2013-04-21 16:56:09 +02:00
parent 21366e15a8
commit 0204dadc3f

View File

@@ -26,6 +26,9 @@ import com.sun.syndication.io.SyndFeedInput;
public class FeedParser {
private static final Date START = new Date(0);
private static final Date END = new Date(Integer.MAX_VALUE);
private static final Function<SyndContent, String> CONTENT_TO_STRING = new Function<SyndContent, String>() {
public String apply(SyndContent content) {
return content.getValue();
@@ -56,7 +59,7 @@ public class FeedParser {
entry.setGuid(item.getUri());
entry.setGuidHash(DigestUtils.sha1Hex(item.getUri()));
entry.setUrl(item.getLink());
entry.setUpdated(getUpdateDate(item));
entry.setUpdated(validateDate(getUpdateDate(item)));
FeedEntryContent content = new FeedEntryContent();
content.setContent(getContent(item));
@@ -71,7 +74,7 @@ public class FeedParser {
feed.getEntries().add(entry);
}
Date publishedDate = rss.getPublishedDate();
Date publishedDate = validateDate(rss.getPublishedDate());
if (publishedDate == null && !feed.getEntries().isEmpty()) {
FeedEntry first = feed.getEntries().iterator().next();
publishedDate = first.getUpdated();
@@ -97,6 +100,16 @@ public class FeedParser {
return date;
}
private Date validateDate(Date date) {
if (date == null) {
return null;
}
if (date.before(START) || date.after(END)) {
return null;
}
return date;
}
@SuppressWarnings("unchecked")
private String getContent(SyndEntry item) {
String content = null;