package com.sys.core;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jfinal.handler.Handler;
import com.sys.bus.hr.model.Person;

public class ActionExtentionHandler extends Handler {
    public void handle(String target, HttpServletRequest request, 
    		HttpServletResponse response, boolean[] isHandled) {
        //  if (target.endsWith(".ctf"))
        //    target = target.substring(0, target.length() - 4);
        Person p = (Person)request.getSession().getAttribute("person");
        if((target.startsWith("/_view/")||target.endsWith(".xlsx")) && p == null) {
            try {
                response.sendRedirect("/nologin?url=" + target);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }else if(!target.endsWith("error.jsp")&&target.endsWith(".jsp") && p == null){
                try{
                    response.sendRedirect("error.jsp?url=" + target);
                }catch (Exception e){
                    e.printStackTrace();
                }

        }else{
            next.handle(target, request, response, isHandled);
        }

    }
}