comparison src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/browsing/ShowBoardMessageServlet.java @ 4:5acde010c6db

add jungle browsing system
author tatsuki
date Tue, 28 Jun 2016 19:45:55 +0900
parents src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/local/ShowBoardMessageServlet.java@64a72a7a0491
children 2b3542c5be34
comparison
equal deleted inserted replaced
3:f3d30646c863 4:5acde010c6db
1 package jp.ac.u_ryukyu.ie.cr.bbs.browsing;
2
3
4 import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNode;
5 import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNodeAttributes;
6
7 import javax.servlet.http.HttpServlet;
8 import javax.servlet.http.HttpServletRequest;
9 import javax.servlet.http.HttpServletResponse;
10 import java.io.PrintWriter;
11 import java.util.Iterator;
12
13 public class ShowBoardMessageServlet extends HttpServlet {
14 /**
15 *
16 */
17 private static final long serialVersionUID = 1L;
18 private final BrowsingBulletinBoard bbs;
19 private final String createBoardMessagePath;
20 private final String createChildPath;
21 private final String showBoardMessagePath;
22 private final String editMessagePath;
23 private static final String PARAM_BOARD_NAME = "bname";
24 private static final String PARAM_NODE_PATH = "path";
25
26 public ShowBoardMessageServlet(BrowsingBulletinBoard _bbs, String _createBoardMessagePath,String _createChildMessagePath ,String _editMessagePath, String _showBoardMessagePath) {
27 bbs = _bbs;
28 createBoardMessagePath = _createBoardMessagePath;
29 showBoardMessagePath = _showBoardMessagePath;
30 createChildPath = _createChildMessagePath;
31 editMessagePath = _editMessagePath;
32 }
33
34 public void doGet(HttpServletRequest _req, HttpServletResponse _res) {
35 String bname = _req.getParameter(PARAM_BOARD_NAME);
36 String path = _req.getParameter(PARAM_NODE_PATH);
37 try {
38 printBoard(bname, path, _res.getWriter());
39 } catch (Exception _e) {
40 _res.setStatus(500);
41 }
42
43 }
44
45 private void printBoard(String bname, String path, PrintWriter _pw) throws Exception {
46 _pw.write("<html><body>\n");
47 _pw.write("<h1> TreeName = " + bbs.sanitize(bname) + " <br>Node Path = " + path + "</h1>\n");
48
49
50 _pw.write("<p>add new Child</p>\n");
51 _pw.write("<form action='" + createChildPath + "' method='POST'\n");
52 _pw.write("<p><input type='hidden' name='bname' value='" + bname + "'/></p>\n");
53 _pw.write("<p>ChildName<br/> <input type='textarea' name='nodeName'/> </p>\n");
54 _pw.write("<p><input type='hidden' name='path' value='" + path + "'/></p>\n");
55 _pw.write("<p><input type='submit' value='submit'/></form></p>\n");
56
57 _pw.write("<p>Children</p>\n");
58 Iterator<TreeNode> children = bbs.getChildren(bname, path);
59 for (int childCount = 0;children.hasNext();childCount++) {
60 TreeNode child = children.next();
61 TreeNodeAttributes attribute = child.getAttributes();
62 String childName = attribute.getString("NodeName");
63 _pw.write("<p><a href='" + showBoardMessagePath + "?bname=" + bname + "&path=" + path + "," +childCount + "'>" +childName + "</a></p>");
64 }
65
66
67 _pw.write("<p>put attribute</p>\n");
68 _pw.write("<form action='" + createBoardMessagePath + "' method='POST'\n");
69 _pw.write("<p><input type='hidden' name='bname' value='" + bname + "'/></p>\n");
70 _pw.write("<p>Key<br/> <input type='textarea' name='key'/> </p>\n");
71 _pw.write("<p>attribute<br/> <input type='textarea' name='attribute'/> </p>\n");
72 _pw.write("<p><input type='hidden' name='path' value='" + path + "'/></p>\n");
73 _pw.write("<p><input type='submit' value='submit'/></form></p>\n");
74
75
76
77
78 _pw.write("<p>Attribute</p>\n");
79 GetAttributeImp attribute = bbs.getAttribute(bname, path);
80 Iterator<String> keys = attribute.getKeys();
81 for (;keys.hasNext();) {
82 String key = keys.next();
83 String mesage = attribute.getMessage(key);
84 _pw.write("<p><a href='"+editMessagePath+"?bname=" + bbs.sanitize(bname) + "&path=" + path + "&key=" + key + "'>" + key + " = " + mesage +"</a></p>");
85 }
86
87 _pw.write("</body></html>");
88 _pw.flush();
89 }
90 }