/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  javax.servlet.Filter
 *  javax.servlet.FilterChain
 *  javax.servlet.FilterConfig
 *  javax.servlet.RequestDispatcher
 *  javax.servlet.ServletException
 *  javax.servlet.ServletRequest
 *  javax.servlet.ServletResponse
 *  javax.servlet.http.HttpServletRequest
 */
package com.hst.common.filter;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

public class ServletFilter
implements Filter {
    private List<String> includes;

    public void init(FilterConfig config) throws ServletException {
        this.setIncludes(Arrays.asList(config.getInitParameter("includeServlets").split(",")));
    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest)req;
        String target = request.getRequestURI();
        String string = target = target.lastIndexOf("?") > 0 ? target.substring(target.lastIndexOf("/") + 1, target.lastIndexOf("?") - target.lastIndexOf("/")) : target.substring(target.lastIndexOf("/") + 1);
        if (this.includes.contains(target)) {
            RequestDispatcher rdsp = request.getRequestDispatcher(target);
            rdsp.forward(req, resp);
        } else {
            chain.doFilter(req, resp);
        }
    }

    public void destroy() {
    }

    public List<String> getIncludes() {
        if (this.includes == null) {
            this.includes = new ArrayList<String>();
        }
        return this.includes;
    }

    public void setIncludes(List<String> includes) {
        this.includes = includes;
    }
}
