package kr.co.kihyun.text.hml;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import kr.co.kihyun.moumi.MoumiConfig;
//import kr.co.kihyun.text.hml.HtmlUtil;
//import kr.co.kihyun.text.hml.VirtualHtml;
import kr.co.kihyun.text.html.TagFilter;

// TODO : refactoring
public class CyberHtm {
	// public static final String tmpSavePath = Moumi.getTotRoot() + "/hml";
      //v2. 5.static final 필드 변조 가능성 : Update by KWON,HAN        
//	public static final String tmpSavePath = MoumiConfig.getTotRoot().getPath() + System.getProperty("file.separator")
//			+ "hml";
        
	private static final String tmpSavePath = MoumiConfig.getTotRoot().getPath() + System.getProperty("file.separator") + "hml";        
      //==========================================================                  
        
	public CyberHtm() {
	}

	public static String getCyberHtm(String s) throws IOException, UnsupportedEncodingException {
		VirtualHtml VH = null;
		StringBuffer sb = null;
		StringBuilder htm = null;

		int offset = 0;

		int opener_idx = 0;
		int closer_idx = 0;

		VH = new VirtualHtml();
		/*
		 * VH.IOhandler(tmpSavePath + "/virtual.html", tmpSavePath + "/tresh/VirtualHtml.src");
		 */

		VH.IOhandler(tmpSavePath + System.getProperty("file.separator") + "virtual.html",
				tmpSavePath + System.getProperty("file.separator") + "tresh" + System.getProperty("file.separator")
						+ "VirtualHtml.src");
		htm = new StringBuilder();
		htm.append(s);

		opener_idx = htm.indexOf("<Table");
		closer_idx = htm.lastIndexOf("</td></tr></table>");

		sb = new StringBuffer();
		if (opener_idx != -1) {
			String H = VH.getHead();
			sb.append(H);

			htm = TagFilter.replace(htm, "<html>", "");
			htm = TagFilter.replace(htm, "</html>", "");
			htm = TagFilter.replace(htm, "<head>", "");
			htm = TagFilter.replace(htm, "</head>", "");

			int tag_title_idx = 0;
			int tag_title_lidx = 0;
			while (true) {
				tag_title_idx = htm.indexOf("<title>", tag_title_idx);
				if (tag_title_idx != -1) {
					tag_title_lidx = htm.indexOf("</title>", tag_title_idx);
					htm = htm.replace(tag_title_idx, tag_title_lidx + 8, "");
					tag_title_idx++;
				} else
					break;
			}

			int tag_meta_idx = 0;
			while (true) {
				tag_meta_idx = htm.indexOf("<meta");
				if (tag_meta_idx != -1) {
					int serch_idx1 = htm.indexOf(">", tag_meta_idx);
					htm = htm.replace(tag_meta_idx, serch_idx1 + 1, "");
				} else
					break;
			}

			int tag_body_idx = 0;
			while (true) {
				tag_body_idx = htm.indexOf("<body");
				if (tag_body_idx != -1) {
					int serch_idx2 = htm.indexOf(">", tag_body_idx);
					htm = htm.replace(tag_body_idx, serch_idx2 + 1, "");
				} else
					break;
			}

			htm = TagFilter.replace(htm, "</body>", "");
			htm = TagFilter.replace(htm, "<hr>", "");
			htm = TagFilter.replace(htm, "<br>", "");

			int tag_p_idx = 0;
			while (true) {
				tag_p_idx = htm.indexOf("<p");
				if (tag_p_idx != -1) {
					int serch_idx3 = htm.indexOf(">", tag_p_idx);
					htm = htm.replace(tag_p_idx, serch_idx3 + 1, "");
				} else
					break;
			}

			htm = TagFilter.replace(htm, "</p>", "");
			htm = TagFilter.replace(htm, "<center>", "");
			htm = TagFilter.replace(htm, "</center>", "");

			int tag_div_idx = 0;
			while (true) {
				tag_div_idx = htm.indexOf("<div");
				if (tag_div_idx != -1) {
					int serch_idx4 = htm.indexOf(">", tag_div_idx);
					htm = htm.replace(tag_div_idx, serch_idx4 + 1, "");
				} else
					break;
			}

			htm = TagFilter.replace(htm, "</div>", "");
			htm = TagFilter.replace(htm, "<pre>", "");
			htm = TagFilter.replace(htm, "</pre>", "");

			int tag_marquee_idx = 0;
			while (true) {
				tag_marquee_idx = htm.indexOf("<marquee");
				if (tag_marquee_idx != -1) {
					int serch_idx5 = htm.indexOf(">", tag_marquee_idx);
					htm = htm.replace(tag_marquee_idx, serch_idx5 + 1, "");
				} else
					break;
			}

			int tag_marquee_lidx = 0;

			while (true) {
				tag_marquee_lidx = htm.indexOf("</marquee>");
				if (tag_marquee_lidx != -1) {
					htm = htm.replace(tag_marquee_lidx, tag_marquee_lidx + 10, "");
				} else
					break;
			}

			int tag_hnumber_idx = 0;

			while (true) {
				tag_hnumber_idx = htm.indexOf("<hnumber>");
				if (tag_hnumber_idx != -1) {
					htm = htm.replace(tag_hnumber_idx, tag_hnumber_idx + 9, "");
				} else
					break;
			}

			int tag_hnumber_lidx = 0;

			while (true) {
				tag_hnumber_lidx = htm.indexOf("</hnumber>");
				if (tag_hnumber_lidx != -1) {
					htm = htm.replace(tag_hnumber_lidx, tag_hnumber_lidx + 10, "");
				} else
					break;
			}

			int tag_h_idx = 0;
			int tag_h_lidx = 0;
			for (int i = 1; i < 8; i++) {
				tag_h_idx = 0;
				while (true) {
					tag_h_idx = htm.indexOf("<h" + i + ">");
					if (tag_h_idx != -1) {
						htm = htm.replace(tag_h_idx, tag_h_idx + 4, "");
					} else
						break;
				}

				tag_h_lidx = 0;
				while (true) {
					tag_h_lidx = htm.indexOf("</h" + i + ">");
					if (tag_h_lidx != -1) {
						htm = htm.replace(tag_h_lidx, tag_h_lidx + 5, "");
					} else
						break;
				}
			}

			int tag_font_idx = 0;
			while (true) {
				tag_font_idx = htm.indexOf("<font");
				if (tag_font_idx != -1) {
					int serch_idx6 = htm.indexOf(">", tag_font_idx);
					htm = htm.replace(tag_font_idx, serch_idx6 + 1, "");
				} else
					break;
			}

			int tag_font_lidx = 0;
			while (true) {
				tag_font_lidx = htm.indexOf("</font>");
				if (tag_font_lidx != -1) {
					htm = htm.replace(tag_font_lidx, tag_font_lidx + 7, "");
				} else
					break;
			}

			int tag_basefont_idx = 0;
			while (true) {
				tag_basefont_idx = htm.indexOf("<basefont");
				if (tag_basefont_idx != -1) {
					int serch_idx7 = htm.indexOf(">", tag_basefont_idx);
					htm = htm.replace(tag_basefont_idx, serch_idx7 + 1, "");
				} else
					break;
			}

			int tag_b_idx = 0;
			while (true) {
				tag_b_idx = htm.indexOf("<b>");
				if (tag_b_idx != -1) {
					htm = htm.replace(tag_b_idx, tag_b_idx + 3, "");
				} else
					break;
			}

			int tag_b_lidx = 0;
			while (true) {
				tag_b_lidx = htm.indexOf("</b>");
				if (tag_b_lidx != -1) {
					htm = htm.replace(tag_b_lidx, tag_b_lidx + 4, "");
				} else
					break;
			}

			int tag_i_idx = 0;
			while (true) {
				tag_i_idx = htm.indexOf("<i>");
				if (tag_i_idx != -1) {
					htm = htm.replace(tag_i_idx, tag_i_idx + 3, "");
				} else
					break;
			}

			int tag_i_lidx = 0;
			while (true) {
				tag_i_lidx = htm.indexOf("</i>");
				if (tag_i_lidx != -1) {
					htm = htm.replace(tag_i_lidx, tag_i_lidx + 4, "");
				} else
					break;
			}

			int tag_s_idx = 0;
			while (true) {
				tag_s_idx = htm.indexOf("<s>");
				if (tag_s_idx != -1) {
					htm = htm.replace(tag_s_idx, tag_s_idx + 3, "");
				} else
					break;
			}

			int tag_s_lidx = 0;
			while (true) {
				tag_s_lidx = htm.indexOf("</s>");
				if (tag_s_lidx != -1) {
					htm = htm.replace(tag_s_lidx, tag_s_lidx + 4, "");
				} else
					break;
			}

			int tag_tt_idx = 0;
			while (true) {
				tag_tt_idx = htm.indexOf("<tt>");
				if (tag_tt_idx != -1) {
					htm = htm.replace(tag_tt_idx, tag_tt_idx + 4, "");
				} else
					break;
			}

			int tag_tt_lidx = 0;
			while (true) {
				tag_tt_lidx = htm.indexOf("</tt>");
				if (tag_tt_lidx != -1) {
					htm = htm.replace(tag_tt_lidx, tag_tt_lidx + 5, "");
				} else
					break;
			}

			int tag_u_idx = 0;
			while (true) {
				tag_u_idx = htm.indexOf("<u>");
				if (tag_u_idx != -1) {
					htm = htm.replace(tag_u_idx, tag_u_idx + 3, "");
				} else
					break;
			}

			int tag_u_lidx = 0;
			while (true) {
				tag_u_lidx = htm.indexOf("</u>");
				if (tag_u_lidx != -1) {
					htm = htm.replace(tag_u_lidx, tag_u_lidx + 4, "");
				} else
					break;
			}

			int tag_blink_idx = 0;
			while (true) {
				tag_blink_idx = htm.indexOf("<blink>");
				if (tag_blink_idx != -1) {
					htm = htm.replace(tag_blink_idx, tag_blink_idx + 7, "");
				} else
					break;
			}

			int tag_blink_lidx = 0;
			while (true) {
				tag_blink_lidx = htm.indexOf("</blink>");
				if (tag_blink_lidx != -1) {
					htm = htm.replace(tag_blink_lidx, tag_blink_lidx + 8, "");
				} else
					break;
			}

			int tag_sub_idx = 0;
			while (true) {
				tag_sub_idx = htm.indexOf("<sub>");
				if (tag_sub_idx != -1) {
					htm = htm.replace(tag_sub_idx, tag_sub_idx + 5, "");
				} else
					break;
			}

			int tag_sub_lidx = 0;
			while (true) {
				tag_sub_lidx = htm.indexOf("</sub>");
				if (tag_sub_lidx != -1) {
					htm = htm.replace(tag_sub_lidx, tag_sub_lidx + 6, "");
				} else
					break;
			}

			int tag_sup_idx = 0;

			while (true) {
				tag_sup_idx = htm.indexOf("<sup>");
				if (tag_sup_idx != -1) {
					htm = htm.replace(tag_sup_idx, tag_sup_idx + 5, "");
				} else
					break;
			}

			int tag_sup_lidx = 0;
			while (true) {
				tag_sup_lidx = htm.indexOf("</sup>");
				if (tag_sup_lidx != -1) {
					htm = htm.replace(tag_sup_lidx, tag_sup_lidx + 6, "");
				} else
					break;
			}

			int tag_ul_idx = 0;
			while (true) {
				tag_ul_idx = htm.indexOf("<ul>");
				if (tag_ul_idx != -1) {
					htm = htm.replace(tag_ul_idx, tag_ul_idx + 4, "");
				} else
					break;
			}

			int tag_ul_lidx = 0;
			while (true) {
				tag_ul_lidx = htm.indexOf("</ul>");
				if (tag_ul_lidx != -1) {
					htm = htm.replace(tag_ul_lidx, tag_ul_lidx + 5, "");
				} else
					break;
			}

			int tag_ol_idx = 0;
			while (true) {
				tag_ol_idx = htm.indexOf("<ol>");
				if (tag_ol_idx != -1) {
					htm = htm.replace(tag_ol_idx, tag_ol_idx + 4, "");
				} else
					break;
			}

			int tag_ol_lidx = 0;
			while (true) {
				tag_ol_lidx = htm.indexOf("</ol>");
				if (tag_ol_lidx != -1) {
					htm = htm.replace(tag_ol_lidx, tag_ol_lidx + 5, "");
				} else
					break;
			}

			int tag_li_idx = 0;
			while (true) {
				tag_li_idx = htm.indexOf("<li");
				if (tag_li_idx != -1) {
					int serch_idx8 = htm.indexOf(">", tag_li_idx);
					htm = htm.replace(tag_li_idx, serch_idx8 + 1, "");
				} else
					break;
			}

			int tag_blockquote_idx = 0;
			while (true) {
				tag_blockquote_idx = htm.indexOf("<blockquote>");
				if (tag_blockquote_idx != -1) {
					htm = htm.replace(tag_blockquote_idx, tag_blockquote_idx + 12, "");
				} else
					break;
			}

			int tag_blockquote_lidx = 0;
			while (true) {
				tag_blockquote_lidx = htm.indexOf("</blockquote>");
				if (tag_blockquote_lidx != -1) {
					htm = htm.replace(tag_blockquote_lidx, tag_blockquote_lidx + 13, "");
				} else
					break;
			}

			int tag_a_idx = 0;
			while (true) {
				tag_a_idx = htm.indexOf("<a");
				if (tag_a_idx != -1) {
					int serch_idx9 = htm.indexOf(">", tag_a_idx);
					htm = htm.replace(tag_a_idx, serch_idx9 + 1, "");
				} else
					break;
			}

			int tag_a_lidx = 0;
			while (true) {
				tag_a_lidx = htm.indexOf("</a>");
				if (tag_a_lidx != -1) {
					htm = htm.replace(tag_a_lidx, tag_a_lidx + 4, "");
				} else
					break;
			}

			int tag_img_idx = 0;
			while (true) {
				tag_img_idx = htm.indexOf("<img");
				if (tag_img_idx != -1) {
					int serch_idx10 = htm.indexOf(">", tag_img_idx);
					htm = htm.replace(tag_img_idx, serch_idx10 + 1, "");
				} else
					break;
			}

			int tag_th_idx = 0;
			while (true) {
				tag_th_idx = htm.indexOf("<th>");
				if (tag_th_idx != -1) {
					htm = htm.replace(tag_th_idx, tag_th_idx + 4, "");
				} else
					break;
			}

			int tag_th_lidx = 0;
			while (true) {
				tag_th_lidx = htm.indexOf("</th>");
				if (tag_th_lidx != -1) {
					htm = htm.replace(tag_th_lidx, tag_th_lidx + 5, "");
				} else
					break;
			}

			int tag_frameset_idx = 0;
			while (true) {
				tag_frameset_idx = htm.indexOf("<frameset");
				if (tag_frameset_idx != -1) {
					int serch_idx11 = htm.indexOf(">", tag_frameset_idx);
					htm = htm.replace(tag_frameset_idx, serch_idx11 + 1, "");
				} else
					break;
			}

			int tag_frameset_lidx = 0;
			while (true) {
				tag_frameset_lidx = htm.indexOf("</frameset>");
				if (tag_frameset_lidx != -1) {
					htm = htm.replace(tag_frameset_lidx, tag_frameset_lidx + 11, "");
				} else
					break;
			}

			int tag_frame_idx = 0;
			while (true) {
				tag_frame_idx = htm.indexOf("<frame");
				if (tag_frame_idx != -1) {
					int serch_idx12 = htm.indexOf(">", tag_frame_idx);
					htm = htm.replace(tag_frame_idx, serch_idx12 + 1, "");
				} else
					break;
			}

			int tag_frame_lidx = 0;
			while (true) {
				tag_frame_lidx = htm.indexOf("</frame>");
				if (tag_frame_lidx != -1) {
					htm = htm.replace(tag_frame_lidx, tag_frame_lidx + 8, "");
				} else
					break;
			}

			int tag_caption_idx = 0;
			while (true) {
				tag_caption_idx = htm.indexOf("<caption");
				if (tag_caption_idx != -1) {
					int serch_idx13 = htm.indexOf(">", tag_caption_idx);
					htm = htm.replace(tag_caption_idx, serch_idx13 + 1, "");
				} else
					break;
			}

			int tag_caption_lidx = 0;
			while (true) {
				tag_caption_lidx = htm.indexOf("</caption>");
				if (tag_caption_lidx != -1) {
					htm = htm.replace(tag_caption_lidx, tag_caption_lidx + 10, "");
				} else
					break;
			}

			int tag_col_idx = 0;
			while (true) {
				tag_col_idx = htm.indexOf("<col");
				if (tag_col_idx != -1) {
					int serch_idx14 = htm.indexOf(">", tag_col_idx);
					htm = htm.replace(tag_col_idx, serch_idx14 + 1, "");
				} else
					break;
			}

			int tag_span_idx = 0;
			while (true) {
				tag_span_idx = htm.indexOf("<span");
				if (tag_span_idx != -1) {
					int serch_idx15 = htm.indexOf(">", tag_span_idx);
					htm = htm.replace(tag_span_idx, serch_idx15 + 1, "");
				} else
					break;
			}

			int tag_span_lidx = 0;

			while (true) {
				tag_span_lidx = htm.indexOf("</span>");
				if (tag_span_lidx != -1) {
					htm = htm.replace(tag_span_lidx, tag_span_lidx + 7, "");
				} else
					break;
			}

			int not_tag_idx = 0;

			while (true) {
				not_tag_idx = htm.indexOf("<!");
				if (not_tag_idx != -1) {
					int not_tag_lidx = htm.indexOf(">", not_tag_idx);
					htm = htm.replace(not_tag_idx, not_tag_lidx + 1, "");
				} else
					break;
			}

			int tag_oTable_idx = 0;

			while (true) {
				tag_oTable_idx = htm.indexOf("<Table");
				if (tag_oTable_idx != -1) {
					int serch_idx16 = htm.indexOf(">", tag_oTable_idx);
					htm = htm.replace(tag_oTable_idx, serch_idx16 + 1, "<TABLE border=2 Width=100 Height=100>");
				} else
					break;
			}

			int tag_iTABLE_idx = 0;
			int serch_idx17 = 0;

			while (true) {
				tag_iTABLE_idx = htm.indexOf("<table", tag_iTABLE_idx);
				if (tag_iTABLE_idx != -1) {
					serch_idx17 = htm.indexOf(">", tag_iTABLE_idx);
					htm = htm.replace(tag_iTABLE_idx, serch_idx17 + 1, "<TABLE border=1 Width=100 Height=100>");
					tag_iTABLE_idx++;
				} else
					break;
			}

			int tag_tr_idx = 0;
			int serch_idx18 = 0;

			while (true) {
				tag_tr_idx = htm.indexOf("<tr ", tag_tr_idx);
				if (tag_tr_idx != -1) {
					serch_idx18 = htm.indexOf(">", tag_tr_idx);
					htm = htm.replace(tag_tr_idx, serch_idx18 + 1, "<tr>");
					tag_tr_idx++;
				} else
					break;
			}

			int tag_td_idx = 0;
			int serch_idx19 = 0;
			int colspan_idx = 0;
			int rowspan_idx = 0;
			int align_left = 0;
			int align_center = 0;
			int align_right = 0;

			int quotation_mark_idx1 = 0;
			int quotation_mark_idx2 = 0;
			int quotation_mark_idx3 = 0;

			int data_blank_idx1 = 0;
			int data_blank_idx2 = 0;
			int data_blank_idx3 = 0;
			int data_blank_idx4 = 0;

			while (true) {

				tag_td_idx = htm.indexOf("<td ", tag_td_idx);

				if (tag_td_idx != -1) {

					StringBuffer _TD = new StringBuffer();

					serch_idx19 = htm.indexOf(">", tag_td_idx);
					_TD.append(htm.substring(tag_td_idx, serch_idx19 + 1));

					colspan_idx = _TD.indexOf("colspan");
					rowspan_idx = _TD.indexOf("rowspan");

					align_left = _TD.indexOf("align=left");
					align_center = _TD.indexOf("align=center");
					align_right = _TD.indexOf("align=right");

					if (colspan_idx != -1 && rowspan_idx == -1) {
						StringBuffer _ColSpan_ = new StringBuffer();

						data_blank_idx1 = _TD.indexOf(" ", colspan_idx);
						if (data_blank_idx1 == -1)
							data_blank_idx1 = _TD.indexOf(">", colspan_idx);
						if (data_blank_idx1 == -1)
							data_blank_idx1 = _TD.indexOf("\"", colspan_idx);
						if (data_blank_idx1 == -1)
							data_blank_idx1 = _TD.indexOf("/", colspan_idx);

						_ColSpan_.append(_TD.substring(colspan_idx + 8, data_blank_idx1));
						quotation_mark_idx1 = _ColSpan_.indexOf("\"");

						if (quotation_mark_idx1 != -1) {
							StringBuffer DefaultTdColSpan = new StringBuffer();

							DefaultTdColSpan.append("<td colspan=");
							DefaultTdColSpan.append(_ColSpan_.toString());
							DefaultTdColSpan.append(">");

							if (align_left != -1)
								DefaultTdColSpan.append("<PSTYLE ALIGN=LEFT>");
							else if (align_center != -1)
								DefaultTdColSpan.append("<PSTYLE ALIGN=CENTER>");
							else if (align_right != -1)
								DefaultTdColSpan.append("<PSTYLE ALIGN=RIGHT>");

							htm = htm.replace(tag_td_idx, serch_idx19 + 1, DefaultTdColSpan.toString());

						} else {

							StringBuffer DefaultTdColSpan = new StringBuffer();

							DefaultTdColSpan.append("<td colspan=\"");
							DefaultTdColSpan.append(_ColSpan_.toString());
							DefaultTdColSpan.append("\"");
							DefaultTdColSpan.append(">");

							if (align_left != -1)
								DefaultTdColSpan.append("<PSTYLE ALIGN=LEFT>");
							else if (align_center != -1)
								DefaultTdColSpan.append("<PSTYLE ALIGN=CENTER>");
							else if (align_right != -1)
								DefaultTdColSpan.append("<PSTYLE ALIGN=RIGHT>");

							htm = htm.replace(tag_td_idx, serch_idx19 + 1, DefaultTdColSpan.toString());

						}

					} else if (colspan_idx == -1 && rowspan_idx != -1) {

						StringBuffer _RowSpan_ = new StringBuffer();

						data_blank_idx2 = _TD.indexOf(" ", rowspan_idx);
						if (data_blank_idx2 == -1)
							data_blank_idx2 = _TD.indexOf(">", rowspan_idx);
						if (data_blank_idx2 == -1)
							data_blank_idx2 = _TD.indexOf("\"", rowspan_idx);
						if (data_blank_idx2 == -1)
							data_blank_idx2 = _TD.indexOf("/", rowspan_idx);

						_RowSpan_.append(_TD.substring(rowspan_idx + 8, data_blank_idx2));
						quotation_mark_idx2 = _RowSpan_.indexOf("\"");

						if (quotation_mark_idx2 != -1) {

							StringBuffer DefaultTdRowSpan = new StringBuffer();

							DefaultTdRowSpan.append("<td rowspan=");
							DefaultTdRowSpan.append(_RowSpan_.toString());
							DefaultTdRowSpan.append(">");

							if (align_left != -1)
								DefaultTdRowSpan.append("<PSTYLE ALIGN=LEFT>");
							else if (align_center != -1)
								DefaultTdRowSpan.append("<PSTYLE ALIGN=CENTER>");
							else if (align_right != -1)
								DefaultTdRowSpan.append("<PSTYLE ALIGN=RIGHT>");

							htm = htm.replace(tag_td_idx, serch_idx19 + 1, DefaultTdRowSpan.toString());

						} else {

							StringBuffer DefaultTdRowSpan = new StringBuffer();

							DefaultTdRowSpan.append("<td rowspan=\"");
							DefaultTdRowSpan.append(_RowSpan_.toString());
							DefaultTdRowSpan.append("\"");
							DefaultTdRowSpan.append(">");

							if (align_left != -1)
								DefaultTdRowSpan.append("<PSTYLE ALIGN=LEFT>");
							else if (align_center != -1)
								DefaultTdRowSpan.append("<PSTYLE ALIGN=CENTER>");
							else if (align_right != -1)
								DefaultTdRowSpan.append("<PSTYLE ALIGN=RIGHT>");

							htm = htm.replace(tag_td_idx, serch_idx19 + 1, DefaultTdRowSpan.toString());

						}

					} else if (colspan_idx != -1 && rowspan_idx != -1) {

						StringBuffer _ColSpan2_ = new StringBuffer();
						StringBuffer _RowSpan2_ = new StringBuffer();

						data_blank_idx3 = _TD.indexOf(" ", colspan_idx);
						data_blank_idx4 = _TD.indexOf(" ", rowspan_idx);
						_ColSpan2_.append(_TD.substring(colspan_idx + 8, data_blank_idx3));
						_RowSpan2_.append(_TD.substring(rowspan_idx + 8, data_blank_idx4));
						quotation_mark_idx3 = _ColSpan2_.indexOf("\"");

						if (quotation_mark_idx3 != -1) {

							StringBuffer DefaultTdColSpanRowSpan = new StringBuffer();

							DefaultTdColSpanRowSpan.append("<td colspan=");
							DefaultTdColSpanRowSpan.append(_ColSpan2_.toString());
							DefaultTdColSpanRowSpan.append(" rowspan=");
							DefaultTdColSpanRowSpan.append(_RowSpan2_.toString());
							DefaultTdColSpanRowSpan.append(">");

							if (align_left != -1)
								DefaultTdColSpanRowSpan.append("<PSTYLE ALIGN=LEFT>");
							else if (align_center != -1)
								DefaultTdColSpanRowSpan.append("<PSTYLE ALIGN=CENTER>");
							else if (align_right != -1)
								DefaultTdColSpanRowSpan.append("<PSTYLE ALIGN=RIGHT>");

							htm = htm.replace(tag_td_idx, serch_idx19 + 1, DefaultTdColSpanRowSpan.toString());

						} else {

							StringBuffer DefaultTdColSpanRowSpan = new StringBuffer();

							DefaultTdColSpanRowSpan.append("<td colspan=\"");
							DefaultTdColSpanRowSpan.append(_ColSpan2_.toString());
							DefaultTdColSpanRowSpan.append("\"");
							DefaultTdColSpanRowSpan.append(" rowspan=\"");
							DefaultTdColSpanRowSpan.append(_RowSpan2_.toString());
							DefaultTdColSpanRowSpan.append("\"");
							DefaultTdColSpanRowSpan.append(">");

							if (align_left != -1)
								DefaultTdColSpanRowSpan.append("<PSTYLE ALIGN=LEFT>");
							else if (align_center != -1)
								DefaultTdColSpanRowSpan.append("<PSTYLE ALIGN=CENTER>");
							else if (align_right != -1)
								DefaultTdColSpanRowSpan.append("<PSTYLE ALIGN=RIGHT>");
							htm = htm.replace(tag_td_idx, serch_idx19 + 1, DefaultTdColSpanRowSpan.toString());
						}
					} else {
						if (align_left != -1)
							htm = htm.replace(tag_td_idx, serch_idx19 + 1, "<td><PSTYLE ALIGN=LEFT>");
						else if (align_center != -1)
							htm = htm.replace(tag_td_idx, serch_idx19 + 1, "<td><PSTYLE ALIGN=CENTER>");
						else if (align_right != -1)
							htm = htm.replace(tag_td_idx, serch_idx19 + 1, "<td><PSTYLE ALIGN=RIGHT>");
						else
							htm = htm.replace(tag_td_idx, serch_idx19 + 1, "<td>");
					}
					tag_td_idx++;
				} else
					break;
			}

			int tag_correct1_idx = 0;

			while (true) {
				tag_correct1_idx = htm.indexOf("<TABLE border=2 Width=100 Height=100><td");
				if (tag_correct1_idx != -1) {
					htm = htm.replace(tag_correct1_idx, tag_correct1_idx + 40,
							"<TABLE border=2 Width=100 Height=100><tr><td");
				} else
					break;
			}

			int tag_correct2_idx = 0;
			while (true) {
				tag_correct2_idx = htm.indexOf("<td><TABLE");
				if (tag_correct2_idx != -1) {
					htm = htm.replace(tag_correct2_idx, tag_correct2_idx + 10, "<td><INNER><TABLE");
				} else {
					break;
				}
			}

			int tag_correct3_idx = 0;

			while (true) {
				tag_correct3_idx = htm.indexOf("<TABLE border=1 Width=100 Height=100><td");
				if (tag_correct3_idx != -1) {
					htm = htm.replace(tag_correct3_idx, tag_correct3_idx + 40,
							"<TABLE border=1 Width=100 Height=100><tr><td");
				} else
					break;
			}

			int tag_correct4_idx = 0;

			while (true) {
				tag_correct4_idx = htm.indexOf("</td><tr><td");
				if (tag_correct4_idx != -1) {
					htm = htm.replace(tag_correct4_idx, tag_correct4_idx + 12, "</td></tr><tr><td");
				} else
					break;
			}

			int tag_correct5_idx = 0;

			while (true) {
				tag_correct5_idx = htm.indexOf("</td></tr><td");
				if (tag_correct5_idx != -1) {
					htm = htm.replace(tag_correct5_idx, tag_correct5_idx + 13, "</td></tr><tr><td");
				} else
					break;
			}

			int tag_correct6_idx = 0;

			while (true) {
				tag_correct6_idx = htm.indexOf("</td></table>");
				if (tag_correct6_idx != -1) {
					htm = htm.replace(tag_correct6_idx, tag_correct6_idx + 13, "</td></tr></table>");
				} else
					break;
			}

			int tag_correct7_idx = 0;

			while (true) {
				tag_correct7_idx = htm.indexOf("</table></td>");
				if (tag_correct7_idx != -1) {
					htm = htm.replace(tag_correct7_idx, tag_correct7_idx + 13, "</table></INNER></td>");
				} else
					break;
			}

			int tag_correct8_idx = 0;

			while (true) {
				tag_correct8_idx = htm.indexOf("<tr><tr>");
				if (tag_correct8_idx != -1) {
					htm = htm.replace(tag_correct8_idx, tag_correct8_idx + 8, "<tr>");
				} else
					break;
			}

			int tag_correct9_idx = 0;

			while (true) {
				tag_correct9_idx = htm.indexOf("</tr></tr>");
				if (tag_correct9_idx != -1) {
					htm = htm.replace(tag_correct9_idx, tag_correct9_idx + 10, "</tr>");
				} else
					break;
			}

			int tag_correct10_idx = 0;

			while (true) {
				tag_correct10_idx = htm.indexOf("<td><td");
				if (tag_correct10_idx != -1) {
					htm = htm.replace(tag_correct10_idx, tag_correct10_idx + 7, "<td");
				} else
					break;
			}

			int tag_correct11_idx = 0;

			while (true) {
				tag_correct11_idx = htm.indexOf("</td></td>");
				if (tag_correct11_idx != -1) {
					htm = htm.replace(tag_correct11_idx, tag_correct11_idx + 10, "</td>");
				} else
					break;
			}

			htm.indexOf("<TABLE border=2 Width=100 Height=100>");
			htm.indexOf("<INNER>");

			int special_char_idx1 = 0;

			while (true) {
				special_char_idx1 = htm.indexOf("#");
				if (special_char_idx1 != -1) {
					htm = htm.replace(special_char_idx1, special_char_idx1 + 1, "u0023");
				} else
					break;
			}

			int special_char_idx3 = 0;

			while (true) {
				special_char_idx3 = htm.indexOf("&");
				if (special_char_idx3 != -1) {
					htm = htm.replace(special_char_idx3, special_char_idx3 + 1, "u0026");
				} else
					break;
			}

			int special_char_idx4 = 0;

			while (true) {
				special_char_idx4 = htm.indexOf("$");
				if (special_char_idx4 != -1) {
					htm = htm.replace(special_char_idx4, special_char_idx4 + 1, "u0026u002336u003B");
				} else
					break;
			}

			int special_char_idx5 = 0;

			while (true) {
				special_char_idx5 = htm.indexOf("\'");
				if (special_char_idx5 != -1) {
					htm = htm.replace(special_char_idx5, special_char_idx5 + 1, "u0027");
				} else
					break;
			}

			int special_char_idx6 = 0;

			while (true) {
				special_char_idx6 = htm.indexOf("(");
				if (special_char_idx6 != -1) {
					htm = htm.replace(special_char_idx6, special_char_idx6 + 1, "u0028");
				} else
					break;
			}

			int special_char_idx7 = 0;

			while (true) {
				special_char_idx7 = htm.indexOf(")");
				if (special_char_idx7 != -1) {
					htm = htm.replace(special_char_idx7, special_char_idx7 + 1, "u0029");
				} else
					break;
			}

			int special_char_idx8 = 0;

			while (true) {
				special_char_idx8 = htm.indexOf("*");
				if (special_char_idx8 != -1) {
					htm = htm.replace(special_char_idx8, special_char_idx8 + 1, "u002A");
				} else
					break;
			}

			int special_char_idx9 = 0;
			while (true) {
				special_char_idx9 = htm.indexOf("+");
				if (special_char_idx9 != -1) {
					htm = htm.replace(special_char_idx9, special_char_idx9 + 1, "u002B");
				} else
					break;
			}

			int special_char_idx10 = 0;

			while (true) {
				special_char_idx10 = htm.indexOf(",");
				if (special_char_idx10 != -1) {
					htm = htm.replace(special_char_idx10, special_char_idx10 + 1, "u002C");
				} else
					break;
			}

			int special_char_idx11 = 0;

			while (true) {
				special_char_idx11 = htm.indexOf("-");
				if (special_char_idx11 != -1) {
					htm = htm.replace(special_char_idx11, special_char_idx11 + 1, "u002D");
				} else
					break;
			}

			int special_char_idx12 = 0;

			while (true) {
				special_char_idx12 = htm.indexOf(".");
				if (special_char_idx12 != -1) {
					htm = htm.replace(special_char_idx12, special_char_idx12 + 1, "u002E");
				} else
					break;
			}
			int special_char_idx14 = 0;

			while (true) {
				special_char_idx14 = htm.indexOf(":");
				if (special_char_idx14 != -1) {
					htm = htm.replace(special_char_idx14, special_char_idx14 + 1, "u003A");
				} else
					break;
			}
			int special_char_idx15 = 0;

			while (true) {
				special_char_idx15 = htm.indexOf(";");
				if (special_char_idx15 != -1) {
					htm = htm.replace(special_char_idx15, special_char_idx15 + 1, "u003B");
				} else
					break;
			}

			int special_char_idx17 = 0;
			while (true) {
				special_char_idx17 = htm.indexOf("?");
				if (special_char_idx17 != -1) {
					htm = htm.replace(special_char_idx17, special_char_idx17 + 1, "u003F");
				} else
					break;
			}
			int special_char_idx18 = 0;

			while (true) {
				special_char_idx18 = htm.indexOf("[");
				if (special_char_idx18 != -1) {
					htm = htm.replace(special_char_idx18, special_char_idx18 + 1, "u005B");
				} else
					break;
			}
			int special_char_idx19 = 0;
			while (true) {
				special_char_idx19 = htm.indexOf("\\");
				if (special_char_idx19 != -1) {
					htm = htm.replace(special_char_idx19, special_char_idx19 + 1, "u005Cu005C");
				} else
					break;
			}
			int special_char_idx20 = 0;
			while (true) {
				special_char_idx20 = htm.indexOf("]");
				if (special_char_idx20 != -1) {
					htm = htm.replace(special_char_idx20, special_char_idx20 + 1, "u005D");
				} else
					break;
			}
			int special_char_idx21 = 0;
			while (true) {
				special_char_idx21 = htm.indexOf("^");
				if (special_char_idx21 != -1) {
					htm = htm.replace(special_char_idx21, special_char_idx21 + 1, "u005E");
				} else
					break;
			}
			int special_char_idx22 = 0;
			while (true) {
				special_char_idx22 = htm.indexOf("{");
				if (special_char_idx22 != -1) {
					htm = htm.replace(special_char_idx22, special_char_idx22 + 1, "u007B");
				} else
					break;
			}
			int special_char_idx23 = 0;
			while (true) {
				special_char_idx23 = htm.indexOf("}");
				if (special_char_idx23 != -1) {
					htm = htm.replace(special_char_idx23, special_char_idx23 + 1, "u007D");
				} else
					break;
			}
			TagFilter.replace(htm, "|", "u00A6");
			TagFilter.replace(htm, "ㅇ", "o");

			int bug_idx1 = htm.indexOf("<>");
			int bug_idx2 = htm.indexOf("<t>");
			int bug_idx3 = htm.indexOf("<<td>");
			int bug_idx4 = htm.indexOf("</>");
			int bug_idx5 = htm.indexOf("</t>");
			int bug_idx6 = htm.indexOf("</td>>");
			int bug_idx7 = htm.indexOf("<tbody>");
			int bug_idx8 = htm.indexOf("</tbody>");

			if (bug_idx1 != -1 || bug_idx2 != -1 || bug_idx3 != -1 || bug_idx4 != -1 || bug_idx5 != -1
					|| bug_idx6 != -1 || bug_idx7 != -1 || bug_idx8 != -1) {
				String temp = HtmlUtil.tagFilter(htm.toString());
				sb.append(temp);
			} else {
				sb.append(htm.toString());
			}
			String E = VH.getEnd();
			sb.append(E);
		} else {
			sb.append(htm.substring(offset, htm.length()));
		}
		if (closer_idx == -1) {
			offset = closer_idx + 1;
		}
		return sb.toString();
	}
}
