Possible Duplicate:
How To Discover RSS Feeds for a given URL
Given a URL, I'd like to know whether it's a feed or not.
In Zend Framework, it is possible to import a URL as a feed:
try {
$slashdotRss =
Zend_Feed::import('http://rss.slashdot.org/Slashdot/slashdot');
} catch (Zend_Feed_Exception $e) {
// feed import failed
echo "Exception caught importing feed: {$e->getMessage()}\n";
exit;
}
And if an exception is thrown, then I know the URL is not a feed.
I would like to do the same algorithm in Java, so my question is: How does Zend know whether a URL is a feed or not ?
What I'd do is get it to rome and try to parse it. If it fails to parse, it will throw a FeedException:
public boolean tryFeed(String feedUrl) throws IOException,MalformedURLException {
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = null;
try {
feed = input.build(new XmlReader(new URL(feedUrl)));
return true;
} catch (FeedException e) {
// Feed's invalid
return false;
}
}