From 1b960584383766692a257a4cdd92daf19bab172d Mon Sep 17 00:00:00 2001 From: jhjang <jhjang@maprex.co.kr> Date: 월, 27 12월 2021 09:32:50 +0900 Subject: [PATCH] - API 추가/수정시 사용자 정의 필드 항목이 없을 경우 오류 처리 - API 에서 도메인만 추출하여 같은 도메인을 갖는 업체/isp/hosting 자동 입력하도록 수정 --- src/main/java/kr/wisestone/owl/util/CommonUtil.java | 97 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 97 insertions(+), 0 deletions(-) diff --git a/src/main/java/kr/wisestone/owl/util/CommonUtil.java b/src/main/java/kr/wisestone/owl/util/CommonUtil.java index fb52889..079f3a4 100644 --- a/src/main/java/kr/wisestone/owl/util/CommonUtil.java +++ b/src/main/java/kr/wisestone/owl/util/CommonUtil.java @@ -40,7 +40,10 @@ import java.security.MessageDigest; import java.security.spec.KeySpec; import java.text.DecimalFormat; +import java.text.SimpleDateFormat; import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class CommonUtil { private static final Logger LOGGER = LoggerFactory.getLogger(CommonUtil.class); @@ -344,6 +347,24 @@ return fileMap; } + // string file �젙蹂대�� file Map �삎�깭濡� 蹂�寃쏀븳�떎. + public static Map<String, Object> makeFileMap(String fileName, String file, String contentType) { + Map<String, Object> fileMap = new HashMap<>(); + + try { + byte[] bytes = Base64.decodeBase64(file); + + fileMap.put("fileName", fileName); + fileMap.put("fileSize", bytes.length); + fileMap.put("contentType", contentType); + fileMap.put("file", CommonUtil.bytesToFile(fileName, bytes)); + } catch (Exception e) { + LOGGER.debug(e.getMessage()); + } + + return fileMap; + } + public static String getPostDataString(Map<String, String> params) throws UnsupportedEncodingException { StringBuilder result = new StringBuilder(); boolean first = true; @@ -373,6 +394,42 @@ multipart.transferTo(convertFile); } catch (IllegalStateException | IOException e) { LOGGER.debug("multipart �뙆�씪 file 蹂��솚 �삤瑜�"); + } + + return convertFile; + } + + // string�쓣 �뙆�씪濡� 蹂��솚 + public static File stringToFile(String fileName, String file) { + + byte[] bytes = null; + try { + bytes = Base64.decodeBase64(file); + + } catch (Exception ex) { + LOGGER.debug("string to bytes 蹂��솚 �삤瑜�"); + } + + if (bytes != null) { + return bytesToFile(fileName, bytes); + } + return null; + } + + // bytes瑜� �뙆�씪濡� 蹂��솚 + public static File bytesToFile(String fileName, byte[] bytes) { + File convertFile = new File(WebAppUtil.getContextRealPath() + TMP_UPLOAD_FOLDER + getFileNameByUUID(fileName)); + if (!convertFile.exists()) { + convertFile.mkdirs(); + } + + try{ + FileOutputStream lFileOutputStream = new FileOutputStream(convertFile); + lFileOutputStream.write(bytes); + lFileOutputStream.close(); + + }catch (IllegalStateException | IOException e) { + LOGGER.debug("bytes �뙆�씪 file 蹂��솚 �삤瑜�"); } return convertFile; @@ -707,6 +764,20 @@ return stringBuilder.toString(); } + public static List<Date> findSearchPeriod(Date startDate, Date endDate) { + Calendar cal = Calendar.getInstance(); + cal.setTime(endDate); + List<Date> days = Lists.newArrayList(); + + // �씠踰덈떖 �궇吏� 由ъ뒪�듃 媛��졇�삤湲� + while (cal.getTime().after(startDate)){ + days.add(cal.getTime()); + cal.add(Calendar.DATE, -1); + } + + return days; + } + // 寃��깋 �씪�옄瑜� 援ы븳�떎. public static List<Date> findSearchPeriod(String searchPeriod) { List<Date> searchDates = Lists.newArrayList(); @@ -936,4 +1007,30 @@ } } + // 硫붿씤 url留� 異붿텧 + public static String extractUrl(String content){ + try { + String REGEX = "(http(s)?:\\/\\/)([a-z0-9\\w]+\\.*)+[a-z0-9]{2,4}"; + Pattern p = Pattern.compile(REGEX, Pattern.CASE_INSENSITIVE); + Matcher m = p.matcher(content); + if (m.find()) { + return m.group(); + } + return ""; + } catch (Exception e) { + return ""; + } + } + + // 硫붿씤 url 異붿텧�쓣 �쐞�빐 http: �솗�씤 + public static String getUrl(String fullUrl) { + if (fullUrl != null) { + if (fullUrl.indexOf("http") == -1) { + fullUrl = "http://" + fullUrl; + } + + return extractUrl(fullUrl); + } + return ""; + } } -- Gitblit v1.8.0