package kr.co.kihyun.text.hml;

import java.io.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TableTagConverter {
        private static final Logger LOG = LoggerFactory.getLogger(TableTagConverter.class);
	public static final int INITIAL_SIZE = 0;

	private static String VR_STR = "";

	public TableTagConverter() {
	}

	public void IOhandler(String a, String b) throws IOException {
            
                //10.자원 삽입(임의 파일 접근)_CWE-99 : Add by KWON,HAN
                LOG.debug("a, b: {}, {}", a, b); 
                if(a.contains("..") || a. contains("/") || b.contains("..") || b. contains("/")) { // 특수문자열 검증
                    LOG.debug("TableTagConverter IOhandler ===");
                    LOG.debug("10.자원 삽입(임의 파일 접근)_CWE-99 : Not Test {}", a);
                    LOG.debug("===============================");
                    return;
                }
                //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                        
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(b), "utf-8"));
		bw.write(getHtmlToHwp(new FileInputStream(a)));
		bw.flush();
		bw.close();

	}

	// Table Tag
	// Converter--------------------------------------------------------------------------------------------------

	public static String getHtmlToHwp(FileInputStream fis) throws IOException, UnsupportedEncodingException {

		InputStreamReader isr = null;
		BufferedReader br = null;
		StringBuffer sb = null;

		String str = "";
		String html = "";
		String htm_opened = "";

		String xml_heading = "";
		String xml_body = "";
		String xml_ending = "";

		int offset = 0;

		int opener_idx1 = 0;
		int closer_idx1 = 0;

		int opener_idx2 = 0;
		int closer_idx2 = 0;

		isr = new InputStreamReader(fis, "utf-8");
     
            //15.부적절한 자원 해제(Reader/Writer)_CWE-404 : Add by KWON,HAN                    
            try {
            //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                
		if (!isr.ready())
			return null;

		br = new BufferedReader(isr);
                
            //15.부적절한 자원 해제(Reader/Writer)_CWE-404 : Add by KWON,HAN    
            } catch (IOException e) { 
                e.printStackTrace();  
            } finally { 
                isr.close(); 
            }
            //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            
		str = br.readLine();

		while (str != null) {
			html = html + str + "\n";
			str = br.readLine();
		}
            
		htm_opened = html;

		opener_idx1 = html.indexOf("<!--");
		closer_idx1 = html.indexOf("-->");
		opener_idx2 = html.lastIndexOf("<!--");
		closer_idx2 = html.lastIndexOf("-->");

		sb = new StringBuffer(INITIAL_SIZE);

		if (opener_idx1 != -1) {
			xml_heading = html.substring(opener_idx1 + 4, closer_idx1);
			sb.append(xml_heading);

			int inner_table_serch_idx = 0;
			int inner_table_serch_lidx = 0;

			boolean CHANGE_WIDTH = false;

			String INNER_TABLE[] = new String[10000];

			int i = 0;

			while (true) {
				inner_table_serch_idx = htm_opened.indexOf("<INNER><TABLE", inner_table_serch_idx);

				if (inner_table_serch_idx != -1) {
					CHANGE_WIDTH = true;

					inner_table_serch_lidx = htm_opened.indexOf("</INNER>", inner_table_serch_idx);
					INNER_TABLE[i] = htm_opened.substring(inner_table_serch_idx, inner_table_serch_lidx + 8);
					htm_opened = htm_opened.replaceFirst(INNER_TABLE[i], "VIRTUAL DATA" + i);

					inner_table_serch_idx++;
					i++;
				} else
					break;
			}

			xml_body = xml_table_COVERTING(htm_opened, CHANGE_WIDTH);
			String xml_body_array[] = new String[10000];

			for (int j = 0; j < i; j++) {
				xml_body_array[j] = xml_table_COVERTING(INNER_TABLE[j], false);
				xml_body = xml_body.replaceFirst("VIRTUAL DATA" + j, xml_body_array[j]);
			}

			xml_body = xml_body.replaceAll("<CHAR><TABLE", "<TABLE");
			xml_body = xml_body.replaceAll("</TABLE></CHAR>", "</TABLE>");

			sb.append(xml_body);

			xml_ending = html.substring(opener_idx2 + 4, closer_idx2);
			sb.append(xml_ending);

		} else {
			sb.append(html.substring(offset, html.length()));
		}

		if (closer_idx2 == -1) {
			offset = closer_idx2 + 1;
		}

		br.close();
		isr.close();
		fis.close();

		return sb.toString();
	}

	public static String xml_table_COVERTING(String a, boolean oo) {
		StringBuffer s = new StringBuffer(INITIAL_SIZE);

		String html = a;
		String htm_table_opened = "";
		String htm_tr_opened = "";
		String htm_td_opened = "";
		String htm_td_LOADING = "";
		String htm_table_closed = "";

		String htm_table_tag = "";
		String htm_tr_tag = "";
		String htm_td_tag2 = "";
		String htm_tr_tag2 = "";

		String xml_body = "";

		String xml_table_tag = "";
		String xml_row_tag = "";
		String xml_cell_tag2 = "";
		String xml_row_tag2 = "";

		String xml_cell_SAVING = "";
		String xml_cell_LOADING = "";
		String xml_cell_SAVED = "";
		String xml_table_closed = "";

		String DATA = "";

		int tag_table_idx = 0;
		int tag_tr_idx = 0;
		int tag_td_idx = 0;
		int tag_tr_lidx = 0;
		int tag_table_lidx = 0;

		int xml_row_idx = 0;
		int xml_row_lidx = 0;
		int xml_cell_idx = 0;
		int xml_cell_lidx = 0;
		int xml_paralist_lidx = 0;

		int data_serch_idx = 0;

		while (true) {
			htm_table_opened = "";
			htm_tr_opened = "";
			xml_row_idx = 0;
			tag_td_idx = 0;
			xml_cell_idx = 0;

			// table태그와 tr태그를 open ------------------------------------------------------
			tag_table_idx = html.indexOf("<TABLE", tag_table_idx);

			if (tag_table_idx == -1)
				break;

			tag_table_lidx = html.indexOf("</TABLE>", tag_table_idx);

			htm_table_opened = html.substring(tag_table_idx, tag_table_lidx + 8);

			tag_tr_idx = htm_table_opened.indexOf("<TR");
			tag_tr_lidx = htm_table_opened.lastIndexOf("</TR>");

			htm_tr_opened = htm_table_opened.substring(tag_tr_idx, tag_tr_lidx + 5);

			// htm table태그를 xml table태그로 replace
			// ---------------------------------------------------------------------------------------------------------------
			int RowCount = getRowCount(htm_table_opened);
			int ColCount = getColCount(htm_tr_opened);

			htm_table_tag = htm_table_opened.substring(0, tag_tr_idx);
			xml_table_tag = "<TABLE RowCount=\"" + RowCount + "\" ColCount=\"" + ColCount + "\" CellSpacing=\"" + "0"
					+ "\" BorderFill=\"" + "1" + "\">";

			htm_table_opened = htm_table_opened.replaceAll(htm_table_tag, xml_table_tag);

			// htm tr태그를 xml row태그로 replace ---------------------------------------------------
			htm_tr_tag = "<TR>";
			xml_row_tag = "<ROW>";

			htm_table_opened = htm_table_opened.replaceAll(htm_tr_tag, xml_row_tag);

			// htm /tr태그를 xml /row태그로 replace -------------------------------------------------
			htm_tr_tag2 = "</TR>";
			xml_row_tag2 = "</ROW>";

			htm_table_opened = htm_table_opened.replaceAll(htm_tr_tag2, xml_row_tag2);

			// htm /td태그를 xml /cell태그로 replace -------------------------------------------------
			htm_td_tag2 = "</TD>";
			xml_cell_tag2 = "</CELL>";

			htm_table_opened = htm_table_opened.replaceAll(htm_td_tag2, xml_cell_tag2);

			// htm td태그를 xml cell태그로 replace ---------------------------------------------------------------------
			int xx = htm_table_opened.indexOf("ColSpan");
			int yy = htm_table_opened.indexOf("RowSpan");

			if (xx != -1 || yy != -1) {
				xml_cell_LOADING = xml_cell_Default_LOADING(RowCount, ColCount, oo);
				xml_cell_SAVING = xml_SPANING(htm_table_opened, xml_cell_LOADING, ColCount); // row_span / col_span
			} else {
				xml_cell_SAVING = xml_cell_Default_LOADING(RowCount, ColCount, oo); // multi_col / multi_row
			}

			while (true) {
				xml_row_idx = htm_table_opened.indexOf("<ROW>", xml_row_idx);

				if (xml_row_idx == -1)
					break;

				xml_row_lidx = htm_table_opened.indexOf("</ROW>", xml_row_idx);
				htm_td_opened = htm_table_opened.substring(xml_row_idx + 5, xml_row_lidx);

				while (true) {
					tag_td_idx = htm_td_opened.indexOf("<TD", tag_td_idx);

					if (tag_td_idx != -1) {
						data_serch_idx = htm_td_opened.indexOf(">", tag_td_idx);
						xml_cell_lidx = htm_td_opened.indexOf("</CELL>", data_serch_idx + 1);
						DATA = htm_td_opened.substring(data_serch_idx + 1, xml_cell_lidx);
						htm_td_LOADING = htm_td_opened.substring(tag_td_idx, data_serch_idx + 1) + DATA;
						xml_cell_idx = xml_cell_SAVING.indexOf("<CELL", xml_cell_idx);

						if (xml_cell_idx == -1)
							break;

						int data_serch_idx2 = xml_cell_SAVING.indexOf("<CHAR>", xml_cell_idx);
						int xml_char_lidx = xml_cell_SAVING.indexOf("</CHAR>", data_serch_idx2);
						String DATA2 = DATA;
						xml_paralist_lidx = xml_cell_SAVING.indexOf("</PARALIST>", xml_cell_idx);
						xml_cell_SAVED = xml_cell_SAVING.substring(xml_cell_idx, data_serch_idx2 + 6) + DATA2
								+ xml_cell_SAVING.substring(xml_char_lidx, xml_paralist_lidx + 11);
						htm_table_opened = htm_table_opened.replaceFirst(htm_td_LOADING, xml_cell_SAVED);
						tag_td_idx++;
						xml_cell_idx++;
					} else {
						break;
					}
				}
				xml_row_idx++;
			}
			// 특수코드를 특수문자로 replace -----------------------------------
                        //46.메소드이름 생성규칙 위반 Update by YOUNGJUN,CHO  
                        //htm_table_opened = CODE_SPECIALING(htm_table_opened);
                        htm_table_opened = codeSpecialing(htm_table_opened);
                        //================================================
			// -----------------------------------------------------------------------

			// table태그를 close ----------------------------------------------
			htm_table_closed = htm_table_closed + htm_table_opened;
			// -------------------------------------------------------------------

			tag_table_idx++;
		}

		String htm_table_Completely_disappeared = htm_table_closed;
		xml_table_closed = xml_table_closed + htm_table_Completely_disappeared;
		xml_body = xml_table_closed;

		s.append(xml_body);

		return s.toString();

	}

	// RowCount, ColCount-------------------------------------------------------------------------------------------

	public static int getRowCount(String a) {
		int i = 0;
		int j = 0;

		while (true) {
			j = a.indexOf("<tr>", j);
			if (j < 0)
				break;
			i++;
			j++;
		}

		return i;
	}

	public static int getColCount(String a) {
		int i = 0;
		int j = 0;
		int k = 0;
		int l = 0;

		int x = 0;
		int y = 0;
		int z = 0;

		String v = "";
		String v1 = "";

		int max = 0;
		int col = 0;

		while (true) {
			i = a.indexOf("<tr>", i);

			col = 0;

			if (i == -1)
				break;

			j = a.indexOf("</tr>", i);
			v = a.substring(i + 4, j);

			while (true) {
				k = v.indexOf("<td", k);

				if (k != -1) {
					l = v.indexOf("</td>", k);
					v1 = v.substring(k, l);

					x = v1.indexOf("colspan");

					if (x != -1) {
						y = v1.indexOf("\"", x);
						z = v1.indexOf("\"", y + 1);
						int ColSpan = Integer.parseInt(v1.substring(y + 1, z));

						col = col + ColSpan - 1;
					}

				} else {
					break;
				}

				k++;
				col++;
			}

			i++;
			max = max > col ? max : col;
		}

		return max;
	}

	// xml cell Default
	// LOADER--------------------------------------------------------------------------------------------------------------------

	public static String xml_cell_Default_LOADING(int a, int b, boolean c) {

		StringBuffer s = new StringBuffer(INITIAL_SIZE);

		String xml_cell_OPENED = "";
		String xml_cell_CLOSED = "";
		String DATA = "";

		boolean CHANGE_WIDTH = c;

		int RowCount = a;
		int ColCount = b;

		int DefaultColSpan = 0;
		int DefaultRowSpan = 0; // 크기조정 control-----------------------
		int DefaultBorderFill = 0; // 테이블 안의 테이블 두께 크기 조정
		int DefaultWidth = 0; // 테이블 안의 테이블 열 넓이 크기 조정
		int DefaultHeight = 0; // 테이블 안의 테이블 행 높이 크기 조정

		for (int i = 0; i < RowCount; i++) {
			for (int j = 0; j < ColCount; j++) {
				xml_cell_OPENED = "<CELL ColAddr=\"" + j + "\" RowAddr=\"" + i + "\"";
				s.append(xml_cell_OPENED);

				DefaultColSpan = 1;
				DefaultRowSpan = 1; // 크기조정 control-----------------------
				DefaultBorderFill = 2; // 테이블 안의 테이블 두께 크기 조정
				DefaultWidth = 3000; // 테이블 안의 테이블 열 넓이 크기 조정
				DefaultHeight = 2000; // 테이블 안의 테이블 행 높이 크기 조정

				if (CHANGE_WIDTH) {
					DefaultColSpan = 1;
					DefaultRowSpan = 1;
					DefaultBorderFill = 2; // 테이블 행 두께 크기 조정
					if (j == 0) {
						DefaultWidth = 7000;
					} else { // 테이블 첫번째 열 넓이 크기 조정
						DefaultWidth = 70000; // 테이블 두번째 열 넓이 크기 조정
						DefaultHeight = 2000;
					}
				} else {
				} // 테이블 행 높이 크기 조정
				// ------------------------------------------
				String DefaultData = "1";

				s.append(" ColSpan=\"" + DefaultColSpan + "\" RowSpan=\"" + DefaultRowSpan + "\"");
				s.append(" BorderFill=\"" + DefaultBorderFill + "\" Width=\"" + DefaultWidth + "\" Height=\""
						+ DefaultHeight + "\">");
				s.append("<PARALIST><P><TEXT><CHAR>");

				DATA = DefaultData;
				s.append(DATA);

				xml_cell_CLOSED = "</CHAR></TEXT></P></PARALIST>";
				s.append(xml_cell_CLOSED);
			}
		}

		return s.toString();
	}

	// SPANING----------------------------------------------------------------------------------------------

	public static String xml_SPANING(String a, String b, int CC) {
		StringBuffer s = new StringBuffer(INITIAL_SIZE);

		String v = "";
		String v1 = "";
		String v2 = "";
		String v3 = "";
		String v4 = "";
		String v5 = "";
		String v6 = "";
		String v7 = "";
		String v8 = "";

		String e = "";
		String e1 = "";
		String e2 = "";
		String e3 = "";

		String J_init1 = "";
		String J_init2 = "";
		String J_init3 = "";
		String J_init4 = "";

		int J_init_idx1 = 0;
		int J_init_idx2 = 0;
		int J_init_idx3 = 0;
		int J_init_idx4 = 0;

		int J_init_lidx1 = 0;
		int J_init_lidx2 = 0;
		int J_init_lidx3 = 0;
		int J_init_lidx4 = 0;

		int c = 0;
		int c1 = 0;
		int c2 = 0;
		int c3 = 0;

		int d = 0;
		int d1 = 0;
		int d2 = 0;
		int d3 = 0;

		int i = 0;
		int j = 0;

		int o = 0;
		int o1 = 0;

		int p = 0;
		int p1 = 0;

		int r = 0;
		int u = 0;

		int t = 0;
		int w = 0;

		int x = 0;
		int y = 0;
		int z = 0;

		int x1 = 0;
		int y1 = 0;
		int z1 = 0;

		int y2 = 0;
		int z2 = 0;

		int y3 = 0;
		int z3 = 0;

		int ColAddr = 0;
		int RowAddr = 0;

		int ColAddr2 = 0;
		int RowAddr2 = 0;

		TableTagConverter TTC = new TableTagConverter();
		TTC.set_VR_STR(b);

		while (true) {
			r = a.indexOf("<ROW>", r);

			v = "";
			v1 = "";
			v2 = "";
			v3 = "";
			v4 = "";
			v5 = "";
			v6 = "";
			v7 = "";
			v8 = "";

			e = "";
			e1 = "";
			e2 = "";
			e3 = "";

			t = 0;

			if (r == -1)
				break;

			u = a.indexOf("</ROW>", r);
			v = a.substring(r + 5, u);

			while (true) {
				t = v.indexOf("<TD", t);

				if (t != -1) {
					w = v.indexOf("</CELL>", t);
					v1 = v.substring(t, w);

					x = v1.indexOf("ColSpan");
					x1 = v1.indexOf("RowSpan");

					if (x != -1 && x1 == -1) {
						y = v1.indexOf("\"", x);
						z = v1.indexOf("\"", y + 1);
						int ColSpan = Integer.parseInt(v1.substring(y + 1, z));

						b = TTC.get_VR_STR();

						J_init_idx1 = b.indexOf("<CELL ColAddr=\"");
						J_init_lidx1 = b.indexOf("\"", J_init_idx1 + 15);
						J_init1 = b.substring(J_init_idx1 + 15, J_init_lidx1);
						j = Integer.parseInt(J_init1);

						e = "<xxxx ColAddr=\"" + j + "\" RowAddr=\"" + i + "\" ColSpan=\"" + ColSpan + "\"";

						c = b.indexOf("<CELL ColAddr=\"" + j + "\" RowAddr=\"" + i + "\"");
						if (c == -1)
							break;
						d = b.indexOf("RowSpan", c);
						v2 = b.substring(c, d - 1);

						b = b.replaceAll(v2, e);

						for (int q = 1; q < ColSpan; q++) {

							ColAddr = j + q;

							o = b.indexOf("<CELL ColAddr=\"" + ColAddr + "\" RowAddr=\"" + i + "\"");
							if (o == -1)
								break;
							p = b.indexOf("</PARALIST>", o);
							v3 = b.substring(o, p + 11);

							b = b.replaceAll(v3, "");

						} // end for

					} else if (x == -1 && x1 != -1) {

						y1 = v1.indexOf("\"", x1);
						z1 = v1.indexOf("\"", y1 + 1);
						int RowSpan = Integer.parseInt(v1.substring(y1 + 1, z1));

						b = TTC.get_VR_STR();

						J_init_idx2 = b.indexOf("<CELL ColAddr=\"");
						J_init_lidx2 = b.indexOf("\"", J_init_idx2 + 15);
						J_init2 = b.substring(J_init_idx2 + 15, J_init_lidx2);
						j = Integer.parseInt(J_init2);

						e1 = "<xxxx ColAddr=\"" + j + "\" RowAddr=\"" + i + "\" ColSpan=\"1\" RowSpan=\"" + RowSpan
								+ "\"";

						c1 = b.indexOf("<CELL ColAddr=\"" + j + "\" RowAddr=\"" + i + "\"");
						if (c1 == -1)
							break;
						d1 = b.indexOf("BorderFill", c1);
						v4 = b.substring(c1, d1 - 1);

						b = b.replaceAll(v4, e1);

						for (int q = 1; q < RowSpan; q++) {

							RowAddr = i + q;

							o1 = b.indexOf("<CELL ColAddr=\"" + j + "\" RowAddr=\"" + RowAddr + "\"");
							if (o1 == -1)
								break;
							p1 = b.indexOf("</PARALIST>", o1);
							v5 = b.substring(o1, p1 + 11);

							b = b.replaceAll(v5, "");

						} // end for

					} else if (x != -1 && x1 != -1) {

						y2 = v1.indexOf("\"", x);
						z2 = v1.indexOf("\"", y2 + 1);
						int ColSpan2 = Integer.parseInt(v1.substring(y2 + 1, z2));

						y3 = v1.indexOf("\"", x1);
						z3 = v1.indexOf("\"", y3 + 1);
						int RowSpan2 = Integer.parseInt(v1.substring(y3 + 1, z3));

						b = TTC.get_VR_STR();

						J_init_idx3 = b.indexOf("<CELL ColAddr=\"");
						J_init_lidx3 = b.indexOf("\"", J_init_idx3 + 15);
						J_init3 = b.substring(J_init_idx3 + 15, J_init_lidx3);
						j = Integer.parseInt(J_init3);

						e2 = "<xxxx ColAddr=\"" + j + "\" RowAddr=\"" + i + "\" ColSpan=\"" + ColSpan2
								+ "\" RowSpan=\"" + RowSpan2 + "\"";

						c2 = b.indexOf("<CELL ColAddr=\"" + j + "\" RowAddr=\"" + i + "\"");
						if (c2 == -1)
							break;
						d2 = b.indexOf("BorderFill", c2);
						v6 = b.substring(c2, d2 - 1);

						b = b.replaceAll(v6, e2);

						for (int q1 = 0; q1 < RowSpan2; q1++) {
							RowAddr2 = i + q1;

							for (int q2 = 0; q2 < ColSpan2; q2++) {
								ColAddr2 = j + q2;
                                                                    
                                                                //42.비어있는 if문 : Delete by YOUNGJUN,CHO
                                                                /*
								// FIXME: 이 코드 정말 돌아가나???
								if (q1 == 0 & q2 == 0) {
								} else {
									int o2 = b.indexOf("<CELL ColAddr=\"" + ColAddr2 + "\" RowAddr=\"" + RowAddr2
											+ "\"");
									if (o2 == -1)
										break;
									int p2 = b.indexOf("</PARALIST>", o2);
									v7 = b.substring(o2, p2 + 11);
									b = b.replaceAll(v7, "");
								}
                                                                */
                                                                //------------------------------------------------
                                                                
                                                                //42.비어있는 if문 : Add by YOUNGJUN,CHO
								if (q1 != 0 || q2 != 0) {
                                                                    int o2 = b.indexOf("<CELL ColAddr=\"" + ColAddr2 + "\" RowAddr=\"" + RowAddr2 + "\"");
                                                                    
                                                                    if (o2 == -1) {
                                                                        break;
                                                                    }
                                                                    
                                                                    int p2 = b.indexOf("</PARALIST>", o2);
                                                                    v7 = b.substring(o2, p2 + 11);
                                                                    b = b.replaceAll(v7, "");
								}
                                                                //++++++++++++++++++++++++++++++++++++++++++++++++
                                                                
							} // end inner for
						} // end outer for
					} else {
						b = TTC.get_VR_STR();

						J_init_idx4 = b.indexOf("<CELL ColAddr=\"");
						J_init_lidx4 = b.indexOf("\"", J_init_idx4 + 15);
						J_init4 = b.substring(J_init_idx4 + 15, J_init_lidx4);
						j = Integer.parseInt(J_init4);

						e3 = "<xxxx ColAddr=\"" + j + "\" RowAddr=\"" + i + "\"";

						c3 = b.indexOf("<CELL ColAddr=\"" + j + "\" RowAddr=\"" + i + "\"");
						if (c3 == -1)
							break;
						d3 = b.indexOf("ColSpan", c3);
						v8 = b.substring(c3, d3 - 1);

						b = b.replaceAll(v8, e3);
					} // end if

					TTC.set_VR_STR("");
					TTC.set_VR_STR(b);

					t++;
				} else {
					break;
				}
			} // end while

			r++;
			i++;
		} // end while

		b = b.replaceAll("<xxxx", "<CELL"); // 셀병합 최종 마무리
		s.append(b);

		return s.toString();
	}

	// SPECIALING--------------------------------------------------------------------------------------------
        //46.메소드이름 생성규칙 위반 Update by YOUNGJUN,CHO  
        //public static String CODE_SPECIALING(String a) {
        public static String codeSpecialing(String a) { 
        //================================================
		StringBuffer s = new StringBuffer(INITIAL_SIZE);

		int UniCode_idx = 0;

		while (true) {
			UniCode_idx = a.indexOf("u00", UniCode_idx);

			if (UniCode_idx != -1) {
				String UniCode = a.substring(UniCode_idx, UniCode_idx + 5).trim();

				if (UniCode.equals("u0022")) {
					a = a.replaceAll(UniCode, "#");
					a = a.replace('#', '"');
				} else if (UniCode.equals("u0026")) {
					a = a.replaceAll(UniCode, "#");
					a = a.replace('#', '&');
				} else if (UniCode.equals("u0027")) {
					a = a.replaceAll(UniCode, "#");
					a = a.replace('#', '\'');
				} else if (UniCode.equals("u0028")) {
					a = a.replaceAll(UniCode, "#");
					a = a.replace('#', '(');
				} else if (UniCode.equals("u0029")) {
					a = a.replaceAll(UniCode, "#");
					a = a.replace('#', ')');
				} else if (UniCode.equals("u002A")) {
					a = a.replaceAll(UniCode, "#");
					a = a.replace('#', '*');
				} else if (UniCode.equals("u002B")) {
					a = a.replaceAll(UniCode, "#");
					a = a.replace('#', '+');
				} else if (UniCode.equals("u002C")) {
					a = a.replaceAll(UniCode, "#");
					a = a.replace('#', ',');
				} else if (UniCode.equals("u002D")) {
					a = a.replaceAll(UniCode, "#");
					a = a.replace('#', '-');
				} else if (UniCode.equals("u002E")) {
					a = a.replaceAll(UniCode, "#");
					a = a.replace('#', '.');
				} else if (UniCode.equals("u002F")) {
					a = a.replaceAll(UniCode, "#");
					a = a.replace('#', '/');
				} else if (UniCode.equals("u003A")) {
					a = a.replaceAll(UniCode, "#");
					a = a.replace('#', ':');
				} else if (UniCode.equals("u003B")) {
					a = a.replaceAll(UniCode, "#");
					a = a.replace('#', ';');
				} else if (UniCode.equals("u003D")) {
					a = a.replaceAll(UniCode, "#");
					a = a.replace('#', '=');
				} else if (UniCode.equals("u003F")) {
					a = a.replaceAll(UniCode, "#");
					a = a.replace('#', '?');
				} else if (UniCode.equals("u005B")) {
					a = a.replaceAll(UniCode, "#");
					a = a.replace('#', '[');
				} else if (UniCode.equals("u005C")) {
					a = a.replaceAll(UniCode, "#");
					a = a.replace('#', '\\');
				} else if (UniCode.equals("u005D")) {
					a = a.replaceAll(UniCode, "#");
					a = a.replace('#', ']');
				} else if (UniCode.equals("u005E")) {
					a = a.replaceAll(UniCode, "#");
					a = a.replace('#', '^');
				} else if (UniCode.equals("u007B")) {
					a = a.replaceAll(UniCode, "#");
					a = a.replace('#', '{');
				} else if (UniCode.equals("u007D")) {
					a = a.replaceAll(UniCode, "#");
					a = a.replace('#', '}');
				} else if (UniCode.equals("u00A6")) {
					a = a.replaceAll(UniCode, "#");
					a = a.replace('#', '|');
				} else {
				}

				UniCode_idx++;
			} else {
				break;
			}
		}
		a = a.replaceAll("u0023", "#");

		s.append(a);

		return s.toString();
	}

	public void set_VR_STR(String s) {
		this.VR_STR = s;
	}

	public static String get_VR_STR() {
		return VR_STR;
	}
}
