本文整理汇总了Java中com.rometools.rome.feed.synd.SyndEntry.getPublishedDate方法的典型用法代码示例。如果您正苦于以下问题:Java SyndEntry.getPublishedDate方法的具体用法?Java SyndEntry.getPublishedDate怎么用?Java SyndEntry.getPublishedDate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.rometools.rome.feed.synd.SyndEntry
的用法示例。
在下文中一共展示了SyndEntry.getPublishedDate方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getEntryComparator
import com.rometools.rome.feed.synd.SyndEntry; //导入方法依赖的package包/类
/**
* This Comparator assumes that SyndEntry returns a valid Date either for
* getPublishedDate() or getUpdatedDate().
*/
private Comparator<SyndEntry> getEntryComparator() {
return new Comparator<SyndEntry>() {
@Override
public int compare(SyndEntry e1, SyndEntry e2) {
if (e1.getPublishedDate() == null &&
e1.getUpdatedDate() == null) {
// we will be ignoring such entries anyway
return 0;
}
Date d1 =
e1.getPublishedDate() != null ? e1.getPublishedDate() :
e1.getUpdatedDate();
Date d2 =
e2.getPublishedDate() != null ? e2.getPublishedDate() :
e2.getUpdatedDate();
if (d1.after(d2)) return 1;
if (d1.before(d2)) return -1;
return 0;
}
};
}
示例2: toJson
import com.rometools.rome.feed.synd.SyndEntry; //导入方法依赖的package包/类
static JsonObject toJson(SyndEntry entry) {
JsonObject json = new JsonObject();
json.put("title", entry.getTitle());
Date published = entry.getPublishedDate();
if (published == null) {
// TODO : log warning ? use another date ?
LOG.warn("!!!!!! The RSS has no published date : this will lead to duplicates entry");
published = new Date(); // FIXME : absolutely wrong...
}
json.put("published", toJson(published));
json.put("score", (double)published.getTime());
json.put("link", entry.getLink());
SyndContent description = entry.getDescription();
if (description != null) {
json.put("description", description.getValue());
}
return json;
}
示例3: postFeedEntries
import com.rometools.rome.feed.synd.SyndEntry; //导入方法依赖的package包/类
private long postFeedEntries(Feed feed, List<SyndEntry> entries)
throws DbException {
long lastEntryTime = feed.getLastEntryTime();
Transaction txn = db.startTransaction(false);
try {
Collections.sort(entries, getEntryComparator());
for (SyndEntry entry : entries) {
long entryTime;
if (entry.getPublishedDate() != null) {
entryTime = entry.getPublishedDate().getTime();
} else if (entry.getUpdatedDate() != null) {
entryTime = entry.getUpdatedDate().getTime();
} else {
// no time information available, ignore this entry
LOG.warning("Entry has no date, ignored.");
continue;
}
if (entryTime > feed.getLastEntryTime()) {
postEntry(txn, feed, entry);
if (entryTime > lastEntryTime) lastEntryTime = entryTime;
}
}
db.commitTransaction(txn);
} finally {
db.endTransaction(txn);
}
return lastEntryTime;
}
示例4: getLastDate
import com.rometools.rome.feed.synd.SyndEntry; //导入方法依赖的package包/类
private Date getLastDate(SyndEntry entry) {
if(entry.getUpdatedDate() != null) {
return entry.getUpdatedDate();
} else {
return entry.getPublishedDate();
}
}
示例5: computeEntryTag
import com.rometools.rome.feed.synd.SyndEntry; //导入方法依赖的package包/类
private String computeEntryTag(final SyndEntry entry) {
// Following hash algorithm suggested by Robert Cooper needs to be
// evaluated in future.
// int hash = ( entry.getUri() != null ? entry.getUri().hashCode() :
// entry.getLink().hashCode() ) ^
// (entry.getUpdatedDate() != null ? entry.getUpdatedDate().hashCode() :
// entry.getPublishedDate().hashCode()) ^
// entry.getTitle().hashCode() ^
// entry.getDescription().hashCode();
final String id = entry.getUri();
Date updateDate = entry.getUpdatedDate();
final Date publishedDate = entry.getPublishedDate();
if (updateDate == null) {
if (publishedDate != null) {
updateDate = publishedDate;
} else {
// For misbehaving feeds that do not set updateDate or
// publishedDate we use current tiem which pretty mucg assures
// that it will be viewed as
// changed even when it is not
updateDate = new Date();
}
}
final String key = id + ":" + entry.getUpdatedDate();
return computeDigest(key);
}
示例6: createSyndEntry
import com.rometools.rome.feed.synd.SyndEntry; //导入方法依赖的package包/类
@Override
protected SyndEntry createSyndEntry(final Item item, final boolean preserveWireItem) {
final SyndEntry syndEntry = super.createSyndEntry(item, preserveWireItem);
final Date pubDate = item.getPubDate();
final Date publishedDate = syndEntry.getPublishedDate();
if (pubDate != null && publishedDate == null) {
syndEntry.setPublishedDate(pubDate); // c
}
return syndEntry;
}
示例7: getEntryUpdateDate
import com.rometools.rome.feed.synd.SyndEntry; //导入方法依赖的package包/类
private Date getEntryUpdateDate(SyndEntry item) {
Date date = item.getUpdatedDate();
if (date == null) {
date = item.getPublishedDate();
}
if (date == null) {
date = new Date();
}
return date;
}
示例8: getTitle
import com.rometools.rome.feed.synd.SyndEntry; //导入方法依赖的package包/类
private String getTitle(SyndEntry item) {
String title = item.getTitle();
if (StringUtils.isBlank(title)) {
Date date = item.getPublishedDate();
if (date != null) {
title = DateFormat.getInstance().format(date);
} else {
title = "(no title)";
}
}
return StringUtils.trimToNull(title);
}
示例9: parseFeed
import com.rometools.rome.feed.synd.SyndEntry; //导入方法依赖的package包/类
private List<Outlink> parseFeed(String url, byte[] content,
Metadata parentMetadata) throws Exception {
List<Outlink> links = new ArrayList<>();
SyndFeed feed = null;
try (ByteArrayInputStream is = new ByteArrayInputStream(content)) {
SyndFeedInput input = new SyndFeedInput();
feed = input.build(new InputSource(is));
}
URL sURL = new URL(url);
List<SyndEntry> entries = feed.getEntries();
for (SyndEntry entry : entries) {
String targetURL = entry.getLink();
// targetURL can be null?!?
// e.g. feed does not use links but guid
if (StringUtils.isBlank(targetURL)) {
targetURL = entry.getUri();
if (StringUtils.isBlank(targetURL)) {
continue;
}
}
Outlink newLink = filterOutlink(sURL, targetURL, parentMetadata);
if (newLink == null)
continue;
String title = entry.getTitle();
if (StringUtils.isNotBlank(title)) {
newLink.getMetadata().setValue("feed.title", title.trim());
}
Date publishedDate = entry.getPublishedDate();
if (publishedDate != null) {
// filter based on the published date
if (filterHoursSincePub != -1) {
Calendar rightNow = Calendar.getInstance();
rightNow.add(Calendar.HOUR, -filterHoursSincePub);
if (publishedDate.before(rightNow.getTime())) {
LOG.info(
"{} has a published date {} which is more than {} hours old",
targetURL, publishedDate.toString(),
filterHoursSincePub);
continue;
}
}
newLink.getMetadata().setValue("feed.publishedDate",
publishedDate.toString());
}
SyndContent description = entry.getDescription();
if (description != null
&& StringUtils.isNotBlank(description.getValue())) {
newLink.getMetadata().setValue("feed.description",
description.getValue());
}
links.add(newLink);
}
return links;
}
示例10: parseRss
import com.rometools.rome.feed.synd.SyndEntry; //导入方法依赖的package包/类
/**
* RSSの解析処理。
* @param rss 1つのRSS情報
* @return 解析後のLink情報
* @throws FeedException Feedの解析失敗時の例外
* @throws IOException IOException IO例外
* @throws URISyntaxException URIの形式が不正な場合の例外
* @throws CrawlerException Crawler共通例外
*/
@SuppressWarnings("deprecation")
public ArrayList<ArticleEntityBean> parseRss(RssEntityBean rss) throws IOException, FeedException,
URISyntaxException, CrawlerException {
log.info("start feed parse : " + rss.url);
SyndFeed feed = null;
feed = buildSyndFeed(new URI(rss.url));
ArrayList<ArticleEntityBean> result = new ArrayList<ArticleEntityBean>();
TimeZone tz = TimeZone.getTimeZone("GMT");
if (feed != null) {
List<SyndEntry> entries = feed.getEntries();
log.info("feed entries count : " + entries.size());
for (Object obj : entries) {
SyndEntry entry = (SyndEntry) obj;
String link = entry.getLink();
DateTime createdAt = new DateTime(entry.getPublishedDate(), tz);
String createdAtStr = Util.formatIsoDate(createdAt);
String title = org.apache.commons.lang.StringEscapeUtils.unescapeXml(entry.getTitle());
log.info("article : " + title + " / " + createdAtStr + " / " + link);
if (isExistArticle(link, createdAt)) {
log.info("-> article already exists");
continue;
}
log.info("-> article not exists");
ArticleEntityBean article = new ArticleEntityBean();
article.link = link;
article.title = title;
article.auther = entry.getAuthor();
article.url = entry.getUri();
article.createdAt = createdAt;
String fixHour = Conf.getValue("fix_time");
Date now = new Date();
Date fixDate = new Date(now.getYear(), now.getMonth(), now.getDate(), Integer.parseInt(fixHour), 0);
if (now.getTime() > fixDate.getTime()) {
article.publishedAt = tomorrow;
} else {
article.publishedAt = today;
}
article.site = rss.site;
article.type = rss.type;
article.description = null;
SyndContent sc = entry.getDescription();
if (sc != null) {
article.description = sc.getValue();
if (rss.replaceCR != null) {
article.rawHTML = article.description.replaceAll("\n", rss.replaceCR);
} else {
article.rawHTML = article.description;
}
}
article.tags = rss.defaultTag;
result.add(article);
}
} else {
log.warn("feed parse error url : " + rss.site);
throw new CrawlerException();
}
return result;
}
示例11: getEntryPublishedDate
import com.rometools.rome.feed.synd.SyndEntry; //导入方法依赖的package包/类
public Date getEntryPublishedDate(final Object o) {
final SyndEntry e = (SyndEntry) o;
return e.getPublishedDate();
}