4
|
1 package jp.ac.u_ryukyu.ie.cr.bbs.browsing;
|
|
2
|
10
|
3 import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode;
|
|
4 import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNodeAttributes;
|
1
|
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 ShowBoardMessageServlet extends HttpServlet {
|
|
13 /**
|
|
14 *
|
|
15 */
|
|
16 private static final long serialVersionUID = 1L;
|
4
|
17 private final BrowsingBulletinBoard bbs;
|
1
|
18 private final String createBoardMessagePath;
|
4
|
19 private final String createChildPath;
|
|
20 private final String showBoardMessagePath;
|
|
21 private final String editMessagePath;
|
|
22 private static final String PARAM_BOARD_NAME = "bname";
|
|
23 private static final String PARAM_NODE_PATH = "path";
|
5
|
24 private static final String PARAM_CHILDNUM = "childNum";
|
|
25 private static final String MOVE = "move";
|
1
|
26
|
5
|
27 public ShowBoardMessageServlet(BrowsingBulletinBoard _bbs, String _createBoardMessagePath, String _createChildMessagePath, String _editMessagePath, String _showBoardMessagePath) {
|
1
|
28 bbs = _bbs;
|
|
29 createBoardMessagePath = _createBoardMessagePath;
|
4
|
30 showBoardMessagePath = _showBoardMessagePath;
|
|
31 createChildPath = _createChildMessagePath;
|
|
32 editMessagePath = _editMessagePath;
|
1
|
33 }
|
|
34
|
|
35 public void doGet(HttpServletRequest _req, HttpServletResponse _res) {
|
|
36 String bname = _req.getParameter(PARAM_BOARD_NAME);
|
4
|
37 String path = _req.getParameter(PARAM_NODE_PATH);
|
5
|
38 String childNum = _req.getParameter(PARAM_CHILDNUM);
|
|
39 boolean moveSuccess = true;
|
|
40 if (childNum != null) {
|
|
41 String move = _req.getParameter(MOVE);
|
|
42 moveSuccess = bbs.childMove(bname, path, childNum, move);
|
|
43 }
|
1
|
44 try {
|
5
|
45 if (moveSuccess)
|
|
46 printBoard(bname, path, _res.getWriter());
|
|
47 else {
|
|
48 PrintWriter pw = _res.getWriter();
|
|
49 pw.write("</body></html>");
|
|
50 pw.flush();
|
|
51 }
|
1
|
52 } catch (Exception _e) {
|
|
53 _res.setStatus(500);
|
|
54 }
|
|
55
|
|
56 }
|
|
57
|
4
|
58 private void printBoard(String bname, String path, PrintWriter _pw) throws Exception {
|
1
|
59 _pw.write("<html><body>\n");
|
4
|
60 _pw.write("<h1> TreeName = " + bbs.sanitize(bname) + " <br>Node Path = " + path + "</h1>\n");
|
|
61
|
|
62
|
|
63 _pw.write("<p>add new Child</p>\n");
|
|
64 _pw.write("<form action='" + createChildPath + "' method='POST'\n");
|
|
65 _pw.write("<p><input type='hidden' name='bname' value='" + bname + "'/></p>\n");
|
|
66 _pw.write("<p>ChildName<br/> <input type='textarea' name='nodeName'/> </p>\n");
|
|
67 _pw.write("<p><input type='hidden' name='path' value='" + path + "'/></p>\n");
|
|
68 _pw.write("<p><input type='submit' value='submit'/></form></p>\n");
|
1
|
69
|
4
|
70 _pw.write("<p>Children</p>\n");
|
10
|
71 Iterator<jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode> children = bbs.getChildren(bname, path);
|
5
|
72 for (int childCount = 0; children.hasNext(); childCount++) {
|
4
|
73 TreeNode child = children.next();
|
|
74 TreeNodeAttributes attribute = child.getAttributes();
|
|
75 String childName = attribute.getString("NodeName");
|
5
|
76 _pw.write("<p><a href='" + showBoardMessagePath + "?bname=" + bname + "&path=" + path + "," + childCount + "'>" + childName + "</a>" + " " +
|
|
77 "<a href='" + showBoardMessagePath + "?bname=" + bname + "&path=" + path + "&move=" + "up" + "&childNum=" + childCount + "'>" + "▲" + "</a>" + " " +
|
|
78 "<a href='" + showBoardMessagePath + "?bname=" + bname + "&path=" + path + "&move=" + "down" + "&childNum=" + childCount + "'>" + "▼" + "</a>" +
|
|
79 "</p>");
|
4
|
80 }
|
|
81
|
|
82
|
|
83 _pw.write("<p>put attribute</p>\n");
|
1
|
84 _pw.write("<form action='" + createBoardMessagePath + "' method='POST'\n");
|
4
|
85 _pw.write("<p><input type='hidden' name='bname' value='" + bname + "'/></p>\n");
|
|
86 _pw.write("<p>Key<br/> <input type='textarea' name='key'/> </p>\n");
|
|
87 _pw.write("<p>attribute<br/> <input type='textarea' name='attribute'/> </p>\n");
|
|
88 _pw.write("<p><input type='hidden' name='path' value='" + path + "'/></p>\n");
|
|
89 _pw.write("<p><input type='submit' value='submit'/></form></p>\n");
|
|
90
|
|
91 _pw.write("<p>Attribute</p>\n");
|
|
92 GetAttributeImp attribute = bbs.getAttribute(bname, path);
|
1
|
93 Iterator<String> keys = attribute.getKeys();
|
5
|
94 for (; keys.hasNext(); ) {
|
1
|
95 String key = keys.next();
|
|
96 String mesage = attribute.getMessage(key);
|
5
|
97 _pw.write("<p><a href='" + editMessagePath + "?bname=" + bbs.sanitize(bname) + "&path=" + path + "&key=" + key + "'>" + key + " = " + mesage + "</a></p>");
|
4
|
98 }
|
1
|
99
|
|
100 _pw.write("</body></html>");
|
|
101 _pw.flush();
|
|
102 }
|
|
103 }
|