public Cart getCurrent() { RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes(); if (requestAttributes != null) { HttpServletRequest httpServletRequest = ((ServletRequestAttributes) requestAttributes).getRequest(); Principal principal = (Principal) httpServletRequest.getSession().getAttribute(Member.PRINCIPAL_ATTRIBUTE_NAME); Member member = principal != null ? (Member) this.memberDao.find(principal.getId()) : null; if (member != null) { Cart cart = member.getCart(); if (cart != null) { if (!cart.hasExpired()) { if (!DateUtils.isSameDay(cart.getUpdateDate(), new Date())) { cart.setUpdateDate(new Date()); this.cartDao.merge(cart); } return cart; } this.cartDao.remove(cart); } } else { String cartIdString = CookieUtils.getCookie(httpServletRequest, "cartId"); String cartKeyString = CookieUtils.getCookie(httpServletRequest, "cartKey"); if ((StringUtils.isNotEmpty(cartIdString)) && (StringUtils.isNumeric(cartIdString)) && (StringUtils.isNotEmpty(cartKeyString))) { Cart cart = (Cart) this.cartDao.find(Long.valueOf(cartIdString)); if ((cart != null) && (cart.getMember() == null) && (StringUtils.equals(cart.getKey(), cartKeyString))) { if (!cart.hasExpired()) { if (!DateUtils.isSameDay(cart.getUpdateDate(), new Date())) { cart.setUpdateDate(new Date()); this.cartDao.merge(cart); } return cart; } this.cartDao.remove(cart); } } } } return null; }
public void postHandle( HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) { if ((modelAndView != null) && (modelAndView.isReference())) { String str1 = modelAndView.getViewName(); if (StringUtils.startsWith(str1, REDIRECT)) { String str2 = CookieUtils.getCookie(request, LIST_QUERY); if (StringUtils.isNotEmpty(str2)) { if (StringUtils.startsWith(str2, "?")) str2 = str2.substring(1); if (StringUtils.contains(str1, "?")) modelAndView.setViewName(str1 + "&" + str2); else modelAndView.setViewName(str1 + "?" + str2); CookieUtils.removeCookie(request, response, LIST_QUERY); } } } }