Esempio n. 1
0
  /**
   * Sets the variable kkAppEng to the KKAppEng instance saved in the session. If cannot be found,
   * then it is instantiated and attached.
   *
   * @param request
   * @param response
   * @return Returns a KonaKart client engine instance
   * @throws KKException
   * @throws KKAppException
   */
  protected KKAppEng getKKAppEng(HttpServletRequest request, HttpServletResponse response)
      throws KKAppException, KKException {
    HttpSession session = request.getSession();
    KKAppEng kkAppEng = (KKAppEng) session.getAttribute(KKAppEng.KONAKART_KEY);
    if (kkAppEng == null) {
      if (log.isInfoEnabled()) {
        log.info("KKAppEng not found on the session");
      }

      String storeIdForNewEngine = getStoreIdFromRequest(request);

      StoreInfo si = new StoreInfo();
      si.setStoreId(storeIdForNewEngine);
      kkAppEng = new KKAppEng(si, session);

      if (log.isInfoEnabled()) {
        log.info("Set KKAppEng on the session for storeId " + si.getStoreId());
      }

      /*
       * Add KKAppEng to the struts and the HTTP sessions. In order for the struts jsp tags to
       * see it, it has to be added to the struts session as well.
       */
      session.setAttribute(KKAppEng.KONAKART_KEY, kkAppEng);
      strutsSession.put(KKAppEng.KONAKART_KEY, kkAppEng);

      String customerUuid = manageCookies(request, response, kkAppEng);
      if (customerUuid != null) {
        // Get the locale from the cookie
        String savedLocale = getKKCookie(customerUuid, CUSTOMER_LOCALE, kkAppEng);
        if (savedLocale != null) {
          // Set the engine with the new locale
          kkAppEng.setLocale(savedLocale);
        }
      }

      // Insert event
      insertCustomerEvent(kkAppEng, ACTION_NEW_CUSTOMER_VISIT);
    }

    kkAppEng.setPageTitle(kkAppEng.getMsg("seo.default.title"));
    kkAppEng.setMetaDescription(kkAppEng.getMsg("seo.default.meta.description"));
    kkAppEng.setMetaKeywords(kkAppEng.getMsg("seo.default.meta.keywords"));

    /* Save a copy in the base action */
    appEng = kkAppEng;

    /* Used by the JSP */
    jspEng = kkAppEng;

    return kkAppEng;
  }