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