Java tutorial
/* * Copyright 2010 MOPAS(Ministry of Public Administration and Security). * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package egovframework.oe1.cms.cmm.web; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.net.URLEncoder; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import net.sf.jxls.transformer.XLSTransformer; import org.apache.log4j.Logger; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.ui.ModelMap; import org.springframework.util.FileCopyUtils; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.support.SessionStatus; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springmodules.validation.commons.DefaultBeanValidator; import egovframework.oe1.cms.cmm.service.EgovOe1DicTermService; import egovframework.oe1.cms.cmm.service.EgovOe1DicTermVO; import egovframework.oe1.cms.com.service.EgovOe1CmmUseService; import egovframework.oe1.cms.com.service.EgovOe1ComDefaultCodeVO; //import egovframework.oe1.cms.com.service.EgovOe1FileMngUtil; import egovframework.oe1.cms.com.service.EgovOe1LoginVO; import egovframework.rte.fdl.excel.EgovExcelService; import egovframework.rte.fdl.property.EgovPropertyService; import egovframework.rte.fdl.security.userdetails.util.EgovUserDetailsHelper; import egovframework.rte.ptl.mvc.tags.ui.pagination.PaginationInfo; /** * * - ? controller ? ?. * * ? * - ? ?, , , ? . * - ? ? ?, ? ?. * @author ?1 * @since 2010.08.11 * @version 1.0 * @see * * <pre> * == ?(Modification Information) == * * ? ? * ------- -------- --------------------------- * 2010.08.11 ? * * </pre> */ @Controller public class EgovOe1DicTermController { /** EgovOe1DicTermService */ @Resource(name = "egovOe1DicTermService") private EgovOe1DicTermService egovOe1DicTermService; /** EgovPropertyService */ @Resource(name = "propertiesService") protected EgovPropertyService propertiesService; /** EgovCmmUseService */ @Resource(name = "EgovCmmUseService") public EgovOe1CmmUseService egovCmmUseService; /** Validator */ @Resource(name = "beanValidator") protected DefaultBeanValidator beanValidator; /** * ? */ //@Resource(name = "EgovFileMngUtil") //private EgovOe1FileMngUtil fileUtil; /** * */ /***/ @Resource(name = "excelService") private EgovExcelService excelService; @Resource(name = "propertiesService") protected EgovPropertyService propertyService; Logger log = Logger.getLogger(this.getClass()); /** * ? * @param : EgovOe1DicTermVO * @return : "/cms/cmm/EgovDicTermList" * @exception Exception */ @RequestMapping(value = "/cms/cmm/selectDicTermList.do") public String selectDicTermList(@ModelAttribute("egovOe1DicTermVO") EgovOe1DicTermVO egovOe1DicTermVO, ModelMap model) throws Exception { log.debug(this.getClass().getName() + " ==> ?"); /** EgovPropertyService.egovOe1DicTermService */ egovOe1DicTermVO.setPageUnit(propertiesService.getInt("pageUnit")); egovOe1DicTermVO.setPageSize(propertiesService.getInt("pageSize")); /** pageing setting */ PaginationInfo paginationInfo = new PaginationInfo(); paginationInfo.setCurrentPageNo(egovOe1DicTermVO.getPageIndex()); paginationInfo.setRecordCountPerPage(egovOe1DicTermVO.getPageUnit()); paginationInfo.setPageSize(egovOe1DicTermVO.getPageSize()); egovOe1DicTermVO.setFirstIndex(paginationInfo.getFirstRecordIndex()); egovOe1DicTermVO.setLastIndex(paginationInfo.getLastRecordIndex()); egovOe1DicTermVO.setRecordCountPerPage(paginationInfo.getRecordCountPerPage()); String authorCode = ""; Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated(); if (isAuthenticated) { // ? ? List authorList = EgovUserDetailsHelper.getAuthorities(); for (int i = 0; i < authorList.size(); i++) { if ("ROLE_ADMIN".equals(authorList.get(i).toString())) { authorCode = "ROLE_ADMIN"; break; } } } model.addAttribute("authorCode", authorCode); // List dicTermList = egovOe1DicTermService.selectDicTermList(egovOe1DicTermVO); model.addAttribute("resultList", dicTermList); int totCnt = egovOe1DicTermService.selectDicTermListTot(egovOe1DicTermVO); paginationInfo.setTotalRecordCount(totCnt); model.addAttribute("paginationInfo", paginationInfo); model.addAttribute("resultCnt", totCnt); return "/cms/cmm/EgovDicTermList"; } /** * ? ? . * @param EgovOe1DicTermVO - ? VO * @param model * @return "/cms/cmm/EgovDicTermRegist" * @exception Exception */ @RequestMapping("/cms/cmm/addDicTerm.do") public String addDicTerm(@ModelAttribute("egovOe1DicTermVO") EgovOe1DicTermVO egovOe1DicTermVO, Model model) throws Exception { log.debug(this.getClass().getName() + " ==> ? "); Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated(); if (!isAuthenticated) { return "/cms/com/EgovLoginUsr"; //? ?? } //? ? ??. model.addAttribute("searchMode", egovOe1DicTermVO); return "/cms/cmm/EgovDicTermRegist"; } /** * ? * @param egovOe1DicTermVO - ? VO * @param status * @return "forward:/cms/cmm/selectDicTermList.do" * @exception Exception */ @RequestMapping("/cms/cmm/addDicTermOK.do") public String addDicTermOK(@ModelAttribute("egovOe1DicTermVO") EgovOe1DicTermVO egovOe1DicTermVO, BindingResult bindingResult, Model model, SessionStatus status) throws Exception { log.debug(this.getClass().getName() + " ==> ?"); Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated(); if (!isAuthenticated) { return "/cms/com/EgovLoginUsr"; //? ?? } //? ? ??. model.addAttribute("searchMode", egovOe1DicTermVO); // Server-Side Validation beanValidator.validate(egovOe1DicTermVO, bindingResult); if (bindingResult.hasErrors()) { model.addAttribute("egovOe1DicTermVO", egovOe1DicTermVO); return "/cms/cmm/addDicTerm.do"; } // EgovOe1LoginVO user = (EgovOe1LoginVO) EgovUserDetailsHelper.getAuthenticatedUser(); egovOe1DicTermVO.setFrstRegisterId(user.getMberId()); if (("".equals(egovOe1DicTermVO.getWordDc())) || (egovOe1DicTermVO.getWordDc() == null)) { egovOe1DicTermVO.setWordDc(egovOe1DicTermVO.getWordNm()); } int dup_count = egovOe1DicTermService.dupCheckDicTerm(egovOe1DicTermVO); if (dup_count > 0) { model.addAttribute("resultMsg", "? . ."); return "forward:/cms/cmm/addDicTerm.do"; } egovOe1DicTermService.insertDicTerm(egovOe1DicTermVO); status.setComplete(); if (status.isComplete()) { model.addAttribute("resultMsg", " ? "); } else { model.addAttribute("resultMsg", " ? "); } return "forward:/cms/cmm/selectDicTermList.do"; } /** * ? * @param : EgovOe1DicTermVO * @return : /cms/cmm/EgovDicTermDetail * @Exception Exception */ @RequestMapping("/cms/cmm/selectDicTerm.do") public String selectDicTerm(@RequestParam("selectedId") String selectedId, @ModelAttribute("egovOe1DicTermVO") EgovOe1DicTermVO egovOe1DicTermVO, Model model) throws Exception { log.debug(this.getClass().getName() + " ==> ?"); //? ? ??. model.addAttribute("searchMode", egovOe1DicTermVO); //selectedId VO? . egovOe1DicTermVO.setWordId(selectedId); // ? model.addAttribute("egovOe1DicTermVO", egovOe1DicTermService.selectDicTerm(egovOe1DicTermVO)); return "/cms/cmm/EgovDicTermDetail"; } /** * ? . * @param id - id * @param egovOe1DicTermVO - ? VO * @param model * @return "forward:/cms/cmm/selectDicTermList.do" * @exception Exception */ @RequestMapping("/cms/cmm/updateDicTerm.do") public String updateDicTerm(@RequestParam("selectedId") String selectedId, @ModelAttribute("egovOe1DicTermVO") EgovOe1DicTermVO egovOe1DicTermVO, Model model) throws Exception { log.debug(this.getClass().getName() + " ==> "); Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated(); if (!isAuthenticated) { return "/cms/com/EgovLoginUsr"; //? ?? } //? ? ??. model.addAttribute("searchMode", egovOe1DicTermVO); //selectedId VO? . egovOe1DicTermVO.setWordId(selectedId); //? ? model.addAttribute(egovOe1DicTermService.selectDicTerm(egovOe1DicTermVO)); return "/cms/cmm/EgovDicTermUpdt"; } /** * ? . * @param egovOe1DicTermVO - VO * @param status * @return "forward:/cms/cmm/selectDicTermList.do" * @exception Exception */ @RequestMapping("/cms/cmm/updateDicTermOK.do") public String updateDicTermOK(@RequestParam("selectedId") String selectedId, @ModelAttribute("egovOe1DicTermVO") EgovOe1DicTermVO egovOe1DicTermVO, BindingResult bindingResult, Model model, SessionStatus status) throws Exception { log.debug(this.getClass().getName() + " ==> "); Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated(); if (!isAuthenticated) { return "/cms/com/EgovLoginUsr"; //? ?? } //? ? ??. model.addAttribute("searchMode", egovOe1DicTermVO); beanValidator.validate(egovOe1DicTermVO, bindingResult); if (bindingResult.hasErrors()) { model.addAttribute("egovOe1DicTermVO", egovOe1DicTermVO); return "/cms/cmm/EgovDicTermUpdt"; } // EgovOe1LoginVO user = (EgovOe1LoginVO) EgovUserDetailsHelper.getAuthenticatedUser(); egovOe1DicTermVO.setLastUpdusrId(user.getMberId()); if (("".equals(egovOe1DicTermVO.getWordDc())) || (egovOe1DicTermVO.getWordDc() == null)) { egovOe1DicTermVO.setWordDc(egovOe1DicTermVO.getWordNm()); } //selectedId VO? . egovOe1DicTermVO.setWordId(selectedId); egovOe1DicTermService.updateDicTerm(egovOe1DicTermVO); status.setComplete(); if (status.isComplete()) { model.addAttribute("resultMsg", " "); } else { model.addAttribute("resultMsg", " "); } return "forward:/cms/cmm/selectDicTermList.do"; } /** * ? . * @param egovOe1DicTermVO - VO * @param status * @return "forward:/cms/cmm/selectDicTermList.do" * @exception Exception */ @RequestMapping("/cms/cmm/removeDicTermOK.do") public String removeDicTermOK(@RequestParam("selectedId") String selectedId, @ModelAttribute("egovOe1DicTermVO") EgovOe1DicTermVO egovOe1DicTermVO, Model model, SessionStatus status) throws Exception { log.debug(this.getClass().getName() + " ==> "); Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated(); if (!isAuthenticated) { return "/cms/com/EgovLoginUsr"; //? ?? } //? ? ??. model.addAttribute("searchMode", egovOe1DicTermVO); egovOe1DicTermVO.setWordId(selectedId); egovOe1DicTermService.deleteDicTerm(egovOe1DicTermVO); status.setComplete(); if (status.isComplete()) { model.addAttribute("resultMsg", " "); } else { model.addAttribute("resultMsg", " "); } return "forward:/cms/cmm/selectDicTermList.do"; } /** * ? ? * @param : EgovOe1DicTermVO * @return : "/cms/cmm/EgovDicWordListPopup" * * @Exception Exception */ @RequestMapping(value = "/cms/cmm/searchWordPopup.do") public String searchWordPopup(EgovOe1DicTermVO egovOe1DicTermVO, ModelMap model) throws Exception { log.debug(this.getClass().getName() + " ==> ?? "); /** EgovPropertyService.egovOe1DicTermService */ egovOe1DicTermVO.setPageUnit(propertiesService.getInt("pageUnit")); egovOe1DicTermVO.setPageSize(propertiesService.getInt("pageSize")); /** pageing setting */ PaginationInfo paginationInfo = new PaginationInfo(); paginationInfo.setCurrentPageNo(egovOe1DicTermVO.getPageIndex()); paginationInfo.setRecordCountPerPage(egovOe1DicTermVO.getPageUnit()); paginationInfo.setPageSize(egovOe1DicTermVO.getPageSize()); egovOe1DicTermVO.setFirstIndex(paginationInfo.getFirstRecordIndex()); egovOe1DicTermVO.setLastIndex(paginationInfo.getLastRecordIndex()); egovOe1DicTermVO.setRecordCountPerPage(paginationInfo.getRecordCountPerPage()); List dicTermList = egovOe1DicTermService.selectDicTermListPopup(egovOe1DicTermVO); model.addAttribute("resultList", dicTermList); int totCnt = egovOe1DicTermService.selectDicTermListPopupTot(egovOe1DicTermVO); paginationInfo.setTotalRecordCount(totCnt); model.addAttribute("paginationInfo", paginationInfo); return "/cms/cmm/EgovDicWordListPopup"; } @RequestMapping(value = "/cms/cmm/searchPopup.do") public String searchPopup(EgovOe1DicTermVO egovOe1DicTermVO, ModelMap model) throws Exception { log.debug(this.getClass().getName() + " ==> ? ? ?? "); return "/cms/cmm/EgovSearchPopup"; } /** * ? ?? * @param ComDefaultVO - ? VO * @param model * @return "/cms/cmm/EgovDicTermExcelRegist" * @exception Exception */ @RequestMapping("/cms/cmm/addDicTermExcel.do") public String addDicTermExcel(@ModelAttribute("egovOe1DicTermVO") EgovOe1DicTermVO egovOe1DicTermVO, Model model) throws Exception { Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated(); if (!isAuthenticated) { return "/cms/com/EgovLoginUsr"; //? ?? } //? ? ??. model.addAttribute("searchMode", egovOe1DicTermVO); return "/cms/cmm/EgovDicTermExcelRegist"; } /** * ? * @param ComDefaultVO - ? VO * @param model * @return "forward:/cms/cmm/selectDicTermList.do" * @exception Exception */ @RequestMapping("/cms/cmm/addDicTermExcelOK.do") public String addDicTermExcelRegister(final HttpServletRequest request, @ModelAttribute("egovOe1DicTermVO") EgovOe1DicTermVO egovOe1DicTermVO, BindingResult bindingResult, Model model, SessionStatus status) throws Exception { Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated(); if (!isAuthenticated) { return "/cms/com/EgovLoginUsr"; //? ?? } if (bindingResult.hasErrors()) { model.addAttribute("egovOe1DicTermVO", egovOe1DicTermVO); return "/cms/cmm/addDicTermExcel"; } model.addAttribute("searchMode", egovOe1DicTermVO); // EgovOe1LoginVO user = (EgovOe1LoginVO) EgovUserDetailsHelper.getAuthenticatedUser(); try { final MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request; final Map<String, MultipartFile> files = multiRequest.getFileMap(); Iterator<Entry<String, MultipartFile>> itr = files.entrySet().iterator(); MultipartFile file; String filePath = ""; while (itr.hasNext()) { Entry<String, MultipartFile> entry = itr.next(); file = entry.getValue(); if (!"".equals(file.getOriginalFilename())) { String _storePath = propertyService.getString("Globals.fileStorePath"); File saveFolder = new File(_storePath); if (!saveFolder.exists() || saveFolder.isFile()) { saveFolder.mkdirs(); } String orginFileName = file.getOriginalFilename(); int _index = orginFileName.lastIndexOf("."); String fileName = orginFileName.substring(0, _index); String fileExt = orginFileName.substring(_index + 1); long _size = file.getSize(); if (!"".equals(orginFileName)) { filePath = _storePath + File.separator + "StandardTermStatus.xls"; file.transferTo(new File(filePath)); } // System.out.println("?=====>"+orginFileName); // System.out.println("?=====>"+fileName); // System.out.println("?=====>"+fileExt); // System.out.println("??=====>"+_size); // System.out.println("??=====>"+filePath); if ((fileExt.equals("xls") || fileExt.equals("xlsx")) && (filePath != null && !"".equals(filePath))) { HSSFWorkbook wbT = excelService.loadWorkbook(filePath); HSSFSheet sheetT = wbT.getSheet(wbT.getSheetName(0)); HSSFRow rowValue = sheetT.getRow(2); HSSFCell cellValue0 = rowValue.getCell(0); // HSSFCell cellValue1 = rowValue.getCell(1); // HSSFCell cellValue2 = rowValue.getCell(2); //?(Full Name) HSSFCell cellValue3 = rowValue.getCell(3); //? HSSFCell cellValue4 = rowValue.getCell(4); // HSSFCell cellValue6 = rowValue.getCell(6); //? String synonm = (cellValue0 + "").trim(); String wordNm = (cellValue1 + "").trim(); String engNm = (cellValue2 + "").trim(); String wordNmEngAbrv = (cellValue3 + "").trim(); String wordDc = (cellValue4 + "").trim(); String useAt = (cellValue6 + "").trim(); //System.out.println("synonm====>"+synonm); //System.out.println("wordNm====>"+wordNm); //System.out.println("engNm====>"+engNm); //System.out.println("wordNmEngAbrv====>"+wordNmEngAbrv); //System.out.println("wordDc====>"+wordDc); //System.out.println("useAt====>"+useAt); if (!"".equals(synonm) || !"".equals(wordNm) || !"?(Full Name)".equals(engNm) || !"?".equals(wordNmEngAbrv) || !"".equals(wordDc) || !"?".equals(useAt)) { model.addAttribute("resultMsg", " EXCEL ?? . ."); return "/cms/cmm/EgovDicTermExcelRegist"; } List<EgovOe1DicTermVO> dicTermListVO = new ArrayList<EgovOe1DicTermVO>(); for (int i = 3; i <= sheetT.getLastRowNum(); i++) { HSSFRow row1 = sheetT.getRow(i); HSSFCell cell0 = row1.getCell(0); //(/??) HSSFCell cell1 = row1.getCell(1); // HSSFCell cell2 = row1.getCell(2); //? HSSFCell cell3 = row1.getCell(3); //? HSSFCell cell4 = row1.getCell(4); // HSSFCell cell6 = row1.getCell(6); // synonm = (cell0 + "").trim(); wordNm = (cell1 + "").trim(); engNm = (cell2 + "").trim(); wordNmEngAbrv = (cell3 + "").trim(); wordDc = (cell4 + "").trim(); useAt = (cell6 + "").trim(); // System.out.println("synonm=======>"+synonm); // System.out.println("wordNm=======>"+wordNm); // System.out.println("engNm=======>"+engNm); // System.out.println("wordNmEngAbrv=======>"+wordNmEngAbrv); // System.out.println("wordDc=======>"+wordDc); // System.out.println("useAt=======>"+useAt); if (("".equals(synonm) || "??".equals(synonm)) && (!"".equals(synonm) && synonm != null) && (!"".equals(wordNm) && wordNm != null) && (!"".equals(engNm) && engNm != null) && (!"".equals(wordNmEngAbrv) && wordNmEngAbrv != null)) { EgovOe1DicTermVO egovOe1DicTermExcelVO = new EgovOe1DicTermVO(); egovOe1DicTermExcelVO.setSynonm(synonm); egovOe1DicTermExcelVO.setWordNm(wordNm); egovOe1DicTermExcelVO.setEngNm(engNm); egovOe1DicTermExcelVO.setWordNmEngAbrv(wordNmEngAbrv); egovOe1DicTermExcelVO.setWordDc(wordDc); if (useAt.equals("")) { egovOe1DicTermExcelVO.setUseAt("Y"); } else { egovOe1DicTermExcelVO.setUseAt("N"); } egovOe1DicTermExcelVO.setFrstRegisterId(user.getMberId()); dicTermListVO.add(egovOe1DicTermExcelVO); for (int kk = 0; kk < dicTermListVO.size(); kk++) { if (kk > 1) { // System.out.println("synonm=======>"+egovOe1DicTermExcelVO.getSynonm()); // System.out.println("wordNm=======>"+egovOe1DicTermExcelVO.getWordNm()); // System.out.println("engNm=======>"+egovOe1DicTermExcelVO.getEngNm()); // System.out.println("wordNmEngAbrv=======>"+egovOe1DicTermExcelVO.getWordNmEngAbrv()); // System.out.println("wordDc=======>"+egovOe1DicTermExcelVO.getWordDc()); // System.out.println("useAt=======>"+egovOe1DicTermExcelVO.getUseAt()); // System.out.println("dicTermListVO.get(kk-1).getWordNm().trim()====>"+dicTermListVO.get(kk-1).getWordNm().trim()); // System.out.println("kk=================="+kk); // System.out.println("jj=================="+i); // System.out.println("============================================"); if (dicTermListVO.get(kk - 1).getWordNm().trim().equals(wordNm)) { model.addAttribute("resultMsg", (i + 1) + "??? ? . ? ."); return "/cms/cmm/EgovDicTermExcelRegist"; } if (dicTermListVO.get(kk - 1).getEngNm().trim().equals(engNm)) { model.addAttribute("resultMsg", (i + 1) + "??? ?(Full Name)? . ? ."); return "/cms/cmm/EgovDicTermExcelRegist"; } if (dicTermListVO.get(kk - 1).getWordNmEngAbrv().trim() .equals(wordNmEngAbrv)) { model.addAttribute("resultMsg", (i + 1) + "??? ?? . ? ."); return "/cms/cmm/EgovDicTermExcelRegist"; } } else if (kk == 1) { // System.out.println("synonm=======>"+egovOe1DicTermExcelVO.getSynonm()); // System.out.println("wordNm=======>"+egovOe1DicTermExcelVO.getWordNm()); // System.out.println("engNm=======>"+egovOe1DicTermExcelVO.getEngNm()); // System.out.println("wordNmEngAbrv=======>"+egovOe1DicTermExcelVO.getWordNmEngAbrv()); // System.out.println("wordDc=======>"+egovOe1DicTermExcelVO.getWordDc()); // System.out.println("useAt=======>"+egovOe1DicTermExcelVO.getUseAt()); // System.out.println("dicTermListVO.get(kk-1).getWordNm().trim()====>"+dicTermListVO.get(kk-1).getWordNm().trim()); // System.out.println("kk=================="+i); // System.out.println("============================================"); if (dicTermListVO.get(kk - 1).getWordNm().trim().equals(wordNm)) { model.addAttribute("resultMsg", (i + 1) + "??? ? . ? ."); return "/cms/cmm/EgovDicTermExcelRegist"; } if (dicTermListVO.get(kk - 1).getEngNm().trim().equals(engNm)) { model.addAttribute("resultMsg", (i + 1) + "??? ?(Full Name)? . ? ."); return "/cms/cmm/EgovDicTermExcelRegist"; } if (dicTermListVO.get(kk - 1).getWordNmEngAbrv().trim() .equals(wordNmEngAbrv)) { model.addAttribute("resultMsg", (i + 1) + "??? ?? . ? ."); return "/cms/cmm/EgovDicTermExcelRegist"; } } } } else { if (!"".equals(synonm) && !"??".equals(synonm)) { model.addAttribute("resultMsg", (i + 1) + "??? ? /?? . ? ."); } if ("".equals(synonm) || synonm == null) { model.addAttribute("resultMsg", (i + 1) + "??? ? . ? ."); } if ("".equals(wordNm) || wordNm == null) { model.addAttribute("resultMsg", (i + 1) + "??? ? . ? ."); } if ("".equals(engNm) || engNm == null) { model.addAttribute("resultMsg", (i + 1) + "??? ?(Full Name)? . ? ."); } if ("".equals(wordNmEngAbrv) || wordNmEngAbrv == null) { model.addAttribute("resultMsg", (i + 1) + "??? ? . ? ."); } if ("".equals(wordDc) || wordDc == null) { model.addAttribute("resultMsg", (i + 1) + "??? ? . ? ."); } return "/cms/cmm/EgovDicTermExcelRegist"; } } // ? ?? . egovOe1DicTermService.deleteExcelDicTerm(); List<EgovOe1DicTermVO> list = dicTermListVO; for (EgovOe1DicTermVO dicTermVO : list) { if ("??".equals(dicTermVO.getSynonm())) { egovOe1DicTermService.insertExcelDicTermSynonm(dicTermVO); } else { egovOe1DicTermService.insertExcelDicTerm(dicTermVO); } } } else { model.addAttribute("resultMsg", " EXCEL ?? . ."); return "/cms/cmm/EgovDicTermExcelRegist"; } } } status.setComplete(); model.addAttribute("resultMsg", " Excel ? ? "); return "forward:/cms/cmm/selectDicTermList.do"; } catch (Exception ex) { model.addAttribute("resultMsg", " Excel ? ? , Excel ? ? ?. "); return "/cms/cmm/EgovDicTermExcelRegist"; } } /** * ? Excel * @param : EgovOe1DicTermVO * @return : String * @exception Exception */ @RequestMapping(value = "/cms/cmm/addDicTermExcelDwon.do") public String selectDicTermListExcelDown(@ModelAttribute("egovOe1DicTermVO") EgovOe1DicTermVO egovOe1DicTermVO, HttpServletRequest request, HttpServletResponse response) throws Exception { log.debug(this.getClass().getName() + " ==> ? Excel "); Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated(); if (!isAuthenticated) { return "/cms/com/EgovLoginUsr"; //? ?? } EgovOe1LoginVO user = (EgovOe1LoginVO) EgovUserDetailsHelper.getAuthenticatedUser(); java.util.Calendar cal = java.util.Calendar.getInstance(); String year = cal.get(java.util.Calendar.YEAR) + ""; String month = (cal.get(java.util.Calendar.MONTH) + 1) + ""; String date = cal.get(java.util.Calendar.DATE) + ""; year = year; month = month.length() == 1 ? "0" + month : month; date = date.length() == 1 ? "0" + date : date; //? List<EgovOe1DicTermVO> list = egovOe1DicTermService.selectDicTermListExcelDown(egovOe1DicTermVO); // String _storePath = propertyService.getString("Globals.excelStorePath"); // ? path + ? String _storePathName = _storePath + File.separator + "StandardTermStatus.xls"; List<EgovOe1DicTermVO> dicTermListVO = new ArrayList<EgovOe1DicTermVO>(); for (EgovOe1DicTermVO dicTermVO : list) { EgovOe1DicTermVO dicTermValueVO = new EgovOe1DicTermVO(); if ("".equals(dicTermVO.getSynonm()) || dicTermVO.getSynonm() == null) { dicTermValueVO.setSynonm(""); } else { dicTermValueVO.setSynonm("??"); } dicTermValueVO.setWordNm(dicTermVO.getWordNm()); dicTermValueVO.setEngNm(dicTermVO.getEngNm()); dicTermValueVO.setWordNmEngAbrv(dicTermVO.getWordNmEngAbrv()); dicTermValueVO.setWordDc(dicTermVO.getWordDc()); dicTermValueVO.setFrstRegisterPnttm(dicTermVO.getFrstRegisterPnttm()); if ("Y".equals(dicTermVO.getUseAt())) { dicTermValueVO.setUseAt(""); } else { dicTermValueVO.setUseAt(""); } dicTermListVO.add(dicTermValueVO); } Map<String, Object> beans = new HashMap<String, Object>(); beans.put("userName", user.getMberNm()); beans.put("today", year + "." + month + "." + date); beans.put("dicTermListVO", dicTermListVO); XLSTransformer transformer = new XLSTransformer(); File output = File.createTempFile("aaa", ".tmp"); transformer.transformXLS(_storePathName, beans, output.getAbsolutePath()); String mimetype = "application/x-msdownload"; response.setBufferSize((int) output.length()); response.setContentType(mimetype); setDisposition("StandardTermStatus.xls", request, response); BufferedInputStream in = null; BufferedOutputStream out = null; try { in = new BufferedInputStream(new FileInputStream(output)); out = new BufferedOutputStream(response.getOutputStream()); FileCopyUtils.copy(in, out); out.flush(); } catch (Exception ex) { ex.printStackTrace(); // ? Exception // Connection reset by peer: socket write error // System.out.println("IGNORED: " + ex.getMessage()); } finally { if (in != null) { try { in.close(); } catch (Exception ignore) { ignore.printStackTrace(); //System.out.println("IGNORED: " + ignore.getMessage()); } } if (out != null) { try { out.close(); } catch (Exception ignore) { ignore.printStackTrace(); //System.out.println("IGNORED: " + ignore.getMessage()); } } } return ""; } /** * ? . * * @param request * @Exception Exception */ private String getBrowser(HttpServletRequest request) { String header = request.getHeader("User-Agent"); if (header.indexOf("MSIE") > -1) { return "MSIE"; } else if (header.indexOf("Chrome") > -1) { return "Chrome"; } else if (header.indexOf("Opera") > -1) { return "Opera"; } return "Firefox"; } /** * Disposition . * * @param filename * @param request * @param response * @Exception Exception */ private void setDisposition(String filename, HttpServletRequest request, HttpServletResponse response) throws Exception { String browser = getBrowser(request); String dispositionPrefix = "attachment; filename="; String encodedFilename = null; if (browser.equals("MSIE")) { encodedFilename = URLEncoder.encode(filename, "UTF-8").replaceAll("\\+", "%20"); } else if (browser.equals("Firefox")) { encodedFilename = "\"" + new String(filename.getBytes("UTF-8"), "8859_1") + "\""; } else if (browser.equals("Opera")) { encodedFilename = "\"" + new String(filename.getBytes("UTF-8"), "8859_1") + "\""; } else if (browser.equals("Chrome")) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < filename.length(); i++) { char c = filename.charAt(i); if (c > '~') { sb.append(URLEncoder.encode("" + c, "UTF-8")); } else { sb.append(c); } } encodedFilename = sb.toString(); } else { // throw new RuntimeException("Not supported browser"); throw new IOException("Not supported browser"); } response.setHeader("Content-Disposition", dispositionPrefix + encodedFilename); if ("Opera".equals(browser)) { response.setContentType("application/octet-stream;charset=UTF-8"); } } /** * Excel * @param : EgovOe1DicTermVO * @Exception Exception */ @RequestMapping(value = "/cms/cmm/addDicTermExcelTempletDwon.do") public void selectDicTermExcelTempletDown(@ModelAttribute("egovOe1DicTermVO") EgovOe1DicTermVO egovOe1DicTermVO, HttpServletRequest request, HttpServletResponse response) throws Exception { log.debug(this.getClass().getName() + " ==> Excel "); // String _storePath = propertyService.getString("Globals.excelStoreDownPath"); File uFile = new File(_storePath, "StandardTermStatus.xls"); int fSize = (int) uFile.length(); if (fSize > 0) { String mimetype = "application/x-msdownload"; response.setBufferSize(fSize); response.setContentType(mimetype); //response.setHeader("Content-Disposition", "attachment; filename=\"" + URLEncoder.encode(fvo.getOrignlFileNm(), "utf-8") + "\""); setDisposition("StandardTermStatus.xls", request, response); response.setContentLength(fSize); /* * FileCopyUtils.copy(in, response.getOutputStream()); * in.close(); * response.getOutputStream().flush(); * response.getOutputStream().close(); */ BufferedInputStream in = null; BufferedOutputStream out = null; try { in = new BufferedInputStream(new FileInputStream(uFile)); out = new BufferedOutputStream(response.getOutputStream()); FileCopyUtils.copy(in, out); out.flush(); } catch (Exception ex) { //ex.printStackTrace(); // ? Exception // Connection reset by peer: socket write error log.debug("IGNORED: " + ex.getMessage()); } finally { if (in != null) { try { in.close(); } catch (Exception ignore) { // no-op log.debug("IGNORED: " + ignore.getMessage()); } } if (out != null) { try { out.close(); } catch (Exception ignore) { // no-op log.debug("IGNORED: " + ignore.getMessage()); } } } } } }