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