package org.unidle.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.tiles3.TilesConfigurer;
import org.springframework.web.servlet.view.tiles3.TilesViewResolver;
import org.unidle.service.LocationService;
import org.unidle.web.BuildTimestampInterceptor;
import org.unidle.web.LocationHandlerMethodArgumentResolver;

import java.util.List;

@ComponentScan("org.unidle.controller")
@Configuration
@EnableWebMvc
public class MvcConfiguration extends WebMvcConfigurerAdapter {

    @Value("${unidle.build.timestamp}")
    private String buildTimestamp;

    @Autowired
    private LocationService locationService;

    @Value("${unidle.resource.cachePeriod}")
    private int resourceCachePeriod;

    @Bean
    public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
        return new PropertySourcesPlaceholderConfigurer();
    }

    @Override
    public void addArgumentResolvers(final List<HandlerMethodArgumentResolver> argumentResolvers) {
        argumentResolvers.add(locationHandlerMethodArgumentResolver());
    }

    @Override
    public void addInterceptors(final InterceptorRegistry registry) {
        registry.addInterceptor(buildTimestampInterceptor());
    }

    @Bean
    public HandlerInterceptor buildTimestampInterceptor() {
        return new BuildTimestampInterceptor(buildTimestamp);
    }

    @Override
    public void addResourceHandlers(final ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/font/*")
                .addResourceLocations("classpath:/META-INF/resources/webjars/font-awesome/3.2.1/font/")
                .setCachePeriod(resourceCachePeriod);
        registry.addResourceHandler("/images/*")
                .addResourceLocations("/WEB-INF/images/")
                .setCachePeriod(resourceCachePeriod);
    }

    @Bean
    public LocationHandlerMethodArgumentResolver locationHandlerMethodArgumentResolver() {
        return new LocationHandlerMethodArgumentResolver(locationService);
    }

    @Bean
    public TilesConfigurer tilesConfigurer() {
        return new TilesConfigurer();
    }

    @Bean
    public ViewResolver viewResolver() {
        return new TilesViewResolver();
    }

}

@@ -21,16 +21,132 @@
 onfig;%0A%0A
+import de.bripkens.gravatar.DefaultImage;%0Aimport de.bripkens.gravatar.Gravatar;%0Aimport de.bripkens.gravatar.Rating;%0A
 import o
@@ -1542,16 +1542,339 @@
 stamp;%0A%0A
+    @Value(%22$%7Bunidle.gravatar.https%7D%22)%0A    private boolean gravatarHttps;%0A%0A    @Value(%22$%7Bunidle.gravatar.rating%7D%22)%0A    private Rating gravatarRating;%0A%0A    @Value(%22$%7Bunidle.gravatar.size%7D%22)%0A    private int gravatarSize;%0A%0A    @Value(%22$%7Bunidle.gravatar.defaultImage%7D%22)%0A    private DefaultImage gravatarStandardDefaultImages;%0A%0A
     @Aut
@@ -3339,178 +3339,627 @@
 lic 
-TilesConfigurer tilesConfigurer() %7B%0A        return new TilesConfigurer();%0A    %7D%0A%0A    @Bean%0A    public ViewResolver viewResolver() %7B%0A        return new TilesViewResolver()
+Gravatar gravatar() %7B%0A        final Gravatar gravatar = new Gravatar();%0A%0A        gravatar.setRating(gravatarRating);%0A        gravatar.setSize(gravatarSize);%0A        gravatar.setHttps(gravatarHttps);%0A        gravatar.setStandardDefaultImage(gravatarStandardDefaultImages);%0A%0A        return gravatar;%0A    %7D%0A%0A    @Bean%0A    public TilesConfigurer tilesConfigurer() %7B%0A        return new TilesConfigurer();%0A    %7D%0A%0A    @Bean%0A    public ViewResolver viewResolver() %7B%0A        final TilesViewResolver viewResolver = new TilesViewResolver();%0A%0A        viewResolver.setExposePathVariables(Boolean.FALSE);%0A%0A        return viewResolver
 ;%0A  
@@ -3963,10 +3963,11 @@
 %0A    %7D%0A%0A
+%0A
 %7D%0A

Add gravatar configuration