ROME Library는..
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.아래는 ROME Library를 이요한 예제 코드입니다.
import java.net.URL;
import java.util.Date;
import java.util.List;
import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.io.SyndFeedInput;
import com.sun.syndication.io.XmlReader;
public class RssAtomTest {
private static String url ="http://www.sjava.net/rss";
/**
* @param args
*/
public static void main(String[] args) throws Exception {
URL feedUrl = new URL(url);
SyndFeedInput input = new SyndFeedInput();
SyndFeed syndFeed = input.build(new XmlReader(feedUrl));
System.out.println("----------------------- title ------------------------------");
System.out.println(syndFeed.getTitle());
System.out.println("-------------------------------------------------------------");
System.out.println("----------------- updatedAt -------------------------");
System.out.println(syndFeed.getPublishedDate() );
System.out.println("-------------------------------------------------------------");
@SuppressWarnings("unchecked")
List<SyndEntry> entries = syndFeed.getEntries();
SyndEntry entry = null;
for(int i = 0; i < entries.size(); i++) {
entry = entries.get(i);
String title = entry.getTitle();
String url = entry.getUri();
String content = entry.getDescription().getValue();
Date updatedAt = entry.getUpdatedDate();
if(updatedAt == null)
updatedAt = entry.getPublishedDate();
System.out.println("-----------------------------------------------"+i+"-----------------------------------------------------------------");
System.out.println("title : " + title);
System.out.println("------------------------------------------------------------------------------------------------------------------");
System.out.println("url : " + url);
System.out.println("------------------------------------------------------------------------------------------------------------------");
System.out.println("data : "+ content);
System.out.println("------------------------------------------------------------------------------------------------------------------");
System.out.println("date : " + updatedAt.getTime());
System.out.println("------------------------------------------------------------------------------------------------------------------");
}
}
}
import java.util.Date;
import java.util.List;
import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.io.SyndFeedInput;
import com.sun.syndication.io.XmlReader;
public class RssAtomTest {
private static String url ="http://www.sjava.net/rss";
/**
* @param args
*/
public static void main(String[] args) throws Exception {
URL feedUrl = new URL(url);
SyndFeedInput input = new SyndFeedInput();
SyndFeed syndFeed = input.build(new XmlReader(feedUrl));
System.out.println("----------------------- title ------------------------------");
System.out.println(syndFeed.getTitle());
System.out.println("-------------------------------------------------------------");
System.out.println("----------------- updatedAt -------------------------");
System.out.println(syndFeed.getPublishedDate() );
System.out.println("-------------------------------------------------------------");
@SuppressWarnings("unchecked")
List<SyndEntry> entries = syndFeed.getEntries();
SyndEntry entry = null;
for(int i = 0; i < entries.size(); i++) {
entry = entries.get(i);
String title = entry.getTitle();
String url = entry.getUri();
String content = entry.getDescription().getValue();
Date updatedAt = entry.getUpdatedDate();
if(updatedAt == null)
updatedAt = entry.getPublishedDate();
System.out.println("-----------------------------------------------"+i+"-----------------------------------------------------------------");
System.out.println("title : " + title);
System.out.println("------------------------------------------------------------------------------------------------------------------");
System.out.println("url : " + url);
System.out.println("------------------------------------------------------------------------------------------------------------------");
System.out.println("data : "+ content);
System.out.println("------------------------------------------------------------------------------------------------------------------");
System.out.println("date : " + updatedAt.getTime());
System.out.println("------------------------------------------------------------------------------------------------------------------");
}
}
}
'Tools' 카테고리의 다른 글
| ant를 이용해서, lib 폴더의 denendency jar file을 manifest의 class-path에 손쉽게 추가하기... (0) | 2010/11/09 |
|---|---|
| json java 라이브러리 google-gson의 기본 캐릭터셋은 utf-8 이군요.. (1) | 2010/11/04 |
| ROME Library를 이용한 Atom/RSS 읽어오기.. (0) | 2010/10/26 |
| eclipse에서 toString()을 자동으로 해 주네요.. ^^;; (0) | 2010/10/25 |
| eclipse에서 다국어를 쉽게 지원하기.. (0) | 2010/08/19 |