/*
 * Copyright (C) 2008 feilong
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.feilong.spring.web.servlet.interceptor.i18n;

import java.util.List;

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

import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;

import com.feilong.core.Validator;

/**
 * 如果直接使用 {@link org.springframework.web.servlet.i18n.LocaleChangeInterceptor} ,而参数中传入了 不存在的/不支持的 locale 调用
 * {@link org.springframework.util.StringUtils#parseLocaleString(String)}会报错
 *
 * @author feilong
 * @version 1.0.9 2014年12月18日 上午2:29:55
 * @since 1.0.9
 */
public class SupportLocaleChangeInterceptor extends LocaleChangeInterceptor{

    /** The support locales. */
    private List<String> supportLocales;

    /*
     * (non-Javadoc)
     * 
     * @see org.springframework.web.servlet.i18n.LocaleChangeInterceptor#preHandle(javax.servlet.http.HttpServletRequest,
     * javax.servlet.http.HttpServletResponse, java.lang.Object)
     */
    @Override
    public boolean preHandle(HttpServletRequest request,HttpServletResponse response,Object handler) throws ServletException{
        boolean canHandle = isSupport(request);
        if (canHandle){
            super.preHandle(request, response, handler);
        }
        //不管支不支持  都return true
        return true;
    }

    /**
     * Checks if is support.
     *
     * @param request
     *            the request
     * @return true, if checks if is support
     * @since 1.0.9
     */
    private boolean isSupport(HttpServletRequest request){
        boolean canHandle = false;

        if (Validator.isNotNullOrEmpty(supportLocales)){
            String newLocale = request.getParameter(getParamName());
            if (supportLocales.contains(newLocale)){
                canHandle = true;
            }
            //不属于支持的locale
        }else{
            //如果isNotNullOrEmpty  supportLocales ,那么 就是个普通的  LocaleChangeInterceptor
            canHandle = true;
        }
        return canHandle;
    }

    /**
     * 设置 support locales.
     *
     * @param supportLocales
     *            the supportLocales to set
     */
    public void setSupportLocales(List<String> supportLocales){
        this.supportLocales = supportLocales;
    }
}
@@ -807,16 +807,73 @@
 ponse;%0A%0A
+import org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A
 import o
@@ -1319,16 +1319,150 @@
 eptor%7B%0A%0A
+    /** The Constant log. */%0A    private static final Logger LOGGER = LoggerFactory.getLogger(SupportLocaleChangeInterceptor.class);%0A%0A
     /** 
@@ -1501,32 +1501,39 @@
 ate List%3CString%3E
+       
  supportLocales;
@@ -2343,58 +2343,219 @@
     
-boolean canHandle = false;%0A%0A        if (Validator.
+if (Validator.isNullOrEmpty(supportLocales))%7B%0A            LOGGER.warn(%22SupportLocaleChangeInterceptor's supportLocales is isNullOrEmpty,you can direct use LocaleChangeInterceptor%22);%0A            return true; //%E5%A6%82%E6%9E%9C
 isNo
@@ -2558,33 +2558,33 @@
 isNotNullOrEmpty
-(
+ 
 supportLocales))
@@ -2577,32 +2577,71 @@
 pportLocales
-))%7B
+,%E9%82%A3%E4%B9%88 %E5%B0%B1%E6%98%AF%E4%B8%AA%E6%99%AE%E9%80%9A%E7%9A%84  LocaleChangeInterceptor
 %0A    
+    %7D%0A%0A
         Stri
@@ -2652,16 +2652,21 @@
 ewLocale
+Value
  = reque
@@ -2706,24 +2706,35 @@
         
-    if (
+boolean contains = 
 supportL
@@ -2762,44 +2762,14 @@
 cale
-))%7B%0A                canHandle = tr
+Val
 ue
+)
 ;%0A  
@@ -2778,169 +2778,153 @@
     
-    %7D%0A            //%E4%B8%8D%E5%B1%9E%E4%BA%8E%E6%94%AF%E6%8C%81%E7%9A%84locale%0A        %7Delse%7B%0A            //%E5%A6%82%E6%9E%9CisNotNullOrEmpty  supportLocales ,%E9%82%A3%E4%B9%88 %E5%B0%B1%E6%98%AF%E4%B8%AA%E6%99%AE%E9%80%9A%E7%9A%84  LocaleChangeInterceptor%0A            canHandle = tr
+if (!contains)%7B%0A            LOGGER.warn(%22SupportLocaleChangeInterceptor's supportLocales:%5B%7B%7D%5D not contains %5B%7B%7D%5D%22, supportLocales, newLocaleVal
 ue
+)
 ;%0A  
@@ -2951,17 +2951,32 @@
 rn c
-anHand
+ontains; //%E6%98%AF%E5%90%A6%E5%B1%9E%E4%BA%8E%E6%94%AF%E6%8C%81%E7%9A%84loca
 le
-;
 %0A   

update javadoc