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 ModerateComment 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 75 sp = new ServletPrinter(response, "ModerateComment"); 76 77 String comment_table, commentId; 78 79 ResultSet rs = null; 80 81 comment_table = request.getParameter("comment_table"); 82 commentId = request.getParameter("commentId"); 83 84 if (comment_table == null) 85 { 86 sp.printHTML("Moderating comment, You must provide a comment table!<br>"); 87 return; 88 } 89 90 if (commentId == null) 91 { 92 sp 93 .printHTML("Moderating comment, You must provide a comment identifier!<br>"); 94 return; 95 } 96 97 sp.printHTMLheader("RUBBoS: Comment moderation"); 98 99 conn = getConnection(); 100 101 try 102 { 103 stmt = conn.prepareStatement("SELECT * FROM " + comment_table 104 + " WHERE id=" + commentId); 105 rs = stmt.executeQuery(); 106 } 107 catch (Exception e) 108 { 109 sp.printHTML("Failed to execute Query for ModerateComment: " + e); 110 closeConnection(stmt, conn); 111 return; 112 } 113 114 try 115 { 116 if (!rs.first()) 117 { 118 sp 119 .printHTML("<h3>ERROR: Sorry, but this comment does not exist.</h3><br>\n"); 120 closeConnection(stmt, conn); 121 return; 122 } 123 } 124 catch (Exception e) 125 { 126 sp.printHTML("Exception moderating comments: " + e + "<br>"); 127 closeConnection(stmt, conn); 128 return; 129 } 130 131 try 132 { 133 String storyId = rs.getString("story_id"); 134 sp 135 .printHTML("<p><br><center><h2>Moderate a comment !</h2></center><br>\n<br><hr><br>"); 136 String username = sp.getUserName(rs.getInt("writer"), conn); 137 sp 138 .printHTML("<TABLE width=\"100%\" bgcolor=\"#CCCCFF\"><TR><TD><FONT size=\"4\" color=\"#000000\"><center><B><a HREF=\"/rubbos/servlet/edu.rice.rubbos.servlets.ViewComment?comment_table=" 139 + comment_table 140 + "&storyId=" 141 + storyId 142 + "&commentId=" 143 + rs.getInt("id") 144 + "\">" 145 + rs.getString("subject") 146 + "</a></B> </FONT> (Score:" 147 + rs.getString("rating") 148 + ")</center></TABLE>\n"); 149 sp.printHTML("<TABLE><TR><TD><B>Posted by " + username + " on " 150 + rs.getString("date") + "</B><p>\n"); 151 sp 152 .printHTML("<TR><TD>" 153 + rs.getString("comment") 154 + "</TABLE><p><hr><p>\n" 155 + "<form action=\"/rubbos/servlet/edu.rice.rubbos.servlets.StoreModeratorLog\" method=POST>\n" 156 + "<input type=hidden name=commentId value=" 157 + commentId 158 + ">\n" 159 + "<input type=hidden name=comment_table value=" 160 + comment_table 161 + ">\n" 162 + "<center><table>\n" 163 + "<tr><td><b>Nickname</b><td><input type=text size=20 name=nickname>\n" 164 + "<tr><td><b>Password</b><td><input type=text size=20 name=password>\n" 165 + "<tr><td><b>Rating</b><td><SELECT name=rating>\n" 166 + "<OPTION value=\"-1\">-1: Offtopic</OPTION>\n" 167 + "<OPTION selected value=\"0\">0: Not rated</OPTION>\n" 168 + "<OPTION value=\"1\">1: Interesting</OPTION>\n" 169 + "</SELECT></table><p><br>\n" 170 + "<input type=submit value=\"Moderate this comment now!\"></center><p>\n"); 171 } 172 catch (Exception e2) 173 { 174 sp.printHTML("Exception moderating comments part 2: " + e2 + "<br>"); 175 } 176 177 closeConnection(stmt, conn); 178 179 sp.printHTMLfooter(); 180 181 } 182 183 public void doPost(HttpServletRequest request, HttpServletResponse response) 184 throws IOException , ServletException 185 { 186 doGet(request, response); 187 } 188 189 } 190 | Popular Tags |