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

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import jp.co.sint.beans.front.UICampaign;
import jp.co.sint.config.SIConfig;
import jp.co.sint.database.SIDatabaseConnection;
import jp.co.sint.servlet.SIServlet;
import jp.co.sint.tools.SIUtil;
import jp.co.sint.tools.SIURLParameter;

import org.apache.log4j.Category;

/**
 * @version $Id: SICampaignSrv.java,v 1.0 2006/03/01 Exp $
 * @author  Naotaka Ohsugi
 * <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>
 *  Naotaka Ohsugi 2006/03/01  Original
 */
public class SICampaignSrv 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);
    try {
      String actionName=this.getActionName(urlParam);//画面からのアクション
      UICampaign campaignID=new UICampaign();
      if (this.getServletPath(request).startsWith("/campaign")) {
        if (SIUtil.isNull(actionName) || SIConfig.SIACTION_LIST.equalsIgnoreCase(actionName)){
          //データの取得とデータのチェック
          campaignID =new UICampaign();
          campaignID.init(request,urlParam);
          session.setAttribute(SIConfig.SISESSION_CAMPAIGN_LIST_NAME,campaignID);
          forwardKey(request,response,"webshop.jsp.front"+this.getServletPath(request).replaceAll("/", "."));
        } else if(SIConfig.SIACTION_BACK.equalsIgnoreCase(actionName)){
          forwardKey(request,response,"webshop.jsp.front"+this.getServletPath(request).replaceAll("/", "."));
        }
      } else if (this.getServletPath(request).startsWith("/closedsale")) {
        if (SIUtil.isNull(actionName) || SIConfig.SIACTION_LIST.equalsIgnoreCase(actionName)){
          //データの取得とデータのチェック
          campaignID =new UICampaign();
          campaignID.init(request,urlParam);
          session.setAttribute(SIConfig.SISESSION_CAMPAIGN_LIST_NAME,campaignID);
          forwardKey(request,response,"webshop.jsp.front.closedsale");
        }
      }
    }catch (Exception e){
      e.printStackTrace();
      throw new ServletException();
    }finally{
      databaseConnection.close();
    }
  }
}
