package seed.com.gtm.util; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.URL; import java.net.URLConnection; import java.net.URLDecoder; import java.net.URLEncoder; import java.util.Date; import org.apache.ibatis.logging.Log; import org.apache.ibatis.logging.LogFactory; import org.jdom.CDATA; import org.jdom.Document; import org.jdom.Element; import org.jdom.output.Format; import org.jdom.output.XMLOutputter; import org.json.JSONObject; import org.json.XML; import egovframework.rte.psl.dataaccess.util.EgovMap; import seed.utils.SeedDateUtil; public class Nanum { protected Log log = LogFactory.getLog(this.getClass()); public static int INDENT_FACTOR=4; public Nanum() throws Exception { } public StringBuilder NanumCall(EgovMap params) throws Exception{ StringBuilder html = new StringBuilder(); String data = ""; String htmlString = ""; JSONObject jsonObj = null; SeedDateUtil seedDateUtil = new SeedDateUtil(); try{ /* * protID * userID * jobID * docID * Document */ String protID = (String) params.get("protID"); String userID = (String) params.get("userID"); String jobID = (String) params.get("jobID"); String docID = (String) params.get("docID"); //실서버 //String nanumSubject = (String)params.get("nanumSubject"); //개발서버 String nanumSubject = URLDecoder.decode((String)params.get("nanumSubject"), "UTF-8"); String nanumProcess = (String) params.get("nanumProcess"); String callUrl = (String) params.get("callUrl"); /* 실서버 String content1 = (String) params.get("content1"); String content2 = (String) params.get("content2"); String content3 = (String) params.get("content3"); String content4 = (String) params.get("content4"); String content5 = (String) params.get("content5"); String content6 = (String) params.get("content6"); String content7 = (String) params.get("content7"); String content8 = (String) params.get("content8"); String content9 = (String) params.get("content9"); String content10 = (String) params.get("content10"); String content11 = (String) params.get("content11"); String content12 = (String) params.get("content12"); String content13 = (String) params.get("content13"); String content14 = (String) params.get("content14"); String content15 = (String) params.get("content15");*/ //개발서버 String content1 = URLDecoder.decode( (String) params.get("content1"), "UTF-8"); String content2 = URLDecoder.decode( (String) params.get("content2"), "UTF-8"); String content3 = URLDecoder.decode( (String) params.get("content3"), "UTF-8"); String content4 = URLDecoder.decode( (String) params.get("content4"), "UTF-8"); String content5 = URLDecoder.decode( (String) params.get("content5"), "UTF-8"); String content6 = URLDecoder.decode( (String) params.get("content6"), "UTF-8"); String content7 = URLDecoder.decode( (String) params.get("content7"), "UTF-8"); String content8 = URLDecoder.decode( (String) params.get("content8"), "UTF-8"); String content9 = URLDecoder.decode( (String) params.get("content9"), "UTF-8"); String content10 = URLDecoder.decode( (String) params.get("content10"), "UTF-8"); String content11 = URLDecoder.decode( (String) params.get("content11"), "UTF-8"); String content12 = URLDecoder.decode( (String) params.get("content12"), "UTF-8"); String content13 = URLDecoder.decode( (String) params.get("content13"), "UTF-8"); String content14 = URLDecoder.decode( (String) params.get("content14"), "UTF-8"); String content15 = URLDecoder.decode( (String) params.get("content15"), "UTF-8"); //xml 생성 Document doc = new Document(); Element exchangeableDocument = new Element("exchangeableDocument"); Element documentInformation = new Element("documentInformation"); Element documentType = new Element("documentType"); //서식코드 Element documentID = new Element("documentID"); //업무시스템에서 만든 문서ID Element createTime = new Element("createTime"); //생성시간 Element modifiedTime = new Element("modifiedTime"); //수정시간 Element createSystem = new Element("createSystem"); //업무시스템명 Element createServer = new Element("createServer"); //업무시스템URL Element creator = new Element("creator"); //업무시스템 문서생성자 Element subject = new Element("subject"); //문서제목 Element processInformation = new Element("processInformation"); Element destinationSystem = new Element("destinationSystem"); //전자결제시스템 Element recipient = new Element("recipient"); //수신자(기안자) Element documentStatus = new Element("documentStatus"); //문서상태(업무시스템에서 처음 보내는 상태일때에는 "createDoc") Element workflow = new Element("workflow"); // Element documentDescription = new Element("documentDescription"); Element work = new Element("work"); // Element work_manage = new Element("work_manage"); // Element job_name = new Element("job_name"); //업무시스템의 절차명 Element dept_name = new Element("dept_name"); //부서명 Element work_ref = new Element("work_ref"); // Element workitem1 = new Element("work_item"); //전달할 인자값 셋팅1 Element workitem2 = new Element("work_item"); //전달할 인자값 셋팅2 Element workitem3 = new Element("work_item"); //전달할 인자값 셋팅3 Element workitem4 = new Element("work_item"); //전달할 인자값 셋팅4 Element workitem5 = new Element("work_item"); //전달할 인자값 셋팅5 Element workitem6 = new Element("work_item"); //전달할 인자값 셋팅6 Element workitem7 = new Element("work_item"); //전달할 인자값 셋팅7 Element workitem8 = new Element("work_item"); //전달할 인자값 셋팅8 Element workitem9 = new Element("work_item"); //전달할 인자값 셋팅9 Element workitem10 = new Element("work_item"); //전달할 인자값 셋팅10 Element workitem11 = new Element("work_item"); //전달할 인자값 셋팅11 Element workitem12 = new Element("work_item"); //전달할 인자값 셋팅12 Element workitem13 = new Element("work_item"); //전달할 인자값 셋팅13 Element workitem14 = new Element("work_item"); //전달할 인자값 셋팅14 Element workitem15 = new Element("work_item"); //전달할 인자값 셋팅15 //계층만들기 exchangeableDocument.addContent(documentInformation); exchangeableDocument.addContent(processInformation); exchangeableDocument.addContent(documentDescription); documentInformation.addContent(documentType); documentInformation.addContent(documentID); documentInformation.addContent(createTime); documentInformation.addContent(modifiedTime); documentInformation.addContent(createSystem); documentInformation.addContent(createServer); documentInformation.addContent(creator); documentInformation.addContent(subject); processInformation.addContent(destinationSystem); processInformation.addContent(recipient); processInformation.addContent(documentStatus); processInformation.addContent(workflow); documentDescription.addContent(work); work.addContent(work_manage); work.addContent(work_ref); work_manage.addContent(job_name); work_manage.addContent(dept_name); work.addContent(workitem1); work.addContent(workitem2); work.addContent(workitem3); work.addContent(workitem4); work.addContent(workitem5); work.addContent(workitem6); work.addContent(workitem7); work.addContent(workitem8); work.addContent(workitem9); work.addContent(workitem10); work.addContent(workitem11); work.addContent(workitem12); work.addContent(workitem13); work.addContent(workitem14); work.addContent(workitem15); documentType.setText(jobID); documentID.setText(docID); createTime.setText(seedDateUtil.getSimpleDateFormat(new Date(), "yyyyMMddHHmmss")); modifiedTime.setText(""); //로컬 //createSystem.setText("case"); //createServer.setText("218.234.66.74"); //개발서버 createSystem.setText("testcase"); createServer.setText("218.234.66.99"); //실서버 //createSystem.setText("newcase"); //createServer.setText("211.245.106.116"); creator.setText(userID); subject.setText(nanumSubject); //실서버 //destinationSystem.setText(URLEncoder.encode("전자결제시스템", "UTF-8")); //개발서버 destinationSystem.setText("전자결제시스템"); recipient.setText(userID); documentStatus.setText(protID); job_name.setText(nanumProcess); //실서버 //dept_name.setText(URLEncoder.encode("부서명", "UTF-8")); //개발서버 dept_name.setText("부서명"); //sContent3_1_3.addContent(); /*workitem1.setAttribute("work_item_code", "1-24-1"); workitem1.setAttribute("work_item_type", "string"); workitem2.setAttribute("work_item_code", "1-24-2"); workitem2.setAttribute("work_item_type", "string"); workitem3.setAttribute("work_item_code", "1-24-3"); workitem3.setAttribute("work_item_type", "string"); workitem4.setAttribute("work_item_code", "1-24-4"); workitem4.setAttribute("work_item_type", "string"); workitem5.setAttribute("work_item_code", "1-24-5"); workitem5.setAttribute("work_item_type", "string");*/ workitem1.setAttribute("work_item_code", jobID+"-1"); workitem1.setAttribute("work_item_type", "string"); workitem2.setAttribute("work_item_code", jobID+"-2"); workitem2.setAttribute("work_item_type", "string"); workitem3.setAttribute("work_item_code", jobID+"-3"); workitem3.setAttribute("work_item_type", "string"); workitem4.setAttribute("work_item_code", jobID+"-4"); workitem4.setAttribute("work_item_type", "string"); workitem5.setAttribute("work_item_code", jobID+"-5"); workitem5.setAttribute("work_item_type", "string"); workitem6.setAttribute("work_item_code", jobID+"-6"); workitem6.setAttribute("work_item_type", "string"); workitem7.setAttribute("work_item_code", jobID+"-7"); workitem7.setAttribute("work_item_type", "string"); workitem8.setAttribute("work_item_code", jobID+"-8"); workitem8.setAttribute("work_item_type", "string"); workitem9.setAttribute("work_item_code", jobID+"-9"); workitem9.setAttribute("work_item_type", "string"); workitem10.setAttribute("work_item_code", jobID+"-10"); workitem10.setAttribute("work_item_type", "string"); workitem11.setAttribute("work_item_code", jobID+"-11"); workitem11.setAttribute("work_item_type", "string"); workitem12.setAttribute("work_item_code", jobID+"-12"); workitem12.setAttribute("work_item_type", "string"); workitem13.setAttribute("work_item_code", jobID+"-13"); workitem13.setAttribute("work_item_type", "string"); workitem14.setAttribute("work_item_code", jobID+"-14"); workitem14.setAttribute("work_item_type", "string"); workitem15.setAttribute("work_item_code", jobID+"-15"); workitem15.setAttribute("work_item_type", "string"); /* */ workitem1.addContent(new CDATA(content1)); workitem2.addContent(new CDATA(content2)); workitem3.addContent(new CDATA(content3)); workitem4.addContent(new CDATA(content4)); workitem5.addContent(new CDATA(content5)); workitem6.addContent(new CDATA(content6)); workitem7.addContent(new CDATA(content7)); workitem8.addContent(new CDATA(content8)); workitem9.addContent(new CDATA(content9)); workitem10.addContent(new CDATA(content10)); workitem11.addContent(new CDATA(content11)); workitem12.addContent(new CDATA(content12)); workitem13.addContent(new CDATA(content13)); workitem14.addContent(new CDATA(content14)); workitem15.addContent(new CDATA(content15)); /* */ //CDATA로 감싸고 싶을 때 //CDATASection cData = doc.createCDATASection("20"); len1.appendChild(cData); //workitem1.appendChild(cData); doc.setRootElement(exchangeableDocument); String document = ""; //try { //FileOutputStream out = new FileOutputStream("d:\\test.xml"); //xml 파일을 떨구기 위한 경로와 파일 이름 지정해 주기 XMLOutputter serializer = new XMLOutputter(); Format f = serializer.getFormat(); f.setEncoding("UTF-8"); //encoding 타입을 UTF-8 로 설정 f.setIndent(" "); f.setLineSeparator("\r\n"); f.setTextMode(Format.TextMode.TRIM); serializer.setFormat(f); //serializer.output(doc, out); //out.flush(); //out.close(); //String으로 xml 출력 XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat().setEncoding("UTF-8")) ; document = outputter.outputString(doc); log.warn("document??????????????????????>>>>>>>>>>>"+document); //}catch (IOException e) { //log.warn(e.toString()); //} data += URLEncoder.encode("protID", "UTF-8")+"="+URLEncoder.encode(protID, "UTF-8"); data += "&"+URLEncoder.encode("userID", "UTF-8")+"="+URLEncoder.encode(userID, "UTF-8"); data += "&"+URLEncoder.encode("jobID", "UTF-8")+"="+URLEncoder.encode(jobID, "UTF-8"); data += "&"+URLEncoder.encode("docID", "UTF-8")+"="+URLEncoder.encode(docID, "UTF-8"); data += "&"+URLEncoder.encode("Document", "UTF-8")+"="+document; //URL url = new URL("http://localhost:8080/receiver.jsp"); URL url = new URL(callUrl); URLConnection conn = url.openConnection(); conn.setDoOutput(true); OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); wr.write(data); wr.flush(); BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8")); for(;;){ String line = rd.readLine(); if(line == null) break; html.append(line.trim().replaceAll(" ||@", "")); } EgovMap emap = new EgovMap(); wr.close(); rd.close(); }catch(Exception e){ } //log.warn("html.toString()??>?>>>>>"+html.toString()); jsonObj = XML.toJSONObject(html.toString()); html = new StringBuilder(); html.append(jsonObj); return html; } }