Mercurial > hg > Members > nobuyasu > jungle-network
changeset 167:564f683b7aef
Matrix Date type insert ok
but bad source
author | tatsuki |
---|---|
date | Mon, 28 Jul 2014 17:02:31 +0900 |
parents | b3d5fbe95b9a |
children | 91f6dd655a01 |
files | src/main/java/app/bbs/NetworkBulletinBoard.java src/main/java/app/bbs/NetworkJungleBulletinBoard.java src/main/java/app/bbs/ShowMessageWithTimeStampServlet.java src/main/java/app/bbs/thinks/ShowMatrix.java src/main/java/app/bbs/thinks/getAttributeImp.java |
diffstat | 5 files changed, 175 insertions(+), 68 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/app/bbs/NetworkBulletinBoard.java Mon Jul 28 14:09:54 2014 +0900 +++ b/src/main/java/app/bbs/NetworkBulletinBoard.java Mon Jul 28 17:02:31 2014 +0900 @@ -1,5 +1,8 @@ package app.bbs; +import java.nio.ByteBuffer; + +import app.bbs.thinks.getAttributeImp; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs.BoardMessage; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs.BulletinBoard; @@ -11,4 +14,5 @@ public Iterable<BoardMessage> getFolder(String _boardName, String nodeNum); public void createFolder(String boardName, String author, String msg,String key, String _nodeNum); public void createAttribute(String boardName, String uuid, String author, String msg, String key); + public getAttributeImp getAttribute(String _bname, String nodeNum); }
--- a/src/main/java/app/bbs/NetworkJungleBulletinBoard.java Mon Jul 28 14:09:54 2014 +0900 +++ b/src/main/java/app/bbs/NetworkJungleBulletinBoard.java Mon Jul 28 17:02:31 2014 +0900 @@ -10,6 +10,7 @@ import alice.jungle.persistent.NetworkJournal; import alice.jungle.persistent.PersistentJournal; import alice.jungle.transaction.JungleUpdater; +import app.bbs.thinks.getAttributeImp; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; @@ -211,12 +212,13 @@ if (tree == null) { throw new IllegalStateException(); } - // //--------------------------------------------------------------------------------- + DefaultNodePath path = new DefaultNodePath(); try { for (int count = 0; _nodeNum.substring(count, count + 1) != null; count++) { if (!_nodeNum.substring(count, count + 1).equals("/")) - path = path.add(Integer.parseInt(_nodeNum.substring(count,count + 1))); + path = path.add(Integer.parseInt(_nodeNum.substring(count, + count + 1))); } } catch (Exception _e) { } @@ -227,19 +229,20 @@ tBuffer.putLong(timestamp); do { Node node = tree.getRootNode(); - - + DefaultTraverser traverser = new DefaultTraverser(); - TraversableNodeWrapper<Node> traversable = new TraversableNodeWrapper<Node>(node); + TraversableNodeWrapper<Node> traversable = new TraversableNodeWrapper<Node>( + node); DefaultEvaluator evaluator = new DefaultEvaluator(path); - Either<Error, Traversal<TraversableNodeWrapper<Node>>> ret = traverser.traverse(traversable, evaluator); + Either<Error, Traversal<TraversableNodeWrapper<Node>>> ret = traverser + .traverse(traversable, evaluator); if (ret.isA()) { Assert.fail(); } Traversal<TraversableNodeWrapper<Node>> traversal = ret.b(); TraversableNodeWrapper<Node> target = traversal.destination(); - int size = target.getWrapped().getChildren().size() ; + int size = target.getWrapped().getChildren().size(); JungleTreeEditor editor = tree.getTreeEditor(); either = editor.addNewChildAt(path, size); if (either.isA()) { @@ -249,9 +252,15 @@ NodeEditor e = new NodeEditor() { public <T extends EditableNode<T>> Either<Error, T> edit(T _e) { - _e = _e.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b(); - _e = _e.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b(); - _e = _e.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b(); + _e = _e.getAttributes() + .put("author", ByteBuffer.wrap(_author.getBytes())) + .b(); + _e = _e.getAttributes() + .put("mes", ByteBuffer.wrap(_message.getBytes())) + .b(); + _e = _e.getAttributes() + .put("key", ByteBuffer.wrap(_editKey.getBytes())) + .b(); _e = _e.getAttributes().put("timestamp", tBuffer).b(); return DefaultEither.newB(_e); } @@ -332,9 +341,15 @@ JungleTreeEditor editor = tree.getTreeEditor(); NodeEditor e = new NodeEditor() { public <T extends EditableNode<T>> Either<Error, T> edit(T _e) { - _e = _e.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b(); - _e = _e.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b(); - _e = _e.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b(); + _e = _e.getAttributes() + .put("author", ByteBuffer.wrap(_author.getBytes())) + .b(); + _e = _e.getAttributes() + .put("mes", ByteBuffer.wrap(_message.getBytes())) + .b(); + _e = _e.getAttributes() + .put("key", ByteBuffer.wrap(_editKey.getBytes())) + .b(); _e = _e.getAttributes().put("timestamp", tBuffer).b(); return DefaultEither.newB(_e); } @@ -348,9 +363,9 @@ } while (either.isA()); renewTime = timestamp; } - - public void createAttribute(String _board, String _uuid, final String _author, - final String _message, final String _editKey) { + + public void createAttribute(String _board, String _uuid, + final String _author, final String _message, final String _editKey) { requestCounter.incrementAndGet(); final long timestamp = System.currentTimeMillis(); final ByteBuffer tBuffer = ByteBuffer.allocate(16); @@ -362,17 +377,19 @@ try { for (int count = 0; _uuid.substring(count, count + 1) != null; count++) { if (!_uuid.substring(count, count + 1).equals("/")) - path = path.add(Integer.parseInt(_uuid.substring(count,count + 1))); + path = path.add(Integer.parseInt(_uuid.substring(count, + count + 1))); } } catch (Exception _e) { } Node node = tree.getRootNode(); - - + DefaultTraverser traverser = new DefaultTraverser(); - TraversableNodeWrapper<Node> traversable = new TraversableNodeWrapper<Node>(node); + TraversableNodeWrapper<Node> traversable = new TraversableNodeWrapper<Node>( + node); DefaultEvaluator evaluator = new DefaultEvaluator(path); - Either<Error, Traversal<TraversableNodeWrapper<Node>>> ret = traverser.traverse(traversable, evaluator); + Either<Error, Traversal<TraversableNodeWrapper<Node>>> ret = traverser + .traverse(traversable, evaluator); if (ret.isA()) { Assert.fail(); } @@ -381,17 +398,20 @@ TraversableNodeWrapper<Node> target = traversal.destination(); final Node cheakNode = target.getWrapped(); System.out.println(cheakNode.getAttributes().get("attribute")); - - + JungleTreeEditor editor = tree.getTreeEditor(); NodeEditor e = new NodeEditor() { public <T extends EditableNode<T>> Either<Error, T> edit(T _e) { - // EnableNodeWrapper<T> node = _e.getWrap(); - _e = _e.getAttributes().put("author" , ByteBuffer.wrap(_author.getBytes())).b(); - _e = _e.getAttributes().put("mes" , ByteBuffer.wrap(_message.getBytes())).b(); - _e = _e.getAttributes().put("key" , ByteBuffer.wrap(_editKey.getBytes())).b(); - _e = _e.getAttributes().put("timestamp", tBuffer).b(); - + // EnableNodeWrapper<T> node = _e.getWrap(); + String str = "0"; + int count = 0; + for (; _e.getAttributes().get("author" + String.valueOf(count)) != null; count++) { + } + str = String.valueOf(count); + _e = _e.getAttributes().put("author" + str, ByteBuffer.wrap(_author.getBytes())).b(); + _e = _e.getAttributes().put("mes" + str, ByteBuffer.wrap(_message.getBytes())).b(); + _e = _e.getAttributes().put("key" + str, ByteBuffer.wrap(_editKey.getBytes())).b(); + _e = _e.getAttributes().put("timestamp" + str, tBuffer).b(); return DefaultEither.newB(_e); } }; @@ -403,9 +423,9 @@ either = editor.success(); } while (either.isA()); } - - public void editMatrixMessage(String _board, String _uuid, final String _author, - final String _message, final String _editKey) { + + public void editMatrixMessage(String _board, String _uuid, + final String _author, final String _message, final String _editKey) { requestCounter.incrementAndGet(); final long timestamp = System.currentTimeMillis(); final ByteBuffer tBuffer = ByteBuffer.allocate(16); @@ -419,9 +439,15 @@ JungleTreeEditor editor = tree.getTreeEditor(); NodeEditor e = new NodeEditor() { public <T extends EditableNode<T>> Either<Error, T> edit(T _e) { - _e = _e.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b(); - _e = _e.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b(); - _e = _e.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b(); + _e = _e.getAttributes() + .put("author", ByteBuffer.wrap(_author.getBytes())) + .b(); + _e = _e.getAttributes() + .put("mes", ByteBuffer.wrap(_message.getBytes())) + .b(); + _e = _e.getAttributes() + .put("key", ByteBuffer.wrap(_editKey.getBytes())) + .b(); _e = _e.getAttributes().put("timestamp", tBuffer).b(); return DefaultEither.newB(_e); } @@ -457,12 +483,13 @@ } public Iterable<BoardMessage> getFolder(String _boardName, String _nodeNum) { - + DefaultNodePath path = new DefaultNodePath(); try { for (int count = 0; _nodeNum.substring(count, count + 1) != null; count++) { if (!_nodeNum.substring(count, count + 1).equals("/")) - path = path.add(Integer.parseInt(_nodeNum.substring(count,count + 1))); + path = path.add(Integer.parseInt(_nodeNum.substring(count, + count + 1))); } } catch (Exception _e) { } @@ -471,9 +498,11 @@ Node node = tree.getRootNode(); DefaultTraverser traverser = new DefaultTraverser(); - TraversableNodeWrapper<Node> traversable = new TraversableNodeWrapper<Node>(node); + TraversableNodeWrapper<Node> traversable = new TraversableNodeWrapper<Node>( + node); DefaultEvaluator evaluator = new DefaultEvaluator(path); - Either<Error, Traversal<TraversableNodeWrapper<Node>>> ret = traverser.traverse(traversable, evaluator); + Either<Error, Traversal<TraversableNodeWrapper<Node>>> ret = traverser + .traverse(traversable, evaluator); if (ret.isA()) { Assert.fail(); } @@ -494,6 +523,35 @@ }; return new IterableConverter<BoardMessage, Node>(chs, converter); } + + + public getAttributeImp getAttribute(String _boardName, String _nodeNum) { + + DefaultNodePath path = new DefaultNodePath(); + try { + for (int count = 0; _nodeNum.substring(count, count + 1) != null; count++) { + if (!_nodeNum.substring(count, count + 1).equals("/")) + path = path.add(Integer.parseInt(_nodeNum.substring(count, + count + 1))); + } + } catch (Exception _e) { + } + requestCounter.incrementAndGet(); + JungleTree tree = jungle.getTreeByName(_boardName); + Node node = tree.getRootNode(); + + DefaultTraverser traverser = new DefaultTraverser(); + TraversableNodeWrapper<Node> traversable = new TraversableNodeWrapper<Node>(node); + DefaultEvaluator evaluator = new DefaultEvaluator(path); + Either<Error, Traversal<TraversableNodeWrapper<Node>>> ret = traverser.traverse(traversable, evaluator); + if (ret.isA()) { + Assert.fail(); + } + + Traversal<TraversableNodeWrapper<Node>> traversal = ret.b(); + TraversableNodeWrapper<Node> target = traversal.destination(); + return new getAttributeImp(target.getWrapped()); + } public int getRequestNum() { return requestCounter.get();
--- a/src/main/java/app/bbs/ShowMessageWithTimeStampServlet.java Mon Jul 28 14:09:54 2014 +0900 +++ b/src/main/java/app/bbs/ShowMessageWithTimeStampServlet.java Mon Jul 28 17:02:31 2014 +0900 @@ -33,7 +33,6 @@ public void doGet(HttpServletRequest _req, HttpServletResponse _res) { final String bname = _req.getParameter(PARAM_BOARD_NAME); - final String name = _req.getParameter("key"); try { printBoard(bname, _res.getWriter()); } catch (Exception _e) { @@ -46,8 +45,7 @@ _pw.write("<h1>" + _bname + "</h1>\n"); _pw.write("<p>Latest renew time : " + bbs.getRenewTime(_bname) + "</p>\n"); - ; - + _pw.write("<form action='" + createBoardMessagePath + "' method='POST'\n"); _pw.write("<p>Author : <input type='text' name='author'/> <input type='hidden' name='bname' value='"
--- a/src/main/java/app/bbs/thinks/ShowMatrix.java Mon Jul 28 14:09:54 2014 +0900 +++ b/src/main/java/app/bbs/thinks/ShowMatrix.java Mon Jul 28 17:02:31 2014 +0900 @@ -20,12 +20,12 @@ private final String createBoardMessagePath; private final String editMessagePath; private final String showMatrixPath; - private final String createAttributePath ; + private final String createAttributePath; private static final String PARAM_BOARD_NAME = "bname"; public ShowMatrix(NetworkBulletinBoard _bbs, - String _createBoardMessagePath, String _editMessagePath, String _showMatrixPath, String _createAttributePath, - ThreadPool thp) { + String _createBoardMessagePath, String _editMessagePath, + String _showMatrixPath, String _createAttributePath, ThreadPool thp) { bbs = _bbs; createAttributePath = _createAttributePath; showMatrixPath = _showMatrixPath; @@ -35,7 +35,7 @@ public void doGet(HttpServletRequest _req, HttpServletResponse _res) { final String bname = _req.getParameter(PARAM_BOARD_NAME); - String nodeNum = _req.getParameter("uuid"); + String nodeNum = _req.getParameter("uuid"); try { printBoard(bname, nodeNum, _res.getWriter()); } catch (Exception _e) { @@ -43,42 +43,56 @@ } } - private void printBoard(String _bname, String nodeNum, PrintWriter _pw) throws Exception { + private void printBoard(String _bname, String nodeNum, PrintWriter _pw) + throws Exception { _pw.write("<html><body>\n"); _pw.write("<h1>" + " This Borad is Test Board " + "</h1>\n"); _pw.write("<p>Latest renew time : " + bbs.getRenewTime(_bname) + "</p>\n"); ; - _pw.write("<form action='" + createBoardMessagePath + "' method='POST'>\n"); - _pw.write("<p><input type='hidden' name='author'/> "+ "<input type='hidden' name='bname' value='" + _bname + "'/> <input type='hidden' name='key'/></p>\n"); + _pw.write("<form action='" + createBoardMessagePath + + "' method='POST'>\n"); + _pw.write("<p><input type='hidden' name='author'/> " + + "<input type='hidden' name='bname' value='" + _bname + + "'/> <input type='hidden' name='key'/></p>\n"); _pw.write("<p>Folder Name<br/> <input type='textarea' name='msg'/> </p>\n"); - _pw.write("<input type='hidden' name='uuid' value='"+nodeNum+"'/>"); + _pw.write("<input type='hidden' name='uuid' value='" + nodeNum + "'/>"); + _pw.write("<p><input type='submit' value='submit'/></p>\n"); + _pw.write("</form>"); + + _pw.write("<p><br>add Attribute</p>"); + _pw.write("<form action='" + createAttributePath + "' method='POST'\n"); + _pw.write("<p>AUTHOR :<input type='textarea' name='author'/> " + + "<input type='hidden' name='bname' value='" + _bname + + "'/> KEY :<input type='textarea' name='key'/></p>\n"); + _pw.write("<p>attributeName<br/> <input type='textarea' name='msg'/> </p>\n"); + _pw.write("<input type='hidden' name='uuid' value='" + nodeNum + "'/>"); _pw.write("<p><input type='submit' value='submit'/></p>\n"); _pw.write("</form>"); - - _pw.write("<p><br>add Attribute</p>"); - _pw.write("<form action='" + createAttributePath + "' method='POST'\n"); - _pw.write("<p>AUTHOR :<input type='textarea' name='author'/> "+ "<input type='hidden' name='bname' value='" + _bname + "'/> KEY :<input type='textarea' name='key'/></p>\n"); - _pw.write("<p>attributeName<br/> <input type='textarea' name='msg'/> </p>\n"); - _pw.write("<input type='hidden' name='uuid' value='"+nodeNum+"'/>"); - _pw.write("<p><input type='submit' value='submit'/></p>\n"); - _pw.write("</form>"); -//やることはgetChildren(Folderを持ってくる)とgetMessage(中身の表示) + _pw.write("<p>Folder</p>"); + for (BoardMessage msg : bbs.getFolder(_bname, nodeNum)) { _pw.write("<hr/>"); _pw.write("<small><a href=" + showMatrixPath + "?bname=" + _bname - + "&uuid=" +nodeNum+"/"+ msg.getUUID() + ">"+msg.getMessage()+"(folder)"+"</a></small><br>"); - _pw.write("<small><a href='" + createAttributePath + "?bname=" + _bname - + "&uuid=0" + msg.getUUID() + "'>edit(not s)</a></small>"); + + "&uuid=" + nodeNum + "/" + msg.getUUID() + ">" + + msg.getMessage() + "(folder)" + "</a></small><br>"); + _pw.write("<small><a href='" + createAttributePath + "?bname=" + + _bname + "&uuid=0" + msg.getUUID() + + "'>edit(not s)</a></small>"); } - /* for (BoardMessage msg : bbs.getMessages(_bname)) { - _pw.write("<hr/>"); - _pw.write("<p><b>" + "Author : " + msg.getAuthor() + "</b></p>"); - _pw.write("<small><a href='" + createAttributePath + "?bname=" + _bname - + "&uuid=" + msg.getUUID() + "'>edit</a></small>"); - }*/ + _pw.write("<br><br><hr/><p>Value</p><br><br>"); + getAttributeImp attribute = (bbs.getAttribute(_bname, nodeNum)); + + for (int count = 0; attribute.getMessage(count) != null; count++) { + + _pw.write("<p><b>" + "Author : " + attribute.getMessage(count) + + "</b></p>"); + // _pw.write("<small><a href='" + createAttributePath + "?bname=" + + // _bname + // + "&uuid=" + msg.getUUID() + "'>edit</a></small>"); + } _pw.write("</body></html>"); _pw.flush();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/app/bbs/thinks/getAttributeImp.java Mon Jul 28 17:02:31 2014 +0900 @@ -0,0 +1,33 @@ +package app.bbs.thinks; + + + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs.BoardMessage; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Node; + +public class getAttributeImp +{ + private final Node node; + + public getAttributeImp(Node _node) + { + node = _node; + } + + public String getUUID(int num) { + // TODO Auto-generated method stub + return String.valueOf(num); + } + + public String getAuthor(int num) { + // TODO Auto-generated method stub + return new String(node.getAttributes().get("author" + String.valueOf(num)).array()); + } + + public String getMessage(int num) { + // TODO Auto-generated method stub + return new String(node.getAttributes().get("mes" + String.valueOf(num)).array()); + } + +} +