Mercurial > hg > Members > shoshi > jungle > bulletinboard
changeset 0:e7a9b10dd844
added cassandra bulletin board
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README Thu Feb 07 00:26:21 2013 +0900 @@ -0,0 +1,6 @@ +launch App.class to run CassandraBBS + +requirements. + +Cassandra 1.2.1 + and others are in pom.xml \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pom.xml Thu Feb 07 00:26:21 2013 +0900 @@ -0,0 +1,51 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>jp.ac.u_ryukyu.ie.cr.shoshi.jungle</groupId> + <artifactId>bulletinboard</artifactId> + <version>0.0.1-SNAPSHOT</version> + <packaging>jar</packaging> + + <name>bulletinboard</name> + <url>http://maven.apache.org</url> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mortbay.jetty</groupId> + <artifactId>jetty</artifactId> + <version>6.1.26</version> + </dependency> + <dependency> + <groupId>org.hectorclient</groupId> + <artifactId>hector-core</artifactId> + <version>1.1-2</version> + </dependency> + <dependency> + <groupId>org.apache.cassandra</groupId> + <artifactId>cassandra-all</artifactId> + <version>1.2.1</version> + </dependency> + <dependency> + <groupId>com.eaio.uuid</groupId> + <artifactId>uuid</artifactId> + <version>3.3</version> + </dependency> + </dependencies> + <repositories> + <repository> + <id>eaio.com</id> + <url>http://eaio.com/maven2</url> + </repository> + </repositories> +</project>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/App.java Thu Feb 07 00:26:21 2013 +0900 @@ -0,0 +1,40 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs; + +import javax.servlet.Servlet; + +import org.mortbay.jetty.Server; +import org.mortbay.jetty.servlet.ServletHandler; +import org.mortbay.jetty.servlet.ServletHolder; + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) throws Exception + { + BulletinBoard cassaBBS = new CassandraBulletinBoard("test-cluster","localhost:9160","cassaBBS2"); + + String createBoardMessagePath = "/createBoardMessage"; + String createBoardPath = "/createBoard"; + String editMessagePath = "/editMessage"; + String showBoardMessagePath = "/showBoardMessage"; + + Servlet createBoardMessage = new CreateBoardMessageServlet(cassaBBS); + Servlet createBoard = new CreateBoardServlet(cassaBBS); + Servlet editBoardMessage = new EditMessageServlet(cassaBBS); + Servlet index = new ShowBoardsServlet(cassaBBS,createBoardPath,showBoardMessagePath); + Servlet board = new ShowBoardMessageServlet(cassaBBS,createBoardMessagePath,editMessagePath); + + Server serv = new Server(8080); + ServletHandler context = new ServletHandler(); + context.addServletWithMapping(new ServletHolder(createBoardMessage),createBoardMessagePath); + context.addServletWithMapping(new ServletHolder(createBoard),createBoardPath); + context.addServletWithMapping(new ServletHolder(editBoardMessage),editMessagePath); + context.addServletWithMapping(new ServletHolder(index),"/"); + context.addServletWithMapping(new ServletHolder(board),showBoardMessagePath); + serv.addHandler(context); + serv.start(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/BoardMessage.java Thu Feb 07 00:26:21 2013 +0900 @@ -0,0 +1,8 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs; + +public interface BoardMessage +{ + public String getUUID(); + public String getAuthor(); + public String getMessage(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/BulletinBoard.java Thu Feb 07 00:26:21 2013 +0900 @@ -0,0 +1,11 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs; + +public interface BulletinBoard +{ + public Iterable<String> getBoards(); + public void createBoards(String _name,String _author,String _initMessage,String _editKey); + public void createBoardMessage(String _board,String _author,String _message,String _editKey); + public void editMessage(String _board,String _uuid,String _author,String _message,String _editKey); + + public Iterable<BoardMessage> getMessages(String _boardName); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/CassandraBulletinBoard.java Thu Feb 07 00:26:21 2013 +0900 @@ -0,0 +1,192 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs; + +import java.util.Collections; +import java.util.List; +import java.util.UUID; + +import org.apache.cassandra.locator.SimpleStrategy; + +import me.prettyprint.cassandra.serializers.StringSerializer; +import me.prettyprint.cassandra.serializers.UUIDSerializer; +import me.prettyprint.cassandra.service.CassandraHost; +import me.prettyprint.cassandra.service.template.SuperCfResult; +import me.prettyprint.cassandra.service.template.SuperCfUpdater; +import me.prettyprint.cassandra.service.template.ThriftSuperCfTemplate; +import me.prettyprint.cassandra.utils.TimeUUIDUtils; +import me.prettyprint.hector.api.Cluster; +import me.prettyprint.hector.api.Keyspace; +import me.prettyprint.hector.api.beans.HSuperColumn; +import me.prettyprint.hector.api.beans.OrderedSuperRows; +import me.prettyprint.hector.api.beans.SuperRow; +import me.prettyprint.hector.api.beans.SuperSlice; +import me.prettyprint.hector.api.ddl.ColumnFamilyDefinition; +import me.prettyprint.hector.api.ddl.ColumnType; +import me.prettyprint.hector.api.ddl.ComparatorType; +import me.prettyprint.hector.api.ddl.KeyspaceDefinition; +import me.prettyprint.hector.api.factory.HFactory; +import me.prettyprint.hector.api.query.QueryResult; +import me.prettyprint.hector.api.query.RangeSuperSlicesQuery; +import me.prettyprint.hector.api.query.SuperSliceQuery; + +public class CassandraBulletinBoard implements BulletinBoard +{ + private final String address; + private final String clusterName; + private final Cluster cluster; + private final String keyspace; + + private static final String COLUMN_FAMILY_BOARD = "boards"; + + public CassandraBulletinBoard(String _clusterName,String _address,String _keyspaceName) + { + address = _address; + clusterName = _clusterName; + keyspace = _keyspaceName; + cluster = HFactory.getOrCreateCluster(clusterName,address); + + initialize(); + } + + private void initialize() + { + if(cluster.describeKeyspace(keyspace) == null){ + KeyspaceDefinition keyspaceDefinition = HFactory.createKeyspaceDefinition(keyspace, + SimpleStrategy.class.getName(),1,Collections.<ColumnFamilyDefinition> emptyList()); + cluster.addKeyspace(keyspaceDefinition,false); + ColumnFamilyDefinition columnFamilyDefinition = HFactory.createColumnFamilyDefinition(keyspace,COLUMN_FAMILY_BOARD,ComparatorType.UUIDTYPE); + columnFamilyDefinition.setColumnType(ColumnType.SUPER); + cluster.addColumnFamily(columnFamilyDefinition); + } + } + + public Iterable<String> getBoards() + { + Keyspace ksp = HFactory.createKeyspace(keyspace, cluster); + RangeSuperSlicesQuery<String,UUID,String,String> query = HFactory.createRangeSuperSlicesQuery(ksp,StringSerializer.get(), + UUIDSerializer.get(),StringSerializer.get(),StringSerializer.get()); + query.setColumnFamily(COLUMN_FAMILY_BOARD).setKeys(null,null).setRange(null,null,false,0); + + QueryResult<OrderedSuperRows<String,UUID,String,String>> result = query.execute(); + OrderedSuperRows<String,UUID,String,String> rows = result.get(); + List<SuperRow<String,UUID,String,String>> list = rows.getList(); + + IterableConverter.Converter<String,SuperRow<String,UUID,String,String>> converter + = new IterableConverter.Converter<String, SuperRow<String,UUID,String,String>>(){ + public String conv(SuperRow<String, UUID, String, String> _b) { + return _b.getKey(); + } + }; + + return new IterableConverter<String,SuperRow<String,UUID,String,String>>(list,converter); + } + + private static final String COLUMN_MESSAGE_AUTHOR = "author"; + private static final String COLUMN_MESSAGE_BODY = "message"; + private static final String COLUMN_MESSAGE_EDIT_KEY = "edit"; + + public void createBoardMessage(UUID _time,String _name,String _author,String _message,String _editKey) + { + Keyspace ksp = HFactory.createKeyspace(keyspace,cluster); + ThriftSuperCfTemplate<String,UUID,String> template = + new ThriftSuperCfTemplate<String,UUID,String>(ksp,COLUMN_FAMILY_BOARD,StringSerializer.get(), + UUIDSerializer.get(),StringSerializer.get()); + + SuperCfUpdater<String,UUID,String> updater = template.createUpdater(_name,_time); + updater.setString(COLUMN_MESSAGE_AUTHOR,_author); + updater.setString(COLUMN_MESSAGE_BODY,_message); + updater.setString(COLUMN_MESSAGE_EDIT_KEY,_editKey); + + template.update(updater); + } + + public void createBoards(String _name,String _author,String _initMessage,String _editKey) + { + UUID time = TimeUUIDUtils.getTimeUUID(0); + createBoardMessage(time,_name,_author,_initMessage,_editKey); + } + + public Iterable<BoardMessage> getMessages(String _boardName) + { + Keyspace ksp = HFactory.createKeyspace(keyspace,cluster); + SuperSliceQuery<String, UUID, String, String> query = HFactory.createSuperSliceQuery(ksp, StringSerializer.get(), UUIDSerializer.get(), StringSerializer.get(), StringSerializer.get()); + + UUID start = TimeUUIDUtils.getTimeUUID(0); + query.setKey(_boardName).setColumnFamily(COLUMN_FAMILY_BOARD).setRange(start,null,false,100); + + QueryResult<SuperSlice<UUID, String, String>> result = query.execute(); + SuperSlice<UUID,String,String> ss = result.get(); + List<HSuperColumn<UUID,String,String>> list = ss.getSuperColumns(); + + IterableConverter.Converter<BoardMessage,HSuperColumn<UUID,String,String>> converter = + new IterableConverter.Converter<BoardMessage,HSuperColumn<UUID,String,String>>(){ + public BoardMessage conv(HSuperColumn<UUID, String, String> _b){ + UUID uuid = _b.getName(); + String author = _b.getSubColumnByName(COLUMN_MESSAGE_AUTHOR).getValue(); + String message = _b.getSubColumnByName(COLUMN_MESSAGE_BODY).getValue(); + BoardMessageImpl bm = new BoardMessageImpl(author,message,uuid.toString()); + return bm; + } + }; + + + return new IterableConverter<BoardMessage,HSuperColumn<UUID,String,String>>(list,converter); + } + + private static class BoardMessageImpl implements BoardMessage + { + private final String author; + private final String message; + private final String uuid; + + public BoardMessageImpl(String _author,String _message,String _uuid) + { + author = _author; + message = _message; + uuid = _uuid; + } + + public String getAuthor() + { + return author; + } + + public String getMessage() + { + return message; + } + + public String getUUID() + { + return uuid; + } + } + + public void createBoardMessage(String _board, String _author, String _message,String _editKey) + { + UUID time = TimeUUIDUtils.getUniqueTimeUUIDinMillis(); + createBoardMessage(time,_board,_author,_message,_editKey); + } + + public void editMessage(String _board,String _uuid,String _author,String _message,String _editKey) + { + Keyspace ksp = HFactory.createKeyspace(keyspace, cluster); + UUID time = UUID.fromString(_uuid); + ThriftSuperCfTemplate<String,UUID,String> template = + new ThriftSuperCfTemplate<String,UUID,String>(ksp,COLUMN_FAMILY_BOARD,StringSerializer.get(), + UUIDSerializer.get(),StringSerializer.get()); + + SuperCfResult<String,UUID,String> result = template.querySuperColumn(_board,time); + String editKey = result.getString(COLUMN_MESSAGE_EDIT_KEY); + if(!editKey.equals(editKey)){ + return; + } + + SuperCfUpdater<String, UUID, String> updater = template.createUpdater(_board,time); + updater.setString(COLUMN_MESSAGE_AUTHOR,_author); + updater.setString(COLUMN_MESSAGE_BODY,_message); + updater.setString(COLUMN_MESSAGE_EDIT_KEY,_editKey); + + template.update(updater); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/CreateBoardMessageServlet.java Thu Feb 07 00:26:21 2013 +0900 @@ -0,0 +1,40 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs; + +import java.io.PrintWriter; + +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class CreateBoardMessageServlet extends HttpServlet +{ + private final BulletinBoard bbs; + private static final String PARAM_BOARD_NAME = "bname"; + private static final String PARAM_BOARD_AUTHOR = "author"; + private static final String PARAM_BOARD_MESSAGE= "msg"; + private static final String PARAM_BOARD_EDITKEY = "key"; + + private static final long serialVersionUID = 1L; + + public CreateBoardMessageServlet(BulletinBoard _bbs) + { + bbs = _bbs; + } + + @Override + public void doPost(HttpServletRequest _req,HttpServletResponse _res) + { + String boardName = _req.getParameter(PARAM_BOARD_NAME); + String author = _req.getParameter(PARAM_BOARD_AUTHOR); + String msg = _req.getParameter(PARAM_BOARD_MESSAGE); + String key = _req.getParameter(PARAM_BOARD_EDITKEY); + + try{ + bbs.createBoardMessage(boardName,author,msg,key); + PrintWriter pw = _res.getWriter(); + pw.write("successfully written"); + }catch(Exception _e){ + _res.setStatus(500); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/CreateBoardServlet.java Thu Feb 07 00:26:21 2013 +0900 @@ -0,0 +1,39 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs; + +import java.io.PrintWriter; + +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class CreateBoardServlet extends HttpServlet +{ + private final BulletinBoard bbs; + private static final String PARAM_BOARD_NAME = "bname"; + private static final String PARAM_BOARD_AUTHOR = "author"; + private static final String PARAM_BOARD_INITMESSAGE= "msg"; + private static final String PARAM_BOARD_EDITKEY = "key"; + + private static final long serialVersionUID = 1L; + + public CreateBoardServlet(BulletinBoard _bbs) + { + bbs = _bbs; + } + + public void doPost(HttpServletRequest _req,HttpServletResponse _res) + { + String boardName = _req.getParameter(PARAM_BOARD_NAME); + String author = _req.getParameter(PARAM_BOARD_AUTHOR); + String msg = _req.getParameter(PARAM_BOARD_INITMESSAGE); + String key = _req.getParameter(PARAM_BOARD_EDITKEY); + + try{ + bbs.createBoards(boardName,author,msg,key); + PrintWriter pw = _res.getWriter(); + pw.write("successfully written"); + }catch(Exception _e){ + _res.setStatus(500); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/EditMessageServlet.java Thu Feb 07 00:26:21 2013 +0900 @@ -0,0 +1,64 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs; + +import java.io.PrintWriter; + +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class EditMessageServlet extends HttpServlet +{ + private final BulletinBoard bbs; + private static final String PARAM_BOARD_NAME = "bname"; + private static final String PARAM_BOARD_MSGID = "uuid"; + private static final String PARAM_BOARD_AUTHOR = "author"; + private static final String PARAM_BOARD_MESSAGE= "msg"; + private static final String PARAM_BOARD_EDITKEY = "key"; + + private static final long serialVersionUID = 1L; + + public EditMessageServlet(BulletinBoard _bbs) + { + bbs = _bbs; + } + + public void doGet(HttpServletRequest _req,HttpServletResponse _res) + { + String bname = _req.getParameter(PARAM_BOARD_NAME); + String uuid = _req.getParameter(PARAM_BOARD_MSGID); + + + try{ + PrintWriter pw = _res.getWriter(); + pw.write("<html><body><h1>edit message</h1>"); + pw.write("<form method='POST'\n"); + pw.write("<p>Author : <input type='text' name='author'/>" + + "<input type='hidden' name='key' value='"+uuid+"'/>" + + "<input type='hidden' name='bname' value='"+bname+"'</p>\n"); + pw.write("<p>Message<br/> <input type='textarea' name='msg'/> </p>\n"); + pw.write("<p><input type='submit' value='submit'/></p>\n"); + pw.write("</body></html>"); + pw.flush(); + }catch(Exception _e){ + _res.setStatus(500); + } + } + + public void doPost(HttpServletRequest _req,HttpServletResponse _res) + { + String boardName = _req.getParameter(PARAM_BOARD_NAME); + String author = _req.getParameter(PARAM_BOARD_AUTHOR); + String msg = _req.getParameter(PARAM_BOARD_MESSAGE); + String key = _req.getParameter(PARAM_BOARD_EDITKEY); + String uuid = _req.getParameter(PARAM_BOARD_MSGID); + + try{ + bbs.editMessage(boardName, uuid, author, msg, key); + PrintWriter pw = _res.getWriter(); + pw.write("successfully written"); + pw.flush(); + }catch(Exception _e){ + _res.setStatus(500); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/HectorSample.java Thu Feb 07 00:26:21 2013 +0900 @@ -0,0 +1,70 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs; + +import java.util.List; +import java.util.UUID; +import me.prettyprint.cassandra.serializers.StringSerializer; +import me.prettyprint.cassandra.serializers.UUIDSerializer; +import me.prettyprint.cassandra.service.template.SuperCfUpdater; +import me.prettyprint.cassandra.service.template.ThriftSuperCfTemplate; +import me.prettyprint.cassandra.utils.TimeUUIDUtils; +import me.prettyprint.hector.api.*; +import me.prettyprint.hector.api.beans.HColumn; +import me.prettyprint.hector.api.beans.HSuperColumn; +import me.prettyprint.hector.api.beans.OrderedSuperRows; +import me.prettyprint.hector.api.beans.SuperRow; +import me.prettyprint.hector.api.beans.SuperSlice; +import me.prettyprint.hector.api.factory.HFactory; +import me.prettyprint.hector.api.query.QueryResult; +import me.prettyprint.hector.api.query.RangeSuperSlicesQuery; +import me.prettyprint.hector.api.query.SuperSliceQuery; + +public class HectorSample +{ + public static void main(String _args[]) + { + Cluster myCluster = HFactory.getOrCreateCluster("test-cluster","localhost:9160"); + + Keyspace ksp = HFactory.createKeyspace("cassaBBS",myCluster); + /* + ColumnFamilyDefinition newCF = HFactory.createColumnFamilyDefinition("DEMO","ccc",ComparatorType.UUIDTYPE); + newCF.setColumnType(ColumnType.SUPER); + myCluster.addColumnFamily(newCF); + */ + + ThriftSuperCfTemplate<String,UUID,String> template = + new ThriftSuperCfTemplate<String,UUID,String>(ksp,"boards",StringSerializer.get(), + UUIDSerializer.get(),StringSerializer.get()); + UUID time = TimeUUIDUtils.getUniqueTimeUUIDinMillis(); + SuperCfUpdater<String,UUID,String> updater = template.createUpdater("board1",TimeUUIDUtils.getTimeUUID(0)); + updater.setString("name","peter"); + updater.setString("message",time.toString()); + + template.update(updater); + + UUID start = TimeUUIDUtils.getTimeUUID(0); + + SuperSliceQuery<String, UUID, String, String> sq = HFactory.createSuperSliceQuery(ksp, StringSerializer.get(), UUIDSerializer.get(), StringSerializer.get(), StringSerializer.get()); + sq.setKey("board1").setColumnFamily("ccc").setRange(start,null,false,100); + + QueryResult<SuperSlice<UUID,String,String>> results = sq.execute(); + + SuperSlice<UUID,String,String> ss = results.get(); + List<HSuperColumn<UUID,String,String>> list = ss.getSuperColumns(); + for(HSuperColumn<UUID,String,String> sc : list){ + HColumn<String,String> sub = sc.getSubColumnByName("name"); + System.out.println(sub.getValue()); + sub = sc.getSubColumnByName("message"); + System.out.println(sub.getValue()); + } + + RangeSuperSlicesQuery<String,UUID,String,String> rsq = HFactory.createRangeSuperSlicesQuery(ksp,StringSerializer.get(), + UUIDSerializer.get(),StringSerializer.get(),StringSerializer.get()); + rsq.setKeys(null,null).setRange(null,null,false,0).setColumnFamily("ccc"); + + QueryResult<OrderedSuperRows<String,UUID,String,String>> rsqResult = rsq.execute(); + OrderedSuperRows<String, UUID, String, String> rows = rsqResult.get(); + for(SuperRow<String, UUID, String, String> row : rows.getList()){ + System.out.println(row.getKey()); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/IterableConverter.java Thu Feb 07 00:26:21 2013 +0900 @@ -0,0 +1,52 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs; + +import java.util.Iterator; + +public class IterableConverter<A,B> implements Iterable<A> +{ + private final Iterable<B> iterable; + private final Converter<A,B> converter; + + public IterableConverter(Iterable<B> _iterable,Converter<A,B> _converter) + { + iterable = _iterable; + converter = _converter; + } + + public Iterator<A> iterator() + { + return new IteratorConverter<A,B>(iterable.iterator(),converter); + } + + private static final class IteratorConverter<A,B> implements Iterator<A> + { + private final Iterator<B> iterator; + private final Converter<A,B> converter; + + public IteratorConverter(Iterator<B> _iterator,Converter<A,B> _converter) + { + iterator = _iterator; + converter = _converter; + } + + public boolean hasNext() + { + return iterator.hasNext(); + } + + public A next() + { + return converter.conv(iterator.next()); + } + + public void remove() + { + iterator.remove(); + } + } + + public static interface Converter<A,B> + { + public A conv(B _b); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/ShowBoardMessageServlet.java Thu Feb 07 00:26:21 2013 +0900 @@ -0,0 +1,60 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs; + +import java.io.PrintWriter; + +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class ShowBoardMessageServlet extends HttpServlet +{ + /** + * + */ + private static final long serialVersionUID = 1L; + private final BulletinBoard bbs; + private final String createBoardMessagePath; + private final String editMessagePath; + + private static final String PARAM_BOARD_NAME = "bname"; + + public ShowBoardMessageServlet(BulletinBoard _bbs,String _createBoardMessagePath, String _editMessagePath) + { + bbs = _bbs; + createBoardMessagePath = _createBoardMessagePath; + editMessagePath = _editMessagePath; + } + + public void doGet(HttpServletRequest _req,HttpServletResponse _res) + { + String bname = _req.getParameter(PARAM_BOARD_NAME); + + try{ + printBoard(bname,_res.getWriter()); + }catch(Exception _e){ + _res.setStatus(500); + } + + } + + private void printBoard(String _bname,PrintWriter _pw) throws Exception + { + _pw.write("<html><body>\n"); + _pw.write("<h1>"+_bname+"</h1>\n"); + + _pw.write("<form action='"+createBoardMessagePath+"' method='POST'\n"); + _pw.write("<p>Author : <input type='text' name='author'/> <input type='hidden' name='bname' value='"+_bname+"'/> EditKey : <input type='text' name='key'/></p>\n"); + _pw.write("<p>Message<br/> <input type='textarea' name='msg'/> </p>\n"); + _pw.write("<p><input type='submit' value='submit'/></p>\n"); + + for(BoardMessage msg : bbs.getMessages(_bname)){ + _pw.write("<hr/>"); + _pw.write("<p><b>"+msg.getAuthor()+"</b></p>"); + _pw.write("<p>"+msg.getMessage()+"</p>"); + _pw.write("<small><a href='"+editMessagePath+"?bname="+_bname+"&uuid="+msg.getUUID()+"'>edit</a></small>"); + } + + _pw.write("</body></html>"); + _pw.flush(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/ShowBoardsServlet.java Thu Feb 07 00:26:21 2013 +0900 @@ -0,0 +1,55 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs; + +import java.io.PrintWriter; + +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class ShowBoardsServlet extends HttpServlet +{ + /** + * + */ + private static final long serialVersionUID = 1L; + private final BulletinBoard bbs; + private final String createBoardPath; + private final String showBoardMessagePath; + + public ShowBoardsServlet(BulletinBoard _bbs, String _createBoardPath,String _showBoardMessagePath) + { + bbs = _bbs; + createBoardPath = _createBoardPath; + showBoardMessagePath = _showBoardMessagePath; + } + + public void doGet(HttpServletRequest _req,HttpServletResponse _res) + { + try{ + printBoard(_res.getWriter()); + }catch(Exception _e){ + _res.setStatus(500); + } + + } + + private void printBoard(PrintWriter _pw) throws Exception + { + _pw.write("<html><body>\n"); + _pw.write("<h1>BBS</h1>\n"); + _pw.write("<form action='"+createBoardPath+"' method='POST'\n"); + _pw.write("<p>Create new board.</p>"); + _pw.write("<p>BoardName : <input type='text' name='bname'/></p>\n"); + _pw.write("<p>Author : <input type='text' name='author'/> EditKey : <input type='text' name='key'/></p>\n"); + _pw.write("<p>Message<br/> <input type='textarea' name='msg'/> </p>\n"); + _pw.write("<p><input type='submit' value='submit'/></p><hr/>\n"); + + _pw.write("<h2>list of boards</h2>"); + for(String board : bbs.getBoards()){ + _pw.write("<p><a href='"+showBoardMessagePath+"?bname="+board+"'>"+board+"</a></p>"); + } + + _pw.write("</body></html>"); + _pw.flush(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/AppTest.java Thu Feb 07 00:26:21 2013 +0900 @@ -0,0 +1,38 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/target/classes/META-INF/MANIFEST.MF Thu Feb 07 00:26:21 2013 +0900 @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +Built-By: shoshi +Build-Jdk: 1.6.0_37 +Created-By: Maven Integration for Eclipse +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/target/classes/META-INF/maven/jp.ac.u_ryukyu.ie.cr.shoshi.jungle/bulletinboard/pom.properties Thu Feb 07 00:26:21 2013 +0900 @@ -0,0 +1,7 @@ +#Generated by Maven Integration for Eclipse +#Thu Feb 07 00:25:48 JST 2013 +version=0.0.1-SNAPSHOT +groupId=jp.ac.u_ryukyu.ie.cr.shoshi.jungle +m2e.projectName=bulletinboard +m2e.projectLocation=/Users/shoshi/Documents/eclipse/jungle/bulletinboard +artifactId=bulletinboard
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/target/classes/META-INF/maven/jp.ac.u_ryukyu.ie.cr.shoshi.jungle/bulletinboard/pom.xml Thu Feb 07 00:26:21 2013 +0900 @@ -0,0 +1,51 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>jp.ac.u_ryukyu.ie.cr.shoshi.jungle</groupId> + <artifactId>bulletinboard</artifactId> + <version>0.0.1-SNAPSHOT</version> + <packaging>jar</packaging> + + <name>bulletinboard</name> + <url>http://maven.apache.org</url> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mortbay.jetty</groupId> + <artifactId>jetty</artifactId> + <version>6.1.26</version> + </dependency> + <dependency> + <groupId>org.hectorclient</groupId> + <artifactId>hector-core</artifactId> + <version>1.1-2</version> + </dependency> + <dependency> + <groupId>org.apache.cassandra</groupId> + <artifactId>cassandra-all</artifactId> + <version>1.2.1</version> + </dependency> + <dependency> + <groupId>com.eaio.uuid</groupId> + <artifactId>uuid</artifactId> + <version>3.3</version> + </dependency> + </dependencies> + <repositories> + <repository> + <id>eaio.com</id> + <url>http://eaio.com/maven2</url> + </repository> + </repositories> +</project>