<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:context="http://www.springframework.org/schema/context"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-2.5.xsd">

  <import resource="applicationContext-controller.xml"/>

  <context:annotation-config/>

  <context:component-scan base-package="org.unitedfront2.web.handler"/>

  <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="file:/etc/unitedfront2/localConfiguration.properties"/>
  </bean>

  <!-- URL Mapping -->
  <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    <property name="interceptors">
      <list>
        <ref bean="localeChangeInterceptor"/>
        <ref bean="themeChangeInterceptor"/>
        <ref bean="terminalChangeInterceptor"/>
        <ref bean="titleInterceptor"/>
        <ref bean="userInterceptor"/>
        <ref bean="widgetInterceptor"/>
        <ref bean="localConfigurationInterceptor"/>
        <ref bean="accessLogInterceptor"/>
      </list>
    </property>
    <property name="mappings">
      <props>
        <prop key="/**/*.html">flowController</prop>
        <prop key="/index.xml">rssController</prop>
        <prop key="/blog/view.xml">blog.rssController</prop>
        <prop key="/community/index.xml">community.myCommunitiesRssController</prop>
        <prop key="/community/view.xml">community.communityRssController</prop>
        <prop key="/community/threadView.xml">community.threadRssController</prop>
      </props>
    </property>
  </bean>

  <bean id="localeChangeInterceptor" class="org.unitedfront2.web.handler.LocaleChangeInterceptor">
    <property name="availableLocales" ref="availableLocales"/>
  </bean>

  <bean id="terminalChangeInterceptor" class="org.unitedfront2.web.handler.TerminalChangeInterceptor">
    <property name="mobileUserAgentsRegex">
      <list>
        <value>^DoCoMo.*$</value>
        <value>^(UP\\.Browser\\/|KDDI-).*$</value>
        <value>^(J-PHONE|Vodafone|MOT|SoftBank).*$</value>
      </list>
    </property>
  </bean>

  <bean id="titleInterceptor" class="org.unitedfront2.web.handler.TitleInterceptor">
    <property name="ignoreViewNames">
      <list>
        <value>Index</value>
      </list>
    </property>
  </bean>

  <bean id="localConfigurationInterceptor" class="org.unitedfront2.web.handler.LocalConfigurationInterceptor">
    <property name="properties">
      <map>
        <entry key="_version" value="2.0.0-RC1"/>
        <entry key="_usingEmail" value="${mailSender.enable}"/>
        <entry key="_dojoDebug" value="${dojo.debug}"/>
        <entry key="_systemUrl" value="${systemUrl}"/>
        <entry key="_serverName" value="${serverName}"/>
      </map>
    </property>
  </bean>

  <!-- Web Flow Controller -->
  <bean id="flowController" class="org.springframework.webflow.executor.mvc.FlowController">
    <property name="flowExecutor" ref="flowExecutor"/>
    <property name="argumentHandler" ref="argumentHandler"/>
  </bean>

  <!-- Web Flow Executor -->
  <bean id="flowExecutor" class="org.springframework.webflow.config.FlowExecutorFactoryBean">
    <property name="definitionLocator" ref="flowRegistry"/>
    <property name="executionAttributes">
      <map>
        <entry key="alwaysRedirectOnPause">
          <value type="java.lang.Boolean">false</value>
        </entry>
      </map>
    </property>
    <property name="repositoryType" value="SIMPLE"/>
  </bean>

  <!-- Web Flow Registry -->
  <bean id="flowRegistry" class="org.unitedfront2.web.flow.HierarchyXmlFlowRegistryFactoryBean">
    <property name="flowLocations">
      <list>
        <value>/WEB-INF/flows/**/*-flow.xml</value>
      </list>
    </property>
  </bean>

  <bean id="argumentHandler" class="org.unitedfront2.web.flow.UriFlowExecutorArgumentHandler"/>

  <!-- Locale Resolver -->
  <bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver"/>

  <!-- Exception Resolver -->
  <bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
    <property name="defaultErrorView" value="error.Error"/>
    <property name="defaultStatusCode" value="500"/>
    <property name="exceptionMappings">
      <props>
        <prop key="org.springframework.binding.convert.ConversionException">error.BadRequest</prop>
        <prop key="org.springframework.web.bind.ServletRequestBindingException">error.BadRequest</prop>
        <prop key="org.springframework.webflow.definition.registry.NoSuchFlowDefinitionException">error.NotFound</prop>
        <prop key="org.unitedfront2.web.AccessDeniedException">error.AccessDenied</prop>
        <prop key="org.unitedfront2.web.BadRequestException">error.BadRequest</prop>
        <prop key="org.unitedfront2.web.PageNotFoundException">error.NotFound</prop>
        <prop key="org.unitedfront2.web.flow.AccessDeniedException">error.AccessDenied</prop>
        <prop key="org.unitedfront2.web.flow.BadRequestException">error.BadRequest</prop>
        <prop key="org.unitedfront2.web.flow.PageNotFoundException">error.NotFound</prop>
      </props>
    </property>
    <property name="warnLogCategory" value="WARN"/>
  </bean>

  <!-- View Resolver -->
  <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/>
  </bean>

  <!-- Theme Resolver -->
  <bean id="themeResolver" class="org.springframework.web.servlet.theme.CookieThemeResolver">
    <property name="cookieMaxAge" value="-1"/>
    <property name="defaultThemeName" value="default"/>
  </bean>

  <!-- Tiles Configuration -->
  <bean id="tilesConfigurer" class="org.unitedfront2.web.TilesConfigurer">
    <property name="baseDir" value="/WEB-INF/view"/>
    <property name="preparerFactoryClass" value="org.springframework.web.servlet.view.tiles2.SpringBeanPreparerFactory"/>
  </bean>

</beans>
