1 25 package org.snipsnap.net; 26 27 import org.snipsnap.app.Application; 28 import org.snipsnap.config.Configuration; 29 import org.snipsnap.container.Components; 30 import org.snipsnap.feeder.Feeder; 31 import org.snipsnap.feeder.FeederRepository; 32 import org.snipsnap.render.PlainTextRenderEngine; 33 import org.snipsnap.semanticweb.rss.BlogFeeder; 34 import org.snipsnap.snip.Snip; 35 import org.snipsnap.snip.SnipSpace; 36 import org.snipsnap.snip.SnipSpaceFactory; 37 38 import javax.servlet.RequestDispatcher ; 39 import javax.servlet.ServletException ; 40 import javax.servlet.http.HttpServlet ; 41 import javax.servlet.http.HttpServletRequest ; 42 import javax.servlet.http.HttpServletResponse ; 43 import java.io.IOException ; 44 45 46 52 public class RssServlet extends HttpServlet { 53 public void doGet(HttpServletRequest request, HttpServletResponse response) 54 throws IOException , ServletException { 55 56 SnipSpace space = SnipSpaceFactory.getInstance(); 57 Configuration config = Application.get().getConfiguration(); 58 59 String eTag = request.getHeader("If-None-Match"); 60 if (null != eTag && eTag.equals(space.getETag())) { 61 response.setHeader("ETag", space.getETag()); 62 response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); 63 return; 64 } else { 65 String version = request.getParameter("version"); 66 String type = request.getParameter("type"); 67 String sourceSnipName = request.getParameter("snip"); 68 69 if (null == sourceSnipName) { 70 sourceSnipName = config.getStartSnip(); 71 } 72 73 Snip sourceSnip = space.load(sourceSnipName); 74 75 Object object = Components.getComponent(PlainTextRenderEngine.class); 76 System.err.println("object = " + object.getClass()); 77 78 FeederRepository repository = (FeederRepository) Components.getComponent(FeederRepository.class); 79 80 Feeder feeder = (Feeder) repository.get(type); 81 82 if (null == feeder || "blog".equals(feeder.getName())) { 84 if (sourceSnip.isWeblog()) { 85 feeder = new BlogFeeder(sourceSnipName); 86 } else { 87 feeder = new BlogFeeder(); 88 } 89 } 90 91 Snip snip = feeder.getContextSnip(); 92 93 request.setAttribute("snip", snip); 94 request.setAttribute("rsssnips", feeder.getFeed()); 95 request.setAttribute("space", space); 96 request.setAttribute("config", config); 97 98 request.setAttribute("url", config.getUrl("/space")); 99 100 RequestDispatcher dispatcher; 101 if ("1.0".equals(version)) { 102 dispatcher = request.getRequestDispatcher("/rdf.jsp"); 103 } else if ("0.92".equals(version)) { 104 dispatcher = request.getRequestDispatcher("/rss.jsp"); 105 } else if ("plain".equals(version)) { 106 dispatcher = request.getRequestDispatcher("/plain.jsp"); 107 } else { 108 dispatcher = request.getRequestDispatcher("/rss2.jsp"); 109 } 110 111 dispatcher.forward(request, response); 112 } 113 } 114 } 115 | Popular Tags |