package kr.co.kihyun.text.hml; import java.util.Vector; public class Hwp97Deci { public static final int INITIAL_SIZE = 0; private static int POSX = 0; private static int POSY = 0; private static int VALUE1 = 0; private static int VALUE2 = 0; public Hwp97Deci() { } // Table Tag // Converter-------------------------------------------------------------------------------------------------- public static String getCODE(String s) { StringBuffer sb = null; StringBuffer html = null; 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; html = new StringBuffer(INITIAL_SIZE); html.append(s); htm_opened = s; // --------------------------------------------------------------------------------------------------------------------- opener_idx1 = html.indexOf(""); opener_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; // HWP97 //////////////////////////// int RowCount[] = new int[10000]; Vector v = new Vector(); boolean INIT_DOING = true; // ///////////////////////////////////// String INNER_TABLE[] = new String[10000]; // HWP97 /////////////////////////////// String TABLE[] = new String[10000]; // ///////////////////////////////////////// int i = 0; while (true) { inner_table_serch_idx = htm_opened.indexOf("", inner_table_serch_idx); INNER_TABLE[i] = htm_opened.substring(inner_table_serch_idx + 7, inner_table_serch_lidx); htm_opened = htm_opened.replaceFirst(INNER_TABLE[i], "VIRTUAL DATA" + i); // HWP97 // /////////////////////////////////////////////////////////////////////////////////////////////// TABLE[i] = INNER_TABLE[i]; RowCount[i] = TableTagConverter.getRowCount(TABLE[i]); v.addElement(new Integer(RowCount[i])); // ///////////////////////////////////////////////////////////////////////////////////////////////////////// inner_table_serch_idx++; i++; } else break; } xml_body = hwp_COVERTING(htm_opened, v, INIT_DOING); String xml_body_array[] = new String[10000]; for (int j = 0; j < i; j++) { xml_body_array[j] = hwp_COVERTING(TABLE[j], null, false); xml_body = xml_body.replaceFirst("VIRTUAL DATA" + j, xml_body_array[j]); } // HWP97 크기 재조정 -------------------------------------------------------------- xml_body = xml_body.replaceAll("HWIDTH=x0xx", "HWIDTH=" + VALUE1); // ------------------------------------------------------------------------------------- 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; } return sb.toString(); } // COVERTING // --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- public static String hwp_COVERTING(String a, Vector vector, boolean oo) { long time1, time2; time1 = System.currentTimeMillis(); StringBuffer s = new StringBuffer(INITIAL_SIZE); Vector v = vector; boolean INIT_DOING = oo; String html = a; String htm_table_opened = ""; String htm_td_opened = ""; String htm_td_LOADING = ""; String htm_table_closed = ""; String hml_body = ""; String hml_cell_SAVING = ""; String hml_cell_LOADING = ""; String hml_cell_SAVED = ""; String hml_table_closed = ""; int tag_table_idx = 0; int tag_tr_idx = 0; int tag_td_idx = 0; // int tag_td_lidx = 0; int tag_tr_lidx = 0; int tag_table_lidx = 0; int hml_cell_idx = 0; int hml_cell_lidx = 0; int hml_p_lidx = 0; String DATA = ""; int data_serch_idx = 0; html = html.replaceAll("", ""); while (true) { htm_table_opened = ""; // 테이블 open ----------------------------------------------------------------------- tag_table_idx = html.indexOf("", tag_table_idx); htm_table_opened = html.substring(tag_table_idx, tag_table_lidx + 8); if (INIT_DOING) { Hwp97Deci set1 = new Hwp97Deci(); set1.value2(); int HHEIGHT = Hwp97Deci.VALUE2; int HHEIGHT_defaultValue = HHEIGHT; // Default Value ////////////////////////// int HPOSX = 0; int HPOSY = 0; // /////////////////////////////////////////// htm_table_opened = htm_table_opened.replaceAll("", ""); htm_table_opened = htm_table_opened.replaceAll("", "

"); int Tr_idx = 0; int Tr_lidx = 0; String VIRTUAL_STRING1 = ""; String VIRTUAL_STRING2 = ""; String CELL = ""; int i = 0; while (true) { Tr_idx = htm_table_opened.indexOf("", Tr_idx); if (Tr_idx != -1) { Tr_lidx = htm_table_opened.indexOf("", Tr_idx); VIRTUAL_STRING1 = htm_table_opened.substring(Tr_idx + 4, Tr_lidx); VIRTUAL_STRING2 = htm_table_opened.substring(Tr_idx + 4, Tr_lidx); while (true) { tag_td_idx = VIRTUAL_STRING2.indexOf("", ""); // ------------------------------------------------------------------------------------ // htm td태그를 hml cell태그로 replace // ------------------------------------------------------------------------------------ int xx = htm_table_opened.indexOf("colspan"); int yy = htm_table_opened.indexOf("rowspan"); if (xx != -1 || yy != -1) { hml_cell_LOADING = hml_cell_Default_LOADING(RowCount, ColCount); hml_cell_SAVING = hml_SPANING(htm_table_opened, hml_cell_LOADING, ColCount); // row_span / col_span } else { hml_cell_SAVING = hml_cell_Default_LOADING(RowCount, ColCount); // multi_col / multi_row } while (true) { tag_tr_idx = htm_table_opened.indexOf("", tag_tr_idx); if (tag_tr_idx == -1) break; tag_tr_lidx = htm_table_opened.indexOf("", tag_tr_idx); htm_td_opened = htm_table_opened.substring(tag_tr_idx + 4, tag_tr_lidx); while (true) { tag_td_idx = htm_td_opened.indexOf("", tag_td_idx); hml_cell_lidx = htm_td_opened.indexOf("", data_serch_idx + 1); DATA = htm_td_opened.substring(data_serch_idx + 1, hml_cell_lidx); htm_td_LOADING = htm_td_opened.substring(tag_td_idx, data_serch_idx + 1) + DATA; hml_cell_idx = hml_cell_SAVING.indexOf("", hml_cell_idx); int hml_text_lidx = hml_cell_SAVING.indexOf("", data_serch_idx2); String DATA2 = DATA; hml_p_lidx = hml_cell_SAVING.indexOf("

", hml_cell_idx); hml_cell_SAVED = hml_cell_SAVING.substring(hml_cell_idx, data_serch_idx2 + 6) + DATA2 + hml_cell_SAVING.substring(hml_text_lidx, hml_p_lidx + 4); htm_table_opened = htm_table_opened.replaceFirst(htm_td_LOADING, hml_cell_SAVED); tag_td_idx++; hml_cell_idx++; } else break; } tag_tr_idx++; } // htm table태그를 없애기 // ---------------------------------------------------------------------------------------------------- htm_table_opened = htm_table_opened.replaceAll("
", ""); htm_table_opened = htm_table_opened.replaceAll("
", tag_td_idx); if (tag_td_idx != -1) { if (v != null) { Integer ROWSPAN = (Integer) v.elementAt(i); HHEIGHT = HHEIGHT_defaultValue * ROWSPAN.intValue(); CELL = "

"; VIRTUAL_STRING2 = VIRTUAL_STRING2.replaceFirst("

", CELL); } tag_td_idx++; } else { break; } } htm_table_opened = htm_table_opened.replaceFirst(VIRTUAL_STRING1, VIRTUAL_STRING2); i++; Tr_idx++; } else break; } htm_table_opened = htm_table_opened.replaceAll("", ""); htm_table_opened = htm_table_opened.replaceAll("", "

"); htm_table_opened = htm_table_opened.replaceAll("

", "

"); htm_table_opened = htm_table_opened.replaceAll("
", ""); htm_table_opened = htm_table_opened.replaceAll("", ""); htm_table_opened = htm_table_opened.replaceAll("", ""); int Cell_idx = 0; int Cell_lidx = 0; while (true) { Cell_idx = htm_table_opened.indexOf("", Cell_idx + 1); String Cell = htm_table_opened.substring(Cell_idx, Cell_lidx + 7); htm_table_opened = htm_table_opened.replaceFirst(Cell, ""); } else { break; } } } else { int RowCount = TableTagConverter.getRowCount(htm_table_opened); int ColCount = TableTagConverter.getColCount(htm_table_opened); // htm /td태그를 hml /cell태그로 replace ---------------------------------------- htm_table_opened = htm_table_opened.replaceAll("
", ""); // -------------------------------------------------------------------------------------------------------------------------------- // htm tr태그를 없애기 ------------------------------------------------- htm_table_opened = htm_table_opened.replaceAll("", ""); // ------------------------------------------------------------------------- // htm /tr태그를 없애기 ------------------------------------------------- htm_table_opened = htm_table_opened.replaceAll("", ""); // -------------------------------------------------------------------------- // htm /table태그를 없애기 -------------------------------------------------- htm_table_opened = htm_table_opened.replaceAll("
", ""); // ------------------------------------------------------------------------------ } // END IF // 특수코드를 특수문자로 replace ---------------------------------------------------------- //46.메소드이름 생성규칙 위반 Update by YOUNGJUN,CHO //htm_table_opened = TableTagConverter.CODE_SPECIALING(htm_table_opened); htm_table_opened = TableTagConverter.codeSpecialing(htm_table_opened); //================================================ // ---------------------------------------------------------------------------------------------- // 테이블 close ---------------------------------------------------- htm_table_closed = htm_table_closed + htm_table_opened; // ------------------------------------------------------------------- tag_table_idx++; } // 97기능판, 2002, 2002SE 상호 호환을 위한 코드///////////////////////////////////////////////////// String htm_table_Completely_disappeared = htm_table_closed; htm_table_Completely_disappeared = htm_table_Completely_disappeared.replace('\n', ' '); // ////////////////////////////////////////////////////////////////////////////////////////////////////////// hml_table_closed = hml_table_closed + htm_table_Completely_disappeared; hml_body = hml_table_closed; s.append(hml_body); time2 = System.currentTimeMillis(); return s.toString(); } // TD 생성기-------------------------------------------------------------------------- public static String makeTD(String a, int b) { StringBuffer s = new StringBuffer(INITIAL_SIZE); int t = 0; int u = 0; int c = 0; int r = 0; int q = 0; String T = ""; String R = ""; while (true) { t = a.indexOf("", t); T = a.substring(t, u); c = TableTagConverter.getColCount(T); if (b == c && c != 1) { s.append(T); s.append(""); s.append("RLINE=0"); for (int j = 0; j < b - 2; j++) { s.append("LLINE=0 RLINE=0"); } s.append("LLINE=0"); s.append(""); } else if (b > c) { boolean TRUE = true; s.append(""); while (true) { r = T.indexOf("", r); if (r == -1) break; q = T.indexOf("", r); R = T.substring(r, q); if ((b - c) != 1) { if (TRUE) { s.append(R); s.append(""); for (int j = 0; j < b - c - 2; j++) { s.append(""); } s.append(""); s.append(""); } else { s.append(R); s.append(""); for (int j = 0; j < b - c - 2; j++) { s.append(""); } s.append(""); s.append(""); } } else { if (TRUE) { s.append(R); s.append(""); s.append(""); } else { s.append(R); s.append(""); s.append(""); } } r++; TRUE = false; } s.append(""); s.append(""); for (int j = 0; j < c - 1; j++) { s.append(""); } for (int j = 0; j < b - c - 1; j++) { s.append(""); } s.append(""); s.append(""); } else { s.append(T); } s.append("
RLINE=0 BLINE=0LLINE=0 RLINE=0 BLINE=0LLINE=0 BLINE=0
RLINE=0 TLINE=0 BLINE=0LLINE=0 RLINE=0 TLINE=0 BLINE=0LLINE=0 TLINE=0 BLINE=0
BLINE=0
TLINE=0 BLINE=0
RLINE=0LLINE=0 RLINE=0LLINE=0 RLINE=0 TLINE=0LLINE=0 TLINE=0
"); t++; } return s.toString(); } // hml cell Default LOADER // --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- public static String hml_cell_Default_LOADING(int a, int b) { StringBuffer s = new StringBuffer(INITIAL_SIZE); String DATA = ""; int RowCount = a; int ColCount = b; int DefaultWidth = 0; int DefaultHeight = 0; // 크기조정 ///////////////////// Hwp97Deci set2 = new Hwp97Deci(); set2.value1(b); set2.value2(); DefaultWidth = Hwp97Deci.VALUE1; DefaultHeight = Hwp97Deci.VALUE2; // //////////////////////////////// // 한글97 X,Y, 초기화 //////// Hwp97Deci Hx = new Hwp97Deci(); Hx.setPOSX(DefaultWidth); Hwp97Deci Hy = new Hwp97Deci(); Hy.setPOSY(DefaultHeight); // ////////////////////////////// for (int i = 0; i < RowCount; i++) { for (int j = 0; j < ColCount; j++) { s.append("

"); DATA = " "; // DATA 값 초기화 s.append(DATA); s.append("

\n"); } } return s.toString(); } // SPANING // -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- public static String hml_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 DefaultWidth = 0; int DefaultHeight = 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; DefaultWidth = Hwp97Deci.getPOSX(); DefaultHeight = Hwp97Deci.getPOSY(); TableTagConverter TTC = new TableTagConverter(); TTC.set_VR_STR(b); while (true) { r = a.indexOf("", r); v = ""; v1 = ""; v2 = ""; v3 = ""; v4 = ""; v5 = ""; v6 = ""; v7 = ""; v8 = ""; e = ""; e1 = ""; e2 = ""; e3 = ""; t = 0; if (r == -1) break; u = a.indexOf("", r); v = a.substring(r + 4, u); while (true) { t = v.indexOf("", 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 = TableTagConverter.get_VR_STR(); J_init_idx1 = b.indexOf("", o); v3 = b.substring(o, p + 4); 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 = TableTagConverter.get_VR_STR(); J_init_idx2 = b.indexOf("", c1); v4 = b.substring(c1, d1); b = b.replaceAll(v4, e1); for (int q = 1; q < RowSpan; q++) { RowAddr = i + q; o1 = b.indexOf("", o1); v5 = b.substring(o1, p1 + 4); 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 = TableTagConverter.get_VR_STR(); J_init_idx3 = b.indexOf("", c2); v6 = b.substring(c2, d2); 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 /* if (q1 == 0 & q2 == 0) { } else { int o2 = b.indexOf("", o2); v7 = b.substring(o2, p2 + 4); b = b.replaceAll(v7, ""); } */ //------------------------------------------------ //42.비어있는 if문 : Add by YOUNGJUN,CHO if (q1 != 0 || q2 != 0) { int o2 = b.indexOf("", o2); v7 = b.substring(o2, p2 + 4); b = b.replaceAll(v7, ""); } //++++++++++++++++++++++++++++++++++++++++++++++++ } // end inner for } // end outer for } else { b = TableTagConverter.get_VR_STR(); J_init_idx4 = b.indexOf("