1
|
1 package jp.ac.u_ryukyu.cr.ie.tatsuki.bbs;
|
|
2
|
|
3 import java.io.FileInputStream;
|
|
4 import java.nio.ByteBuffer;
|
41
|
5 import java.util.Iterator;
|
1
|
6 import java.util.concurrent.atomic.AtomicInteger;
|
|
7
|
|
8 import javax.xml.parsers.SAXParser;
|
|
9 import javax.xml.parsers.SAXParserFactory;
|
|
10
|
41
|
11 import fj.data.List;
|
1
|
12 import ac.jp.u_ryukyu.cr.ie.tatsuki.xmlReader.ReadXmlHandler;
|
|
13 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.DefaultJungle;
|
|
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;
|
|
17 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs.BoardMessage;
|
|
18 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Children;
|
|
19 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath;
|
|
20 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultTreeEditor;
|
|
21 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode;
|
|
22 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.DefaultOperationLog;
|
|
23 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.LoggingNode;
|
|
24 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.OperationLog;
|
|
25 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.NodeEditor;
|
|
26 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultEvaluator;
|
|
27 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser;
|
|
28 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.Traversal;
|
|
29 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither;
|
|
30 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either;
|
|
31 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error;
|
|
32 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.IterableConverter;
|
|
33 import junit.framework.Assert;
|
|
34
|
|
35 public class JungleBulletinBoard implements XmlBulletinBoard {
|
|
36
|
41
|
37 private final Jungle jungle;
|
1
|
38
|
41
|
39 public JungleBulletinBoard() {
|
|
40 jungle = new DefaultJungle(null, "hoge", new DefaultTreeEditor(new DefaultTraverser()));
|
|
41 jungle.createNewTree("boards");
|
|
42 }
|
1
|
43
|
41
|
44 public IterableConverter<String, TreeNode> getBoards() {
|
|
45 JungleTree tree = jungle.getTreeByName("boards");
|
|
46 TreeNode node = tree.getRootNode();
|
|
47 Children chs = node.getChildren();
|
1
|
48
|
41
|
49 IterableConverter.Converter<String, TreeNode> converter = new IterableConverter.Converter<String, TreeNode>() {
|
1
|
50
|
41
|
51 public String conv(TreeNode _b) {
|
|
52 List<ByteBuffer> byteBufferList = _b.getAttributes().get("name");
|
|
53 if (byteBufferList.isNotEmpty())
|
|
54 return byteBufferList.head().toString();
|
|
55 return "";
|
|
56 }
|
|
57 };
|
1
|
58
|
41
|
59 return new IterableConverter<String, TreeNode>(chs, converter);
|
|
60 }
|
1
|
61
|
41
|
62 public void createBoards(final String _name) {
|
|
63 if (null == jungle.createNewTree(_name)) {
|
|
64 throw new IllegalStateException();
|
|
65 }
|
1
|
66
|
41
|
67 JungleTree tree = jungle.getTreeByName("boards");
|
|
68 JungleTreeEditor editor = tree.getTreeEditor();
|
|
69 DefaultNodePath root = new DefaultNodePath();
|
|
70 Either<Error, JungleTreeEditor> either = editor.addNewChildAt(root, 0);
|
|
71 if (either.isA()) {
|
|
72 throw new IllegalStateException();
|
|
73 }
|
|
74 editor = either.b();
|
1
|
75
|
41
|
76 either = editor.putAttribute(root.add(0), "name", ByteBuffer.wrap(_name.getBytes()));
|
|
77 if (either.isA()) {
|
|
78 throw new IllegalStateException();
|
|
79 }
|
|
80 editor = either.b();
|
|
81 either = either.b().success();
|
|
82 if (either.isA()) {
|
|
83 throw new IllegalStateException();
|
|
84 }
|
1
|
85
|
41
|
86 }
|
1
|
87
|
41
|
88 public void createFolder(final String _board, final String _author, final String _message, final String _editKey,
|
|
89 String _nodeNum) {
|
|
90 JungleTree tree = jungle.getTreeByName(_board);
|
|
91 if (tree == null) {
|
|
92 throw new IllegalStateException();
|
|
93 }
|
1
|
94
|
41
|
95 DefaultNodePath path = new DefaultNodePath();
|
|
96 try {
|
|
97 for (int count = 0; _nodeNum.substring(count, count + 1) != null; count++) {
|
|
98 if (!_nodeNum.substring(count, count + 1).equals("/"))
|
|
99 path = path.add(Integer.parseInt(_nodeNum.substring(count, count + 1)));
|
|
100 }
|
|
101 } catch (Exception _e) {
|
|
102 }
|
|
103 Either<Error, JungleTreeEditor> either;
|
|
104 final long timestamp = System.currentTimeMillis();
|
|
105 final ByteBuffer tBuffer = ByteBuffer.allocate(16);
|
|
106 tBuffer.putLong(timestamp);
|
1
|
107
|
41
|
108 do {
|
|
109 TreeNode node = tree.getRootNode();
|
|
110 DefaultTraverser traverser = new DefaultTraverser();
|
|
111 // TraversableNodeWrapper<Node> traversable = new
|
|
112 // TraversableNodeWrapper<Node>(node);
|
|
113 DefaultEvaluator evaluator = new DefaultEvaluator(path);
|
|
114 Either<Error, Traversal> ret = traverser.traverse(node, evaluator);
|
|
115 if (ret.isA()) {
|
|
116 Assert.fail();
|
|
117 }
|
1
|
118
|
41
|
119 Traversal traversal = ret.b();
|
|
120 TreeNode target = traversal.destination();
|
|
121 int size = target.getChildren().size();
|
|
122 JungleTreeEditor editor = tree.getTreeEditor();
|
|
123 either = editor.addNewChildAt(path, size);
|
|
124 if (either.isA()) {
|
|
125 throw new IllegalStateException();
|
|
126 }
|
|
127 editor = either.b();
|
1
|
128
|
41
|
129 NodeEditor e = new NodeEditor() {
|
1
|
130
|
41
|
131 public Either<Error, LoggingNode> edit(TreeNode node) {
|
|
132 LoggingNode logNode = wrap(node, new DefaultOperationLog());
|
|
133 logNode = logNode.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b();
|
|
134 logNode = logNode.getAttributes().put("timestamp", tBuffer).b();
|
|
135 return DefaultEither.newB(logNode);
|
|
136 }
|
1
|
137
|
41
|
138 @Override
|
|
139 public LoggingNode wrap(TreeNode node, OperationLog op) {
|
|
140 return new LoggingNode(node, op);
|
|
141 }
|
|
142 };
|
|
143 path = path.add(size);
|
|
144 either = editor.edit(path, e);
|
|
145 if (either.isA()) {
|
|
146 throw new IllegalStateException();
|
|
147 }
|
|
148 editor = either.b();
|
|
149 either = editor.success();
|
|
150 } while (either.isA());
|
1
|
151
|
41
|
152 }
|
1
|
153
|
41
|
154 public void createBoardMessage(final String _board, final String _author, final String _message, final String _editKey) {
|
|
155 JungleTree tree = jungle.getTreeByName(_board);
|
|
156 if (tree == null) {
|
|
157 throw new IllegalStateException();
|
|
158 }
|
1
|
159
|
41
|
160 Either<Error, JungleTreeEditor> either;
|
|
161 final long timestamp = System.currentTimeMillis();
|
|
162 final ByteBuffer tBuffer = ByteBuffer.allocate(16);
|
|
163 tBuffer.putLong(timestamp);
|
|
164 do {
|
1
|
165
|
41
|
166 TreeNode node = tree.getRootNode();
|
|
167 int size = node.getChildren().size();
|
|
168 DefaultNodePath path = new DefaultNodePath();
|
1
|
169
|
41
|
170 JungleTreeEditor editor = tree.getTreeEditor();
|
|
171 either = editor.addNewChildAt(path, size);
|
|
172 if (either.isA()) {
|
|
173 throw new IllegalStateException();
|
|
174 }
|
|
175 editor = either.b();
|
1
|
176
|
41
|
177 NodeEditor e = new NodeEditor() {
|
|
178 public Either<Error, LoggingNode> edit(TreeNode node) {
|
|
179 LoggingNode logNode = wrap(node, new DefaultOperationLog());
|
|
180 logNode = logNode.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b();
|
|
181 logNode = logNode.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b();
|
|
182 logNode = logNode.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b();
|
|
183 logNode = logNode.getAttributes().put("timestamp", tBuffer).b();
|
|
184 return DefaultEither.newB(logNode);
|
|
185 }
|
1
|
186
|
41
|
187 @Override
|
|
188 public LoggingNode wrap(TreeNode node, OperationLog op) {
|
|
189 return new LoggingNode(node, op);
|
|
190 }
|
1
|
191
|
41
|
192 };
|
|
193 path = path.add(size);
|
|
194 either = editor.edit(path, e);
|
|
195 if (either.isA()) {
|
|
196 throw new IllegalStateException();
|
|
197 }
|
|
198 editor = either.b();
|
|
199 either = editor.success();
|
|
200 } while (either.isA());
|
1
|
201
|
41
|
202 }
|
|
203
|
|
204 public void editMessage(String _board, String _nodeNum, final String _author, final String _message,
|
|
205 final String _editKey) {
|
|
206 final long timestamp = System.currentTimeMillis();
|
|
207 final ByteBuffer tBuffer = ByteBuffer.allocate(16);
|
|
208 tBuffer.putLong(timestamp);
|
|
209 JungleTree tree = jungle.getTreeByName(_board);
|
|
210 Either<Error, JungleTreeEditor> either = null;
|
1
|
211
|
41
|
212 do {
|
|
213 DefaultNodePath path = new DefaultNodePath();
|
|
214 try {
|
|
215 for (int count = 0; _nodeNum.substring(count, count + 1) != null; count++) {
|
|
216 if (!_nodeNum.substring(count, count + 1).equals("/"))
|
|
217 path = path.add(Integer.parseInt(_nodeNum.substring(count, count + 1)));
|
|
218 }
|
|
219 } catch (Exception _e) {
|
|
220 }
|
|
221 JungleTreeEditor editor = tree.getTreeEditor();
|
|
222 NodeEditor e = new NodeEditor() {
|
|
223 public Either<Error, LoggingNode> edit(TreeNode node) {
|
|
224 LoggingNode logNode = wrap(node, new DefaultOperationLog());
|
|
225 logNode = logNode.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b();
|
|
226 logNode = logNode.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b();
|
|
227 logNode = logNode.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b();
|
|
228 logNode = logNode.getAttributes().put("timestamp", tBuffer).b();
|
|
229 return DefaultEither.newB(logNode);
|
|
230 }
|
1
|
231
|
41
|
232 @Override
|
|
233 public LoggingNode wrap(TreeNode node, OperationLog op) {
|
|
234 return new LoggingNode(node, op);
|
|
235 }
|
1
|
236
|
41
|
237 };
|
|
238 either = editor.edit(path, e);
|
|
239 if (either.isA()) {
|
|
240 throw new IllegalStateException();
|
|
241 }
|
|
242 editor = either.b();
|
|
243 either = editor.success();
|
|
244 } while (either.isA());
|
|
245 }
|
1
|
246
|
41
|
247 public void createAttribute(String _board, String _uuid, final String _author, final String _message,
|
|
248 final String _editKey) {
|
|
249 final long timestamp = System.currentTimeMillis();
|
|
250 final ByteBuffer tBuffer = ByteBuffer.allocate(16);
|
|
251 tBuffer.putLong(timestamp);
|
|
252 JungleTree tree = jungle.getTreeByName(_board);
|
|
253 Either<Error, JungleTreeEditor> either = null;
|
|
254 DefaultNodePath path = new DefaultNodePath();
|
|
255 do {
|
|
256 try {
|
|
257 for (int count = 0; _uuid.substring(count, count + 1) != null; count++) {
|
|
258 if (!_uuid.substring(count, count + 1).equals("/"))
|
|
259 path = path.add(Integer.parseInt(_uuid.substring(count, count + 1)));
|
|
260 }
|
|
261 } catch (Exception _e) {
|
|
262 }
|
1
|
263
|
41
|
264 JungleTreeEditor editor = tree.getTreeEditor();
|
|
265 NodeEditor e = new NodeEditor() {
|
|
266 String str;
|
1
|
267
|
41
|
268 public Either<Error, LoggingNode> edit(TreeNode node) {
|
|
269 LoggingNode logNode = wrap(node, new DefaultOperationLog());
|
|
270 str = "0";
|
|
271 int count = 0;
|
|
272 for (; logNode.getAttributes().get("mes" + String.valueOf(count)) != null; count++) {
|
|
273 }
|
|
274 str = String.valueOf(count);
|
|
275 logNode = logNode.getAttributes().put("mes" + str, ByteBuffer.wrap(_message.getBytes())).b();
|
|
276 logNode = logNode.getAttributes().put("timestamp" + str, tBuffer).b();
|
|
277 return DefaultEither.newB(logNode);
|
|
278 }
|
1
|
279
|
41
|
280 @Override
|
|
281 public LoggingNode wrap(TreeNode node, OperationLog op) {
|
|
282 return new LoggingNode(node, op);
|
|
283 }
|
|
284 };
|
|
285 either = editor.edit(path, e);
|
|
286 if (either.isA()) {
|
|
287 throw new IllegalStateException();
|
|
288 }
|
|
289 editor = either.b();
|
|
290 either = editor.success();
|
|
291 } while (either.isA());
|
|
292 }
|
1
|
293
|
41
|
294 public void editAttribute(String boardName, String _path, final String id, final String _message) {
|
|
295 final long timestamp = System.currentTimeMillis();
|
|
296 final ByteBuffer tBuffer = ByteBuffer.allocate(16);
|
|
297 tBuffer.putLong(timestamp);
|
|
298 JungleTree tree = jungle.getTreeByName(boardName);
|
|
299 Either<Error, JungleTreeEditor> either = null;
|
|
300 DefaultNodePath path = new DefaultNodePath();
|
|
301 do {
|
|
302 try {
|
|
303 for (int count = 0; _path.substring(count, count + 1) != null; count++) {
|
|
304 if (!_path.substring(count, count + 1).equals("/"))
|
|
305 path = path.add(Integer.parseInt(_path.substring(count, count + 1)));
|
|
306 }
|
|
307 } catch (Exception _e) {
|
|
308 }
|
1
|
309
|
41
|
310 JungleTreeEditor editor = tree.getTreeEditor();
|
|
311 NodeEditor e = new NodeEditor() {
|
|
312 public Either<Error, LoggingNode> edit(TreeNode node) {
|
|
313 LoggingNode logNode = wrap(node, new DefaultOperationLog());
|
|
314 // EnableNodeWrapper<T> node = _e.getWrap();
|
|
315 logNode = logNode.getAttributes().put("mes" + id, ByteBuffer.wrap(_message.getBytes())).b();
|
|
316 logNode = logNode.getAttributes().put("timestamp" + id, tBuffer).b();
|
|
317 return DefaultEither.newB(logNode);
|
|
318 }
|
1
|
319
|
41
|
320 @Override
|
|
321 public LoggingNode wrap(TreeNode node, OperationLog op) {
|
|
322 return new LoggingNode(node, op);
|
|
323 }
|
1
|
324
|
41
|
325 };
|
|
326 either = editor.edit(path, e);
|
|
327 if (either.isA()) {
|
|
328 throw new IllegalStateException();
|
|
329 }
|
|
330 editor = either.b();
|
|
331 either = editor.success();
|
|
332 } while (either.isA());
|
|
333 }
|
1
|
334
|
41
|
335 public void deleteNode(String _board, String _path, String _id) {
|
|
336 int id = Integer.parseInt(_id);
|
|
337 final long timestamp = System.currentTimeMillis();
|
|
338 final ByteBuffer tBuffer = ByteBuffer.allocate(16);
|
|
339 tBuffer.putLong(timestamp);
|
|
340 JungleTree tree = jungle.getTreeByName(_board);
|
|
341 Either<Error, JungleTreeEditor> either = null;
|
|
342 DefaultNodePath path = new DefaultNodePath();
|
|
343 do {
|
|
344 try {
|
|
345 for (int count = 0; _path.substring(count, count + 1) != null; count++) {
|
|
346 if (!_path.substring(count, count + 1).equals("/"))
|
|
347 path = path.add(Integer.parseInt(_path.substring(count, count + 1)));
|
|
348 }
|
|
349 } catch (Exception _e) {
|
|
350 }
|
1
|
351
|
41
|
352 JungleTreeEditor editor = tree.getTreeEditor();
|
1
|
353
|
41
|
354 either = editor.deleteChildAt(path, id);
|
|
355 if (either.isA()) {
|
|
356 throw new IllegalStateException();
|
|
357 }
|
|
358 editor = either.b();
|
|
359 either = editor.success();
|
|
360 } while (either.isA());
|
1
|
361
|
41
|
362 }
|
1
|
363
|
41
|
364 public void deleteAttribute(String _board, String _path, final String id) {
|
|
365 final long timestamp = System.currentTimeMillis();
|
|
366 final ByteBuffer tBuffer = ByteBuffer.allocate(16);
|
|
367 tBuffer.putLong(timestamp);
|
|
368 JungleTree tree = jungle.getTreeByName(_board);
|
|
369 Either<Error, JungleTreeEditor> either = null;
|
|
370 DefaultNodePath path = new DefaultNodePath();
|
|
371 do {
|
|
372 try {
|
|
373 for (int count = 0; _path.substring(count, count + 1) != null; count++) {
|
|
374 if (!_path.substring(count, count + 1).equals("/"))
|
|
375 path = path.add(Integer.parseInt(_path.substring(count, count + 1)));
|
|
376 }
|
|
377 } catch (Exception _e) {
|
|
378 System.out.println("屑");
|
|
379 }
|
1
|
380
|
41
|
381 JungleTreeEditor editor = tree.getTreeEditor();
|
|
382 NodeEditor e = new NodeEditor() {
|
|
383 public Either<Error, LoggingNode> edit(TreeNode node) {
|
|
384 LoggingNode logNode = wrap(node, new DefaultOperationLog());
|
|
385 logNode = logNode.getAttributes().delete("mes" + id).b();
|
|
386 logNode = logNode.getAttributes().delete("timestamp" + id).b();
|
|
387 int count = Integer.parseInt(id);
|
|
388 for (; logNode.getAttributes().get("mes" + String.valueOf(count + 1)) != null;) {
|
|
389 logNode = logNode.getAttributes()
|
|
390 .put("mes" + count, node.getAttributes().get("mes" + String.valueOf(count + 1)).head()).b();
|
|
391 logNode = logNode.getAttributes().put("timestamp" + count, tBuffer).b();
|
|
392 count++;
|
|
393 }
|
|
394 if (count != Integer.parseInt(id)) {
|
|
395 logNode = logNode.getAttributes().delete("timestamp" + count).b();
|
|
396 logNode = logNode.getAttributes().delete("mes" + count).b();
|
|
397 }
|
1
|
398
|
41
|
399 return DefaultEither.newB(logNode);
|
|
400 }
|
1
|
401
|
41
|
402 @Override
|
|
403 public LoggingNode wrap(TreeNode node, OperationLog op) {
|
|
404 return new LoggingNode(node, op);
|
|
405 }
|
|
406 };
|
|
407 either = editor.edit(path, e);
|
|
408 if (either.isA()) {
|
|
409 throw new IllegalStateException();
|
|
410 }
|
|
411 editor = either.b();
|
|
412 either = editor.success();
|
|
413 } while (either.isA());
|
|
414 }
|
1
|
415
|
41
|
416 public void editMatrixMessage(String _board, String _uuid, final String _author, final String _message,
|
|
417 final String _editKey) {
|
|
418 final long timestamp = System.currentTimeMillis();
|
|
419 final ByteBuffer tBuffer = ByteBuffer.allocate(16);
|
|
420 tBuffer.putLong(timestamp);
|
|
421 JungleTree tree = jungle.getTreeByName(_board);
|
|
422 Either<Error, JungleTreeEditor> either = null;
|
|
423 do {
|
|
424 DefaultNodePath path = new DefaultNodePath();
|
|
425 path = path.add(Integer.parseInt(_uuid));
|
1
|
426
|
41
|
427 JungleTreeEditor editor = tree.getTreeEditor();
|
|
428 NodeEditor e = new NodeEditor() {
|
|
429 public Either<Error, LoggingNode> edit(TreeNode node) {
|
|
430 LoggingNode logNode = wrap(node, new DefaultOperationLog());
|
|
431 logNode = logNode.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b();
|
|
432 logNode = logNode.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b();
|
|
433 logNode = logNode.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b();
|
|
434 logNode = logNode.getAttributes().put("timestamp", tBuffer).b();
|
|
435 return DefaultEither.newB(logNode);
|
|
436 }
|
1
|
437
|
41
|
438 @Override
|
|
439 public LoggingNode wrap(TreeNode node, OperationLog op) {
|
|
440 return new LoggingNode(node, op);
|
|
441 }
|
1
|
442
|
41
|
443 };
|
|
444 either = editor.edit(path, e);
|
|
445 if (either.isA()) {
|
|
446 throw new IllegalStateException();
|
|
447 }
|
|
448 editor = either.b();
|
|
449 either = editor.success();
|
|
450 } while (either.isA());
|
|
451 }
|
1
|
452
|
41
|
453 public Iterable<BoardMessage> getMessages(String _boardName) {
|
|
454 JungleTree tree = jungle.getTreeByName(_boardName);
|
|
455 TreeNode node = tree.getRootNode();
|
|
456 Children chs = node.getChildren();
|
|
457 final AtomicInteger counter = new AtomicInteger(0);
|
|
458 IterableConverter.Converter<BoardMessage, TreeNode> converter = new IterableConverter.Converter<BoardMessage, TreeNode>() {
|
|
459 public BoardMessage conv(TreeNode _b) {
|
|
460 String uuid = Integer.toString(counter.get());
|
|
461 String author = new String(_b.getAttributes().get("author").head().array());
|
|
462 String message = new String(_b.getAttributes().get("mes").head().array());
|
|
463 counter.incrementAndGet();
|
|
464 return new BoardMessageImpl(author, message, uuid);
|
|
465 }
|
|
466 };
|
|
467 return new IterableConverter<BoardMessage, TreeNode>(chs, converter);
|
|
468 }
|
1
|
469
|
41
|
470 public Iterable<BoardMessage> getFolder(String _boardName, String _nodeNum) {
|
1
|
471
|
41
|
472 DefaultNodePath path = new DefaultNodePath();
|
|
473 try {
|
|
474 for (int count = 0; _nodeNum.substring(count, count + 1) != null; count++) {
|
|
475 if (!_nodeNum.substring(count, count + 1).equals("/"))
|
|
476 path = path.add(Integer.parseInt(_nodeNum.substring(count, count + 1)));
|
|
477 }
|
|
478 } catch (Exception _e) {
|
|
479 }
|
|
480 JungleTree tree = jungle.getTreeByName(_boardName);
|
|
481 TreeNode node = tree.getRootNode();
|
1
|
482
|
41
|
483 DefaultTraverser traverser = new DefaultTraverser();
|
|
484 DefaultEvaluator evaluator = new DefaultEvaluator(path);
|
|
485 Either<Error, Traversal> ret = traverser.traverse(node, evaluator);
|
|
486 if (ret.isA()) {
|
|
487 Assert.fail();
|
|
488 }
|
1
|
489
|
41
|
490 Traversal traversal = ret.b();
|
|
491 TreeNode target = traversal.destination();
|
|
492 Children chs = target.getChildren();
|
1
|
493
|
41
|
494 final AtomicInteger counter = new AtomicInteger(0);
|
|
495 IterableConverter.Converter<BoardMessage, TreeNode> converter = new IterableConverter.Converter<BoardMessage, TreeNode>() {
|
|
496 public BoardMessage conv(TreeNode _b) {
|
|
497 String uuid = Integer.toString(counter.get());
|
|
498 String message = new String(_b.getAttributes().get("element").head().array());
|
|
499 counter.incrementAndGet();
|
|
500 return new BoardMessageImpl(null, message, uuid);
|
|
501 }
|
|
502 };
|
|
503 return new IterableConverter<BoardMessage, TreeNode>(chs, converter);
|
|
504 }
|
1
|
505
|
41
|
506 public GetAttributeImp getAttribute(String _boardName, String _nodeNum) {
|
1
|
507
|
41
|
508 DefaultNodePath path = new DefaultNodePath();
|
|
509 try {
|
|
510 for (int count = 0; _nodeNum.substring(count, count + 1) != null; count++) {
|
|
511 if (!_nodeNum.substring(count, count + 1).equals("/"))
|
|
512 path = path.add(Integer.parseInt(_nodeNum.substring(count, count + 1)));
|
|
513 }
|
|
514 } catch (Exception _e) {
|
|
515 }
|
|
516 JungleTree tree = jungle.getTreeByName(_boardName);
|
|
517 TreeNode node = tree.getRootNode();
|
1
|
518
|
41
|
519 DefaultTraverser traverser = new DefaultTraverser();
|
|
520 DefaultEvaluator evaluator = new DefaultEvaluator(path);
|
|
521 Either<Error, Traversal> ret = traverser.traverse(node, evaluator);
|
|
522 if (ret.isA()) {
|
|
523 Assert.fail();
|
|
524 }
|
1
|
525
|
41
|
526 Traversal traversal = ret.b();
|
|
527 TreeNode target = traversal.destination();
|
|
528 return new GetAttributeImp(target);
|
|
529 }
|
1
|
530
|
41
|
531 private static class BoardMessageImpl implements BoardMessage {
|
|
532 private final String author;
|
|
533 private final String message;
|
|
534 private final String uuid;
|
1
|
535
|
41
|
536 public BoardMessageImpl(String _author, String _message, String _uuid) {
|
|
537 author = _author;
|
|
538 message = _message;
|
|
539 uuid = _uuid;
|
|
540 }
|
1
|
541
|
41
|
542 public String getAuthor() {
|
|
543 return author;
|
|
544 }
|
1
|
545
|
41
|
546 public String getMessage() {
|
|
547 return message;
|
|
548 }
|
1
|
549
|
41
|
550 public String getUUID() {
|
|
551 return uuid;
|
|
552 }
|
|
553
|
|
554 }
|
1
|
555
|
41
|
556 public void readXml(String xmlPath) {
|
|
557 try {
|
|
558 SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
|
|
559 SAXParser saxParser = saxParserFactory.newSAXParser();
|
|
560 createBoards(xmlPath);
|
|
561 JungleTree tree = jungle.getTreeByName(xmlPath);
|
|
562 ReadXmlHandler readXmlHandler = new ReadXmlHandler(tree);
|
|
563 saxParser.parse(new FileInputStream("xml/" + xmlPath), readXmlHandler);
|
|
564 } catch (Exception e) {
|
|
565 e.printStackTrace();
|
|
566 }
|
|
567 }
|
1
|
568
|
41
|
569 public String sanitize(String str) {
|
|
570 if (str == null) {
|
|
571 return str;
|
|
572 }
|
|
573 str = str.replaceAll("&", "&");
|
|
574 str = str.replaceAll("<", "<");
|
|
575 str = str.replaceAll(">", ">");
|
|
576 str = str.replaceAll("\"", """);
|
|
577 str = str.replaceAll("'", "'");
|
|
578 return str;
|
|
579 }
|
1
|
580
|
41
|
581 @Override
|
|
582 public void createBoards(String _name, String _author, String _initMessage, String _editKey) {
|
|
583 }
|
1
|
584
|
|
585 }
|