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

  <input-mapper>
    <input-attribute name="pageTitleCode" required="true"/>
    <input-attribute name="lastSubmitCode" required="true"/>
    <input-attribute name="blog" required="true"/>
  </input-mapper>

  <start-state idref="init"/>

  <action-state id="init">
    <action bean="blog.formAction" method="init"/>
    <transition on="success" to="codeForm"/>
  </action-state>

  <view-state id="codeForm" view="blog.Form">
    <render-actions>
      <action bean="blog.formAction" method="setupForm"/>
    </render-actions>
    <transition on="submit" to="readAccessControlForm">
      <action bean="blog.formAction" method="bindAndValidate"/>
    </transition>
  </view-state>

  <subflow-state flow="accesscontrol/form-sub-flow" id="readAccessControlForm">
    <attribute-mapper>
      <input-mapper>
        <input-attribute name="pageTitleCode" required="true"/>
        <input-attribute name="formSubmitCode" required="true"/>
        <mapping source="flowScope.blog.readAccessControl" target="accessControl" required="true"/>
        <mapping source="flowScope.formReadAccessControlDescription" target="pageDescriptionCode" required="true"/>
      </input-mapper>
    </attribute-mapper>
    <transition on="finish" to="commentAccessControlForm"/>
  </subflow-state>

  <subflow-state flow="accesscontrol/form-sub-flow" id="commentAccessControlForm">
    <attribute-mapper>
      <input-mapper>
        <input-attribute name="pageTitleCode" required="true"/>
        <input-attribute name="formSubmitCode" required="true"/>
        <mapping source="flowScope.blog.commentAccessControl" target="accessControl" required="true"/>
        <mapping source="flowScope.formCommentAccessControlDescription" target="pageDescriptionCode" required="true"/>
      </input-mapper>
    </attribute-mapper>
    <transition on="finish" to="messageForm"/>
  </subflow-state>

  <subflow-state flow="message/form-sub-flow" id="messageForm">
    <attribute-mapper>
      <input-mapper>
        <input-attribute name="pageTitleCode" required="true"/>
        <input-attribute name="subjectRequired" required="true"/>
        <mapping source="flowScope.blog.overview" target="message"/>
        <mapping source="flowScope.formMessageDescription" target="pageDescriptionCode" required="true"/>
        <mapping source="flowScope.lastSubmitCode" target="formSubmitCode" required="true"/>
      </input-mapper>
    </attribute-mapper>
    <transition on="finish" to="store"/>
  </subflow-state>

  <action-state id="store">
    <action bean="blog.formAction" method="store"/>
    <transition on-exception="org.unitedfront2.domain.communication.BlogCodeUsedByOtherException" to="codeForm"/>
    <transition on="success" to="finish"/>
  </action-state>

  <end-state id="finish">
    <output-mapper>
      <output-attribute name="blog" required="true"/>
    </output-mapper>
  </end-state>

</flow>
