개인 목적으로 RSS 읽어오는 것은 불법이 아니지만 홈페이지나 개인 블로그에 개재하는 것은

불법 및 저작권 위반일수 있으니 이는 확인 하시기 바랍니다.

 

jsp 자바 웹서비스에서 RSS 읽어 보여주는 테스트를 진행했습니다.

 

기존의 RSS 기본 구조가 있으며 이를 토대로 변경 및 변형이 조금씩 이뤄진 상태입니다.

물론 완벽히 지키고 있는 곳도 있습니다.

 

네이버의 경우 RSS 주소 찾기가 수월하지 않습니다.

먼저 주소를 확인합니다.

네이버 뉴스 RSS 주소

먼저, 검색어가 필요하고

뉴스 탭으로 이동하게 되면 우측 하단에 RSS 보기가 나타나게 됩니다.

 

위와 같은 결과를 볼수 있습니다.

자 그럼 살짝 분석을 해보면 됩니다.

구조를 보면 

RSS 하위에 channel 이 가 있고 같은 레벨에 ITEM 들이 즐비하게 있습니다. (50개)

 


웹 프로젝트에서 사용을 해보도록 하겠습니다.

준비는 VO식으로 형태를 잡아줄 Feed.java 와 Item(messag)을 잡을 FeedMessage.java를 준비합니다.

한글 주석은 개인적으로 달아 놓은 것으므로 의미상의 분류를 했으니 참고만 하시기 바랍니다.

 

소스 Feed.java

import java.util.ArrayList;
import java.util.List;

/**
 * 피드 읽어 오기
 * @author torrms
 *
 */
public class Feed {
	
	private String title;          /* FEED 제목    title         */
	private String link;           /* 링크         link          */
	private String description;    /* 설명         description   */
	private String language;       /* 언어         language      */
	private String lastbuilddate;  /* 발생일       lastBuildDate */
	

	final List<FeedMessage> entries = new ArrayList<FeedMessage>();

	public Feed(String title, String link, String description, String language, String lastbuilddate) {
        this.title = title;
        this.link = link;
        this.description = description;
        this.language = language;
        this.lastbuilddate = lastbuilddate;
    }
	
	public List<FeedMessage> getMessages() {
        return entries;
    }

	public String getTitle()        { return this.title;        }  /* GET FEED 제목    title         */
	public String getLink()         { return this.link;         }  /* GET 링크         link          */
	public String getDescription()  { return this.description;  }  /* GET 설명         description   */
	public String getLanguage()     { return this.language;     }  /* GET 언어         language      */
	public String getLastbuilddate(){ return this.lastbuilddate;}  /* GET 발생일       lastBuildDate */

	@Override
    public String toString() {
        return "Feed [ description=" + description
                + ", language=" + language + ", link=" + link + ", lastbuilddate="
                + lastbuilddate + ", title=" + title + "]";
    }
}

FeedMessage.java

 

/**
 * RSS 피드 리딩 테스트
 * @author torrms
 *
 */
public class FeedMessage {
	private String title;        /* 제목         title         */
	private String link;         /* 링크         link          */
	private String description;  /* 내용         description   */
	private String pubdate;      /* 날짜         pubDate       */
	private String author;       /* 저작자       author        */
	private String category;     /* 카테고리     category      */
	private String thumbnail;    /* 쎔네일(URL)  thumbnail     */

	public String getTitle()      { return this.title;      }  /* GET 제목         title         */
	public String getLink()       { return this.link;       }  /* GET 링크         link          */
	public String getDescription(){ return this.description;}  /* GET 내용         description   */
	public String getPubdate()    { return this.pubdate;    }  /* GET 날짜         pubDate       */
	public String getAuthor()     { return this.author;     }  /* GET 저작자       author        */
	public String getCategory()   { return this.category;   }  /* GET 카테고리     category      */
	public String getThumbnail()  { return this.thumbnail;  }  /* GET 쎔네일(URL)  thumbnail     */

	public void setTitle(String title)            { this.title       = title;       }   /* SET 제목         title         */
	public void setLink(String link)              { this.link        = link;        }   /* SET 링크         link          */
	public void setDescription(String description){ this.description = description; }   /* SET 내용         description   */
	public void setPubdate(String pubdate)        { this.pubdate     = pubdate;     }   /* SET 날짜         pubDate       */
	public void setAuthor(String author)          { this.author      = author;      }   /* SET 저작자       author        */
	public void setCategory(String category)      { this.category    = category;    }   /* SET 카테고리     category      */
	public void setThumbnail(String thumbnail)    { this.thumbnail   = thumbnail;   }   /* SET 쎔네일(URL)  thumbnail     */

	public String toString() {
        return "FeedMessage [title=" + title + ", description=" + description
                + ", link=" + link + ", author=" + author + ", pubDate = " + pubdate + ", category=" + category + ", thumbnail=" + thumbnail
                + "]";
    }
}

이렇게 준비하면 기본 준비는 끝납니다.

그럼 이제 파싱을 해서 서비스는 부분을 만들어 보겠습니다.

다음글에 계속이어집니다.

 

+ Recent posts