1 24 25 package edu.rice.rubbos.servlets; 26 27 import java.io.IOException ; 28 import java.sql.Connection ; 29 import java.sql.PreparedStatement ; 30 import java.sql.ResultSet ; 31 32 import javax.servlet.ServletException ; 33 import javax.servlet.http.HttpServletRequest ; 34 import javax.servlet.http.HttpServletResponse ; 35 36 public class ReviewStories extends RubbosHttpServlet 37 { 38 39 public int getPoolSize() 40 { 41 return Config.BrowseCategoriesPoolSize; 42 } 43 44 private void closeConnection(PreparedStatement stmt, Connection conn) 45 { 46 try 47 { 48 if (stmt != null) 49 stmt.close(); } 51 catch (Exception ignore) 52 { 53 } 54 55 try 56 { 57 if (conn != null) 58 releaseConnection(conn); 59 } 60 catch (Exception ignore) 61 { 62 } 63 64 } 65 66 67 public void doGet(HttpServletRequest request, HttpServletResponse response) 68 throws IOException , ServletException 69 { 70 71 ServletPrinter sp = null; 72 PreparedStatement stmt = null; 73 Connection conn = null; 74 String date, title, id, body, username; 75 ResultSet rs = null; 76 77 sp = new ServletPrinter(response, "ReviewStories"); 78 sp.printHTMLheader("RUBBoS: Review Stories"); 79 80 conn = getConnection(); 81 82 try 83 { 84 stmt = conn 85 .prepareStatement("SELECT * FROM submissions ORDER BY date DESC LIMIT 10"); 86 rs = stmt.executeQuery(); 87 } 88 catch (Exception e) 89 { 90 sp.printHTML("Failed to execute Query for ReviewStories " + e); 91 closeConnection(stmt, conn); 92 return; 93 } 94 95 try 96 { 97 if (!rs.first()) 98 { 99 sp 100 .printHTML("<h2>Sorry, but there is no submitted story available at this time.</h2><br>\n"); 101 closeConnection(stmt, conn); 102 return; 103 } 104 do 105 { 106 title = rs.getString("title"); 107 date = rs.getString("date"); 108 id = rs.getString("id"); 109 body = rs.getString("body"); 110 111 sp.printHTML("<br><hr>\n"); 112 sp.printHTMLHighlighted(title); 113 username = rs.getString("writer"); 114 sp.printHTML("<B>Posted by " + username + " on " + date + "</B><br>\n"); 115 sp.printHTML(body); 116 sp 117 .printHTML("<br><p><center><B>[ <a HREF=\"/rubbos/servlet/edu.rice.rubbos.servlets.AcceptStory?storyId=" 118 + id 119 + "\">Accept</a> | <a HREF=\"/rubbos/servlet/edu.rice.rubbos.servlets.RejectStory?storyId=" 120 + id + "\">Reject</a> ]</B><p>\n"); 121 } 122 while (rs.next()); 123 } 124 catch (Exception e) 125 { 126 sp.printHTML("Exception rejecting story: " + e + "<br>"); 127 } 128 129 closeConnection(stmt, conn); 130 131 sp.printHTMLfooter(); 132 133 } 134 135 public void doPost(HttpServletRequest request, HttpServletResponse response) 136 throws IOException , ServletException 137 { 138 doGet(request, response); 139 } 140 141 } 142 | Popular Tags |