01/29
2014
ROME: RSS and Atom Utilities
RSS리더모듈이 필요해서 검색한결과 ROME가 가장 많이 쓰이고 있었다.
http://wiki.java.net/bin/view/Javawsxml/Rome
ROME: RSS and Atom Utilities
ROME is an set of open source Java tools for parsing, generating and publishing RSS and Atom feeds. The core ROME library depends only on the JDOM XML parser and supports parsing, generating and converting all of the popular RSS and Atom formats including RSS 0.90, RSS 0.91 Netscape, RSS 0.91 Userland, RSS 0.92, RSS 0.93, RSS 0.94, RSS 1.0, RSS 2.0, Atom 0.3, and Atom 1.0. You can parse to an RSS object model, an Atom object model or an abstract SyndFeed model that can model either family of formats.
Latest release: ROME v1.0 RC1 Release (Jul/16/2008)
사용방법은
try {
URL feedUrl = new URL("http://starpl.com/byuri/rss");
SyndFeedInput input = new SyndFeedInput();
SyndFeed syndFeed = input.build(new XmlReader(feedUrl));
List<SyndEntry> entries = syndFeeds.getEntries();
for (SyndEntry entry : entries)
{
System.out.println(entry.getTitle());
System.out.println(entry.getUri());
System.out.println(entry.getAuthor());
System.out.println(entry.getDescription().getValue());
}
}
catch (Exception e) {
e.printStackTrace();
}
이런 식으로 하면 된다.
그런데. 위와같이 하면 인식을 못하는 RSS가 있다.
그런경우 http://wiki.java.net/bin/view/Javawsxml/RomeFetcher
를 참고로 Rome 서브프로젝트중 하나인 Rome Fetcher 사용해서 요렇게 수정해주면 된다.
SyndFeedInput input = new SyndFeedInput();
SyndFeed syndFeed = input.build(new XmlReader(feedUrl));
↓↓↓↓↓
HttpClientFeedFetcher fetcher = new HttpClientFeedFetcher();
SyndFeed syndFeeds = fetcher.retrieveFeed(feedUrl);