/*
 * 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.mvc;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.annotation.Resource;

import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.MessageSourceResolvable;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.servlet.view.UrlBasedViewResolver;

import com.feilong.core.DatePattern;
import com.feilong.core.Validator;
import com.feilong.servlet.http.HttpHeaders;
import com.feilong.spring.web.servlet.LocaleUtil;

/**
 * 通用的 父类 AbstractController.
 * 
 * @author <a href="http://feitianbenyue.iteye.com/">feilong</a>
 * @since 1.0.3
 */
public abstract class AbstractController{

    /** The Constant header_with_ajax_springmvc. */
    public static final String   HEADER_WITH_AJAX_SPRINGMVC = HttpHeaders.X_REQUESTED_WITH + "=" + HttpHeaders.X_REQUESTED_WITH_VALUE_AJAX;

    /** The context. */
    @Resource
    protected ApplicationContext context;

    // @Autowired
    // protected ReloadableResourceBundleMessageSource reloadableResourceBundleMessageSource;

    /**
     * Inits the binder.
     * 
     * @param webDataBinder
     *            the web data binder
     */
    @InitBinder
    public void initBinder(WebDataBinder webDataBinder){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DatePattern.COMMON_DATE);
        webDataBinder.registerCustomEditor(Date.class, new CustomDateEditor(simpleDateFormat, true));

        // can be override to add new binding
        initBinderInternal(webDataBinder);
    }

    /**
     * can be override to add new binding.
     * 
     * @param webDataBinder
     *            webDataBinder
     */
    protected void initBinderInternal(@SuppressWarnings("unused") WebDataBinder webDataBinder){
    }

    /**
     * 生成spring 的跳转路径<br>
     * e.g. getSpringRedirectPath("/shoppingcart") <br>
     * 注:不需要你手工的 拼接request.getContextPath()
     * 
     * @param targetUrl
     *            如果是相对根目录路径 只需要传递 如"/shoppingcart" spring会自动添加request.getContextPath() <br>
     *            也可以传入绝对路径 如:http://www.baidu.com
     * @return the spring redirect path
     */
    protected String redirect(String targetUrl){
        return UrlBasedViewResolver.REDIRECT_URL_PREFIX + targetUrl;
    }

    /**
     * 生成 spring Forward 路径.
     * 
     * @param forwardUrl
     *            the forward url
     * @return the spring forward path
     */
    protected String forward(String forwardUrl){
        return UrlBasedViewResolver.FORWARD_URL_PREFIX + forwardUrl;
    }

    // **********************************************************************************************

    /**
     * 获得消息信息.
     * 
     * @param errorCode
     *            the error code
     * @return the message
     */
    protected String getMessage(Integer errorCode){
        Object[] args = null;
        return getMessage(errorCode, args);
    }

    /**
     * 获得消息信息.
     * 
     * @param errorCode
     *            the error code
     * @param args
     *            args
     * @return the message
     */
    protected String getMessage(Integer errorCode,Object...args){
        if (Validator.isNotNullOrEmpty(errorCode)){
            String prefix = "ExceptionResolver.BUSINESS_EXCEPTION_PREFIX";
            return getMessage(prefix + errorCode, args);
        }
        return null;
    }

    /**
     * 获得消息信息.
     * 
     * @param code
     *            code
     * @param args
     *            args
     * @return the message
     */
    protected String getMessage(String code,Object...args){
        if (Validator.isNotNullOrEmpty(code)){
            return context.getMessage(code, args, LocaleUtil.getLocale());
        }
        return null;
    }

    /**
     * 获得消息信息.
     * 
     * @param messageSourceResolvable
     *            适用于 ObjectError 以及 FieldError
     * @return the message
     */
    protected String getMessage(MessageSourceResolvable messageSourceResolvable){
        return context.getMessage(messageSourceResolvable, LocaleUtil.getLocale());
    }

}

@@ -3430,721 +3430,11 @@
 ram 
-errorCode%0A     *            the error code%0A     * @return the message%0A     */%0A    protected String getMessage(Integer errorCode)%7B%0A        Object%5B%5D args = null;%0A        return getMessage(errorCode, args);%0A    %7D%0A%0A    /**%0A     * %E8%8E%B7%E5%BE%97%E6%B6%88%E6%81%AF%E4%BF%A1%E6%81%AF.%0A     * %0A     * @param errorCode%0A     *            the error code%0A     * @param args%0A     *            args%0A     * @return the message%0A     */%0A    protected String getMessage(Integer errorCode,Object...args)%7B%0A        if (Validator.isNotNullOrEmpty(errorCode))%7B%0A            String prefix = %22ExceptionResolver.BUSINESS_EXCEPTION_PREFIX%22;%0A            return getMessage(prefix + errorCode, args);%0A        %7D%0A        return null;%0A    %7D%0A%0A    /**%0A     * %E8%8E%B7%E5%BE%97%E6%B6%88%E6%81%AF%E4%BF%A1%E6%81%AF.%0A     * %0A     * @param code
+key
 %0A   
@@ -3569,20 +3569,19 @@
 (String 
-code
+key
 ,Object.
@@ -3628,20 +3628,19 @@
 OrEmpty(
-code
+key
 ))%7B%0A    
@@ -3673,20 +3673,19 @@
 Message(
-code
+key
 , args, 

remove AbstractController `getMessage(Integer errorCode,Object...args)` method