本文整理汇总了Java中com.rometools.rome.feed.synd.SyndEntry类的典型用法代码示例。如果您正苦于以下问题:Java SyndEntry类的具体用法?Java SyndEntry怎么用?Java SyndEntry使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SyndEntry类属于com.rometools.rome.feed.synd包,在下文中一共展示了SyndEntry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.rometools.rome.feed.synd.SyndEntry; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static void main (String[] args){
ConfigurableApplicationContext ac =
new ClassPathXmlApplicationContext("/context.xml");
PollableChannel feedChannel = ac.getBean("feedChannel", PollableChannel.class);
for (int i = 0; i < 10; i++) {
Message<SyndEntry> message = (Message<SyndEntry>) feedChannel.receive(1000);
if (message != null){
System.out.println("==========="+i+"===========");
SyndEntry entry = message.getPayload();
System.out.println(entry.getAuthor());
System.out.println(entry.getPublishedDate());
System.out.println(entry.getTitle());
System.out.println(entry.getUri());
System.out.println(entry.getLink());
System.out.println("======================");
}
}
ac.close();
}
示例2: 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;
}
};
}
示例3: convert
import com.rometools.rome.feed.synd.SyndEntry; //导入依赖的package包/类
public static void convert(final String feed, final List<SyndEntry> items, final ConversionCallback c) {
Realm.getInstance(BaseApplication.config).executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
Feed f = realm.where(Feed.class).equalTo("name", feed).findFirst();
ArrayList<Article> toAdd = new ArrayList<>();
for (SyndEntry i : items) {
if (realm.where(Article.class).equalTo("title", i.getTitle()).findFirst() == null) {
Article a = new Article();
a.setAll(i, f);
realm.copyToRealmOrUpdate(a);
toAdd.add(a);
}
}
Collections.reverse(toAdd);
c.onCompletion(toAdd.size());
}
});
}
示例4: convertSync
import com.rometools.rome.feed.synd.SyndEntry; //导入依赖的package包/类
public static void convertSync(final Feed feed, final List<SyndEntry> items, final ConversionCallback c, Activity baseActivity) {
baseActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
Realm.getDefaultInstance().executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
ArrayList<Article> toAdd = new ArrayList<>();
for (SyndEntry i : items) {
Article a = new Article();
a.setAll(i, feed);
boolean exists = realm.where(Article.class).equalTo("id", a.getId()).findFirst() != null;
if (!exists) {
realm.copyToRealmOrUpdate(a);
toAdd.add(a);
}
}
Collections.reverse(toAdd);
c.onCompletion(toAdd.size());
}
});
}
});
}
示例5: getCategories
import com.rometools.rome.feed.synd.SyndEntry; //导入依赖的package包/类
public static List<String> getCategories() {
final List<String> allCategories = new ArrayList<>();
for (final SyndEntry entry : sCurrentFeed.getEntries()) {
for (final SyndCategory category : entry.getCategories()) {
final String name = category.getName();
if (!TextUtils.isEmpty(name) && !allCategories.contains(name)) {
allCategories.add(name);
}
}
}
Collections.sort(allCategories);
return allCategories;
}
示例6: getCategoriesPositions
import com.rometools.rome.feed.synd.SyndEntry; //导入依赖的package包/类
public static List<Integer> getCategoriesPositions(final List<String> categories) {
final List<Integer> positions = new ArrayList<>();
int i = 1;
for (final SyndEntry entry : sCurrentFeed.getEntries()) {
for (final SyndCategory category : entry.getCategories()) {
if (categories.contains(category.getName()) && !positions.contains(i)) {
positions.add(i);
}
}
i++;
}
Collections.sort(positions);
return positions;
}
示例7: getSearchResults
import com.rometools.rome.feed.synd.SyndEntry; //导入依赖的package包/类
public static SearchResultsCursor getSearchResults(final String query) {
final List<Integer> positions = new ArrayList<>();
final List<LinkedHashMap<Integer, Integer>> indicesTitle = new ArrayList<>();
int i = 1;
for (final SyndEntry entry : sCurrentFeed.getEntries()) {
final String title = entry.getTitle();
if (StringUtils.containsIgnoreCase(title, query)) {
indicesTitle.add(SearchUtils.getIndicesForQuery(title, query));
positions.add(i);
}
i++;
}
return new SearchResultsCursor(positions, indicesTitle);
}
示例8: importPublications
import com.rometools.rome.feed.synd.SyndEntry; //导入依赖的package包/类
public void importPublications(String projectID) throws Exception {
LOGGER.info("Getting new publications from {} RSS feed...", sourceSystemID);
SyndFeed feed = retrieveFeed();
List<MCRObject> importedObjects = new ArrayList<>();
for (SyndEntry entry : feed.getEntries()) {
MCRObject importedObject = handleFeedEntry(entry, projectID);
if (importedObject != null) {
importedObjects.add(importedObject);
}
}
int numPublicationsImported = importedObjects.size();
LOGGER.info("imported {} publications.", numPublicationsImported);
if ((numPublicationsImported > 0) && (xsl2BuildNotificationMail != null)) {
sendNotificationMail(importedObjects);
}
}
示例9: handleFeedEntry
import com.rometools.rome.feed.synd.SyndEntry; //导入依赖的package包/类
private MCRObject handleFeedEntry(SyndEntry entry, String projectID)
throws MCRPersistenceException, MCRAccessException {
String publicationID = getPublicationID(entry);
if (publicationID == null) {
return null;
}
if (isAlreadyStored(publicationID)) {
LOGGER.info("publication with ID {} already existing, will not import.", publicationID);
return null;
}
LOGGER.info("publication with ID {} does not exist yet, retrieving data...", publicationID);
Element publicationXML = retrieveAndConvertPublication(publicationID);
if (shouldIgnore(publicationXML)) {
LOGGER.info("publication will be ignored, do not store.");
return null;
}
MCRObject obj = buildMCRObject(publicationXML, projectID);
MCRMetadataManager.create(obj);
return obj;
}
示例10: saveEntryAsItem
import com.rometools.rome.feed.synd.SyndEntry; //导入依赖的package包/类
private void saveEntryAsItem(RssFeedInfoEntity feedInfo, SyndEntry entry) {
String title = ofNullable(entry.getTitle()).orElse("no title");
String link = ofNullable(entry.getLink()).orElse(feedInfo.getUrl() + "#" + title);
Date publishedDate = ofNullable(entry.getPublishedDate()).orElse(new Date());
String content = getContent(entry, feedInfo).orElse(title + ": " + publishedDate.toString());
if (streamItemRepository.findByExternalRefAndUser(feedInfo.getOwner().getUsername(), link).isEmpty()) {
log.info("importing: " + link);
streamItemService.newItemEntity(feedInfo.getOwner().getUsername(),
content,
Optional.of(title),
Optional.of(StreamItemSource.RSS.value()),
Optional.of(link),
Optional.of(publishedDate),
empty());
}
}
示例11: getContent
import com.rometools.rome.feed.synd.SyndEntry; //导入依赖的package包/类
private Optional<String> getContent(SyndEntry entry, RssFeedInfoEntity feedInfo) {
Optional<String> entryDescription = entryDescription(entry);
Optional<String> firstContent = entry
.getContents()
.stream()
.findFirst()
.flatMap(content -> ofNullable(content.getValue()));
Optional<String> customDescription = getCustomDescription(entry);
if (customDescription.isPresent()) {
return customDescription;
} else if (firstContent.isPresent() && shouldUseContent(feedInfo)){
return firstContent;
} else if (entryDescription.isPresent()) {
return entryDescription;
} else if (firstContent.isPresent()) {
return firstContent;
} else {
return Optional.empty();
}
}
示例12: extractSoupDescription
import com.rometools.rome.feed.synd.SyndEntry; //导入依赖的package包/类
private Function<Element, String> extractSoupDescription(SyndEntry entry) {
return element -> {
try {
Map<String, Object> json = new ObjectMapper().readValue(element.getValue(), Map.class);
String type = ofNullable(json.get("type")).orElse("").toString();
String source = ofNullable(json.get("source")).orElse("").toString();
if (type.equals("video")) {
return source.contains("youtube") ? YoutubeUtil.embed(source) : source;
} else {
return entryDescription(entry).orElse(source);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
};
}
示例13: getLastNewsByCity
import com.rometools.rome.feed.synd.SyndEntry; //导入依赖的package包/类
/**
* Récupère la derniere news qui s'est produite dans la ville donnée
* @param city
* @return Une string décrivant la news
*/
public String getLastNewsByCity(String city)
{
city = city.toLowerCase();
for( SyndEntry news : this._inputFeed.getEntries() )
{
String currentCityOfNews = getCityFromNews(news);
//On verifie que la news actuelle s'est produite dans la ville demandée
if( currentCityOfNews == null ? city == null : currentCityOfNews.equals(city) )
{
return formatNewsString(news);
}
}
return "rien a dire";
}
示例14: getCityFromNews
import com.rometools.rome.feed.synd.SyndEntry; //导入依赖的package包/类
/**
* Récupère le nom de la ville concernée par la news
* @param news news à analyser
* @return La ville ou la news s'est produite
*/
private String getCityFromNews(SyndEntry news)
{
//Gros bricolage on utilise
String description = news.getDescription().getValue();
String pattern = "(,|\\.| )";
Pattern splitter = Pattern.compile(pattern);
String[] splitted;
//On applique une limite, on ne veut a la fin qu'un tableau avec deux entrées
splitted = splitter.split(description,2);
return splitted[0].toLowerCase();
}
示例15: run
import com.rometools.rome.feed.synd.SyndEntry; //导入依赖的package包/类
@Scheduled(fixedRate=DateTimeConstants.MILLIS_PER_DAY)
public void run() {
LocalDateTime lastImport = service.getLastImportDate(PublicationSource.ARXIV);
for (String feedKey : FEEDS) {
SyndFeedInput input = new SyndFeedInput();
try {
SyndFeed feed = input.build(new XmlReader(new URL(ROOT_RSS_URL + feedKey)));
List<String> ids = new ArrayList<String>(feed.getEntries().size());
for (SyndEntry entry : feed.getEntries()) {
ids.add(entry.getLink().replace(URI_PREFIX, ""));
}
URL url = new URL("http://export.arxiv.org/api/query?id_list=" + joiner.join(ids) + "&max_results=100");
try (InputStream inputStream = url.openStream()) {
List<Publication> publications = extractPublications(inputStream, lastImport, ids.size());
publications = publications.stream().filter(p -> p.getCreated().isAfter(lastImport)).collect(Collectors.toList());
logger.info("Obtained publications from arxiv for category {}: {}", feedKey, publications.size());
service.storePublication(publications);
}
} catch (IllegalArgumentException | FeedException | IOException e) {
logger.error("Problem getting arxiv RSS feed", e);
}
}
}