/***********************************************************************************
 * @@ Program Name : HttpReFormReader.java Description : 집계문서 폼 정의시 파일 폼 정의, 재사용 폼정의, 복사 폼정의 등으로 분리 해줌 Author : 강원중
 *    Create Date : 2004.10.13 History :
 * @@
 ***********************************************************************************/

package kr.co.kihyun.beans.totsys.doc;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import kr.co.kihyun.io.MultipartRequest;
import kr.co.kihyun.moumi.MoumiConfig;
import kr.co.kihyun.text.html.CallbackHandler;
@WebServlet("/servlet/kr.co.kihyun.beans.totsys.doc.HttpReFormReader2")
public class HttpReFormReader2 extends HttpServlet {

	private static final long serialVersionUID = 1L;

	String savePath = MoumiConfig.getTotPerTmp().getPath(); // 업로드된 파일의 임시 저장 경로
	MultipartRequest multi;

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out = response.getWriter();
		HttpSession session = request.getSession(true);

		try {
			multi = new MultipartRequest(request, savePath);

			String docID = multi.getParameter("docID");
			String docForm;
			String isAdmin = multi.getParameter("isAdmin");

			// 등록 단계에서 처음단계로 갔을때 data 보관용으로 사용
			String action = "/totsys/totper/mydocbox/prssbox/doc_form_config2.jsp";
			if (isAdmin != null) {
				if (isAdmin.equals("admin")) {
					action = "/totsys/sysadm/prssbox/doc_form_config2.jsp";
				} else if (isAdmin.equals("form")) {
					action = "/totsys/totper/mydocbox/formbox/doc_reform_config2.jsp";
				}
			}

			// form 복사
			docForm = multi.getParameter("docFCM");
			docForm = docForm.replaceAll(MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.inputWindow"),
					"<table width=700 border=0><tr><td width='100%'></td></tr></table>");
			docForm = CallbackHandler.getCutPreTag(docForm);
			session.setAttribute("docForm", docForm);
			StringBuffer strbuf = new StringBuffer();
			strbuf.append("<html>");
			strbuf.append("<body topmargin=0 leftmargin=0 onload=\"document.copyform.submit();\">\n");
			strbuf.append("<form name='copyform' method='POST' action='");
			strbuf.append(action);
			strbuf.append("'>\n");
			strbuf.append("<input type=hidden name =\"changeStructure\" value='"+multi.getParameter("changeStructure")+"'/>");
			strbuf.append("		<input type=hidden name =\"docID\" value=\"");
			strbuf.append(docID);
			strbuf.append("\">\n");
			strbuf.append("</body>\n");
			strbuf.append("</html>");
			out.println(strbuf.toString());
			return;
                //44.적절하지 않은 예외처리(광범위예외클래스)_CWE-754 Add by YOUNGJUN,CHO
        } catch (IOException ioex) {
                ioex.printStackTrace();
        //++++++++++++++++++++++++++++++++++++++++++++++++
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
}
