Java tutorial
package com.devpia.service; import java.io.File; import java.io.IOException; import java.math.BigDecimal; import java.net.URLDecoder; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.io.FileUtils; import org.apache.commons.io.filefilter.DirectoryFileFilter; import org.apache.commons.io.filefilter.FileFilterUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; import devpia.dextupload.DEXTUploadException; import devpia.dextupload.FileDownload; import devpia.dextupload.FileItem; import devpia.dextupload.FileUpload; import egovframework.let.ngi.chg.service.ChangeInfoService; import egovframework.let.ngi.chg.service.ChangeSttemntInfoVO; import egovframework.let.ngi.chg.service.TnAtchmnflVO; import egovframework.let.ngi.chg.service.impl.TnAtchmnflService; import egovframework.rte.fdl.property.EgovPropertyService; /** * DEXTUploadJ ? / . * @author devpia * */ @Controller public class DEXTUploadJController { @Resource(name = "propertiesService") protected EgovPropertyService propertyService; protected Log log = LogFactory.getLog(this.getClass()); @Resource(name = "tnAtchmnflService") private TnAtchmnflService tnAtchmnflService; @Resource(name = "changeInfoService") private ChangeInfoService changeInfoService; private String fileSaveSubPath = "\\dext\\"; private String getUploadDirectory() { String fileSavePath = null; fileSavePath = propertyService.getString("Globals.fileStorePath"); fileSavePath = fileSavePath.concat(fileSaveSubPath); File saveFolder = new File(fileSavePath); if (!saveFolder.exists() || saveFolder.isFile()) { saveFolder.mkdirs(); } return fileSavePath; } /** * ? ? ? virtual.up ? ? ?? * ??? ? ??(?) ?? ?. * @param req HttpServletRequest ? * @param res HttpServletResponse ? * @throws Exception */ @RequestMapping(value = "/virtual.up", method = RequestMethod.POST) public void uploadVirtualDeleted(HttpServletRequest req, HttpServletResponse res) throws Exception { req.setCharacterEncoding("utf-8"); res.setContentType("text/plain"); res.setCharacterEncoding("utf-8"); FileUpload dextj = new FileUpload(req, res); String appRootPath = null; // ?? ?? ? ?? ? . // ? OS ? ? . (, ?/ .) File temp = new File(getUploadDirectory()); File repository = new File(getUploadDirectory()); try { // ?/ ? ?? . if (!temp.exists() || !temp.canRead() || !temp.canWrite()) { throw new Exception( " ?? ?/ ? ."); } // ? ?/ ? ?? . if (!repository.exists() || !repository.canRead() || !repository.canWrite()) { throw new Exception( "? ?? ?/ ? ."); } // DEXTUploadJ ?? ?(dextuploadj.config)? ?? ? ? . // ? ? . appRootPath = req.getSession().getServletContext().getRealPath("/") + "/"; dextj.setLicenseFilePath(appRootPath.concat("dextuploadj.config")); // ? . // ?? . dextj.UploadStart(temp.getAbsolutePath()); // ? ? ?? . // "DEXTUploadNX_VirtualDeleted"? DEXTUploadNX? ? ? ?? ? . StringBuilder sb = new StringBuilder(); res.setContentType("text/plain"); String[] deletedVirtualFileKeys = dextj.getParameterValues("DEXTUploadNX_VirtualDeleted"); if (deletedVirtualFileKeys != null && deletedVirtualFileKeys.length > 0) { boolean first = true; for (String value : deletedVirtualFileKeys) { if (first == true) { sb.append(value); first = false; } else { sb.append(", ".concat(value)); } } res.getWriter().write("Deleted files: ".concat(sb.toString())); } else { res.getWriter().write("Deleted files do not exist."); } } catch (DEXTUploadException ex) { throw new Exception(" ? .", ex); } catch (Exception ex) { throw new Exception(" ? .", ex); } finally { // ? ??? . // ?? ? ? . dextj.dispose(); } } /** * ? ? ? virtual.up ? ? ?? * ??? ? ??(?) ?? ?. * @param req HttpServletRequest ? * @param res HttpServletResponse ? * @throws Exception */ @RequestMapping(value = "/virtual2.up", method = RequestMethod.POST) public void uploadVirtualDeleted2(HttpServletRequest req, HttpServletResponse res) throws Exception { req.setCharacterEncoding("utf-8"); res.setContentType("text/plain"); res.setCharacterEncoding("utf-8"); FileUpload dextj = new FileUpload(req, res); String appRootPath = null; // ?? ?? ? ?? ? . // ? OS ? ? . (, ?/ .) File temp = new File(getUploadDirectory()); File repository = new File(getUploadDirectory()); try { // ?/ ? ?? . if (!temp.exists() || !temp.canRead() || !temp.canWrite()) { throw new Exception( " ?? ?/ ? ."); } // ? ?/ ? ?? . if (!repository.exists() || !repository.canRead() || !repository.canWrite()) { throw new Exception( "? ?? ?/ ? ."); } // DEXTUploadJ ?? ?(dextuploadj.config)? ?? ? ? . // ? ? . appRootPath = req.getSession().getServletContext().getRealPath("/") + "/"; dextj.setLicenseFilePath(appRootPath.concat("dextuploadj.config")); // ? . // ?? . dextj.UploadStart(temp.getAbsolutePath()); // ? ? ?? . // "DEXTUploadNX_VirtualDeleted"? DEXTUploadNX? ? ? ?? ? . StringBuilder sb = new StringBuilder(); res.setContentType("text/plain"); String[] deletedVirtualFileKeys = dextj.getParameterValues("DEXTUploadNX_VirtualDeleted"); if (deletedVirtualFileKeys != null && deletedVirtualFileKeys.length > 0) { boolean first = true; for (String value : deletedVirtualFileKeys) { if (first == true) { sb.append(value); first = false; } else { sb.append(", ".concat(value)); } } res.getWriter().write("Deleted files: ".concat(sb.toString())); } else { res.getWriter().write("Deleted files do not exist."); } } catch (DEXTUploadException ex) { throw new Exception(" ? .", ex); } catch (Exception ex) { throw new Exception(" ? .", ex); } finally { // ? ??? . // ?? ? ? . dextj.dispose(); } } /** * ? ? ? upload.up ? ? ?? * ??? ? ??(?) ?? . * @param req HttpServletRequest ? * @param res HttpServletResponse ? * @throws Exception */ @RequestMapping(value = "/cntrwkFileUpManage_upload.up", method = RequestMethod.POST) public void upload(HttpServletRequest req, HttpServletResponse res, @RequestParam(value = "changeInfoId", required = true) String changeInfoId, @RequestParam(value = "fileType", required = true) String fileType) throws Exception { req.setCharacterEncoding("utf-8"); FileUpload dextj = new FileUpload(req, res); String appRootPath = null; // ?? ?? ? ?? ? . // ? OS ? ? . (, ?/ .) File temp = new File(getUploadDirectory()); File repository = new File(getUploadDirectory()); try { // ?/ ? ?? . if (!temp.exists() || !temp.canRead() || !temp.canWrite()) { throw new Exception( " ?? ?/ ? ."); } // ? ?/ ? ?? . if (!repository.exists() || !repository.canRead() || !repository.canWrite()) { throw new Exception( "? ?? ?/ ? ."); } // DEXTUploadJ ?? ?(dextuploadj.config)? ?? ? ? . // ? ? . appRootPath = req.getSession().getServletContext().getRealPath("/") + "/"; dextj.setLicenseFilePath(appRootPath.concat("dextuploadj.config")); // ? . // ?? . dextj.UploadStart(temp.getAbsolutePath()); File targetFolder = null; // "DEXTUploadNX_EmptyFolderPath"? DEXTUploadNX? ? ??() ? . String[] emptyFolderNames = dextj.getParameterValues("DEXTUploadNX_EmptyFolderPath"); if (emptyFolderNames == null) emptyFolderNames = new String[0]; for (String nextName : emptyFolderNames) { targetFolder = new File(repository, nextName); if (!targetFolder.exists()) targetFolder.mkdir(); } // "DEXTUploadNX_FolderPath"? DEXTUploadNX? ? ??() ? . String[] folderNames = dextj.getParameterValues("DEXTUploadNX_FolderPath"); if (folderNames == null) folderNames = new String[0]; // "DEXTUploadNX"? DEXTUploadNX? ? ? ?? . FileItem[] fileItems = dextj.getFileItemValues("DEXTUploadNX"); if (fileItems == null) fileItems = new FileItem[0]; // "DEXTUploadNX_FolderPath", "DEXTUploadNX" ? ? ?? ?? ?? ? ?. for (int i = 0; i < folderNames.length; i++) { targetFolder = new File(repository, folderNames[i]); if (!targetFolder.exists()) targetFolder.mkdir(); if (fileItems[i].IsUploaded()) { fileItems[i].SaveAs(targetFolder.getAbsolutePath(), changeInfoId + "_" + fileItems[i].getFileName(), true); TnAtchmnflVO tnAtchmnflVO = getTnAtchmnflVOFromFileItem(fileItems[i], changeInfoId, fileType); tnAtchmnflService.deleteTnAtchmnfl(tnAtchmnflVO); tnAtchmnflService.insertTnAtchmnfl(tnAtchmnflVO); } } } catch (DEXTUploadException ex) { throw new Exception(" ? .", ex); } catch (Exception ex) { throw new Exception(" ? .", ex); } finally { // ? ??? . // ?? ? ? . dextj.dispose(); } } private TnAtchmnflVO getTnAtchmnflVOFromFileItem(FileItem fileItem, String changeInfoId, String fileType) throws Exception { TnAtchmnflVO tnAtchmnflVO = new TnAtchmnflVO(); tnAtchmnflVO.setChangeInfoId(new BigDecimal(changeInfoId)); // . tnAtchmnflVO.setFileNm(fileItem.getFileName()); //? tnAtchmnflVO.setFileMg(String.valueOf(fileItem.length())); // ? ? tnAtchmnflVO.setFlpthNm(fileItem.getLastSavedFileName()); // ?. tnAtchmnflVO.setFileFomCodeTy(fileType); // ??, (CHG014, 01?, 02. /?, 03. ? return tnAtchmnflVO; } /** * ? ? ? userdata.up ? ? ?? * ??? ? ??(?) ?? . * @param req HttpServletRequest ? * @param res HttpServletResponse ? * @throws Exception */ @RequestMapping(value = "/userdata.up", method = RequestMethod.POST) public void uploadUserData(HttpServletRequest req, HttpServletResponse res) throws Exception { req.setCharacterEncoding("utf-8"); res.setContentType("text/plain"); res.setCharacterEncoding("utf-8"); FileUpload dextj = new FileUpload(req, res); String appRootPath = null; // ?? ?? ? ?? ? . // ? OS ? ? . (, ?/ .) File temp = new File(getUploadDirectory()); File repository = new File(getUploadDirectory()); try { // ?/ ? ?? . if (!temp.exists() || !temp.canRead() || !temp.canWrite()) { throw new Exception( " ?? ?/ ? ."); } // ? ?/ ? ?? . if (!repository.exists() || !repository.canRead() || !repository.canWrite()) { throw new Exception( "? ?? ?/ ? ."); } // DEXTUploadJ ?? ?(dextuploadj.config)? ?? ? ? . // ? ? . appRootPath = req.getSession().getServletContext().getRealPath("/") + "/"; dextj.setLicenseFilePath(appRootPath.concat("dextuploadj.config")); // ? . // ?? . dextj.UploadStart(temp.getAbsolutePath()); // "DEXTUploadNX_UserData"? DEXTUploadNX? ? ? ? ? ?? ? . String[] userData = dextj.getParameterValues("DEXTUploadNX_UserData"); if (userData == null) userData = new String[0]; // "DEXTUploadNX"? DEXTUploadNX? ? ? ?? . FileItem[] fileItems = dextj.getFileItemValues("DEXTUploadNX"); if (fileItems == null) fileItems = new FileItem[0]; // "DEXTUploadNX_UserData", "DEXTUploadNX" ? ? ?? ?? ? ?. StringBuilder sb = new StringBuilder(); for (int i = 0; i < fileItems.length; i++) { if (fileItems[i].IsUploaded()) { fileItems[i].Save(repository.getAbsolutePath(), true); sb.append("file: ".concat(fileItems[i].getLastSavedFileName()).concat(", user-data: ") .concat(userData[i])); } else { sb.append("file: ".concat(fileItems[i].getFileName()).concat(", user-data: ") .concat(userData[i])); } } res.getWriter().write(sb.toString()); } catch (DEXTUploadException ex) { throw new Exception(" ? .", ex); } catch (Exception ex) { throw new Exception(" ? .", ex); } finally { // ? ??? . // ?? ? ? . dextj.dispose(); } } /** * ? ? ? formdata.up ? ? ?? * ??? ? ??(?) ?? . * @param req HttpServletRequest ? * @param res HttpServletResponse ? * @throws Exception */ @RequestMapping(value = "/formdata.up", method = RequestMethod.POST) public void uploadFormData(HttpServletRequest req, HttpServletResponse res) throws Exception { req.setCharacterEncoding("utf-8"); res.setContentType("text/plain"); res.setCharacterEncoding("utf-8"); FileUpload dextj = new FileUpload(req, res); String appRootPath = null; // ?? ?? ? ?? ? . // ? OS ? ? . (, ?/ .) File temp = new File(getUploadDirectory()); File repository = new File(getUploadDirectory()); try { // ?/ ? ?? . if (!temp.exists() || !temp.canRead() || !temp.canWrite()) { throw new Exception( " ?? ?/ ? ."); } // ? ?/ ? ?? . if (!repository.exists() || !repository.canRead() || !repository.canWrite()) { throw new Exception( "? ?? ?/ ? ."); } // DEXTUploadJ ?? ?(dextuploadj.config)? ?? ? ? . // ? ? . appRootPath = req.getSession().getServletContext().getRealPath("/") + "/"; dextj.setLicenseFilePath(appRootPath.concat("dextuploadj.config")); // ? . // ?? . dextj.UploadStart(temp.getAbsolutePath()); // "DEXTUploadNX"? DEXTUploadNX? ? ? ?? . FileItem[] fileItems = dextj.getFileItemValues("DEXTUploadNX"); if (fileItems == null) fileItems = new FileItem[0]; // ? ?? . for (FileItem item : fileItems) { if (item.IsUploaded()) { item.Save(repository.getAbsolutePath(), true); } } String autoForm1Value = dextj.getParameter("auto_include_form1"); String autoForm2Value = dextj.getParameter("auto_include_form2"); String userForm1Value = dextj.getParameter("UserForm1"); String userForm2Value = dextj.getParameter("UserForm2"); if (autoForm1Value == null) autoForm1Value = ""; if (autoForm2Value == null) autoForm2Value = ""; if (userForm1Value == null) userForm1Value = ""; if (userForm2Value == null) userForm2Value = ""; res.getWriter() .write("[Webformname : auto_include_form1, formvalue: ".concat(autoForm1Value).concat("]")); res.getWriter() .write("[Webformname : auto_include_form2, formvalue: ".concat(autoForm2Value).concat("]")); res.getWriter().write("[forname : UserForm1, formvalue: ".concat(userForm1Value).concat("]")); res.getWriter().write("[forname : UserForm2, formvalue: ".concat(userForm2Value).concat("]")); } catch (DEXTUploadException ex) { throw new Exception(" ? .", ex); } catch (Exception ex) { throw new Exception(" ? .", ex); } finally { // ? ??? . // ?? ? ? . dextj.dispose(); } } /** * ? ? ? exifdata.up ? ? ?? * ??? ? ??(?) ?? . * @param req HttpServletRequest ? * @param res HttpServletResponse ? * @throws Exception */ @RequestMapping(value = "/exifdata.up", method = RequestMethod.POST) public void uploadExifData(HttpServletRequest req, HttpServletResponse res) throws Exception { req.setCharacterEncoding("utf-8"); res.setContentType("text/plain"); res.setCharacterEncoding("utf-8"); FileUpload dextj = new FileUpload(req, res); String appRootPath = null; // ?? ?? ? ?? ? . // ? OS ? ? . (, ?/ .) File temp = new File(getUploadDirectory()); File repository = new File(getUploadDirectory()); try { // ?/ ? ?? . if (!temp.exists() || !temp.canRead() || !temp.canWrite()) { throw new Exception( " ?? ?/ ? ."); } // ? ?/ ? ?? . if (!repository.exists() || !repository.canRead() || !repository.canWrite()) { throw new Exception( "? ?? ?/ ? ."); } // DEXTUploadJ ?? ?(dextuploadj.config)? ?? ? ? . // ? ? . appRootPath = req.getSession().getServletContext().getRealPath("/") + "/"; dextj.setLicenseFilePath(appRootPath.concat("dextuploadj.config")); // ? . // ?? . dextj.UploadStart(temp.getAbsolutePath()); // "DEXTUploadNX"? DEXTUploadNX? ? ? ?? . FileItem[] fileItems = dextj.getFileItemValues("DEXTUploadNX"); if (fileItems == null) fileItems = new FileItem[0]; // "DEXTUploadNX_ExifData"? DEXTUploadNX? ? EXIF ?? . String[] exifData = dextj.getParameterValues("DEXTUploadNX_ExifData"); if (exifData == null) exifData = new String[0]; // ? ?? . for (int i = 0; i < fileItems.length; i++) { if (fileItems[i].IsUploaded()) { fileItems[i].Save(repository.getAbsolutePath(), true); res.getWriter().write("Save : ".concat(fileItems[i].getFileName())); } if (exifData[i] != null && exifData[i].length() > 0) { res.getWriter().write("[SPLIT]"); res.getWriter().write(exifData[i]); } res.getWriter().write("[SPLIT]"); } } catch (DEXTUploadException ex) { throw new Exception(" ? .", ex); } catch (Exception ex) { throw new Exception(" ? .", ex); } finally { // ? ??? . // ?? ? ? . dextj.dispose(); } } /** * ? ? ? response.up ? ? ?? * ??? ? ??(?) ?? . * @param req HttpServletRequest ? * @param res HttpServletResponse ? * @throws Exception */ @RequestMapping(value = "/response.up", method = RequestMethod.POST) public void uploadResponse(HttpServletRequest req, HttpServletResponse res) throws Exception { req.setCharacterEncoding("utf-8"); res.setContentType("text/plain"); res.setCharacterEncoding("utf-8"); FileUpload dextj = new FileUpload(req, res); String appRootPath = null; // ?? ?? ? ?? ? . // ? OS ? ? . (, ?/ .) File temp = new File(getUploadDirectory()); File repository = new File(getUploadDirectory()); try { // ?/ ? ?? . if (!temp.exists() || !temp.canRead() || !temp.canWrite()) { throw new Exception( " ?? ?/ ? ."); } // ? ?/ ? ?? . if (!repository.exists() || !repository.canRead() || !repository.canWrite()) { throw new Exception( "? ?? ?/ ? ."); } // DEXTUploadJ ?? ?(dextuploadj.config)? ?? ? ? . // ? ? . appRootPath = req.getSession().getServletContext().getRealPath("/") + "/"; dextj.setLicenseFilePath(appRootPath.concat("dextuploadj.config")); // ? . // ?? . dextj.UploadStart(temp.getAbsolutePath()); File targetFolder = null; StringBuilder responseData = new StringBuilder(); // "DEXTUploadNX_EmptyFolderPath"? DEXTUploadNX? ? ??() ? . String[] emptyFolderNames = dextj.getParameterValues("DEXTUploadNX_EmptyFolderPath"); if (emptyFolderNames == null) emptyFolderNames = new String[0]; for (String nextName : emptyFolderNames) { targetFolder = new File(repository, nextName); if (!targetFolder.exists()) { targetFolder.mkdir(); responseData.append("Create Folder : ".concat(targetFolder.getName())); responseData.append("[SPLIT]"); } else { responseData.append("Existing Folder : ".concat(targetFolder.getName())); responseData.append("[SPLIT]"); } } // "DEXTUploadNX_FolderPath"? DEXTUploadNX? ? ??() ? . String[] folderNames = dextj.getParameterValues("DEXTUploadNX_FolderPath"); if (folderNames == null) folderNames = new String[0]; // "DEXTUploadNX"? DEXTUploadNX? ? ? ?? . FileItem[] fileItems = dextj.getFileItemValues("DEXTUploadNX"); if (fileItems == null) fileItems = new FileItem[0]; // "DEXTUploadNX_FolderPath", "DEXTUploadNX" ? ? ?? ?? ?? ? ?. for (int i = 0; i < folderNames.length; i++) { targetFolder = new File(repository, folderNames[i]); if (!targetFolder.exists()) { targetFolder.mkdir(); responseData.append("Create Folder : ".concat(targetFolder.getName())); responseData.append("[SPLIT]"); } else { responseData.append("Existing Folder : ".concat(targetFolder.getName())); responseData.append("[SPLIT]"); } if (fileItems[i].IsUploaded()) { fileItems[i].Save(targetFolder.getAbsolutePath(), true); responseData.append("Save file : ".concat(fileItems[i].getLastSavedFileName())); responseData.append("[SPLIT]"); } } res.getWriter().write(responseData.toString()); } catch (DEXTUploadException ex) { throw new Exception(" ? .", ex); } catch (Exception ex) { throw new Exception(" ? .", ex); } finally { // ? ??? . // ?? ? ? . dextj.dispose(); } } /** * ? ? ? behind.down ? ? ?? * ??? ??(?) . * @param req HttpServletRequest ? * @param res HttpServletResponse ? * @throws Exception */ @RequestMapping(value = "/behind.down", method = RequestMethod.GET) public void download(HttpServletRequest req, HttpServletResponse res, @RequestParam(value = "atchmnflId") String atchmnflId, @RequestParam(value = "changeInfoId") String changeInfoId) throws Exception { req.setCharacterEncoding("utf-8"); // UTF-8 ? ?? QueryString ? . //String filename = new String(req.getParameter("DownloadInfo").getBytes("8859_1"), "utf-8"); FileDownload dextj = new FileDownload(req, res); // ?? ? . // ? . // File repository = new File(req.getSession().getServletContext().getRealPath("/Datas/")); File repository = new File(getUploadDirectory()); TnAtchmnflVO searchVo = new TnAtchmnflVO(); searchVo.setAtchmnflId(new BigDecimal(atchmnflId)); searchVo.setChangeInfoId(new BigDecimal(changeInfoId)); TnAtchmnflVO fileVO = tnAtchmnflService.selectTnAtchmnfl(searchVo); String filename = fileVO.getFlpthNm(); try { // ? ? ? ?? . if (!repository.exists() || !repository.canRead()) { throw new Exception( "? ? ? ."); } File target = new File(repository, filename); if (target.exists()) { dextj.Download(target.getAbsolutePath(), true, false); } else { res.sendError(404, filename.concat(" not found")); } } catch (DEXTUploadException ex) { throw new IOException(" ? .", ex); } catch (Exception ex) { throw new IOException(" ? .", ex); } finally { } } /** ? */ @RequestMapping(value = "/cntrwkFileUpManage_delete.down", method = RequestMethod.POST) public void cntrwkFileUpManage_delete(HttpServletRequest req, HttpServletResponse res, @RequestParam(value = "fileType") String fileType, @RequestParam(value = "changeInfoId") String changeInfoId, @RequestParam(value = "fileName") String fileName, @RequestParam(value = "atchmnflId") String atchmnflId) throws Exception { req.setCharacterEncoding("utf-8"); res.setContentType("text/html; charset=UTF-8"); TnAtchmnflVO vo = new TnAtchmnflVO(); vo.setChangeInfoId(new BigDecimal(changeInfoId)); vo.setFileFomCodeTy(fileType); vo.setFileNm(fileName); vo.setAtchmnflId(new BigDecimal(atchmnflId)); tnAtchmnflService.deleteTnAtchmnfl(vo); } /* @RequestMapping(value="/dextfile/downloadFile/{filePath}/{fileName}/down.do", method=RequestMethod.GET) public ModelAndView downloadFile(@PathVariable("filePath") String filePath , @PathVariable("fileName") String fileName , HttpServletRequest request, HttpServletResponse res, ModelMap model) throws Exception { request.setCharacterEncoding("utf-8"); res.setContentType("text/html; charset=UTF-8"); filePath = new String(filePath.getBytes("8859_1"), "utf-8"); fileName = new String(fileName.getBytes("8859_1"), "utf-8"); //System.err.println(filePath); //System.err.println(fileName); filePath = StringUtils.replace(filePath, "__", File.separatorChar+""); String fileExt = StringUtils.split(request.getServletPath(),".")[1]; ModelAndView mav = new ModelAndView("downloadView"); mav.addObject("downloadFile", new File(propertyService.getString("Globals.folderStorePath")+filePath+File.separatorChar+fileName+"."+fileExt)); mav.addObject("fileName", fileName); return mav; } */ @RequestMapping(value = "/dextfile/downloadFile/{filePath}/{fileName}/down.do", method = RequestMethod.GET) public void downloadFile(@PathVariable("filePath") String filePath, @PathVariable("fileName") String fileName, HttpServletRequest request, HttpServletResponse res, ModelMap model) throws Exception { request.setCharacterEncoding("utf-8"); res.setContentType("text/html; charset=UTF-8"); //filePath = new String(filePath.getBytes("8859_1"), "utf-8"); //fileName = new String(fileName.getBytes("8859_1"), "utf-8"); //System.err.println(filePath); //System.err.println(fileName); System.out.println(" ? : " + filePath); String repositoryPath = StringUtils.replace(filePath + fileName, "__", File.separatorChar + ""); System.out.println(" ?: " + repositoryPath); // String repositoryPath =StringUtils.replace( propertyService.getString("Globals.folderStorePath")+filePath+fileName, "__", File.separatorChar+""); // File repository = new File(repositoryPath); // Collection<File> list = FileUtils.listFiles(repository, FileFilterUtils.fileFileFilter(), DirectoryFileFilter.INSTANCE); // ModelAndView mav = new ModelAndView("downloadView"); // mav.addObject("downloadFile", new File(repositoryPath)); // mav.addObject("fileName", fileName); // return mav; FileDownload dextj = new FileDownload(request, res); File target = new File(repositoryPath); if (target.exists()) { dextj.Download(target.getAbsolutePath(), true, false); } else { res.sendError(404, fileName.concat(" not found")); } } @RequestMapping(value = "/dextfile/downloadFile.do", method = RequestMethod.GET) // public ModelAndView downloadFile2(@RequestParam("changeInfoId") String changeInfoId, @RequestParam("idx") String idx public void downloadFile2(HttpServletRequest req, HttpServletResponse res, ModelMap model, @RequestParam("filePath") String filePath, @RequestParam("filename") String filename, @RequestParam Map<String, Object> map) // public void downloadFile2( HttpServletRequest req, HttpServletResponse res, ModelMap model) throws Exception { req.setCharacterEncoding("utf-8"); res.setCharacterEncoding("utf-8"); //System.err.println(new String(req.getParameter("filePath").getBytes("8859_1"), "utf-8") ); //2 // // String filePath = URLDecoder.decode(req.getParameter("filePath"), "UTF-8"); // String filename = URLDecoder.decode(req.getParameter("filename"), "UTF-8"); // String repositoryPath = propertyService.getString("Globals.folderStorePath")+File.separatorChar+changeInfoId+File.separatorChar+idx; String repositoryPath = StringUtils.replace( propertyService.getString("Globals.folderStorePath") + filePath + filename, "__", File.separatorChar + ""); //System.err.println(repositoryPath); // File repository = new File(repositoryPath); // Collection<File> list = FileUtils.listFiles(repository, FileFilterUtils.fileFileFilter(), DirectoryFileFilter.INSTANCE); // ModelAndView mav = new ModelAndView("downloadView"); // mav.addObject("downloadFile", new File(repositoryPath)); // mav.addObject("fileName", filename); // return mav; FileDownload dextj = new FileDownload(req, res); File target = new File(repositoryPath); if (target.exists()) { dextj.Download(target.getAbsolutePath(), true, false); } else { res.sendError(404, filename.concat(" not found")); } } @RequestMapping(value = "/dextfile/selectSubFileList.do", method = RequestMethod.POST, produces = "application/json") @ResponseBody public ModelAndView selectSubFileList2(@RequestParam(value = "idNums", required = true) String idNums, HttpServletRequest request, ModelMap model) throws Exception { ModelAndView mav = new ModelAndView("jsonView"); String[] changeInfoIdArray = idNums.split(","); String[] idxArray = new String[] { "SHP", "NGI_NDA", "DWG_DXF_5", "DWG_DXF_25" }; List<String[]> subFileList = new ArrayList<String[]>(); String repositoryPath = null; File repository = null; for (String changeInfoId : changeInfoIdArray) { String realPath = ""; String filePath = ""; String fileName = ""; String savePath = ""; String saveRealPath = ""; String sjNm = ""; ChangeSttemntInfoVO changeSttemntInfoVO = new ChangeSttemntInfoVO(); changeSttemntInfoVO.setChangeInfoId(Integer.parseInt(changeInfoId)); ChangeSttemntInfoVO resultcvo = changeInfoService.selectChangeSttemntInfo(changeSttemntInfoVO); sjNm = resultcvo.getChangeSj(); for (String idx : idxArray) { repositoryPath = propertyService.getString("Globals.folderStorePath") + File.separatorChar + changeInfoId + File.separatorChar + idx; repository = new File(repositoryPath); log.debug("repositoryPath : " + repositoryPath); Collection<File> list = null; try { list = FileUtils.listFiles(repository, FileFilterUtils.fileFileFilter(), DirectoryFileFilter.INSTANCE); for (File file : list) { if (file.exists()) { fileName = file.getName(); filePath = StringUtils .replace( file.getAbsolutePath() .replace(propertyService.getString("Globals.folderStorePath"), "") .replace(fileName, ""), File.separatorChar + "", "__"); realPath = file.getAbsolutePath().replace(repositoryPath, "").replace(fileName, ""); //savePath = changeInfoId + File.separatorChar + idx+File.separatorChar+""; savePath = changeInfoId + "_" + sjNm + File.separatorChar + idx + File.separatorChar + ""; saveRealPath = StringUtils.replace(filePath, "__", File.separatorChar + ""); subFileList.add(new String[] { realPath, filePath, fileName, String.valueOf(file.length()), savePath, saveRealPath }); } } } catch (Exception e) { //e.printStackTrace(); // ??. } } } mav.addObject("subFileList", subFileList); return mav; } }