| | |
| | | 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; |
| | |
| | | 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); |
| | |
| | | |
| | | 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 : |
| | |
| | | } |
| | | } |
| | | |
| | | // 메인 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 ""; |
| | | } |
| | | } |