package com.chenyang.nse.bussiness.interceptor;

import java.io.PrintWriter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class SessionTimeOut implements HandlerInterceptor {
   public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
      Object obj = request.getSession().getAttribute("loginUser");
      String api = request.getHeader("API");
      if (api != null && "ghca".equals(api)) {
         return true;
      } else if (obj == null) {
         PrintWriter out = response.getWriter();
         out.println("<html>");
         out.println("<script>");
         out.println("window.open ('/ghca-platform/','_top')");
         out.println("</script>");
         out.println("</html>");
         return false;
      } else {
         return true;
      }
   }

   public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
   }

   public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
   }
}
