package jp.sourceforge.shovel.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import jp.sourceforge.shovel.exception.ApplicationException;
import jp.sourceforge.shovel.service.IShovelService;

import org.seasar.extension.filter.EncodingFilter;
import org.seasar.framework.container.S2Container;
import org.seasar.framework.container.factory.SingletonS2ContainerFactory;

public class EncodingFilterWrapper extends EncodingFilter implements Filter {
    public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain) throws IOException, ServletException {
        try {
            if (getShovelService().getMobilePhone() != null) {
                request.setCharacterEncoding("Shift_JIS");
            }
        } catch (ApplicationException e) {
            //TODO
        }
        
        super.doFilter(request, response, chain);
    }
    
    S2Container getContainer() {
        return SingletonS2ContainerFactory.getContainer();
    }
    IShovelService getShovelService() {
        return (IShovelService)getContainer().getComponent(IShovelService.class);
    }
}
