diff src/main/java/app/bbs/ShowMessageWithTimeStampServlet.java @ 146:29734d7d6521

Added ShowMessageWithTimeStampServlet
author Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
date Tue, 28 Jan 2014 08:47:45 +0900
parents
children 83e99eba6ec1
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/app/bbs/ShowMessageWithTimeStampServlet.java	Tue Jan 28 08:47:45 2014 +0900
@@ -0,0 +1,63 @@
+package app.bbs;
+
+import java.io.PrintWriter;
+
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs.BoardMessage;
+
+public class ShowMessageWithTimeStampServlet extends HttpServlet
+{
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+	private final NetworkBulletinBoard bbs;
+	private final String createBoardMessagePath;
+	private final String editMessagePath;
+	
+	private static final String PARAM_BOARD_NAME = "bname";
+
+	public ShowMessageWithTimeStampServlet(NetworkBulletinBoard _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("<p>Latest renew time : "+bbs.getRenewTime(_bname)+"</p>\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();
+	}
+}