Mercurial > hg > Members > nobuyasu > jungle-network
annotate src/main/java/app/bbs/NetworkJungleBulletinBoard.java @ 177:6f104ab4eb81
fit jungle core but editMessage is not work
author | tatsuki |
---|---|
date | Mon, 01 Sep 2014 00:04:32 +0900 |
parents | ac7d1070f449 |
children | d6944d788121 |
rev | line source |
---|---|
112 | 1 package app.bbs; |
38 | 2 |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
3 import java.io.File; |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
4 import java.io.IOException; |
38 | 5 import java.nio.ByteBuffer; |
6 import java.util.concurrent.atomic.AtomicInteger; | |
39 | 7 |
8 import alice.jungle.core.NetworkDefaultJungle; | |
124 | 9 import alice.jungle.persistent.AliceJournal; |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
10 import alice.jungle.persistent.NetworkJournal; |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
11 import alice.jungle.persistent.PersistentJournal; |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
12 import alice.jungle.transaction.JungleUpdater; |
167 | 13 import app.bbs.thinks.getAttributeImp; |
38 | 14 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle; |
15 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; | |
16 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; | |
125 | 17 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs.BoardMessage; |
38 | 18 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Children; |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
19 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeList; |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
20 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeListReader; |
38 | 21 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath; |
22 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultTreeEditor; | |
177 | 23 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; |
24 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.DefaultOperationLog; | |
25 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.OperationLog; | |
26 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.PutAttributeOperation; | |
38 | 27 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.NodeEditor; |
166 | 28 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultEvaluator; |
38 | 29 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser; |
166 | 30 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.Traversal; |
38 | 31 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; |
32 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; | |
33 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; | |
34 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.IterableConverter; | |
166 | 35 import junit.framework.Assert; |
38 | 36 |
166 | 37 public class NetworkJungleBulletinBoard implements NetworkBulletinBoard { |
38 | 38 private final Jungle jungle; |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
39 private final NetworkJournal journal; |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
40 private final String LOG_DIR; |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
41 private Boolean persistentFlag; |
166 | 42 private AtomicInteger requestCounter; |
150
eef85b5faa15
Removed renew atribute
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
43 private long renewTime; |
166 | 44 |
45 private NetworkJungleBulletinBoard(String _uuid, NetworkJournal _journal) { | |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
46 journal = _journal; |
177 | 47 jungle = new NetworkDefaultJungle(journal, _uuid, |
48 new DefaultTreeEditor(new DefaultTraverser())); | |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
49 BulletinBoardJungleManager.setJungle(jungle); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
50 persistentFlag = false; |
147
202ea963ec20
Added requestCounter in BulletinBoardJungleManager
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
146
diff
changeset
|
51 requestCounter = BulletinBoardJungleManager.getRequestCounter(); |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
52 LOG_DIR = "./log"; |
150
eef85b5faa15
Removed renew atribute
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
53 renewTime = 0; |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
54 } |
166 | 55 |
56 public NetworkJungleBulletinBoard(String _uuid) { | |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
57 this(_uuid, new AliceJournal()); |
124 | 58 jungle.createNewTree("boards"); |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
59 } |
166 | 60 |
61 public static NetworkBulletinBoard NewPersistentJungle(String _uuid) { | |
177 | 62 NetworkJungleBulletinBoard board = new NetworkJungleBulletinBoard( |
63 _uuid, new PersistentJournal()); | |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
64 board.persistentFlag = true; |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
65 return board; |
38 | 66 } |
166 | 67 |
124 | 68 public void init() { |
166 | 69 if (!persistentFlag) { |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
70 return; |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
71 } |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
72 checkAndCreateLogDirectory(); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
73 try { |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
74 commitLogRecover(); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
75 } catch (IOException e) { |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
76 e.printStackTrace(); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
77 } |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
78 } |
166 | 79 |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
80 public void checkAndCreateLogDirectory() { |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
81 File logFile = new File(LOG_DIR); |
166 | 82 if (!logFile.exists()) { |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
83 logFile.mkdir(); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
84 return; |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
85 } |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
86 if (logFile.isFile()) { |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
87 logFile.delete(); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
88 logFile.mkdir(); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
89 } |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
90 } |
166 | 91 |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
92 public void commitLogRecover() throws IOException { |
166 | 93 File[] logFiles = new File(LOG_DIR).listFiles(); |
94 for (File logFile : logFiles) { | |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
95 commitLogRecover(logFile); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
96 logFile.delete(); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
97 } |
166 | 98 if (jungle.getTreeByName("boards") == null) { |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
99 jungle.createNewTree("boards"); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
100 } |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
101 } |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
102 |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
103 private void commitLogRecover(File logFile) throws IOException { |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
104 journal.setInputFile(logFile); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
105 ChangeListReader reader = journal.getReader(); |
166 | 106 if (reader == null) |
107 return; | |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
108 for (ChangeList chList : reader) { |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
109 String treeName = chList.getTreeName(); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
110 JungleTree tree = jungle.getTreeByName(treeName); |
166 | 111 if (tree == null) { |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
112 tree = jungle.createNewTree(treeName); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
113 } |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
114 JungleTreeEditor editor = tree.getLocalTreeEditor(); |
177 | 115 Either<Error, JungleTreeEditor> either = JungleUpdater.edit(editor, |
116 chList); | |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
117 editor = either.b(); |
166 | 118 if (either.isA()) { |
135
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
119 throw new IOException("Failed commit log recovery"); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
120 } |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
121 editor.success(); |
2e8034524259
Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
122 } |
118
f64ff5bd66f5
Implements persistent for bbs app and Fixed bug JungleUpdater
one
parents:
112
diff
changeset
|
123 } |
38 | 124 |
166 | 125 public Iterable<String> getBoards() { |
38 | 126 JungleTree tree = jungle.getTreeByName("boards"); |
177 | 127 TreeNode node = tree.getRootNode(); |
128 Children<TreeNode> chs = node.getChildren(); | |
166 | 129 |
177 | 130 IterableConverter.Converter<String, TreeNode> converter = new IterableConverter.Converter<String, TreeNode>() { |
131 public String conv(TreeNode _b) { | |
38 | 132 ByteBuffer e = _b.getAttributes().get("name"); |
174 | 133 System.out.println(new String(e.array())); |
38 | 134 return new String(e.array()); |
135 } | |
136 }; | |
166 | 137 |
177 | 138 return new IterableConverter<String, TreeNode>(chs, converter); |
38 | 139 } |
166 | 140 |
146
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
141 public long getRenewTime(String _boardName) { |
150
eef85b5faa15
Removed renew atribute
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
142 return renewTime; |
146
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
143 } |
38 | 144 |
168 | 145 public void createBoards(final String _name, final String _author, final String _initMessage, final String _editKey) { |
143
7a7bac51a3cc
Added RequestNumCheckServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
146 requestCounter.incrementAndGet(); |
166 | 147 if (null == jungle.createNewTree(_name)) { |
38 | 148 throw new IllegalStateException(); |
149 } | |
166 | 150 |
38 | 151 JungleTree tree = jungle.getTreeByName("boards"); |
152 JungleTreeEditor editor = tree.getTreeEditor(); | |
153 DefaultNodePath root = new DefaultNodePath(); | |
166 | 154 Either<Error, JungleTreeEditor> either = editor.addNewChildAt(root, 0); |
155 if (either.isA()) { | |
38 | 156 throw new IllegalStateException(); |
157 } | |
158 editor = either.b(); | |
166 | 159 |
177 | 160 either = editor.putAttribute(root.add(0), "name", |
161 ByteBuffer.wrap(_name.getBytes())); | |
166 | 162 if (either.isA()) { |
38 | 163 throw new IllegalStateException(); |
164 } | |
165 editor = either.b(); | |
149
06cddf529325
Modified lates renew time
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
166 final long timestamp = System.currentTimeMillis(); |
129
1a3edba05f50
Fixed bug NetworkJungleBulletinBoard
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
126
diff
changeset
|
167 ByteBuffer tBuffer = ByteBuffer.allocate(16); |
146
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
168 tBuffer.putLong(timestamp); |
166 | 169 either = editor.putAttribute(root.add(0), "timestamp", tBuffer); |
170 if (either.isA()) { | |
129
1a3edba05f50
Fixed bug NetworkJungleBulletinBoard
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
126
diff
changeset
|
171 throw new IllegalStateException(); |
1a3edba05f50
Fixed bug NetworkJungleBulletinBoard
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
126
diff
changeset
|
172 } |
146
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
173 either = either.b().success(); |
166 | 174 if (either.isA()) { |
38 | 175 throw new IllegalStateException(); |
176 } | |
166 | 177 |
38 | 178 tree = jungle.getTreeByName(_name); |
179 editor = tree.getTreeEditor(); | |
166 | 180 either = editor.addNewChildAt(root, 0); |
181 if (either.isA()) { | |
38 | 182 throw new IllegalStateException(); |
183 } | |
184 editor = either.b(); | |
166 | 185 |
186 NodeEditor e = new NodeEditor() { | |
177 | 187 ByteBuffer tBuffer2 = ByteBuffer.allocate(16); |
188 | |
189 public <T extends TreeNode> Either<Error, TreeNode> edit(T _e) { | |
190 TreeNode node = _e; | |
191 node = node.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b(); | |
192 node = node.getAttributes().put("mes", ByteBuffer.wrap(_initMessage.getBytes())).b(); | |
193 node = node.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b(); | |
146
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
194 tBuffer2.putLong(timestamp); |
177 | 195 node = node.getAttributes().put("timestamp", tBuffer2).b(); |
196 return DefaultEither.newB(node); | |
197 } | |
198 | |
199 @Override | |
200 public OperationLog getLog() { | |
201 OperationLog op = new DefaultOperationLog(); | |
202 op = op.add(new PutAttributeOperation("author", ByteBuffer.wrap(_author.getBytes()))); | |
203 op = op.add(new PutAttributeOperation("mes", ByteBuffer.wrap(_initMessage.getBytes()))); | |
204 op = op.add(new PutAttributeOperation("key", ByteBuffer.wrap(_editKey.getBytes()))); | |
205 op = op.add(new PutAttributeOperation("timestamp", tBuffer2)); | |
206 return op; | |
38 | 207 } |
208 }; | |
166 | 209 |
210 either = editor.edit(root.add(0), e); | |
211 if (either.isA()) { | |
38 | 212 throw new IllegalStateException(); |
213 } | |
146
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
214 either.b().success(); |
147
202ea963ec20
Added requestCounter in BulletinBoardJungleManager
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
146
diff
changeset
|
215 |
38 | 216 } |
217 | |
168 | 218 public void createFolder(final String _board, final String _author, final String _message, final String _editKey, String _nodeNum) { |
38 | 219 JungleTree tree = jungle.getTreeByName(_board); |
166 | 220 if (tree == null) { |
38 | 221 throw new IllegalStateException(); |
222 } | |
177 | 223 |
166 | 224 DefaultNodePath path = new DefaultNodePath(); |
225 try { | |
226 for (int count = 0; _nodeNum.substring(count, count + 1) != null; count++) { | |
227 if (!_nodeNum.substring(count, count + 1).equals("/")) | |
177 | 228 path = path.add(Integer.parseInt(_nodeNum.substring(count, |
229 count + 1))); | |
166 | 230 } |
231 } catch (Exception _e) { | |
232 } | |
233 requestCounter.incrementAndGet(); | |
46 | 234 Either<Error, JungleTreeEditor> either; |
149
06cddf529325
Modified lates renew time
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
235 final long timestamp = System.currentTimeMillis(); |
146
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
236 final ByteBuffer tBuffer = ByteBuffer.allocate(16); |
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
237 tBuffer.putLong(timestamp); |
177 | 238 |
166 | 239 do { |
177 | 240 TreeNode node = tree.getRootNode(); |
166 | 241 DefaultTraverser traverser = new DefaultTraverser(); |
177 | 242 // TraversableNodeWrapper<Node> traversable = new |
243 // TraversableNodeWrapper<Node>(node); | |
166 | 244 DefaultEvaluator evaluator = new DefaultEvaluator(path); |
177 | 245 Either<Error, Traversal<TreeNode>> ret = traverser.traverse(node, |
246 evaluator); | |
166 | 247 if (ret.isA()) { |
248 Assert.fail(); | |
249 } | |
250 | |
177 | 251 Traversal<TreeNode> traversal = ret.b(); |
252 TreeNode target = traversal.destination(); | |
253 int size = target.getChildren().size(); | |
65 | 254 JungleTreeEditor editor = tree.getTreeEditor(); |
166 | 255 either = editor.addNewChildAt(path, size); |
256 if (either.isA()) { | |
38 | 257 throw new IllegalStateException(); |
258 } | |
259 editor = either.b(); | |
146
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
260 |
166 | 261 NodeEditor e = new NodeEditor() { |
177 | 262 |
263 public <T extends TreeNode> Either<Error, TreeNode> edit(T _e) { | |
264 TreeNode node = _e; | |
265 node = node.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b(); | |
266 node = node.getAttributes().put("timestamp", tBuffer).b(); | |
267 return DefaultEither.newB(node); | |
268 } | |
269 | |
270 @Override | |
271 public OperationLog getLog() { | |
272 OperationLog op = new DefaultOperationLog(); | |
273 op = op.add(new PutAttributeOperation("mes", ByteBuffer.wrap(_message.getBytes()))); | |
274 op = op.add(new PutAttributeOperation("timestamp", tBuffer)); | |
275 return op; | |
38 | 276 } |
277 }; | |
278 path = path.add(size); | |
166 | 279 either = editor.edit(path, e); |
280 if (either.isA()) { | |
38 | 281 throw new IllegalStateException(); |
282 } | |
283 editor = either.b(); | |
46 | 284 either = editor.success(); |
166 | 285 } while (either.isA()); |
93 | 286 |
38 | 287 } |
288 | |
168 | 289 public void createBoardMessage(final String _board, final String _author, final String _message, final String _editKey) { |
166 | 290 requestCounter.incrementAndGet(); |
291 JungleTree tree = jungle.getTreeByName(_board); | |
292 if (tree == null) { | |
293 throw new IllegalStateException(); | |
294 } | |
295 | |
296 Either<Error, JungleTreeEditor> either; | |
297 final long timestamp = System.currentTimeMillis(); | |
298 final ByteBuffer tBuffer = ByteBuffer.allocate(16); | |
299 tBuffer.putLong(timestamp); | |
300 do { | |
177 | 301 |
302 TreeNode node = tree.getRootNode(); | |
166 | 303 int size = node.getChildren().size(); |
304 DefaultNodePath path = new DefaultNodePath(); | |
305 | |
306 JungleTreeEditor editor = tree.getTreeEditor(); | |
307 either = editor.addNewChildAt(path, size); | |
308 if (either.isA()) { | |
309 throw new IllegalStateException(); | |
310 } | |
311 editor = either.b(); | |
312 | |
313 NodeEditor e = new NodeEditor() { | |
177 | 314 public <T extends TreeNode> Either<Error, TreeNode> edit(T _e) { |
315 TreeNode node = _e; | |
316 node = node.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b(); | |
317 node = node.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b(); | |
318 node = node.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b(); | |
319 node = node.getAttributes().put("timestamp", tBuffer).b(); | |
320 return DefaultEither.newB(node); | |
321 } | |
322 | |
323 @Override | |
324 public OperationLog getLog() { | |
325 OperationLog op = new DefaultOperationLog(); | |
326 op = op.add(new PutAttributeOperation("author", ByteBuffer.wrap(_author.getBytes()))); | |
327 op = op.add(new PutAttributeOperation("mes", ByteBuffer.wrap(_message.getBytes()))); | |
328 op = op.add(new PutAttributeOperation("key", ByteBuffer.wrap(_editKey.getBytes()))); | |
329 op = op.add(new PutAttributeOperation("timestamp", tBuffer)); | |
330 return op; | |
166 | 331 } |
332 }; | |
333 path = path.add(size); | |
334 either = editor.edit(path, e); | |
335 if (either.isA()) { | |
336 throw new IllegalStateException(); | |
337 } | |
338 editor = either.b(); | |
339 either = editor.success(); | |
340 } while (either.isA()); | |
341 | |
342 } | |
343 | |
177 | 344 public void editMessage(String _board, String _nodeNum,final String _author, final String _message, final String _editKey) { |
143
7a7bac51a3cc
Added RequestNumCheckServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
345 requestCounter.incrementAndGet(); |
149
06cddf529325
Modified lates renew time
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
346 final long timestamp = System.currentTimeMillis(); |
146
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
347 final ByteBuffer tBuffer = ByteBuffer.allocate(16); |
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
348 tBuffer.putLong(timestamp); |
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
349 JungleTree tree = jungle.getTreeByName(_board); |
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
350 Either<Error, JungleTreeEditor> either = null; |
177 | 351 |
146
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
352 do { |
38 | 353 DefaultNodePath path = new DefaultNodePath(); |
169 | 354 try { |
355 for (int count = 0; _nodeNum.substring(count, count + 1) != null; count++) { | |
356 if (!_nodeNum.substring(count, count + 1).equals("/")) | |
177 | 357 path = path.add(Integer.parseInt(_nodeNum.substring(count, count + 1))); |
169 | 358 } |
359 } catch (Exception _e) { | |
360 } | |
65 | 361 JungleTreeEditor editor = tree.getTreeEditor(); |
166 | 362 NodeEditor e = new NodeEditor() { |
177 | 363 public <T extends TreeNode> Either<Error, TreeNode> edit(T _e) { |
364 TreeNode node = _e; | |
365 System.out.println(new String(node.getAttributes().get("mes").array())); | |
366 node = node.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b(); | |
367 node = node.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b(); | |
368 node = node.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b(); | |
369 node = node.getAttributes().put("timestamp", tBuffer).b(); | |
370 System.out.println(new String(node.getAttributes().get("mes").array())); | |
371 return DefaultEither.newB(node); | |
372 } | |
373 | |
374 @Override | |
375 public OperationLog getLog() { | |
376 OperationLog op = new DefaultOperationLog(); | |
377 op = op.add(new PutAttributeOperation("author", ByteBuffer.wrap(_author.getBytes()))); | |
378 op = op.add(new PutAttributeOperation("mes", ByteBuffer.wrap(_message.getBytes()))); | |
379 op = op.add(new PutAttributeOperation("key", ByteBuffer.wrap(_editKey.getBytes()))); | |
380 op = op.add(new PutAttributeOperation("timestamp", tBuffer)); | |
381 return op; | |
38 | 382 } |
383 }; | |
166 | 384 either = editor.edit(path, e); |
385 if (either.isA()) { | |
38 | 386 throw new IllegalStateException(); |
387 } | |
388 editor = either.b(); | |
46 | 389 either = editor.success(); |
166 | 390 } while (either.isA()); |
391 renewTime = timestamp; | |
392 } | |
167 | 393 |
168 | 394 public void createAttribute(String _board, String _uuid, final String _author, final String _message, final String _editKey) { |
166 | 395 requestCounter.incrementAndGet(); |
396 final long timestamp = System.currentTimeMillis(); | |
397 final ByteBuffer tBuffer = ByteBuffer.allocate(16); | |
398 tBuffer.putLong(timestamp); | |
399 JungleTree tree = jungle.getTreeByName(_board); | |
400 Either<Error, JungleTreeEditor> either = null; | |
401 DefaultNodePath path = new DefaultNodePath(); | |
402 do { | |
403 try { | |
404 for (int count = 0; _uuid.substring(count, count + 1) != null; count++) { | |
405 if (!_uuid.substring(count, count + 1).equals("/")) | |
177 | 406 path = path.add(Integer.parseInt(_uuid.substring(count, |
407 count + 1))); | |
166 | 408 } |
409 } catch (Exception _e) { | |
410 } | |
177 | 411 |
166 | 412 JungleTreeEditor editor = tree.getTreeEditor(); |
413 NodeEditor e = new NodeEditor() { | |
177 | 414 String str; |
415 | |
416 public <T extends TreeNode> Either<Error, TreeNode> edit(T _e) { | |
417 TreeNode node = _e; | |
418 str = "0"; | |
167 | 419 int count = 0; |
177 | 420 for (; _e.getAttributes().get("mes" + String.valueOf(count)) != null; count++) { |
421 } | |
169 | 422 str = String.valueOf(count); |
177 | 423 node = node.getAttributes().put("mes" + str,ByteBuffer.wrap(_message.getBytes())).b(); |
424 node = node.getAttributes().put("timestamp" + str, tBuffer).b(); | |
425 return DefaultEither.newB(node); | |
426 } | |
427 | |
428 @Override | |
429 public OperationLog getLog() { | |
430 OperationLog op = new DefaultOperationLog(); | |
431 op = op.add(new PutAttributeOperation("mes" + str,ByteBuffer.wrap(_message.getBytes()))); | |
432 op = op.add(new PutAttributeOperation("timestamp" + str,tBuffer)); | |
433 return op; | |
166 | 434 } |
435 }; | |
436 either = editor.edit(path, e); | |
437 if (either.isA()) { | |
438 throw new IllegalStateException(); | |
439 } | |
440 editor = either.b(); | |
441 either = editor.success(); | |
442 } while (either.isA()); | |
443 } | |
167 | 444 |
174 | 445 public void editAttribute(String boardName, String _path, final String id, final String _message) { |
169 | 446 requestCounter.incrementAndGet(); |
447 final long timestamp = System.currentTimeMillis(); | |
448 final ByteBuffer tBuffer = ByteBuffer.allocate(16); | |
449 tBuffer.putLong(timestamp); | |
450 JungleTree tree = jungle.getTreeByName(boardName); | |
451 Either<Error, JungleTreeEditor> either = null; | |
452 DefaultNodePath path = new DefaultNodePath(); | |
453 do { | |
454 try { | |
455 for (int count = 0; _path.substring(count, count + 1) != null; count++) { | |
456 if (!_path.substring(count, count + 1).equals("/")) | |
177 | 457 path = path.add(Integer.parseInt(_path.substring(count, |
458 count + 1))); | |
169 | 459 } |
460 } catch (Exception _e) { | |
461 } | |
177 | 462 |
169 | 463 JungleTreeEditor editor = tree.getTreeEditor(); |
464 NodeEditor e = new NodeEditor() { | |
177 | 465 public <T extends TreeNode> Either<Error, TreeNode> edit(T _e) { |
466 TreeNode node = _e; | |
169 | 467 // EnableNodeWrapper<T> node = _e.getWrap(); |
177 | 468 node = node.getAttributes().put("mes" + id,ByteBuffer.wrap(_message.getBytes())).b(); |
469 node = node.getAttributes().put("timestamp" + id, tBuffer).b(); | |
470 return DefaultEither.newB(node); | |
471 } | |
472 | |
473 @Override | |
474 public OperationLog getLog() { | |
475 OperationLog op = new DefaultOperationLog(); | |
476 op = op.add(new PutAttributeOperation("mes"+ id, ByteBuffer.wrap(_message.getBytes()))); | |
477 op = op.add(new PutAttributeOperation("timestamp"+ id, tBuffer)); | |
478 return op; | |
169 | 479 } |
480 }; | |
481 either = editor.edit(path, e); | |
482 if (either.isA()) { | |
483 throw new IllegalStateException(); | |
484 } | |
485 editor = either.b(); | |
486 either = editor.success(); | |
487 } while (either.isA()); | |
488 } | |
177 | 489 |
171 | 490 public void deleteNode(String _board, String _path, String _id) { |
491 requestCounter.incrementAndGet(); | |
492 int id = Integer.parseInt(_id); | |
493 final long timestamp = System.currentTimeMillis(); | |
494 final ByteBuffer tBuffer = ByteBuffer.allocate(16); | |
495 tBuffer.putLong(timestamp); | |
496 JungleTree tree = jungle.getTreeByName(_board); | |
497 Either<Error, JungleTreeEditor> either = null; | |
498 DefaultNodePath path = new DefaultNodePath(); | |
499 do { | |
500 try { | |
501 for (int count = 0; _path.substring(count, count + 1) != null; count++) { | |
502 if (!_path.substring(count, count + 1).equals("/")) | |
177 | 503 path = path.add(Integer.parseInt(_path.substring(count,count + 1))); |
171 | 504 } |
505 } catch (Exception _e) { | |
506 } | |
177 | 507 |
171 | 508 JungleTreeEditor editor = tree.getTreeEditor(); |
169 | 509 |
171 | 510 either = editor.deleteChildAt(path, id); |
511 if (either.isA()) { | |
512 throw new IllegalStateException(); | |
513 } | |
514 editor = either.b(); | |
515 either = editor.success(); | |
516 } while (either.isA()); | |
177 | 517 |
171 | 518 } |
177 | 519 |
520 public void deleteAttribute(String _board, String _path, final String id) { | |
170 | 521 requestCounter.incrementAndGet(); |
522 final long timestamp = System.currentTimeMillis(); | |
523 final ByteBuffer tBuffer = ByteBuffer.allocate(16); | |
524 tBuffer.putLong(timestamp); | |
525 JungleTree tree = jungle.getTreeByName(_board); | |
526 Either<Error, JungleTreeEditor> either = null; | |
527 DefaultNodePath path = new DefaultNodePath(); | |
528 do { | |
529 try { | |
530 for (int count = 0; _path.substring(count, count + 1) != null; count++) { | |
531 if (!_path.substring(count, count + 1).equals("/")) | |
177 | 532 path = path.add(Integer.parseInt(_path.substring(count, |
533 count + 1))); | |
170 | 534 } |
535 } catch (Exception _e) { | |
176 | 536 System.out.println("屑"); |
170 | 537 } |
177 | 538 |
170 | 539 JungleTreeEditor editor = tree.getTreeEditor(); |
540 NodeEditor e = new NodeEditor() { | |
177 | 541 public <T extends TreeNode> Either<Error, TreeNode> edit(T _e) { |
542 TreeNode node = _e; | |
543 node = node.getAttributes().delete("mes" + id).b(); | |
544 node = node.getAttributes().delete("timestamp" + id).b(); | |
170 | 545 int count = Integer.parseInt(id); |
177 | 546 for (; node.getAttributes().get("mes" + String.valueOf(count + 1)) != null;) { |
547 node = node.getAttributes().put("mes" + count,_e.getAttributes().get("mes"+ String.valueOf(count + 1))).b(); | |
548 node = node.getAttributes().put("timestamp" + count, tBuffer).b(); | |
549 count++; | |
550 } | |
551 if (count != Integer.parseInt(id)) { | |
552 node = node.getAttributes().delete("timestamp" + count).b(); | |
553 node = node.getAttributes().delete("mes" + count).b(); | |
172 | 554 } |
555 | |
177 | 556 return DefaultEither.newB(node); |
557 } | |
558 | |
559 @Override | |
560 public OperationLog getLog() { | |
561 return new DefaultOperationLog(); | |
170 | 562 } |
563 }; | |
564 either = editor.edit(path, e); | |
565 if (either.isA()) { | |
566 throw new IllegalStateException(); | |
567 } | |
568 editor = either.b(); | |
569 either = editor.success(); | |
570 } while (either.isA()); | |
571 } | |
572 | |
177 | 573 public void editMatrixMessage(String _board, String _uuid, |
574 final String _author, final String _message, final String _editKey) { | |
166 | 575 requestCounter.incrementAndGet(); |
576 final long timestamp = System.currentTimeMillis(); | |
577 final ByteBuffer tBuffer = ByteBuffer.allocate(16); | |
578 tBuffer.putLong(timestamp); | |
579 JungleTree tree = jungle.getTreeByName(_board); | |
580 Either<Error, JungleTreeEditor> either = null; | |
581 do { | |
582 DefaultNodePath path = new DefaultNodePath(); | |
583 path = path.add(Integer.parseInt(_uuid)); | |
584 | |
585 JungleTreeEditor editor = tree.getTreeEditor(); | |
586 NodeEditor e = new NodeEditor() { | |
177 | 587 public <T extends TreeNode> Either<Error, TreeNode> edit(T _e) { |
588 TreeNode node = _e; | |
589 node = node.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b(); | |
590 node = node.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b(); | |
591 node = node.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b(); | |
592 node = node.getAttributes().put("timestamp", tBuffer).b(); | |
593 return DefaultEither.newB(node); | |
594 } | |
595 | |
596 @Override | |
597 public OperationLog getLog() { | |
598 OperationLog op = new DefaultOperationLog(); | |
599 op = op.add(new PutAttributeOperation("author", ByteBuffer.wrap(_author.getBytes()))); | |
600 op = op.add(new PutAttributeOperation("mes", ByteBuffer.wrap(_message.getBytes()))); | |
601 op = op.add(new PutAttributeOperation("key", ByteBuffer.wrap(_editKey.getBytes()))); | |
602 op = op.add(new PutAttributeOperation("timestamp", tBuffer)); | |
603 return op; | |
166 | 604 } |
605 }; | |
606 either = editor.edit(path, e); | |
607 if (either.isA()) { | |
608 throw new IllegalStateException(); | |
609 } | |
610 editor = either.b(); | |
611 either = editor.success(); | |
612 } while (either.isA()); | |
150
eef85b5faa15
Removed renew atribute
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
149
diff
changeset
|
613 renewTime = timestamp; |
38 | 614 } |
615 | |
166 | 616 public Iterable<BoardMessage> getMessages(String _boardName) { |
143
7a7bac51a3cc
Added RequestNumCheckServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
617 requestCounter.incrementAndGet(); |
38 | 618 JungleTree tree = jungle.getTreeByName(_boardName); |
177 | 619 TreeNode node = tree.getRootNode(); |
620 Children<TreeNode> chs = node.getChildren(); | |
38 | 621 final AtomicInteger counter = new AtomicInteger(0); |
177 | 622 IterableConverter.Converter<BoardMessage, TreeNode> converter = new IterableConverter.Converter<BoardMessage, TreeNode>() { |
623 public BoardMessage conv(TreeNode _b) { | |
166 | 624 String uuid = Integer.toString(counter.get()); |
177 | 625 String author = new String(_b.getAttributes().get("author").array()); |
168 | 626 String message = new String(_b.getAttributes().get("mes").array()); |
166 | 627 counter.incrementAndGet(); |
628 return new BoardMessageImpl(author, message, uuid); | |
629 } | |
630 }; | |
177 | 631 return new IterableConverter<BoardMessage, TreeNode>(chs, converter); |
166 | 632 } |
633 | |
634 public Iterable<BoardMessage> getFolder(String _boardName, String _nodeNum) { | |
167 | 635 |
166 | 636 DefaultNodePath path = new DefaultNodePath(); |
637 try { | |
638 for (int count = 0; _nodeNum.substring(count, count + 1) != null; count++) { | |
639 if (!_nodeNum.substring(count, count + 1).equals("/")) | |
168 | 640 path = path.add(Integer.parseInt(_nodeNum.substring(count,count + 1))); |
166 | 641 } |
642 } catch (Exception _e) { | |
643 } | |
644 requestCounter.incrementAndGet(); | |
645 JungleTree tree = jungle.getTreeByName(_boardName); | |
177 | 646 TreeNode node = tree.getRootNode(); |
166 | 647 |
648 DefaultTraverser traverser = new DefaultTraverser(); | |
177 | 649 // TraversableNodeWrapper<Node> traversable = new |
650 // TraversableNodeWrapper<Node>(node); | |
166 | 651 DefaultEvaluator evaluator = new DefaultEvaluator(path); |
177 | 652 Either<Error, Traversal<TreeNode>> ret = traverser.traverse(node, |
653 evaluator); | |
166 | 654 if (ret.isA()) { |
655 Assert.fail(); | |
656 } | |
657 | |
177 | 658 Traversal<TreeNode> traversal = ret.b(); |
659 TreeNode target = traversal.destination(); | |
660 Children<TreeNode> chs = target.getChildren(); | |
166 | 661 |
662 final AtomicInteger counter = new AtomicInteger(0); | |
177 | 663 IterableConverter.Converter<BoardMessage, TreeNode> converter = new IterableConverter.Converter<BoardMessage, TreeNode>() { |
664 public BoardMessage conv(TreeNode _b) { | |
38 | 665 String uuid = Integer.toString(counter.get()); |
177 | 666 String message = new String(_b.getAttributes().get("mes") |
667 .array()); | |
38 | 668 counter.incrementAndGet(); |
168 | 669 return new BoardMessageImpl(null, message, uuid); |
38 | 670 } |
671 }; | |
177 | 672 return new IterableConverter<BoardMessage, TreeNode>(chs, converter); |
38 | 673 } |
167 | 674 |
675 public getAttributeImp getAttribute(String _boardName, String _nodeNum) { | |
676 | |
677 DefaultNodePath path = new DefaultNodePath(); | |
678 try { | |
679 for (int count = 0; _nodeNum.substring(count, count + 1) != null; count++) { | |
680 if (!_nodeNum.substring(count, count + 1).equals("/")) | |
177 | 681 path = path.add(Integer.parseInt(_nodeNum.substring(count, |
682 count + 1))); | |
167 | 683 } |
684 } catch (Exception _e) { | |
685 } | |
686 requestCounter.incrementAndGet(); | |
687 JungleTree tree = jungle.getTreeByName(_boardName); | |
177 | 688 TreeNode node = tree.getRootNode(); |
167 | 689 |
690 DefaultTraverser traverser = new DefaultTraverser(); | |
177 | 691 // TraversableNodeWrapper<Node> traversable = new |
692 // TraversableNodeWrapper<Node>(node); | |
167 | 693 DefaultEvaluator evaluator = new DefaultEvaluator(path); |
177 | 694 Either<Error, Traversal<TreeNode>> ret = traverser.traverse(node, |
695 evaluator); | |
167 | 696 if (ret.isA()) { |
697 Assert.fail(); | |
698 } | |
699 | |
177 | 700 Traversal<TreeNode> traversal = ret.b(); |
701 TreeNode target = traversal.destination(); | |
702 return new getAttributeImp(target); | |
167 | 703 } |
166 | 704 |
143
7a7bac51a3cc
Added RequestNumCheckServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
705 public int getRequestNum() { |
7a7bac51a3cc
Added RequestNumCheckServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
706 return requestCounter.get(); |
7a7bac51a3cc
Added RequestNumCheckServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
707 } |
146
29734d7d6521
Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
143
diff
changeset
|
708 |
166 | 709 private static class BoardMessageImpl implements BoardMessage { |
38 | 710 private final String author; |
711 private final String message; | |
712 private final String uuid; | |
166 | 713 |
714 public BoardMessageImpl(String _author, String _message, String _uuid) { | |
38 | 715 author = _author; |
716 message = _message; | |
717 uuid = _uuid; | |
718 } | |
719 | |
166 | 720 public String getAuthor() { |
38 | 721 return author; |
722 } | |
723 | |
166 | 724 public String getMessage() { |
38 | 725 return message; |
726 } | |
727 | |
166 | 728 public String getUUID() { |
38 | 729 return uuid; |
730 } | |
143
7a7bac51a3cc
Added RequestNumCheckServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
139
diff
changeset
|
731 |
38 | 732 } |
124 | 733 |
177 | 734 public String sanitize(String str) { |
735 if (str == null) { | |
736 return str; | |
737 } | |
738 str = str.replaceAll("&", "&"); | |
739 str = str.replaceAll("<", "<"); | |
740 str = str.replaceAll(">", ">"); | |
741 str = str.replaceAll("\"", """); | |
742 str = str.replaceAll("'", "'"); | |
743 return str; | |
744 } | |
171 | 745 |
38 | 746 } |