/**
 * Copyright (c) 2003-2004 System Integrator Corporation.
 *                 All Rights Reserved.
 */
package jp.co.sint.servlet.front;

import java.io.IOException;
import java.sql.SQLException;

import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Enumeration;

import jp.co.sint.basic.SIFrontBasic;
import jp.co.sint.beans.front.UIReviewInfo;
import jp.co.sint.beans.front.UIShopInfo;
import jp.co.sint.config.SIConfig;
import jp.co.sint.database.SIDatabaseConnection;
import jp.co.sint.servlet.SIServlet;
import jp.co.sint.tools.SIURLMap;
import jp.co.sint.tools.SIURLParameter;//7.1.1 ST0236 追加

import org.apache.log4j.Category;

/**
 * @version $Id: SIOtherSrv.java,v 1.0 2003/10/24 Exp $
 * @author  Jinwang Chen
 * <br>Description:
 * <p>History</p>
 * <p>Author&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Reason</p>
 *  ============&nbsp;&nbsp;&nbsp;==========&nbsp;&nbsp;===========================<br>
 * Jinwang Chen   2003/10/24 15:00:05  Original
 */
public class SIOtherSrv extends SIServlet{
  //ログ用のインスタンスの生成
  private static Category log=Category.getInstance(SIConfig.SILOG4J_WEBSHOP_CATEGORY_NAME);
  /**
   * <b>doUpdate</b>
   * HTTP リクエストの処理
   * @param  request リクエスト
   * @param  response
   * @return なし
   * @throws ServletException
   * @throws IOException
   */
  public void doUpdate(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    HttpSession session=request.getSession(true);//セッションの取得
    SIDatabaseConnection databaseConnection=new SIDatabaseConnection();//DBへのコネクションの作成
    SIURLParameter urlParam = new SIURLParameter(request);//7.1.1 ST0236 追加
    try {
      String actionName=this.getActionName(urlParam);//画面からのアクション //7.1.1 ST0236 修正
      String editMode=this.getEditMode(urlParam);//DBへの編集モード //7.1.1 ST0236 修正
      
      if (this.getServletPath(request).equals("/shopinfo")){//ショップ紹介
        if(!SIConfig.SIACTION_BACK.equals(actionName)){
          UIShopInfo shopInfo=new UIShopInfo();
          //データの取得とデータのチェック
          shopInfo.init(request,urlParam);//7.1.1 ST0236 修正
          session.setAttribute(SIConfig.SISESSION_SHOP_INFO_LIST_NAME,shopInfo);
        }
        forwardKey(request,response,"webshop.jsp.front.shop.info");
      }else if (this.getServletPath(request).equals("/reviewinfo")){
        UIReviewInfo reviewInfo=new UIReviewInfo();
        //データの取得とデータのチェック
        reviewInfo.init(request,databaseConnection.getConnection(),urlParam);//7.1.1 ST0236 修正
        session.setAttribute(SIConfig.SISESSION_REVIEW_INFO_LIST_NAME,reviewInfo);
        forwardKey(request,response,"webshop.jsp.front.review.info");
      }else if (this.getServletPath(request).equals("/mallinfo")){
        if(!SIConfig.SIACTION_BACK.equals(actionName)){
          SIFrontBasic mallInfo=new SIFrontBasic();
          mallInfo.init(request,urlParam);//7.1.1 ST0236 修正
          session.setAttribute(SIConfig.SISESSION_MALL_INFO_LIST_NAME,mallInfo);
        }
        forwardKey(request,response,"webshop.jsp.front.mall.info");
      }else if (this.getServletPath(request).equals("/pickupSrv")){
        String param = (String)urlParam.getParam("param");
        if (SIURLMap.isSmartPhone(request)&&SIURLMap.isSpSwitch(request)) {
          if (param.equals("towelwarmer/index.html")) {
            forward(request,response,"/sp/pickup_sp/"+param);
          }else{
            forward(request,response,"/pickup_sp/"+param);
          }
        }else{
          forward(request,response,"/pickup_pc/"+param);
        }
      }else if (this.getServletPath(request).equals("/listpickupSrv")){
        String param = (String)urlParam.getParam("param");
        if (SIURLMap.isSmartPhone(request)&&SIURLMap.isSpSwitch(request)) {
          forward(request,response,"/listpickup_sp/"+param);
        }else{
          forward(request,response,"/listpickup_pc/"+param);
        }
      }else if (this.getServletPath(request).equals("/guideSrv")){
        String param = (String)urlParam.getParam("param");
        if (SIURLMap.isSmartPhone(request)&&SIURLMap.isSpSwitch(request)) {
          forward(request,response,"/sp/guide_sp/"+param);
        }else{
          forward(request,response,"/guide_pc/"+param);
        }
      }else if (this.getServletPath(request).equals("/showroomSrv")){
        String param = (String)urlParam.getParam("param");
        if (SIURLMap.isSmartPhone(request)&&SIURLMap.isSpSwitch(request)) {
          forward(request,response,"/sp/showroom_sp/"+param);
        }else{
          //if (param.equals("benefits.html")||param.equals("list.html")||param.equals("features.html")) param = "index.html";
          if (param.equals("benefits.html")||param.equals("list.html")||param.equals("features.html")){
            redirect(request,response,"/showroom/index.html");
          }else{
            forward(request,response,"/showroom_pc/"+param);
          }
        }
      }else{
        forwardKey(request,response,"webshop.servlet.front.main");
      }
    }catch (SQLException e){
      e.printStackTrace();
      throw new ServletException();
    }catch (NamingException e){
      e.printStackTrace();
      throw new ServletException();
    }finally{
      databaseConnection.close();
    }
  }
}
