<?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"
  xmlns:aop="http://www.springframework.org/schema/aop"
  xmlns:tx="http://www.springframework.org/schema/tx"
  xmlns:webflow="http://www.springframework.org/schema/webflow-config"
  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
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
    http://www.springframework.org/schema/webflow-config
    http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd">

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

  <context:annotation-config/>

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

  <bean id="mailService" class="org.unitedfront2.web.mail.MailServiceImpl">
    <property name="enable" value="${mailSender.enable}"/>
    <property name="signature" value="${mailSender.signature}"/>
    <property name="subjectPrefix" value="${mailSender.subjectPrefix}"/>
    <property name="mailSender" ref="mailSender"/>
    <property name="simpleMailMessageValidator" ref="simpleMailMessageValidator"/>
    <property name="customProperties">
      <props>
        <prop key="_systemMailAddr">${systemMailAddr}</prop>
        <prop key="_systemUrl">${systemUrl}</prop>
      </props>
    </property>
  </bean>

  <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
    <property name="defaultEncoding" value="ISO-2022-JP"/>
    <property name="host" value="${mailSender.host}"/>
    <property name="port" value="${mailSender.port}"/>
    <property name="username" value="${mailSender.username}"/>
    <property name="password" value="${mailSender.password}"/>
  </bean>

  <bean id="simpleMailMessageValidator" class="org.unitedfront2.web.mail.SimpleMailMessageValidator"/>

  <!-- Actions -->
  <bean id="indexAction" class="org.unitedfront2.web.controller.IndexAction">
    <property name="adminBlogCode" value="${adminBlog.code}"/>
  </bean>

  <bean id="registrationAction" class="org.unitedfront2.web.controller.RegistrationAction">
    <property name="installers">
      <list>
        <ref bean="profileTable"/>
        <ref bean="emailForwardingTable"/>
        <ref bean="widgetTable"/>
      </list>
    </property>
  </bean>

  <bean id="rssController" class="org.unitedfront2.web.controller.RssController">
    <property name="adminBlogCode" value="${adminBlog.code}"/>
  </bean>

  <!-- Web Flow Settings -->
  <bean id="flowController" class="org.springframework.webflow.mvc.servlet.FlowController">
    <property name="flowExecutor" ref="flowExecutor"/>
    <property name="flowUrlHandler" ref="flowUrlHandler"/>
  </bean>

  <bean id="flowUrlHandler" class="org.unitedfront2.web.flow.FlowUrlHandler"/>

  <webflow:flow-executor id="flowExecutor" flow-registry="flowRegistry">
    <webflow:flow-execution-listeners>
      <webflow:listener ref="securityFlowExecutionListener"/>
    </webflow:flow-execution-listeners>
  </webflow:flow-executor>

  <bean id="securityFlowExecutionListener" class="org.springframework.webflow.security.SecurityFlowExecutionListener"/>

  <webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices">
    <webflow:flow-location-pattern value="/WEB-INF/view/**/*-flow.xml"/>
  </webflow:flow-registry>
	
  <webflow:flow-builder-services id="flowBuilderServices" view-factory-creator="mvcViewFactoryCreator" conversion-service="conversionService"/>

  <bean id="mvcViewFactoryCreator" class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator"> 
    <property name="viewResolvers" ref="viewResolver"/> 
  </bean>

  <bean id="conversionService" class="org.unitedfront2.web.flow.ConversionServiceImpl">
    <property name="customConverters">
      <map>
      </map>
    </property>
  </bean>

  <bean id="formActionConfig" class="java.util.Properties">
    <constructor-arg>
      <props>
        <prop key="mail.sendMail">${mailSender.enable}</prop>
        <prop key="mail.systemMailAddr">${systemMailAddr}</prop>
        <prop key="mail.systemUrl">${systemUrl}</prop>
        <prop key="mail.subjectPrefix">${mailSender.subjectPrefix}</prop>
        <prop key="mail.signature">${mailSender.signature}</prop>
      </props>
    </constructor-arg>
  </bean>

  <!-- Aspect (Transaction) -->
  <aop:config>
    <aop:pointcut id="action" expression="execution(public org.springframework.webflow.execution.Event org.springframework.webflow.execution.Action+.execute(..)) &amp;&amp; args(org.springframework.webflow.execution.RequestContext)"/>
    <aop:advisor pointcut-ref="action" advice-ref="txAdvice"/>
  </aop:config>

  <tx:advice id="txAdvice" transaction-manager="txManager">
    <tx:attributes>
      <tx:method name="*" timeout="30" rollback-for="Throwable"/>
    </tx:attributes>
  </tx:advice>

  <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource"/>
  </bean>

</beans>
