2
|
1 package jp.ac.u_ryukyu.ie.cr.bbs.network;
|
|
2
|
3
|
3 import jp.ac.u_ryukyu.ie.cr.bbs.local.GetAttributeImp;
|
2
|
4 import org.eclipse.jetty.util.thread.ThreadPool;
|
|
5
|
|
6 import javax.servlet.http.HttpServlet;
|
|
7 import javax.servlet.http.HttpServletRequest;
|
|
8 import javax.servlet.http.HttpServletResponse;
|
|
9 import java.io.PrintWriter;
|
|
10 import java.util.Iterator;
|
|
11
|
|
12 public class ShowMessageWithTimeStampServlet extends HttpServlet {
|
|
13 /**
|
|
14 *
|
|
15 */
|
|
16 private static final long serialVersionUID = 1L;
|
3
|
17 private final jp.ac.u_ryukyu.ie.cr.bbs.network.NetworkBulletinBoard bbs;
|
2
|
18 private final String createBoardMessagePath;
|
|
19
|
|
20 private static final String PARAM_BOARD_NAME = "bname";
|
|
21 private final String editMessagePath;
|
|
22
|
|
23 public ShowMessageWithTimeStampServlet(NetworkBulletinBoard _bbs,
|
|
24 String _createBoardMessagePath, String _editMessagePath, ThreadPool thp) {
|
|
25 bbs = _bbs;
|
|
26 createBoardMessagePath = _createBoardMessagePath;
|
|
27 editMessagePath = _editMessagePath;
|
|
28 }
|
|
29
|
|
30 public void doGet(HttpServletRequest _req, HttpServletResponse _res) {
|
|
31 final String bname = (_req.getParameter(PARAM_BOARD_NAME));
|
|
32 try {
|
|
33 _res.setCharacterEncoding("UTF-8");
|
|
34 printBoard(bname, _res.getWriter());
|
|
35 } catch (Exception _e) {
|
|
36 _res.setStatus(500);
|
|
37 }
|
|
38 }
|
|
39
|
|
40 private void printBoard(String _bname, PrintWriter _pw) throws Exception {
|
|
41 _pw.write("<html><body>\n");
|
|
42 _pw.write("<h1>" + bbs.sanitize(_bname) + "</h1>\n");
|
|
43 _pw.write("<p>Latest renew time : " + bbs.getRenewTime(_bname)
|
|
44 + "</p>\n");
|
|
45 ;
|
|
46
|
|
47 _pw.write("<form action='" + createBoardMessagePath + "' method='POST'\n");
|
|
48 _pw.write("<p>Author : <input type='text' name='author'/> <input type='hidden' name='bname' value='" + bbs.sanitize(_bname) + "'/> EditKey : <input type='textarea' name='key'/></p>\n");
|
|
49 _pw.write("<p>Message<br/> <input type='textarea' name='msg'/> </p>\n");
|
|
50 _pw.write("<p><input type='submit' value='submit'/></p>\n");
|
|
51
|
4
|
52 GetAttributeImp attribute = bbs.getAttribute(_bname, "[-1]","1");
|
2
|
53 Iterator<String> keys = attribute.getKeys();
|
|
54
|
|
55 while (keys.hasNext()) {
|
|
56 String key = keys.next();
|
|
57 String mesage = attribute.getMessage(key);
|
|
58 _pw.write("<p>" + key + " = " + mesage + "</p>\n");
|
|
59 }
|
|
60 _pw.write("<p><a href='" + editMessagePath + "?bname=" + bbs.sanitize(_bname) + "&uuid=-1,0" + "'>edit" + "</a></p>");
|
|
61 _pw.write("</body></html>");
|
|
62 _pw.flush();
|
|
63 }
|
|
64 }
|