<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xmlns:p="http://www.springframework.org/schema/p"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:oxm="http://www.springframework.org/schema/oxm"
	xmlns:util="http://www.springframework.org/schema/util"
	xsi:schemaLocation="
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
		http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
		http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.1.xsd
		http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
		">
	
	<mvc:default-servlet-handler />
	
	<!-- JAXB mapper -->
	<!-- http://springinpractice.com/2011/12/29/its-back-the-classpathscanningjaxb2marshaller/ -->
	<bean id="marshaller" class="com.springinpractice.ch11.oxm.ClasspathScanningJaxb2Marshaller">
		<property name="basePackages">
			<list>
				<value>com.springinpractice.ch11.integrations.github.model</value>
				<value>com.springinpractice.ch11.model</value>
			</list>
		</property>
	</bean>
		
	<!-- Jackson mapper -->
	<bean id="jaxbAnnIntrospector" class="org.codehaus.jackson.xc.JaxbAnnotationIntrospector" />
	<bean id="jacksonObjectMapper" class="org.codehaus.jackson.map.ObjectMapper">
		<property name="serializationConfig.annotationIntrospector" ref="jaxbAnnIntrospector" />
		<property name="deserializationConfig.annotationIntrospector" ref="jaxbAnnIntrospector" />
	</bean>
	
	<mvc:annotation-driven conversion-service="conversionService">
	
		<!-- Spring 3.1 only -->
		<mvc:message-converters>
			<!-- Converters defined here override the defaults. Here we want to override the default so we can add our
			     custom Jackson ObjectMapper, which understands JAXB annotations. See below. -->
			<bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"
				p:objectMapper-ref="jacksonObjectMapper" />
		</mvc:message-converters>
	</mvc:annotation-driven>
	
<!-- 	<mvc:resources mapping="/images/**" location="/images/" /> -->
<!-- 	<mvc:resources mapping="/resources/**" location="/resources/" /> -->
	
	<bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
		<property name="formatters">
			<list>
				<ref bean="dataCenterFormatter" />
				<ref bean="environmentFormatter" />
				<ref bean="regionFormatter" />
			</list>
		</property>
	</bean>
	
	<mvc:view-controller path="/login" />
	
	<context:component-scan base-package="com.springinpractice.ch11.formatter" />
	<context:component-scan base-package="com.springinpractice.ch11.web.controller" />
	<context:component-scan base-package="com.springinpractice.ch11.web.view" />
	
	<!-- Handles OAuth negotiation for Spring Social -->
	<bean class="org.springframework.social.connect.web.ConnectController" />
	
	<bean id="paths" class="com.springinpractice.ch11.web.sitemap.Paths" />
	
	<bean class="com.springinpractice.ch11.web.sitemap.Sitemap" p:messageSource-ref="messageSource" p:paths-ref="paths">
		<property name="expressionParser">
			<bean class="org.springframework.expression.spel.standard.SpelExpressionParser" />
		</property>
	</bean>
	
	<bean id="messageSource"
		class="org.springframework.context.support.ReloadableResourceBundleMessageSource"
		p:basename="classpath:/spring/messages" />
	
	
	<!-- =========================================================================================================== -->
	<!-- Views                                                                                                       -->
	<!-- =========================================================================================================== -->
	
	<!-- Tiles -->
	<bean class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
		<property name="definitions">
			<list>
				<value>/WEB-INF/tiles/**/*.xml</value>
			</list>
		</property>
		
		<!-- Initialize expression language support for use in Tiles definitions. -->
		<property name="tilesProperties">
			<props>
				<prop key="org.apache.tiles.evaluator.AttributeEvaluator">org.apache.tiles.evaluator.el.ELAttributeEvaluator</prop>
			</props>
		</property>        
	</bean>
	
	<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver" p:favorParameter="true">
		<property name="viewResolvers">
			<list>
				<bean class="org.springframework.web.servlet.view.tiles2.TilesViewResolver" />
				<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
					p:prefix="/WEB-INF/jsp/"
					p:suffix=".jsp" />
			</list>
		</property>
	</bean>
</beans>
