export.jsp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <%@ page
  2. contentType="text/html;charset=utf-8"
  3. %><%@page import="java.util.*, java.io.*, java.lang.String, java.text.*" %><%
  4. request.setCharacterEncoding("utf-8");
  5. //------------------------------------
  6. // 0. 파라메터 받음
  7. //------------------------------------
  8. String pOOF = (request.getParameter("oof") == null ? "" : request.getParameter("oof"));
  9. String pFileName = (request.getParameter("filename") == null ? "" : request.getParameter("filename"));
  10. String pFileType = (request.getParameter("filetype") == null ? "" : request.getParameter("filetype"));
  11. //pOOF = "<?xml version='1.0' encoding='utf-8'?><oof version ='3.0'><document enable-thread='0'><file-list><file type='reb' path='http://localhost:8080/RexServer30/rebfiles/samples/xml_customers_orders.reb'></file></file-list><connection-list><connection type='file' namespace='*'><config-param-list><config-param name='path'>http://localhost:8080/RexServer30/rebfiles/samples/sqlserver_customers_orders.xml</config-param></config-param-list><content content-type='xml'><content-param name='root'>{%dataset.xml.root%}</content-param><content-param name='preservedwhitespace'>1</content-param><content-param name='bindmode'>name</content-param></content></connection></connection-list><field-list><field name='한 글 123 abc'><![CDATA[한글 파라메터]]></field></field-list></document></oof>";
  12. //------------------------------------
  13. // 1. 상수 정의
  14. //------------------------------------
  15. String sBasePath = "D:\\rexpert30\\RexServer30\\export\\";
  16. String sExporter = "D:\\rexpert30\\RexServer30\\bin\\export.dos.exe";
  17. String sessionid = session.getId();
  18. Date date = new Date();
  19. //SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
  20. SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
  21. String sDateTime = sdf.format( date);
  22. //String sOOFFileName = sDateTime + "_" + pFileName + "_" + sessionid + ".xml";
  23. //String sExportFileNameSource = sDateTime + "_" + pFileName + "_" + sessionid + "." + pFileType;
  24. //String sExportFileNameTarget = pFileName + "." + pFileType;
  25. String sExportFileName = pFileName + "." + pFileType;
  26. String sOOFFileName = pFileName + ".xml";
  27. //------------------------------------
  28. // 2. OOF, xml data, img 데이터 파일로 저장
  29. //------------------------------------
  30. saveFile(sBasePath + sOOFFileName, pOOF);
  31. //System.out.println(sBasePath + sXmlDataFile);
  32. //saveFile(sBasePath + sXmlDataFile, pData);
  33. //------------------------------------
  34. // 3. pdf파일 export 저장
  35. //------------------------------------
  36. Runtime rt = Runtime.getRuntime();
  37. //System.out.println(pOOF);
  38. //System.out.println(sBasePath + sExportFileNameSource);
  39. try {
  40. Process proc;
  41. //proc = rt.exec(new String[]{sExporter, "load", pOOF, pFileType, sBasePath + sExportFileNameSource});
  42. proc = rt.exec(new String[]{sExporter, "path", sBasePath + sOOFFileName, pFileType, sBasePath + sExportFileName});
  43. proc.waitFor();
  44. } catch(Exception e) {
  45. throw new Exception(e.getMessage());
  46. }
  47. deleteFile(sBasePath + "" + sOOFFileName);
  48. %><%!
  49. //******************************************************************//
  50. // 공통 함수
  51. //******************************************************************//
  52. public void deleteFile(String sFile) {
  53. File file = null;
  54. try {
  55. file = new File(sFile);
  56. if(file.exists()) {
  57. if (!file.delete()) {
  58. System.gc();
  59. Thread.sleep(200);
  60. file.delete();
  61. }
  62. }
  63. } catch(Exception e) {
  64. //
  65. System.out.println(e);
  66. }
  67. }
  68. // 문자열 replace
  69. public String replaceStr(String content, String old_str, String new_str) {
  70. StringBuffer rtn = new StringBuffer();
  71. int from_idx = 0;
  72. int to_idx = 0;
  73. while ((to_idx = content.indexOf(old_str, from_idx)) >= 0) {
  74. rtn.append(content.substring(from_idx, to_idx));
  75. rtn.append(new_str);
  76. from_idx = to_idx + old_str.length();
  77. }
  78. if (from_idx == 0) {
  79. rtn.append(content);
  80. } else if (from_idx < content.length()) {
  81. rtn.append(content.substring(from_idx));
  82. }
  83. return rtn.toString();
  84. } // replaceStr
  85. // 문자열 split
  86. public String[] fnSplit(String sDelimiter, String sValue) {
  87. int index = sValue.indexOf(sDelimiter);
  88. List list = new ArrayList();
  89. int currPos = 0;
  90. int len = sDelimiter.length();
  91. while (index != -1)
  92. {
  93. list.add(sValue.substring(currPos, index));
  94. currPos = index + len;
  95. index = sValue.indexOf(sDelimiter, currPos);
  96. } // end while
  97. list.add(sValue.substring(currPos));
  98. String[] vAddString = (String[]) list.toArray(new String[list.size()]);
  99. return vAddString;
  100. } // fnSplit
  101. // 파일 저장
  102. boolean saveFile(String fileName, String inputString) {
  103. File f = new File(fileName);
  104. ByteArrayInputStream is = null;
  105. FileOutputStream fos= null;
  106. BufferedOutputStream bos = null;
  107. try{
  108. f.createNewFile();
  109. is = new ByteArrayInputStream(inputString.getBytes("UTF-8"));
  110. fos = new FileOutputStream(f);
  111. bos = new BufferedOutputStream(fos);
  112. // 파일에 저장
  113. int su=0;
  114. byte b[] = new byte[512];
  115. while((su=is.read(b)) != -1){
  116. fos.write(b,0,su);
  117. }
  118. }catch(IOException ie){
  119. ie.printStackTrace();
  120. return false; // 예외가 발생하면 실패
  121. }finally{
  122. try {
  123. bos.close();
  124. fos.close();
  125. } catch (IOException e) {}
  126. }
  127. return true;
  128. }
  129. %>