<?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-2.0.xsd">

  <on-start>
    <set name="requestScope.communityCode" value="requestParameters.communityCode"/>
    <set name="requestScope.threadId" value="requestParameters.threadId" type="int"/>
    <set name="requestScope.user" value="externalContext.requestMap._user"/>
    <set name="flowScope.community" value="communityTable.findByCodeForPost(communityCode, user)"/>
    <set name="flowScope.thread" value="community.getThread(threadId)"/>
  </on-start>

  <subflow-state id="captcha" subflow="captcha-sub-flow">
    <transition on="finish" to="form"/>
  </subflow-state>

  <subflow-state id="form" subflow="thread.entryForm-sub-flow">
    <input name="threadId" value="thread.id" required="true"/>
    <input name="subjectDisabled" value="true"/>
    <transition on="finish" to="finish"/>
  </subflow-state>

  <decision-state id="finish">
    <if test="flowScope.community.class.simpleName == 'SingleThreadCommunity'" then="singleThreadFinish"/>
    <if test="flowScope.community.class.simpleName == 'MultiThreadCommunity'" then="multiThreadFinish"/>
  </decision-state>

  <end-state id="singleThreadFinish" view="externalRedirect:contextRelative:/community/${flowScope.community.code}/index.html"/>
  <end-state id="multiThreadFinish" view="externalRedirect:contextRelative:/community/${flowScope.community.code}/${flowScope.thread.id}/index.html"/>

</flow>
