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