123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- <%@ page
- contentType="text/html;charset=utf-8"
- %><%@page import="java.util.*, java.io.*, java.lang.String, java.text.*" %><%
- request.setCharacterEncoding("utf-8");
-
- //------------------------------------
- // 0. 파라메터 받음
- //------------------------------------
- String pOOF = (request.getParameter("oof") == null ? "" : request.getParameter("oof"));
- String pFileName = (request.getParameter("filename") == null ? "" : request.getParameter("filename"));
- String pFileType = (request.getParameter("filetype") == null ? "" : request.getParameter("filetype"));
-
- //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>";
- //------------------------------------
- // 1. 상수 정의
- //------------------------------------
- String sBasePath = "D:\\rexpert30\\RexServer30\\export\\";
- String sExporter = "D:\\rexpert30\\RexServer30\\bin\\export.dos.exe";
- String sessionid = session.getId();
- Date date = new Date();
- //SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
- SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
- String sDateTime = sdf.format( date);
-
- String sOOFFileName = sDateTime + "_" + pFileName + "_" + sessionid + ".xml";
- String sExportFileNameSource = sDateTime + "_" + pFileName + "_" + sessionid + "." + pFileType;
- String sExportFileNameTarget = pFileName + "." + pFileType;
- //System.out.println(sExportFileNameSource);
- //System.out.println(sExportFileNameTarget);
- //deleteFile(sBasePath + "" + sOOFFileName);
- deleteFile(sBasePath + "" + sExportFileNameSource);
- //------------------------------------
- // 2. OOF, xml data, img 데이터 파일로 저장
- //------------------------------------
- saveFile(sBasePath + sOOFFileName, pOOF);
- //System.out.println(sBasePath + sXmlDataFile);
- //saveFile(sBasePath + sXmlDataFile, pData);
- //------------------------------------
- // 3. pdf파일 export 저장
- //------------------------------------
- Runtime rt = Runtime.getRuntime();
- //System.out.println(pOOF);
- //System.out.println(sBasePath + sExportFileNameSource);
-
- try {
- Process proc;
- //proc = rt.exec(new String[]{sExporter, "load", pOOF, pFileType, sBasePath + sExportFileNameSource});
- proc = rt.exec(new String[]{sExporter, "path", sBasePath + sOOFFileName, pFileType, sBasePath + sExportFileNameSource});
- proc.waitFor();
- } catch(Exception e) {
- throw new Exception(e.getMessage());
- }
- //------------------------------------
- // 4. export 파일 읽어서 전송
- //------------------------------------
- File file = new File(sBasePath + "" + sExportFileNameSource); // 절대경로
- byte b[] = new byte[4062];
- response.reset();
- String strClient=request.getHeader("User-Agent");
- if(strClient.indexOf("MSIE 5.5")>-1)
- {
- response.setContentType("Content-type: application/x-msdownload; charset=euc-kr");
- response.setHeader("Content-Disposition", "attachment;filename="+new String(sExportFileNameTarget.getBytes("utf-8"),"8859_1"));
- } else {
- response.setContentType("Content-type: application/x-msdownload; charset=euc-kr");
- response.setHeader("Content-Disposition", "attachment;filename="+new String(sExportFileNameTarget.getBytes("utf-8"),"8859_1"));
- }
- response.setHeader("Content-Transfer-Encoding", "binary;");
- response.setHeader("Pragma", "no-cache;");
- response.setHeader("Expires", "0;");
- response.setContentLength((int)file.length()); //파일크기를 브라우저에 알려준다.
- // IE 5.5는 형식이 다르므로 헤더를 각각 다르게 처리해 준다.
- if (file.isFile())
- {
- BufferedInputStream fin = new BufferedInputStream(new FileInputStream(file));
- BufferedOutputStream outs = new BufferedOutputStream(response.getOutputStream());
- int read = 0;
- while ((read = fin.read(b)) != -1){
- outs.write(b,0,read);
- outs.flush();
- }
- outs.close();
- fin.close();
- }
-
- file = null;
- //------------------------------------
- // 5. pdf, xml, img 파일 삭제
- //------------------------------------
- deleteFile(sBasePath + "" + sOOFFileName);
- deleteFile(sBasePath + "" + sExportFileNameSource);
- %><%!
- //******************************************************************//
- // 공통 함수
- //******************************************************************//
-
- public void deleteFile(String sFile) {
- File file = null;
-
- try {
- file = new File(sFile);
- if(file.exists()) {
- if (!file.delete()) {
- System.gc();
- Thread.sleep(200);
- file.delete();
- }
- }
- } catch(Exception e) {
- //
- System.out.println(e);
- }
- }
- // 문자열 replace
- public String replaceStr(String content, String old_str, String new_str) {
- StringBuffer rtn = new StringBuffer();
- int from_idx = 0;
- int to_idx = 0;
-
- while ((to_idx = content.indexOf(old_str, from_idx)) >= 0) {
- rtn.append(content.substring(from_idx, to_idx));
- rtn.append(new_str);
- from_idx = to_idx + old_str.length();
- }
-
- if (from_idx == 0) {
- rtn.append(content);
- } else if (from_idx < content.length()) {
- rtn.append(content.substring(from_idx));
- }
-
- return rtn.toString();
- } // replaceStr
- // 문자열 split
- public String[] fnSplit(String sDelimiter, String sValue) {
- int index = sValue.indexOf(sDelimiter);
- List list = new ArrayList();
- int currPos = 0;
- int len = sDelimiter.length();
- while (index != -1)
- {
- list.add(sValue.substring(currPos, index));
- currPos = index + len;
- index = sValue.indexOf(sDelimiter, currPos);
- } // end while
- list.add(sValue.substring(currPos));
- String[] vAddString = (String[]) list.toArray(new String[list.size()]);
- return vAddString;
- } // fnSplit
- // 파일 저장
- boolean saveFile(String fileName, String inputString) {
- File f = new File(fileName);
- ByteArrayInputStream is = null;
- FileOutputStream fos= null;
- BufferedOutputStream bos = null;
- try{
- f.createNewFile();
-
- is = new ByteArrayInputStream(inputString.getBytes("UTF-8"));
-
- fos = new FileOutputStream(f);
- bos = new BufferedOutputStream(fos);
- // 파일에 저장
- int su=0;
- byte b[] = new byte[512];
- while((su=is.read(b)) != -1){
- fos.write(b,0,su);
- }
- }catch(IOException ie){
- ie.printStackTrace();
- return false; // 예외가 발생하면 실패
- }finally{
- try {
- bos.close();
- fos.close();
- } catch (IOException e) {}
- }
- return true;
- }
- %>
|