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