Mercurial > hg > Members > shoshi > jungle > bbs
view src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/browsing/ShowBoardMessageServlet.java @ 10:6e91ad317eb0
fix
author | suruga |
---|---|
date | Wed, 19 Jul 2017 18:07:30 +0900 |
parents | 36f0f18ce6a8 |
children |
line wrap: on
line source
package jp.ac.u_ryukyu.ie.cr.bbs.browsing; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNodeAttributes; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.PrintWriter; import java.util.Iterator; public class ShowBoardMessageServlet extends HttpServlet { /** * */ private static final long serialVersionUID = 1L; private final BrowsingBulletinBoard bbs; private final String createBoardMessagePath; private final String createChildPath; private final String showBoardMessagePath; private final String editMessagePath; private static final String PARAM_BOARD_NAME = "bname"; private static final String PARAM_NODE_PATH = "path"; private static final String PARAM_CHILDNUM = "childNum"; private static final String MOVE = "move"; public ShowBoardMessageServlet(BrowsingBulletinBoard _bbs, String _createBoardMessagePath, String _createChildMessagePath, String _editMessagePath, String _showBoardMessagePath) { bbs = _bbs; createBoardMessagePath = _createBoardMessagePath; showBoardMessagePath = _showBoardMessagePath; createChildPath = _createChildMessagePath; editMessagePath = _editMessagePath; } public void doGet(HttpServletRequest _req, HttpServletResponse _res) { String bname = _req.getParameter(PARAM_BOARD_NAME); String path = _req.getParameter(PARAM_NODE_PATH); String childNum = _req.getParameter(PARAM_CHILDNUM); boolean moveSuccess = true; if (childNum != null) { String move = _req.getParameter(MOVE); moveSuccess = bbs.childMove(bname, path, childNum, move); } try { if (moveSuccess) printBoard(bname, path, _res.getWriter()); else { PrintWriter pw = _res.getWriter(); pw.write("</body></html>"); pw.flush(); } } catch (Exception _e) { _res.setStatus(500); } } private void printBoard(String bname, String path, PrintWriter _pw) throws Exception { _pw.write("<html><body>\n"); _pw.write("<h1> TreeName = " + bbs.sanitize(bname) + " <br>Node Path = " + path + "</h1>\n"); _pw.write("<p>add new Child</p>\n"); _pw.write("<form action='" + createChildPath + "' method='POST'\n"); _pw.write("<p><input type='hidden' name='bname' value='" + bname + "'/></p>\n"); _pw.write("<p>ChildName<br/> <input type='textarea' name='nodeName'/> </p>\n"); _pw.write("<p><input type='hidden' name='path' value='" + path + "'/></p>\n"); _pw.write("<p><input type='submit' value='submit'/></form></p>\n"); _pw.write("<p>Children</p>\n"); Iterator<jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode> children = bbs.getChildren(bname, path); for (int childCount = 0; children.hasNext(); childCount++) { TreeNode child = children.next(); TreeNodeAttributes attribute = child.getAttributes(); String childName = attribute.getString("NodeName"); _pw.write("<p><a href='" + showBoardMessagePath + "?bname=" + bname + "&path=" + path + "," + childCount + "'>" + childName + "</a>" + " " + "<a href='" + showBoardMessagePath + "?bname=" + bname + "&path=" + path + "&move=" + "up" + "&childNum=" + childCount + "'>" + "▲" + "</a>" + " " + "<a href='" + showBoardMessagePath + "?bname=" + bname + "&path=" + path + "&move=" + "down" + "&childNum=" + childCount + "'>" + "▼" + "</a>" + "</p>"); } _pw.write("<p>put attribute</p>\n"); _pw.write("<form action='" + createBoardMessagePath + "' method='POST'\n"); _pw.write("<p><input type='hidden' name='bname' value='" + bname + "'/></p>\n"); _pw.write("<p>Key<br/> <input type='textarea' name='key'/> </p>\n"); _pw.write("<p>attribute<br/> <input type='textarea' name='attribute'/> </p>\n"); _pw.write("<p><input type='hidden' name='path' value='" + path + "'/></p>\n"); _pw.write("<p><input type='submit' value='submit'/></form></p>\n"); _pw.write("<p>Attribute</p>\n"); GetAttributeImp attribute = bbs.getAttribute(bname, path); Iterator<String> keys = attribute.getKeys(); for (; keys.hasNext(); ) { String key = keys.next(); String mesage = attribute.getMessage(key); _pw.write("<p><a href='" + editMessagePath + "?bname=" + bbs.sanitize(bname) + "&path=" + path + "&key=" + key + "'>" + key + " = " + mesage + "</a></p>"); } _pw.write("</body></html>"); _pw.flush(); } }