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