OWL ITS + 탐지시스템(인터넷 진흥원)
이민희
2022-03-17 916a3cbabe4e50062fce61ff6f2f5d46c05dfbd1
src/main/java/kr/wisestone/owl/util/CommonUtil.java
@@ -3,7 +3,7 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists;
import com.google.gson.Gson;
import kr.wisestone.owl.constant.Regular;
import kr.wisestone.owl.domain.enumType.FileType;
import kr.wisestone.owl.type.LikeType;
import kr.wisestone.owl.vo.DepartmentVo;
@@ -12,6 +12,7 @@
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.ss.usermodel.Cell;
import org.jsoup.Jsoup;
import org.slf4j.Logger;
@@ -40,8 +41,11 @@
import java.security.MessageDigest;
import java.security.spec.KeySpec;
import java.text.DecimalFormat;
import java.text.ParseException;
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);
@@ -52,7 +56,9 @@
    private static final String PASS_PHRASE = "1024";   //  AES128 암호화에 사용
    private static final int ITERATION_COUNT = 10000;   //  AES128 암호화에 사용
    private static final int KEY_SIZE = 128;    //  AES128 암호화에 사용
    private static final String TMP_UPLOAD_FOLDER = "/tmpUploadFolder/";    //  이슈 생성, 수정에서 파일 업로드할 때 임시 폴더로 사용
    private static final String TMP_UPLOAD_FOLDER = "/tmpUploadFolder/";    //  이슈 생성, 수정에서 파일 업로드할 때 임시 폴더로 사용'
    public static final String COMMA = ","; // 구분자
    public static String getClinetIp() {
        try {
@@ -957,17 +963,24 @@
        switch (cell.getCellType()) {
            case Cell.CELL_TYPE_NUMERIC :
                double doubleValue = cell.getNumericCellValue();
                int intValue;
                //  날짜 형식인 경우 날짜로 변환
                if (HSSFDateUtil.isCellDateFormatted(cell)) {
                    Date date = cell.getDateCellValue();
                    cellValue = DateUtil.convertDateToStr(date, "yyyy-MM-dd HH:mm:ss");
                if (doubleValue%1 == 0) {
                    intValue = (int)doubleValue;
                    cellValue = intValue + "";
                }
                else {
                    cellValue = doubleValue + "";
                }
                } else {
                    double doubleValue = cell.getNumericCellValue();
                    int intValue;
                    if (doubleValue % 1 == 0) {
                        intValue = (int)doubleValue;
                        cellValue = intValue + "";
                    }
                    else {
                        cellValue = doubleValue + "";
                    }
                }
                break;
            case Cell.CELL_TYPE_STRING :
@@ -1005,4 +1018,62 @@
        }
    }
    // 메인 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 "";
    }
    /**
     * 정규식 검사(URL)
     * @param url 대상 문자열(URL)
     * @return  검사 결과
     */
    public static boolean verifyUrl(String url) {
        return verifyRegular(url, Regular.URL);
    }
    /**
     * 정규식 검사(IP)
     * @param ip 대상 문자열(IP)
     * @return 검사 결과
     */
    public static boolean verifyIp(String ip) {
        return  verifyRegular(ip, Regular.IP);
    }
    /**
     * 정규식 검사
     * @param value 대상 문자열
     * @param regular 정규식 검사를 할 정규식 구문
     * @return 검사 결과
     */
    public static boolean verifyRegular(String value, String regular) {
        if (!StringUtils.isEmpty(value)) {
            return Pattern.matches(regular, value);
        }
        return false;
    }
}