view src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/ShowMatrix.java @ 44:5e8eac03fed3

miner change
author one
date Tue, 25 Nov 2014 17:51:35 +0900
parents 037731e99d6e
children
line wrap: on
line source

package jp.ac.u_ryukyu.cr.ie.tatsuki.bbs;

import java.io.PrintWriter;
import java.util.Iterator;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.eclipse.jetty.util.thread.ThreadPool;

import fj.data.List;
import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs.BoardMessage;

public class ShowMatrix extends HttpServlet {
	/**
	 * edit Node Path is rename editNodePath
	 **/
	private static final long serialVersionUID = 1L;
	private final XmlBulletinBoard bbs;
	private final String createBoardMessagePath;
	private final String showMatrixPath;
	private final String createAttributePath;
	private static final String PARAM_BOARD_NAME = "bname";
	private static final String PARAM_NODE_PATH = "uuid";
	private static final String PARAM_NODE_NAME = "nodeName";

	public ShowMatrix(XmlBulletinBoard _bbs,
			String _createBoardMessagePath, String _editNodePath,
			String _showMatrixPath, String _createAttributePath,
			String _editAttributePath, String _deleteAttributePath,
			String _deleteNodePath, ThreadPool thp) {
		bbs = _bbs;
		createAttributePath = _createAttributePath;
		showMatrixPath = _showMatrixPath;
		createBoardMessagePath = _createBoardMessagePath;
	}

	public void doGet(HttpServletRequest _req, HttpServletResponse _res) {

		final String bname = _req.getParameter(PARAM_BOARD_NAME);
		String path = _req.getParameter(PARAM_NODE_PATH);
		String nodeName = _req.getParameter(PARAM_NODE_NAME);
		try {
			_res.setCharacterEncoding("UTF-8");
			printBoard(bname, path, nodeName, _res.getWriter());
		} catch (Exception _e) {
			_res.setStatus(500);
		}
	}

	private void printBoard(String _bname, String path, String nodeName,
			PrintWriter _pw) throws Exception {
		_pw.write("<html><body>\n");

		if (nodeName == null)
			nodeName = "rootNode";
		if (path == null)
			path = "0";
		
		_pw.write("<h1>" + bbs.sanitize(nodeName) + " Path = " + path + "</h1>\n");

		_pw.write("<form action='" + createBoardMessagePath+ "' method='POST'>\n");
		_pw.write("<p><input type='hidden' name='bname' value='" + bbs.sanitize(_bname)+ "'/> </p>\n");
		_pw.write("<p>Folder Name<br/> <input type='textarea' name='name'/> </p>\n");
		_pw.write("<input type='hidden' name='path' value='" + path + "'/>");
		_pw.write("<p><input type='submit' value='submit'/></p>\n");
		_pw.write("</form>");

		_pw.write("<p><br>add Attribute</p>");
		_pw.write("<form action='" + createAttributePath + "' method='POST'\n");
		_pw.write("<p><input type='hidden' name='bname' value='" + bbs.sanitize(_bname)
				+ "'</p>\n");
		_pw.write("<p>attributeName<br/> <input type='textarea' name='msg'/> </p>\n");
		_pw.write("<input type='hidden' name='path' value='" + path + "'/>");
		_pw.write("<p><input type='submit' value='submit'/></p>\n");
		_pw.write("</form>");
		_pw.write("<hr/>");
		_pw.write("<p>Folder</p>");

		for (BoardMessage msg : bbs.getFolder(_bname, path)) {
			_pw.write("<small><a href=" + showMatrixPath + "?bname=" + bbs.sanitize(_bname)
					+ "&uuid=" + path + "/" + msg.getUUID() + "&nodeName="
					+ bbs.sanitize(msg.getMessage()) + ">" + bbs.sanitize(msg.getMessage())
					+ "</a><br><br></small>");
		}

		_pw.write("<br><hr/><p>Value</p>");
		GetAttributeImp attribute = (bbs.getAttribute(_bname, path));
		List<String> keys = attribute.getKeys();
		
		for (String key : keys) {
		  String mesage = attribute.getMessage(key);
			_pw.write(key + " : " + bbs.sanitize(mesage) + "<br>");		
		}
		
		_pw.write("</body></html>");
		_pw.flush();
	}
}