Example #1
0
 /**
  * RecordSet을 RSS 2.0 형식으로 변환한다. RecordSet에는 다음컬럼이 반드시 포함되어야 한다.(title, link, description, author,
  * category, pubDate). <br>
  * ex) rs를 RSS 형식으로 변환하는 경우 => String rss = RssUtil.format(rs, "utf-8", "제목",
  * "http://www.xxx.com", "설명", "*****@*****.**")
  *
  * @param rs RSS 형식으로 변환할 RecordSet 객체
  * @param encoding 헤더에 포함될 인코딩
  * @param title 제목 : 필수
  * @param link 링크(validator를 통과하기 위해서는 url에 앰퍼센드등은 엔터티표기를 사용하여야 함) : 필수
  * @param description 설명 : 필수
  * @param webMaster 웹마스터 e-mail 주소(validator를 통과하기 위해서는 "이메일주소(이름)" 형식으로 표기하여야 함) : 옵션
  * @return RSS 형식으로 변환된 문자열
  * @throws ColumnNotFoundException
  */
 public static String format(
     RecordSet rs,
     String encoding,
     String title,
     String link,
     String description,
     String webMaster) {
   if (rs == null) {
     return null;
   }
   StringBuilder buffer = new StringBuilder();
   rs.moveRow(0);
   buffer.append(xmlHeaderStr(encoding) + BR);
   buffer.append("<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">" + BR);
   buffer.append("  <channel>" + BR);
   buffer.append("    <title>" + "<![CDATA[" + title + "]]>" + "</title>" + BR);
   buffer.append("    <link>" + link + "</link>" + BR);
   buffer.append("    <description>" + "<![CDATA[" + description + "]]>" + "</description>" + BR);
   buffer.append("    <language>ko</language>" + BR);
   buffer.append(
       "    <atom:link href=\"" + link + "\" rel=\"self\" type=\"application/rss+xml\"/>" + BR);
   buffer.append("    <pubDate>" + toRfc822DateFormat(new Date()) + "</pubDate>" + BR);
   if (webMaster != null && !"".equals(webMaster)) {
     buffer.append("    <webMaster>" + webMaster + "</webMaster>" + BR);
   }
   while (rs.nextRow()) {
     buffer.append(rssItemStr(rs) + BR);
   }
   buffer.append("  </channel>" + BR);
   buffer.append("</rss>" + BR);
   return buffer.toString();
 }
Example #2
0
 /**
  * RecordSet을 RSS 2.0 형식으로 출력한다. RecordSet에는 다음컬럼이 반드시 포함되어야 한다.(title, link, description, author,
  * category, pubDate). <br>
  * ex) response로 rs를 RSS 형식으로 출력하는 경우 => RssUtil.setRecordSet(response, rs, "utf-8", "제목",
  * "http://www.xxx.com", "설명", "*****@*****.**")
  *
  * @param response 클라이언트로 응답할 Response 객체
  * @param rs RSS 형식으로 변환할 RecordSet 객체
  * @param encoding 헤더에 포함될 인코딩
  * @param title 제목 : 필수
  * @param link 링크(validator를 통과하기 위해서는 url에 앰퍼센드등은 엔터티표기를 사용하여야 함) : 필수
  * @param description 설명 : 필수
  * @param webMaster 웹마스터 e-mail 주소(validator를 통과하기 위해서는 "이메일주소(이름)" 형식으로 표기하여야 함) : 옵션
  * @return 처리건수
  * @throws IOException
  * @throws ColumnNotFoundException
  */
 public static int setRecordSet(
     HttpServletResponse response,
     RecordSet rs,
     String encoding,
     String title,
     String link,
     String description,
     String webMaster)
     throws IOException {
   if (rs == null) {
     return 0;
   }
   PrintWriter pw = response.getWriter();
   rs.moveRow(0);
   pw.println(xmlHeaderStr(encoding));
   pw.println("<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">");
   pw.println("  <channel>");
   pw.println("    <title>" + "<![CDATA[" + title + "]]>" + "</title>");
   pw.println("    <link>" + link + "</link>");
   pw.println("    <description>" + "<![CDATA[" + description + "]]>" + "</description>");
   pw.println("    <language>ko</language>");
   pw.println("    <atom:link href=\"" + link + "\" rel=\"self\" type=\"application/rss+xml\"/>");
   pw.println("    <pubDate>" + toRfc822DateFormat(new Date()) + "</pubDate>");
   if (webMaster != null && !"".equals(webMaster)) {
     pw.println("    <webMaster>" + webMaster + "</webMaster>");
   }
   int rowCount = 0;
   while (rs.nextRow()) {
     rowCount++;
     pw.println(rssItemStr(rs));
   }
   pw.println("  </channel>");
   pw.println("</rss>");
   return rowCount;
 }
Example #3
0
 /** rss item 문자열 생성 */
 private static String rssItemStr(RecordSet rs) {
   String title = null;
   String link = null;
   String description = null;
   String author = null;
   String category = null;
   Date pubDate = null;
   try {
     title = rs.getString("TITLE");
   } catch (ColumnNotFoundException e) {
   }
   try {
     link = rs.getString("LINK");
   } catch (ColumnNotFoundException e) {
   }
   try {
     description = rs.getString("DESCRIPTION");
   } catch (ColumnNotFoundException e) {
   }
   try {
     author = rs.getString("AUTHOR");
   } catch (ColumnNotFoundException e) {
   }
   try {
     category = rs.getString("CATEGORY");
   } catch (ColumnNotFoundException e) {
   }
   try {
     pubDate = rs.getTimestamp("PUBDATE");
   } catch (ColumnNotFoundException e) {
   }
   return rssItemStr(makeRssItem(title, link, description, author, category, pubDate));
 }