package me.chyxion.tigon.codegen.freemarker;

import java.util.Locale;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;

/**
 * @version 0.0.1
 * @since 0.0.1
 * @author Shaun Chyxion <br>
 * chyxion@163.com <br>
 * Dec 5, 2014 2:31:39 PM
 */
@Slf4j
public class FreeMarkerViewResolverExt extends FreeMarkerViewResolver {

    /**
     * {@inheritDoc}
     */
    @Override
    public View resolveViewName(String viewName, Locale locale) 
            throws Exception {
        log.debug("Try to resolve view name [{}], locale [{}] as freemarker view.", viewName, locale);
        return super.resolveViewName(viewName.replaceAll("(?i)(^\\s*ftl:)|(\\.ftl\\s*$)", ""), locale);
    }
}
