Java Code Examples for com.rometools.rome.feed.synd.SyndFeed#getLinks()

The following examples show how to use com.rometools.rome.feed.synd.SyndFeed#getLinks() . 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: Subscriptions.java    From rome with Apache License 2.0 6 votes vote down vote up
private void validateLink(final SyndFeed feed, final String source) {
    for (final SyndLink l : feed.getLinks()) {
        if ("self".equalsIgnoreCase(l.getRel())) {
            try {
                final URI u = new URI(l.getHref());
                final URI t = new URI(source);

                if (!u.equals(t)) {
                    throw new HttpStatusCodeException(400, "Feed self link does not match the subscribed URI.", null);
                }

                break;
            } catch (final URISyntaxException ex) {
                LOG.error(null, ex);
            }
        }
    }
}
 
Example 2
Source File: Publisher.java    From rome with Apache License 2.0 5 votes vote down vote up
/**
 * Sends a notification for a feed located at "topic". The feed MUST contain rel="hub".
 *
 * @param topic URL for the feed
 * @param feed The feed itself
 * @throws NotificationException Any failure
 */
public void sendUpdateNotification(final String topic, final SyndFeed feed) throws NotificationException {
    for (final SyndLink link : feed.getLinks()) {
        if ("hub".equals(link.getRel())) {
            sendUpdateNotification(link.getRel(), topic);

            return;
        }
    }
    throw new NotificationException("Hub link not found.");
}
 
Example 3
Source File: Publisher.java    From rome with Apache License 2.0 5 votes vote down vote up
/**
 * Sends a notification for a feed. The feed MUST contain rel="hub" and rel="self" links.
 *
 * @param feed The feed to notify
 * @throws NotificationException Any failure
 */
public void sendUpdateNotification(final SyndFeed feed) throws NotificationException {
    SyndLink hub = null;
    SyndLink self = null;

    for (final SyndLink link : feed.getLinks()) {
        if ("hub".equals(link.getRel())) {
            hub = link;
        }

        if ("self".equals(link.getRel())) {
            self = link;
        }

        if (hub != null && self != null) {
            break;
        }
    }

    if (hub == null) {
        throw new NotificationException("A link rel='hub' was not found in the feed.");
    }

    if (self == null) {
        throw new NotificationException("A link rel='self' was not found in the feed.");
    }

    sendUpdateNotification(hub.getRel(), self.getHref());
}
 
Example 4
Source File: Subscriptions.java    From rome with Apache License 2.0 5 votes vote down vote up
private String findHubUrl(final SyndFeed feed) {
    for (final SyndLink l : feed.getLinks()) {
        if ("hub".equals(l.getRel())) {
            return l.getHref();
        }
    }

    return null;
}
 
Example 5
Source File: ConverterForRSS090.java    From rome with Apache License 2.0 5 votes vote down vote up
protected WireFeed createRealFeed(final String type, final SyndFeed syndFeed) {
    final Channel channel = new Channel(type);
    channel.setModules(ModuleUtils.cloneModules(syndFeed.getModules()));
    channel.setStyleSheet(syndFeed.getStyleSheet());
    channel.setEncoding(syndFeed.getEncoding());

    channel.setTitle(syndFeed.getTitle());
    final String link = syndFeed.getLink();
    final List<SyndLink> links = syndFeed.getLinks();
    if (link != null) {
        channel.setLink(link);
    } else if (!links.isEmpty()) {
        channel.setLink(links.get(0).getHref());
    }

    channel.setDescription(syndFeed.getDescription());

    final SyndImage sImage = syndFeed.getImage();
    if (sImage != null) {
        channel.setImage(createRSSImage(sImage));
    }

    final List<SyndEntry> sEntries = syndFeed.getEntries();
    if (sEntries != null) {
        channel.setItems(createRSSItems(sEntries));
    }

    final List<Element> foreignMarkup = syndFeed.getForeignMarkup();
    if (!foreignMarkup.isEmpty()) {
        channel.setForeignMarkup(foreignMarkup);
    }

    return channel;
}
 
Example 6
Source File: FeedParser.java    From commafeed with Apache License 2.0 5 votes vote down vote up
private String findHub(SyndFeed feed) {
	for (SyndLink l : feed.getLinks()) {
		if ("hub".equalsIgnoreCase(l.getRel())) {
			log.debug("found hub {} for feed {}", l.getHref(), feed.getLink());
			return l.getHref();
		}
	}
	return null;
}
 
Example 7
Source File: FeedParser.java    From commafeed with Apache License 2.0 5 votes vote down vote up
private String findSelf(SyndFeed feed) {
	for (SyndLink l : feed.getLinks()) {
		if ("self".equalsIgnoreCase(l.getRel())) {
			log.debug("found self {} for feed {}", l.getHref(), feed.getLink());
			return l.getHref();
		}
	}
	return null;
}