KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > rice > rubbos > servlets > ModerateComment


1 /**
2  * RUBBoS: Rice University Bulletin Board System.
3  * Copyright (C) 2001-2004 Rice University and French National Institute For
4  * Research In Computer Science And Control (INRIA).
5  * Contact: jmob@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Emmanuel Cecchet.
22  * Contributor(s): Niraj Tolia.
23  */

24
25 package edu.rice.rubbos.servlets;
26
27 import java.io.IOException JavaDoc;
28 import java.sql.Connection JavaDoc;
29 import java.sql.PreparedStatement JavaDoc;
30 import java.sql.ResultSet JavaDoc;
31
32 import javax.servlet.ServletException JavaDoc;
33 import javax.servlet.http.HttpServletRequest JavaDoc;
34 import javax.servlet.http.HttpServletResponse JavaDoc;
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 JavaDoc stmt, Connection JavaDoc conn)
45   {
46     try
47     {
48       if (stmt != null)
49         stmt.close(); // close statement
50
}
51     catch (Exception JavaDoc ignore)
52     {
53     }
54
55     try
56     {
57       if (conn != null)
58           releaseConnection(conn);
59     }
60     catch (Exception JavaDoc ignore)
61     {
62     }
63
64   }
65
66   /** Build the html page for the response */
67   public void doGet(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
68       throws IOException JavaDoc, ServletException JavaDoc
69   {
70
71     ServletPrinter sp = null;
72     PreparedStatement JavaDoc stmt = null;
73     Connection JavaDoc conn = null;
74
75     sp = new ServletPrinter(response, "ModerateComment");
76
77     String JavaDoc comment_table, commentId;
78
79     ResultSet JavaDoc 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 JavaDoc 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 JavaDoc e)
125     {
126       sp.printHTML("Exception moderating comments: " + e + "<br>");
127       closeConnection(stmt, conn);
128       return;
129     }
130
131     try
132     {
133       String JavaDoc 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 JavaDoc 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>&nbsp</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 JavaDoc 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 JavaDoc request, HttpServletResponse JavaDoc response)
184       throws IOException JavaDoc, ServletException JavaDoc
185   {
186     doGet(request, response);
187   }
188
189 }
190
Popular Tags