/*********************************************************************************************************
 * 프로그램명 : MReport.java 프로그램설명 : 집계문서에 대해 보고자가 보고한 Reprt 정보 처리 작성자 : 강원중 작성일 : 2003.11.30 변경일 : 2004.09.16
 **********************************************************************************************************/

package kr.co.kihyun.moumi.report;

import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

import kr.co.kihyun.beans.entity.Recog;
import kr.co.kihyun.beans.entity.TotReport;
import kr.co.kihyun.beans.entity.TotReportProcess;
import kr.co.kihyun.moumi.MoumiConfig;
import kr.co.kihyun.text.html.TagFilter;
import net.htmlparser.jericho.Attributes;
import net.htmlparser.jericho.Element;
import net.htmlparser.jericho.HTMLElementName;
import net.htmlparser.jericho.OutputDocument;
import net.htmlparser.jericho.Source;

public class MReport {

	/*
	 * @Deprecated use kr.co.kihyun.beans.entity.TotReport.Process
	 */
	@Deprecated
	private final static String[] prssList = { TotReportProcess.ACCEPT.toString(),
			TotReportProcess.REASSIGN.toString(), TotReportProcess.ASSIGN.toString(),
			TotReportProcess.RETURN.toString(), TotReportProcess.TEMP.toString(), TotReportProcess.APPROVE.toString(),
			TotReportProcess.COMP.toString(), TotReportProcess.END.toString(), TotReportProcess.READ.toString(),
			TotReportProcess.CANCEL.toString(), TotReportProcess.ALL.toString(), TotReportProcess.NOT.toString(),
            TotReportProcess.NOTE.toString()};

	/****** 보고문서 프로세스 *****/

	/*
	 * @Deprecated use kr.co.kihyun.beans.entity.TotReport.Process
	 */
	@Deprecated
	public final static String[] prss = prssList;


	@Deprecated
	public final static int NOTE = TotReportProcess.NOTE.ordinal(); //자료회수 갯수

	/*
	 * @Deprecated use kr.co.kihyun.beans.entity.TotReport.Process
	 */
	@Deprecated
	public final static int ACCEPT = TotReportProcess.ACCEPT.ordinal(); // 보고관리자 접수
	/*
	 * @Deprecated use kr.co.kihyun.beans.entity.TotReport.Process
	 */
	@Deprecated
	public final static int REASSIGN = TotReportProcess.REASSIGN.ordinal(); // 보고자 재배정 요청
	/*
	 * @Deprecated use kr.co.kihyun.beans.entity.TotReport.Process
	 */
	@Deprecated
	public final static int ASSIGN = TotReportProcess.ASSIGN.ordinal(); // 배정
	/*
	 * @Deprecated use kr.co.kihyun.beans.entity.TotReport.Process
	 */
	@Deprecated
	public final static int RETURN = TotReportProcess.RETURN.ordinal(); // 재입력요청
	/*
	 * @Deprecated use kr.co.kihyun.beans.entity.TotReport.Process
	 */
	@Deprecated
	public final static int TEMP = TotReportProcess.TEMP.ordinal(); // 임시저장
	/*
	 * @Deprecated use kr.co.kihyun.beans.entity.TotReport.Process
	 */
	@Deprecated
	public final static int APPROVE = TotReportProcess.APPROVE.ordinal(); // 승인대기
	/*
	 * @Deprecated use kr.co.kihyun.beans.entity.TotReport.Process
	 */
	@Deprecated
	public final static int COMP = TotReportProcess.COMP.ordinal(); // 제출완료
	/*
	 * @Deprecated use kr.co.kihyun.beans.entity.TotReport.Process
	 */
	@Deprecated
	public final static int END = TotReportProcess.END.ordinal(); // 보고종료
	/*
	 * @Deprecated use kr.co.kihyun.beans.entity.TotReport.Process
	 */
	@Deprecated
	public final static int READ = TotReportProcess.READ.ordinal(); // 열람
	/*
	 * @Deprecated use kr.co.kihyun.beans.entity.TotReport.Process
	 */
	@Deprecated
	public final static int CANCLE = TotReportProcess.CANCEL.ordinal(); // 취소
	/*
	 * @Deprecated use kr.co.kihyun.beans.entity.TotReport.Process
	 */
	@Deprecated
	public final static int ALL = TotReportProcess.ALL.ordinal();
	/*
	 * @Deprecated use kr.co.kihyun.beans.entity.TotReport.Process
	 */
	@Deprecated
	public final static int NOT = TotReportProcess.NOT.ordinal(); // 해당없음

	/****** 보고기관 해당 없음 *****/
	/*
	 * @Deprecated use kr.co.kihyun.beans.entity.TotReport.Type
	 */
	@Deprecated
	public final static int REPORT = 0; // 정상
	/*
	 * @Deprecated use kr.co.kihyun.beans.entity.TotReport.Type
	 */
	@Deprecated
	public final static int NOT_REPORT_REQ = 1; // 보고관리자 해당없음 요청
	/*
	 * @Deprecated use kr.co.kihyun.beans.entity.TotReport.Type
	 */
	@Deprecated
	public final static int NOT_REPORT = 2; // 해당없음 수락
	public final static int REPORT_CANCEL = 1; // 제출부서 취소

	/****** 보고자료 출력 타입 *****/
	public final static int REPORT_OUT = 0; // 일반 출력(보고자료 보기)
	public final static int REPORTS_OUT = 1; // 전체현황 보기
	public final static int SIM_REPORTS_OUT = 2; // 집계현황 보기 전체, 또는 기관별
	public final static int TOTAL_OUT = 3; // 집계표 출력

	/****** 집계자 보고자료 목록 타입 *****/
	public final static int ALL_LIST = ALL;// 전체
	public final static int COMP_LIST = COMP;// 제출완료
	public final static int NOT_COMP_LIST = TotReportProcess.NOT_REPORT.ordinal();// 미제출

	public final static int TEMP_LIST = TEMP;// 임시저장
	public final static int ACCEPT_LIST = ACCEPT;// 접수
	public final static int RETURN_LIST = RETURN;// 재보고요청
	public final static int NOT_LIST = NOT;// 해당없음
    public final static int NOTE_LIST = NOTE;// 자료회수

	/****** 보고된 데이터 구분자 *****/
	@Deprecated
	public final static String splitStr1 = TotReport.COL_DELIMITER; // 열
	@Deprecated
	public final static String splitStr2 = TotReport.ROW_DELIMITER; // 행
	@Deprecated
	public final static String splitStr3 = TotReport.TABLE_DELIMITER; // 테이블

	/************************** 보고 승인 비승인 처리관련 변수 및 메소드 **************************/

	/*
	 * @Deprecated use kr.co.kihyun.beans.entity.TotReport.Recog
	 */
	@Deprecated
	public final static String[] recog = { Recog.NOT_RECOG.toString(), Recog.PRSS.toString(), Recog.COMP.toString(),
			Recog.RETURN_RECOG.toString(), Recog.ARBITRARY.toString(), Recog.FINAL_RECOG.toString() };
	/*
	 * @Deprecated use kr.co.kihyun.beans.entity.TotReport.Recog
	 */
	@Deprecated
	public final static int NOT_RECOG = 0; // 비승인
	/*
	 * @Deprecated use kr.co.kihyun.beans.entity.TotReport.Recog
	 */
	@Deprecated
	public final static int RECOG_PRSS = 1; // 승인진행
	/*
	 * @Deprecated use kr.co.kihyun.beans.entity.TotReport.Recog
	 */
	@Deprecated
	public final static int RECOG = 2; // 승인완료
	/*
	 * @Deprecated use kr.co.kihyun.beans.entity.TotReport.Recog
	 */
	@Deprecated
	public final static int RETURN_RECOG = 3; // 반려

	/****** 보고자료 작성시 html, hwp, excel type *****/
	public final static int HTML = 0;
	public final static int EXCEL = 1;
	public final static int HWP = 2;

	public static String getPrssName(int prss) {
		if (prss >= prssList.length && prss < 0) {
			return "";
		}
                
                //v2 27.Public 메소드로부터 반환된 Private배열_CWE-495 : Update by  YOUNGJUN,CHO
		//return prssList[prss];
                String ret[] = new String[prssList.length];
                
                for (int i = 0 ; i > prssList.length ; i++) {
                    ret[i] = prssList[i];
                }
                
                return ret[prss];
                //====================================================================
	}

	// 집계문서의 하나의 표 삭제, 선택된 표만 삭제
	public static String getDeleteTable(String form, int tableNum) {// 테이블을 삭제 하기 위한 로직.
		// ban lower case form = form.toLowerCase();
		StringBuffer formBuf = new StringBuffer(form);

		String strTag = "<table";
		String endTag = "</table>";

		int strIndex = 0;
		int endIndex = 0;

		for (int i = 1; i <= tableNum; i++) {
			if (i == 1) {
				strIndex = formBuf.indexOf(strTag);
			} else {
				strIndex = formBuf.indexOf(strTag, endIndex);
			}

			endIndex = formBuf.indexOf(endTag, strIndex);
			if (i == tableNum)
				break;

		}

		formBuf = formBuf.delete(strIndex, endIndex + endTag.length());

		return formBuf.toString();
	}

	// 하나의 표의 행삭제, 2면 0행~2행까지 삭제됨
	protected static String rowDelete(String report, int tableCount, int rowDelType, int[] lineNum, boolean isRowDelete) {
		if (rowDelType == 1) {
			int delLine2 = 0;
			for (int jj = 1, k = 0; jj <= tableCount; jj++) {
				if (lineNum[jj - 1] == -1) {
					if (jj == tableCount) {
						report = MReport.getDeleteTableEnd(report, (jj - delLine2));
						report = MReport.getDeleteTableEndBr(report);
					} else {
						report = MReport.getDeleteTable(report, (jj - delLine2));
					}
					delLine2 = delLine2 + 1;
				} else {
					if (isRowDelete) {
						for (k = 0; k < lineNum[jj - 1]; k++) {
							report = MReport.getDeleteTitle(report, jj - delLine2);
						}
					}
					isRowDelete = true;
				}
			}
		}

		return report;
	}

	// 삭제할 행의 테이블 시삭 주소(행삭제에 사용)
	public static String getDeleteTableEnd(String form, int tableNum) {
		// ban lower case form = form.toLowerCase();
		StringBuffer tmp;
		int stTABLE = 0;
		int edTABLE = 0;
		stTABLE = form.indexOf("<table");
		for (int i = 1; i <= tableNum; i++) {
			edTABLE = form.indexOf("</table", stTABLE);//
			if (i == tableNum)
				break;
			stTABLE = form.indexOf("<table", stTABLE + 7);//
		}
		tmp = new StringBuffer(form);
		tmp = tmp.delete(stTABLE, edTABLE + 8);
		return tmp.toString();
	}

	public static String getTableTag(String form) {
		form = form.toLowerCase();
		int stTABLE = 0;
		int edTABLE = 0;
		String tableTag = "";
		stTABLE = form.indexOf("<table");
		edTABLE = form.indexOf("<tr", stTABLE);

		tableTag = form.substring(stTABLE, edTABLE);

		return tableTag;
	}

	public static String getRemoveTableTag(String form) {
		form = form.toLowerCase();
		int stTR = 0;
		String tableTag = "";
		stTR = form.indexOf("<tr");
		tableTag = form.substring(stTR, form.length());

		return tableTag;
	}

	public static String getTitleTag(String form) {
		form = form.toLowerCase();
		int stTABLE = 0;
		int edTABLE = 0;
		String tableTag = "";
		stTABLE = form.indexOf("<table");
		edTABLE = form.indexOf("</tr>", stTABLE);

		tableTag = form.substring(stTABLE, edTABLE);
		tableTag = tableTag + "</tr></table>";

		return tableTag;

	}

	public static String getTitleTag(String form, int tmp1) {
		String Form = form.toLowerCase();
		int here = 0;

		for (int i = 1; i < tmp1; i++) {
			here = Form.indexOf("<table", here);
			here = Form.indexOf("<table", here) + 6;
		}

		Form = Form.substring(here, Form.length());

		Form = MReport.getTitleTag(Form);

		return Form;
	}

	// 삭제할 행의 테이블 끝 주소(행삭제에 사용)
	public static String getDeleteTableEndBr(String form) {
		// ban lower case form = form.toLowerCase();
		StringBuffer result;
		int edTABLE = 0;
		int br = 0;
		edTABLE = form.lastIndexOf("</table");
		br = form.indexOf("<br>", edTABLE);

		result = new StringBuffer(form);
		if (br > 0) {
			result = result.delete(br, br + 4);
		}

		return result.toString();
	}

	public static String[] geteExtractTable(String form) {
		Attributes.setDefaultMaxErrorCount(Integer.MAX_VALUE);
		Source source = new Source(form);
		// OutputDocument outputDocument=new OutputDocument(source);
		List<Element> tableElements = source.getAllElements(HTMLElementName.TABLE);
		String[] tableArray = new String[tableElements.size()];
		List<String> tableList = new ArrayList<String>();

		int i = 0;
		for (Element tableElement : tableElements) {
			tableArray[i++] = tableElement.toString();
			tableList.add(tableElement.toString());
		}
		return tableArray;
	}

	public static String geteExtractTable(String form, int formIndex) {
		// ban lower case form = form.toLowerCase();
		StringBuilder tmp = new StringBuilder();

		tmp.append(form.substring(formIndex, form.indexOf("</table>", formIndex) + 8));
		// tmp.append("<br>");
		return tmp.toString();
	}

	public static String removeLastTableBackTag(String form) {
		String tmp = "";

		tmp = form.substring(0, form.lastIndexOf("</table>") + 8);
		return tmp;
	}

	public static boolean geteExtractTable(String form, String sessionForm) {
		Attributes.setDefaultMaxErrorCount(Integer.MAX_VALUE);
		form = form.toLowerCase();
		sessionForm = sessionForm.toLowerCase();
		Source source = new Source(form);
		// OutputDocument outputDocument=new OutputDocument(source);
		List<Element> tableElements = source.getAllElements(HTMLElementName.TABLE);
		String[] tableArray = new String[tableElements.size()];
		boolean check = true;
		// List<String> tableList = new ArrayList<String>();

		int i = 0;
		for (Element tableElement : tableElements) {
			tableArray[i++] = tableElement.toString();
			// tableList.add(tableElement.toString());
		}

		source = new Source(sessionForm);
		tableElements = source.getAllElements(HTMLElementName.TABLE);
		String[] copyTableArray = new String[tableElements.size()];

		i = 0;
		for (Element tableElement : tableElements) {
			copyTableArray[i++] = tableElement.toString();
			// tableList.add(tableElement.toString());
		}

		if (tableArray.length != copyTableArray.length) {
			check = false;
		} else {
			for (int z = 0; z < tableArray.length; z++) {
				if (!copyTableArray[z].equals(tableArray[z])) {
					check = false;
					break;
				} else {
					check = true;
				}
			}
		}

		return check;
	}

	public static String getRemoveErrTable(String form) {
		Attributes.setDefaultMaxErrorCount(Integer.MAX_VALUE);
		Source source = new Source(form);
		OutputDocument outputDocument = new OutputDocument(source);
		List<Element> tdElements = source.getAllElements(HTMLElementName.TD);
		for (Element tdElement : tdElements) {
			String tableErrVal = tdElement.getAttributeValue("x:err");

			if (tableErrVal != null) {
				form = outputDocument.toString().replaceAll(tdElement.getAttributeValue("x:err"), "");
			}
		}
		return form.replaceAll("x:err=\"\"", "");
	}

	public static int getArrayCount(String form) {
		Attributes.setDefaultMaxErrorCount(Integer.MAX_VALUE);
		Source source = new Source(form);
		List<Element> tdElements = source.getAllElements(HTMLElementName.TD);

		return tdElements.size();
	}

	public static String getHwpToP(String form) {

		String result = form;
		StringBuffer insertedForm = new StringBuffer();

		int stTDIndex = 0;
		int edTD = 0;
		int pStart = 0, pEnd = 0;

		while (true) {
			stTDIndex = result.indexOf("<td");
			if (stTDIndex == -1)
				break;
			edTD = result.indexOf(">", stTDIndex + 1);
			if (edTD == -1)
				break;
			pStart = result.indexOf("<p", edTD);
			if (pStart == -1)
				break;
			pEnd = result.indexOf(">", pStart + 2);
			if (pEnd == -1)
				break;
			insertedForm.append(result.substring(0, pStart));
			result = result.substring(pEnd + 1, result.length());
		}
		insertedForm.append(result);
		return insertedForm.toString();
	}

	// <table에 itempadding, itemspacing이 없으면 추가 하는 로직
	public static String getTableHtmlItem(String form) {
		StringBuffer sInserted = new StringBuffer();
		String endResult = "";
		int stTABLE = 0;
		int itempadding = form.indexOf("itempadding");
		int itemspacing = form.indexOf("itemspacing");
		if (itempadding == -1) {
			while (true) {
				stTABLE = form.indexOf("<table");
				if (stTABLE == -1)
					break;
				sInserted.append(form.substring(0, stTABLE + 6));
				sInserted.append(" itempadding=0 ");
				form = form.substring(stTABLE + 6, form.length());
			}
			sInserted.append(form);
			endResult = sInserted.toString();
		} else {
			endResult = form.replaceAll("itempadding=1", "itempadding=0").replaceAll("itempadding=\"1\"",
					"itempadding=\"0\"");
		}

		form = endResult;
		StringBuffer insertedForm = new StringBuffer();
		if (itemspacing == -1) {
			while (true) {
				stTABLE = form.indexOf("<table");
				if (stTABLE == -1)
					break;
				insertedForm.append(form.substring(0, stTABLE + 6));
				insertedForm.append(" itemspacing=0 ");
				form = form.substring(stTABLE + 6, form.length());
			}
			insertedForm.append(form);
			endResult = insertedForm.toString();
		} else {
			endResult = form.replaceAll("itemspacing=1", "itemspacing=0").replaceAll("itemspacing=\"1\"",
					"itemspacing=\"0\"");
		}
		return endResult;
	}

	// 테이블 수 구하는 로직
	public static int getTableCount(String form) {
		int tableSu = 0;
		int fiTable = 0;
		while (true) {
			fiTable = form.indexOf("<table", fiTable);
			if (fiTable == -1)
				break;
			tableSu = tableSu + 1;
			fiTable = fiTable + 7;
		}

		return tableSu;
	}

	public static String getDeleteTitleAll(String form, int tableLine) {// 사용자가 선택한 라인 부분을 위에서부터 삭제하여 보여주기 위한 함수
		StringBuffer tmp;

		int fiTABLEIndex = 0;
		int scTABLEIndex = 0;

		for (int i = 1; i < tableLine; i++) {
			fiTABLEIndex = form.indexOf("</table", fiTABLEIndex);//
			fiTABLEIndex = fiTABLEIndex + 7;
			scTABLEIndex = form.indexOf("<table", fiTABLEIndex);//
			scTABLEIndex = scTABLEIndex + 6;
		}

		int stTRIndex = form.indexOf("<tr", scTABLEIndex);
		int edTRIndex = form.indexOf("</tr>", stTRIndex);
		int stTDIndex = form.indexOf("<td", stTRIndex);

		if (stTRIndex == -1) {
			stTRIndex = stTDIndex;
		} else if (edTRIndex == -1) {
			if (stTRIndex > stTDIndex) {
				edTRIndex = stTRIndex + 1;
				stTRIndex = stTDIndex;
			} else {
				edTRIndex = form.indexOf("<tr", stTRIndex + 2);
			}
		} else if (stTRIndex != -1 && edTRIndex != -1 && stTRIndex > edTRIndex + 5) {
			stTRIndex = stTDIndex;
		}

		tmp = new StringBuffer(form);
		if (stTRIndex < edTRIndex) {
			tmp = tmp.delete(stTRIndex, edTRIndex + 5);
		}
		return tmp.toString();
	}

	public static String getDeleteTitle(String form, int tableLine) {// 사용자가 선택한 라인 부분을 위에서부터 삭제하여 보여주기 위한 함수
		StringBuffer tmp;

		int fiTABLEIndex = 0;
		int scTABLEIndex = 0;

		for (int i = 1; i < tableLine; i++) {
			fiTABLEIndex = form.indexOf("</table", fiTABLEIndex);//
			fiTABLEIndex = fiTABLEIndex + 7;
			scTABLEIndex = form.indexOf("<table", fiTABLEIndex);//
			scTABLEIndex = scTABLEIndex + 6;
		}

		int stTRIndex = form.indexOf("<tr", scTABLEIndex);
		int edTRIndex = form.indexOf("</tr>", stTRIndex);
		int stTDIndex = form.indexOf("<td", stTRIndex);

		if (stTRIndex == -1) {
			stTRIndex = stTDIndex;
		} else if (edTRIndex == -1) {
			if (stTRIndex > stTDIndex) {
				edTRIndex = stTRIndex + 1;
				stTRIndex = stTDIndex;
			} else {
				edTRIndex = form.indexOf("<tr", stTRIndex + 2);
			}
		} else if (stTRIndex != -1 && edTRIndex != -1 && stTRIndex > edTRIndex + 5) {
			stTRIndex = stTDIndex;
		}

		tmp = new StringBuffer(form);
		if (stTRIndex < edTRIndex) {
			tmp = tmp.delete(stTRIndex, edTRIndex + 5);
		}
		return tmp.toString();
	}

	public static String getDeleteTitle2(String form, int tableLine, int lineNum) {// 사용자가 선택한 라인 부분을 위에서부터 삭제하여 보여주기 위한
																					// 함수

		int fiTABLEIndex = 0;
		int scTABLEIndex = 0;

		for (int i = 1; i < tableLine; i++) {
			fiTABLEIndex = form.indexOf("</table", fiTABLEIndex);//
			fiTABLEIndex = fiTABLEIndex + 7;
			scTABLEIndex = form.indexOf("<table", fiTABLEIndex);//
			scTABLEIndex = scTABLEIndex + 6;
		}

		int stTRIndex = 0;
		int edTRIndex = 0;
		StringBuffer tmp = new StringBuffer(form);
		/*
		 * 1) 먼서 <tr>.... </tr>까지 행을 가저온다. 2) 기존의 style를 날린다 3) 새로운 스타일을 넣는다 4) tmp의 행을 삭제한다. 5) 그곳에 변경된 행을 넣는다.
		 */
		stTRIndex = tmp.indexOf("<tr", scTABLEIndex);
		edTRIndex = tmp.indexOf(">", stTRIndex);

		for (int i = 0; i <= lineNum; i++) {
			if (stTRIndex < edTRIndex && i == lineNum) {

				String inStr = " style='display:none;' ";
				String rowStr = tmp.substring(stTRIndex, edTRIndex);
				rowStr = TagFilter.removeStyle(rowStr);

				tmp = tmp.delete(stTRIndex, edTRIndex);
				tmp.insert(stTRIndex, inStr);
				tmp.insert(stTRIndex, rowStr);
			}
			stTRIndex = tmp.indexOf("<tr", edTRIndex);
			edTRIndex = tmp.indexOf(">", stTRIndex);
		}
		return tmp.toString();
	}

	public static String getDeleteTitle2All(String form, int tableLine, int lineNum) {// 사용자가 선택한 라인 부분을 위에서부터 삭제하여 보여주기
																						// 위한 함수

		int fiTABLEIndex = 0;
		int scTABLEIndex = 0;

		for (int i = 1; i < tableLine; i++) {
			fiTABLEIndex = form.indexOf("</table", fiTABLEIndex);//
			fiTABLEIndex = fiTABLEIndex + 7;
			scTABLEIndex = form.indexOf("<table", fiTABLEIndex);//
			scTABLEIndex = scTABLEIndex + 6;
		}

		int stTRIndex = 0;
		int edTRIndex = 0;
		StringBuffer tmp = new StringBuffer(form);
		/*
		 * 1) 먼서 <tr>.... </tr>까지 행을 가저온다. 2) 기존의 style를 날린다 3) 새로운 스타일을 넣는다 4) tmp의 행을 삭제한다. 5) 그곳에 변경된 행을 넣는다.
		 */
		stTRIndex = tmp.indexOf("<tr", scTABLEIndex);
		edTRIndex = tmp.indexOf(">", stTRIndex);

		for (int i = 0; i <= lineNum; i++) {
			if (stTRIndex < edTRIndex && i == lineNum) {

				String inStr = " style='display:none;' ";
				String rowStr = tmp.substring(stTRIndex, edTRIndex);
				rowStr = TagFilter.removeStyle(rowStr);

				tmp = tmp.delete(stTRIndex, edTRIndex);
				tmp.insert(stTRIndex, inStr);
				tmp.insert(stTRIndex, rowStr);
			}
			stTRIndex = tmp.indexOf("<tr", edTRIndex);
			edTRIndex = tmp.indexOf(">", stTRIndex);
		}
		return tmp.toString();
	}

	public String dataInputStream(String input) {

		StringBuffer str = new StringBuffer();
		StringTokenizer st = new StringTokenizer(input);
		while (st.hasMoreTokens()) {
			str.append(st.nextToken(">").trim());
			str.append(">");
		}

		return str.toString();
	}

	public static String getCharMake(String startChar, char startCh) {
		if (startChar == null)
			return null;
		startChar = startChar.toUpperCase();
		int su = 0;
		char preCh = 0;
		char after = 0;
		int na = 0;

		String result = "";

		if (startChar.length() == 1) {
			char st_Ch = startCh;
			su = (st_Ch / 91);
			if (su == 0) {
				result = st_Ch + "";
			} else {
				preCh = (char) ('A' + su - 1);
				na = (st_Ch % 91);
				// after = (char)('A'+na);
				after = (char) na;
				result = preCh + "" + after;
			}
		} else {
			char st_Ch = startChar.charAt(0);
			char end_Ch = startCh;

			su = (end_Ch / 91);

			if (su == 0) {

				result = st_Ch + "" + end_Ch;
			} else {
				preCh = (char) (st_Ch + su);
				na = (end_Ch % 91);
				// after = (char)('A'+na);
				after = (char) na;
				result = preCh + "" + after;
			}
		}

		return result;
	}

	public static boolean isNum(String s) {
		try {
			Float.parseFloat(s);
			return true;
		} catch (Exception e) {
			return false;
		}
	}

	public static int findName(String tk, String[] itemNameList) {
		for (int i = 0; i < itemNameList.length; i++) {
			if (tk.equals(itemNameList[i]))
				return i;
		}
		return -1;
	}

	public static String getCharacterMake(String startCharacter, char startCh) {
		if (startCharacter == null)
			return null;
		startCharacter = startCharacter.toUpperCase();
		int su = 0;
		char preCh = 0;
		char after = 0;
		int na = 0;

		String result = "";

		if (startCharacter.length() == 1) {
			char st_Ch = startCh;
			su = (st_Ch / 91);
			if (su == 0) {
				result = st_Ch + "";
			} else {
				preCh = (char) ('A' + su - 1);
				na = (st_Ch % 91);
				// after = (char)('A'+na);
				after = (char) na;
				result = preCh + "" + after;
			}
		} else {
			char st_Ch = startCharacter.charAt(0);
			char end_Ch = startCh;

			su = (end_Ch / 91);

			if (su == 0) {

				result = st_Ch + "" + end_Ch;
			} else {
				preCh = (char) (st_Ch + su);
				na = (end_Ch % 91);
				// after = (char)('A'+na);
				after = (char) na;
				result = preCh + "" + after;
			}
		}
		return result;
	}

	public static String getChangeAllScript(String nLineScript, int endNumber, int recordCount) {

		if (nLineScript.trim().equals(""))
			return "";
		StringBuffer sb = new StringBuffer();
		String script = "";

		int stDform = 0;
		int dot = 0;
		String preScript = "";
		recordCount = 8;
		int count = recordCount - endNumber;

		for (int i = 0; i < count; i++) {
			script = nLineScript;
			while (true) {
				stDform = script.indexOf("dform.");
				if (stDform == -1)
					break;
				dot = script.indexOf(".", stDform + 6);
				if (dot == -1)
					break;
				preScript = script.substring(stDform + 6, dot).replaceAll("[0-9]", "");// [A-Z][a-z]
				sb.append(script.substring(0, stDform + 6));
				sb.append(preScript);
				sb.append(endNumber);
				script = script.substring(dot, script.length());
			}
			sb.append(script);
			endNumber++;
		}

		return sb.toString();
	}

	public static String getDivScriptMake(String script) {
		int na = 0;
		int naForms = 0;
		int naForme = 0;
		int isNaN = 0;
		int resultNames = 0;
		int resultNamee = 0;

		String naName = "";
		String resultName = "";
		StringBuffer scriptMake = new StringBuffer();

		while (true) {
			na = script.indexOf("/");
			if (na == -1)
				break;
			naForms = script.indexOf("dform.", na);
			if (naForms == -1)
				break;
			naForme = script.indexOf(".value", naForms);
			if (naForme == -1)
				break;

			isNaN = script.indexOf("isNaN", naForme);
			if (isNaN == -1)
				break;

			resultNames = script.indexOf("dform.", isNaN);
			if (resultNames == -1)
				break;
			resultNamee = script.indexOf(".value", resultNames);
			if (resultNamee == -1)
				break;

			naName = script.substring(naForms + 6, naForme);
			resultName = script.substring(resultNames + 6, resultNamee);

			script = script.substring(resultNamee, script.length());

			scriptMake.append("if(dform.");
			scriptMake.append(naName);
			scriptMake.append(".value == 0){\n");
			scriptMake.append("	dform.");
			scriptMake.append(resultName);
			scriptMake.append(".value = 0;\n");
			scriptMake.append("}\n");

		}

		return scriptMake.toString();
	}

	// 교육부 내부 업무 사용용
	public final static String[] repoStateList = { MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.normality"), MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.unsatisfactory"), MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.regular"), MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.complete") };

	public static String getRepoState(int index) {
		if (index < 0 || index >= repoStateList.length)
			return null;
		return repoStateList[index];
	}

	public static int getRepoIndex(String repoState) {
		for (int i = 0; i < repoStateList.length; i++) {
			if (repoStateList[i].equals(repoState))
				return i;
		}
		return -1;
	}
}
