Beispiel #1
0
  /*
   * (non-Javadoc)
   *
   * Customized cache logic: Donot cache post requests. Infact, we only cache
   * defined urls.
   *
   * @see com.opensymphony.oscache.web.filter.CacheFilter#isCacheable(javax.servlet.ServletRequest)
   */
  public boolean isCacheable(ServletRequest request) {
    boolean cachable = false;
    if (getTime() > 0) {
      /**
       * some AJAX application use post to get the page, need to specify a cache=true parameter to
       * enable cache. Known url includes: /sales/showRecommended, /content/adPublish.html.
       */
      if ("true".equals(request.getParameter("cache"))) {
        cachable = true;
      } else if (request.getParameter("noCache") == null
          && (request instanceof HttpServletRequest)) {
        HttpServletRequest req = (HttpServletRequest) request;
        if (!req.isRequestedSessionIdFromURL() && req.getMethod().equalsIgnoreCase("GET")) {
          ArrayList<Pattern> patterns = matchPatterns.get(RequestContext.getCurrentStoreCode());
          for (Pattern p : patterns) {
            if (p.matcher(req.getRequestURI()).matches()) {
              cachable = true;
              break;
            }
          }
        }
      }
    }

    return cachable;
  }
 public ModelAndView review(HttpServletRequest request, HttpServletResponse response) {
   String uri = request.getRequestURI();
   if (RequestContext.isAnonymousUser() && !ConfigUtil.getInstance().getIsAllowAnonymousReview()) {
     SessionUtil.setAttribute(request.getSession(), "HAS_ERRORS", Boolean.TRUE);
     saveMessage(Message.error("common.loginConfirm"));
     return new ModelAndView(new RedirectView(uri + "#review"));
   }
   Integer pIdcId[] = CatalogHelper.getInstance().getProductIdByUri(uri);
   Integer productId = pIdcId[0];
   String message = request.getParameter("message");
   String customerName = request.getParameter("customerName");
   String subject = request.getParameter("subject");
   Integer productRate = Integer.parseInt(request.getParameter("productRate").split("_")[1]);
   ;
   String attrRates[] = request.getParameterValues("rateItems");
   if (productId.intValue() != 0 && productId.intValue() != 0) {
     ProductReview productReview = new ProductReview();
     productReview.setProductId(productId);
     productReview.setSubject(subject);
     productReview.setMessage(message);
     if (RequestContext.isAnonymousUser()) {
       // TODO 设置匿名用户对象,系统必须存在Id为-2的匿名用户
       productReview.setReviewUserId(Constants.USERID_ANONYMOUS);
     } else {
       productReview.setReviewUserId(RequestContext.getCurrentUserId());
     }
     productReview.setCustomerName(customerName);
     productReview.setRate(productRate);
     productReview.setRemoteIp(request.getRemoteAddr());
     productReview.setStore(ConfigUtil.getInstance().getStore());
     if (attrRates == null) attrRates = new String[] {};
     productMainManager.saveProductReviewAction(productReview, attrRates);
     saveMessage(Message.info("product.addReview.success"));
   }
   return new ModelAndView(new RedirectView(uri + "#review"));
 }
Beispiel #3
0
 /** set the storeCode for generate key. */
 public String createCacheKey(
     HttpServletRequest httpRequest, ServletCacheAdministrator scAdmin, Cache cache) {
   return scAdmin.generateEntryKey(
       null, httpRequest, super.getCacheScope(), RequestContext.getCurrentStoreCode());
 }