Mercurial > hg > Members > shoshi > jungle > bbs
changeset 5:2b3542c5be34
move child
author | tatsuki |
---|---|
date | Tue, 02 Aug 2016 17:46:03 +0900 |
parents | 5acde010c6db |
children | 36f0f18ce6a8 |
files | src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/browsing/App.java src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/browsing/BrowsingBulletinBoard.java src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/browsing/FindNodeservlet.java src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/browsing/JungleBrowsingBulletinBoard.java src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/browsing/ShowBoardMessageServlet.java src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/browsing/ShowBoardsServlet.java src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/browsing/importLayoutServlet.java |
diffstat | 7 files changed, 248 insertions(+), 48 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/browsing/App.java Tue Jun 28 19:45:55 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/browsing/App.java Tue Aug 02 17:46:03 2016 +0900 @@ -12,43 +12,45 @@ /** * Hello world! - * */ -public class App -{ - public static void main( String[] args ) throws Exception - { - BrowsingBulletinBoard cassaBBS = new JungleBrowsingBulletinBoard(); - - String createBoardMessagePath = "/createBoardMessage"; - String createBoardPath = "/createBoard"; - String editMessagePath = "/editMessage"; - String showBoardMessagePath = "/showBoardMessage"; - String createChildPath = "/createChildMessage"; +public class App { + public static void main(String[] args) throws Exception { + BrowsingBulletinBoard cassaBBS = new JungleBrowsingBulletinBoard(); - Servlet createBoardMessage = new CreateBoardMessageServlet(cassaBBS); - Servlet createBoard = new CreateBoardServlet(cassaBBS); - Servlet createChild = new CreateChildServlet(cassaBBS); - Servlet editBoardMessage = new EditMessageServlet(cassaBBS); - Servlet index = new ShowBoardsServlet(cassaBBS,createBoardPath,showBoardMessagePath); - Servlet board = new ShowBoardMessageServlet(cassaBBS,createBoardMessagePath,createChildPath,editMessagePath,showBoardMessagePath); - + String createBoardMessagePath = "/createBoardMessage"; + String createBoardPath = "/createBoard"; + String editMessagePath = "/editMessage"; + String showBoardMessagePath = "/showBoardMessage"; + String createChildPath = "/createChildMessage"; + String layoutImportPath = "/layoutImportPath"; + String findNodeMessagePath = "/findNode"; + Servlet createBoardMessage = new CreateBoardMessageServlet(cassaBBS); + Servlet createBoard = new CreateBoardServlet(cassaBBS); + Servlet importLayout = new importLayoutServlet(cassaBBS); + Servlet createChild = new CreateChildServlet(cassaBBS); + Servlet editBoardMessage = new EditMessageServlet(cassaBBS); + Servlet index = new ShowBoardsServlet(cassaBBS, createBoardPath, showBoardMessagePath, layoutImportPath, findNodeMessagePath); + Servlet find = new FindNodeServlet(cassaBBS, showBoardMessagePath); + Servlet board = new ShowBoardMessageServlet(cassaBBS, createBoardMessagePath, createChildPath, editMessagePath, showBoardMessagePath); + // Server serv = new Server(8080); - Server serv = new Server(); - SelectChannelConnector connector = new SelectChannelConnector(); - connector.setPort(8080); - connector.setThreadPool(new QueuedThreadPool(1000)); - serv.setConnectors(new Connector[] { connector }); - - ServletHandler context = new ServletHandler(); - context.addServletWithMapping(new ServletHolder(createBoardMessage),createBoardMessagePath); - context.addServletWithMapping(new ServletHolder(createBoard),createBoardPath); - context.addServletWithMapping(new ServletHolder(createChild),createChildPath); - context.addServletWithMapping(new ServletHolder(editBoardMessage),editMessagePath); - context.addServletWithMapping(new ServletHolder(index),"/"); - context.addServletWithMapping(new ServletHolder(board),showBoardMessagePath); + Server serv = new Server(); + SelectChannelConnector connector = new SelectChannelConnector(); + connector.setPort(8080); + connector.setThreadPool(new QueuedThreadPool(1000)); + serv.setConnectors(new Connector[]{connector}); - serv.addHandler(context); - serv.start(); + ServletHandler context = new ServletHandler(); + context.addServletWithMapping(new ServletHolder(find), findNodeMessagePath); + context.addServletWithMapping(new ServletHolder(createBoardMessage), createBoardMessagePath); + context.addServletWithMapping(new ServletHolder(createBoard), createBoardPath); + context.addServletWithMapping(new ServletHolder(importLayout), layoutImportPath); + context.addServletWithMapping(new ServletHolder(createChild), createChildPath); + context.addServletWithMapping(new ServletHolder(editBoardMessage), editMessagePath); + context.addServletWithMapping(new ServletHolder(index), "/"); + context.addServletWithMapping(new ServletHolder(board), showBoardMessagePath); + + serv.addHandler(context); + serv.start(); } }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/browsing/BrowsingBulletinBoard.java Tue Jun 28 19:45:55 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/browsing/BrowsingBulletinBoard.java Tue Aug 02 17:46:03 2016 +0900 @@ -13,4 +13,9 @@ String sanitize(String str); GetAttributeImp getAttribute(String bname, String nodePath); Iterator<TreeNode> getChildren(String bname, String nodePath); + void importLayout(String boardName, String path); + + Iterator<TreeNode> findNode(String bname, String key, String value); + String getNodePath(String bname, TreeNode node); + boolean childMove(String bname, String path, String childNum, String move); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/browsing/FindNodeservlet.java Tue Aug 02 17:46:03 2016 +0900 @@ -0,0 +1,67 @@ +package jp.ac.u_ryukyu.ie.cr.bbs.browsing; + +import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNode; + +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 FindNodeServlet extends HttpServlet +{ + private final BrowsingBulletinBoard bbs; + private final String showBoardMessagePath ; + private static final String PARAM_BOARD_NAME = "bname"; + + private static final long serialVersionUID = 1L; + + public FindNodeServlet(BrowsingBulletinBoard _bbs, String _showBoardMessagePath) + { + showBoardMessagePath = _showBoardMessagePath; + bbs = _bbs; + } + + public void doGet(HttpServletRequest _req,HttpServletResponse _res) + { + String bname = _req.getParameter(PARAM_BOARD_NAME); + System.out.println("write"); + + try{ + PrintWriter pw = _res.getWriter(); + pw.write("<html><body><h1>find Node</h1>"); + pw.write("<form 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>value<br/> <input type='textarea' name='value'/> </p>\n"); + pw.write("<p><input type='submit' value='submit'/></p>\n"); + pw.write("</body></html>"); + pw.flush(); + }catch(Exception _e){ + _res.setStatus(500); + } + } + + public void doPost(HttpServletRequest _req,HttpServletResponse _res) + { + String bname = _req.getParameter("bname"); + String key = _req.getParameter("key"); + String value = _req.getParameter("value"); + + try{ + Iterator<TreeNode> iterator = bbs.findNode(bname, key, value); + PrintWriter pw = _res.getWriter(); + pw.write("<p>result</p>\n"); + while (iterator.hasNext()) { + TreeNode node = iterator.next(); + String childName = node.getAttributes().getString("NodeName"); + String path = bbs.getNodePath(bname, node).replace("<","").replace(">",""); + pw.write("<p><a href='" + showBoardMessagePath + "?bname=" + bname + "&path=" + path + "'>" +childName + " : path = <" + path + "></a></p>"); + } + pw.flush(); + }catch(Exception _e){ + _res.setStatus(500); + } + } +}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/browsing/JungleBrowsingBulletinBoard.java Tue Jun 28 19:45:55 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/browsing/JungleBrowsingBulletinBoard.java Tue Aug 02 17:46:03 2016 +0900 @@ -14,8 +14,13 @@ import jp.ac.u_ryukyu.ie.cr.jungle.store.impl.TreeNodeChildren; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.DefaultTreeNode; import jp.ac.u_ryukyu.ie.cr.jungle.traverser.DefaultTraverser; +import jp.ac.u_ryukyu.ie.cr.jungle.traverser.InterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.jungle.util.Error; +import plparser.Property; +import plparser.jungle.PropertyJungleTreeFactoryImpl; +import plparser.jungle.PropertyListJungleNodeFactory; +import plparser.jungle.PropertyListParserCreateTree; import java.nio.ByteBuffer; import java.util.Iterator; @@ -46,7 +51,10 @@ } public void createBoards(final String _name) { - if (null == jungle.createNewTree(_name)) { + createBoards(_name, new DefaultTreeNode()); + } + public void createBoards(final String _name, TreeNode rootNode) { + if (null == jungle.createNewTree(_name, rootNode)) { throw new IllegalStateException(); } JungleTree tree = jungle.getTreeByName("boards"); @@ -184,6 +192,62 @@ return children.iterator(); } + @Override + public void importLayout(String boardName, String path) { + PropertyListParserCreateTree<Property> jp; + PropertyListJungleNodeFactory jlf = new PropertyJungleTreeFactoryImpl(); + jp = new PropertyListParserCreateTree<Property>(jlf); + TreeNode root = jp.parseFile(path); + createBoards(boardName, root); + } + + @Override + public Iterator<TreeNode> findNode(String bname, String key, String value) { + JungleTree tree = jungle.getTreeByName(bname); + InterfaceTraverser traverser = tree.getTraverser(true); + return traverser.find((TreeNode node) -> { + return true; + },key,value); + } + + @Override + public String getNodePath(String bname, TreeNode node) { + JungleTree tree = jungle.getTreeByName(bname); + NodePath path = tree.getNodePath(node); + return path.toString(); + } + + @Override + public boolean childMove(String bname, String pathString, String childNumString, String move) { + int childNum = Integer.parseInt(childNumString); + JungleTree tree = jungle.getTreeByName(bname); + DefaultNodePath path = createNodePath(pathString); + TreeNode node = tree.getNodeOfPath(path).b(); + int childrenCount = node.getChildren().size(); + TreeNode child = node.getChildren().at(childNum).b(); + TreeNodeChildren grandsons = child.getChildren(); + JungleTreeEditor editor = tree.getTreeEditor(); + editor = editor.deleteChildAt(path,childNum).b(); + if (move.equals("up") && childNum != 0) + childNum--; + else if (move.equals("down") && childNum != childrenCount) + childNum++; + editor = editor.addNewChildAt(path,childNum).b(); + + Iterator<String> keys = child.getAttributes().getKeys(); + NodePath newChildPath = path.add(childNum); + while (keys.hasNext()) { + String key = keys.next(); + ByteBuffer value = child.getAttributes().get(key); + editor = editor.putAttribute(newChildPath,key,value).b(); + } + + for (TreeNode grandson : grandsons) { + + } + return editor.success().isB(); + } + private DefaultNodePath createNodePath(String nodePath) { DefaultNodePath path = new DefaultNodePath(); String[] nums = nodePath.split(",");
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/browsing/ShowBoardMessageServlet.java Tue Jun 28 19:45:55 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/browsing/ShowBoardMessageServlet.java Tue Aug 02 17:46:03 2016 +0900 @@ -22,8 +22,10 @@ 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) { + public ShowBoardMessageServlet(BrowsingBulletinBoard _bbs, String _createBoardMessagePath, String _createChildMessagePath, String _editMessagePath, String _showBoardMessagePath) { bbs = _bbs; createBoardMessagePath = _createBoardMessagePath; showBoardMessagePath = _showBoardMessagePath; @@ -34,8 +36,20 @@ 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 { - printBoard(bname, path, _res.getWriter()); + if (moveSuccess) + printBoard(bname, path, _res.getWriter()); + else { + PrintWriter pw = _res.getWriter(); + pw.write("</body></html>"); + pw.flush(); + } } catch (Exception _e) { _res.setStatus(500); } @@ -56,11 +70,14 @@ _pw.write("<p>Children</p>\n"); Iterator<TreeNode> children = bbs.getChildren(bname, path); - for (int childCount = 0;children.hasNext();childCount++) { + 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><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>"); } @@ -73,15 +90,13 @@ _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();) { + 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("<p><a href='" + editMessagePath + "?bname=" + bbs.sanitize(bname) + "&path=" + path + "&key=" + key + "'>" + key + " = " + mesage + "</a></p>"); } _pw.write("</body></html>");
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/browsing/ShowBoardsServlet.java Tue Jun 28 19:45:55 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/browsing/ShowBoardsServlet.java Tue Aug 02 17:46:03 2016 +0900 @@ -14,12 +14,15 @@ private final BrowsingBulletinBoard bbs; private final String createBoardPath; private final String showBoardMessagePath; - - public ShowBoardsServlet(BrowsingBulletinBoard _bbs, String _createBoardPath,String _showBoardMessagePath) + private final String layoutImportPath; + private final String findNodePath; + public ShowBoardsServlet(BrowsingBulletinBoard _bbs, String _createBoardPath,String _showBoardMessagePath,String _layoutImportPath, String _findNodePath) { bbs = _bbs; + findNodePath = _findNodePath; createBoardPath = _createBoardPath; showBoardMessagePath = _showBoardMessagePath; + layoutImportPath = _layoutImportPath; } public void doGet(HttpServletRequest _req,HttpServletResponse _res) @@ -40,11 +43,19 @@ _pw.write("<form action='"+createBoardPath+"' method='POST'\n"); _pw.write("<p>Create new board.</p>"); _pw.write("<p>BoardName : <input type='text' name='bname'/></p>\n"); - _pw.write("<p><input type='submit' value='submit'/></p><hr/>\n"); - + _pw.write("<p><input type='submit' value='submit'/></form></p><hr/>\n"); + + _pw.write("<form action='"+layoutImportPath+"' method='POST'\n"); + _pw.write("<p>import layoutFile</p>"); + _pw.write("<p>BoardName : <input type='text' name='bname'/></p>\n"); + _pw.write("<p>layout path : <input type='text' name='path'/></p>\n"); + _pw.write("<p><input type='submit' value='submit'/></form></p><hr/>\n"); + _pw.write("<h2>list of boards</h2>"); for(String board : bbs.getBoards()){ - _pw.write("<p><a href='"+showBoardMessagePath+"?bname=" + bbs.sanitize(board) + "&path=-1" +"'>"+ bbs.sanitize(board) + "</a></p>"); + _pw.write("<p><a href='"+showBoardMessagePath+"?bname=" + bbs.sanitize(board) + "&path=-1" +"'>"+ bbs.sanitize(board) + "</a> " + + "<a href='"+findNodePath+"?bname=" + bbs.sanitize(board) +"'>"+ "find</a>" + + "</p>"); } _pw.write("</body></html>");
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/browsing/importLayoutServlet.java Tue Aug 02 17:46:03 2016 +0900 @@ -0,0 +1,36 @@ +package jp.ac.u_ryukyu.ie.cr.bbs.browsing; + +import org.apache.commons.lang.StringEscapeUtils; + +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.PrintWriter; + +/** + * Created by e115731 on 2016/07/19. + */ +public class importLayoutServlet extends HttpServlet +{ + private final BrowsingBulletinBoard bbs; + private static final String PARAM_BOARD_NAME = "bname"; + private static final String PARAM_LAYOUT_PATH = "path"; + private static final long serialVersionUID = 1L; + public importLayoutServlet(BrowsingBulletinBoard _bbs) + { + bbs = _bbs; + } + + public void doPost(HttpServletRequest _req, HttpServletResponse _res) + { + String boardName = StringEscapeUtils.unescapeHtml(_req.getParameter(PARAM_BOARD_NAME)); + String path = StringEscapeUtils.unescapeHtml(_req.getParameter(PARAM_LAYOUT_PATH)); + try{ + bbs.importLayout(boardName,path); + PrintWriter pw = _res.getWriter(); + pw.write("successfully written"); + }catch(Exception _e){ + _res.setStatus(500); + } + } +}