Java Code Examples for com.rometools.rome.feed.synd.SyndEntry#getLink()

The following examples show how to use com.rometools.rome.feed.synd.SyndEntry#getLink() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RssConverterManager.java    From entando-components with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public List<Content> getContents(ApsAggregatorItem item) throws ApsSystemException {
	List<Content> contents = new ArrayList<Content>();
	AggregatorConfig aggregatorConfig = this.getMappingMap().get(item.getContentType());
	try {
		List<SyndEntry> entries = this.getRssEntries(IRssConverterManager.RSS_2_0, item.getLink());
		if(null == entries) return contents;
		Iterator<SyndEntry> entriesIt = entries.iterator();
		String linkAttributeName = aggregatorConfig.getLinkAttributeName();// this.getLinkAttributeName(typeCode);
		while (entriesIt.hasNext()) {
			SyndEntry feedItem = entriesIt.next();
			String link = feedItem.getLink();
			Content content = this.getExistingContent(link, linkAttributeName, item.getContentType());
			if (null == content) {
				String typeCode = aggregatorConfig.getContentType();
				content = this.getContentManager().createContentType(typeCode);
			}
			this.getContentBuilder().populateContentFromMapping(content, feedItem, item, this.getMappingMap().get(aggregatorConfig.getContentType()));
			contents.add(content);
		}
	} catch (Throwable t) {
		_logger.error("error transforming feed to content list", t);
		throw new ApsSystemException("error transforming feed to content list", t);
	}
	return contents;
}
 
Example 2
Source File: RssFeed.java    From torrssen2 with MIT License 5 votes vote down vote up
public String getLinkByKey(String key, SyndEntry syndEntry) {
    if (StringUtils.isEmpty(key) || StringUtils.equals(key, "link")) {
        return syndEntry.getLink();
    }

    return null;
}
 
Example 3
Source File: MCRRSSFeedImporter.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
private String getPublicationID(SyndEntry entry) {
    String link = entry.getLink();
    if (link == null) {
        LOGGER.warn("no link found in feed entry");
        return null;
    }
    link = link.trim();
    Matcher m = pattern2findID.matcher(link);
    if (m.matches()) {
        return m.group(1);
    } else {
        LOGGER.warn("no publication ID found in link {}", link);
        return null;
    }
}
 
Example 4
Source File: Utilities.java    From SimpleNews with Apache License 2.0 5 votes vote down vote up
static Entry getEntryFromRSSItem(SyndEntry item, Long feedId, String source, long categoryId) {
    if (item != null) {
        if (item.getTitle() == null) {
            return null;
        }

        Object url = item.getLink();
        if (url == null) {
            return null;
        }

        Date pubDate = item.getPublishedDate();
        Long time = null;
        if (pubDate != null) {
            time = pubDate.getTime();
        }

        SyndContent desc = item.getDescription();
        String description = null;
        if (desc != null && desc.getValue() != null) {
            description = desc.getValue();
            description = description.replaceAll("<.*?>", "").replace("()", "").replace("&nbsp;", "").trim();
        }

        return new Entry(null, feedId, categoryId, item.getTitle().trim(), description, time, source, url.toString(), null, null, null, null,
                false);
    }
    return null;
}
 
Example 5
Source File: RssFeed.java    From torrssen2 with MIT License 4 votes vote down vote up
public void setLinkByKey(String key, SyndEntry syndEntry) {
    if (StringUtils.isEmpty(key) || StringUtils.equals(key, "link")) {
        this.link = syndEntry.getLink();
    }
}
 
Example 6
Source File: SyndFeedTest.java    From rome with Apache License 2.0 4 votes vote down vote up
public String getEntryLink(final Object o) {
    final SyndEntry e = (SyndEntry) o;
    return e.getLink();
}
 
Example 7
Source File: FeedParserBolt.java    From storm-crawler with Apache License 2.0 4 votes vote down vote up
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;
}