001: package org.claros.intouch.rss.services;
002:
003: import java.io.IOException;
004: import java.io.PrintWriter;
005: import java.util.List;
006:
007: import javax.servlet.ServletException;
008: import javax.servlet.http.HttpServletRequest;
009: import javax.servlet.http.HttpServletResponse;
010:
011: import org.claros.commons.utility.Utility;
012: import org.claros.intouch.common.services.BaseService;
013: import org.claros.intouch.rss.controllers.NewsController;
014: import org.claros.intouch.rss.models.NewsItem;
015:
016: public class GetRssItemsService extends BaseService {
017:
018: /**
019: *
020: */
021: private static final long serialVersionUID = -553212879305214811L;
022:
023: /**
024: * The doGet method of the servlet. <br>
025: *
026: * This method is called when a form has its tag value method equals to get.
027: *
028: * @param request the request send by the client to the server
029: * @param response the response send by the server to the client
030: * @throws ServletException if an error occurred
031: * @throws IOException if an error occurred
032: */
033: public void doGet(HttpServletRequest request,
034: HttpServletResponse response) throws ServletException,
035: IOException {
036:
037: response.setHeader("Expires", "-1");
038: response.setHeader("Pragma", "no-cache");
039: response.setHeader("Cache-control", "no-cache");
040: response.setHeader("Content-Type", "text/xml; charset=utf-8");
041: PrintWriter out = response.getWriter();
042:
043: out.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
044: out.write("<data>");
045: out.print("<items>");
046: try {
047: List news = NewsController
048: .getRssItems(getAuthProfile(request));
049: String channelTitle = "";
050: String channelDesc = "";
051: String channelUrl = "";
052:
053: if (news != null) {
054: NewsItem item = null;
055: for (int i = 0; i < news.size(); i++) {
056: item = (NewsItem) news.get(i);
057: out.print("<item>");
058:
059: out.print("<date> "
060: + Utility.htmlSpecialChars(item.getDate())
061: + "</date>");
062: out.print("<description> "
063: + Utility.htmlSpecialChars(item
064: .getDescription())
065: + "</description>");
066: out.print("<url> "
067: + Utility.htmlSpecialChars(item.getLink())
068: + "</url>");
069: out.print("<title> "
070: + Utility.htmlSpecialChars(item.getTitle())
071: + "</title>");
072: if (channelTitle == null || channelTitle.equals("")) {
073: channelTitle = Utility.htmlSpecialChars(item
074: .getChannelTitle());
075: }
076: if (channelDesc == null || channelDesc.equals("")) {
077: channelDesc = Utility.htmlSpecialChars(item
078: .getChannelDescription());
079: }
080: if (channelUrl == null || channelUrl.equals("")) {
081: channelUrl = Utility.htmlSpecialChars(item
082: .getChannelUrl());
083: }
084: out.print("</item>");
085: }
086: }
087: out.print("</items>");
088: out.print("<channelTitle> " + channelTitle
089: + "</channelTitle>");
090: out
091: .print("<channelDesc> " + channelDesc
092: + "</channelDesc>");
093: out.print("<channelUrl> " + channelUrl + "</channelUrl>");
094: out.print("<result>0</result>");
095: } catch (Exception e) {
096: out.print("</items>");
097: out.print("<result>1</result>");
098: }
099: out.print("</data>");
100: }
101:
102: }
|