Mercurial > hg > Members > tatsuki > bbs
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/browsing/ShowBoardMessageServlet.java Tue Jun 28 19:45:55 2016 +0900 @@ -0,0 +1,90 @@ +package jp.ac.u_ryukyu.ie.cr.bbs.browsing; + + +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.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"; + + 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); + try { + printBoard(bname, path, _res.getWriter()); + } 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<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></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(); + } +}