<?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.code" value="requestParameters.code"/>
    <set name="requestScope.user" value="externalContext.requestMap._user"/>
    <set name="flowScope.community" value="communityTable.findByCodeForRead(code, user)"/>
  </on-start>

  <decision-state id="view">
    <on-entry>
      <set name="requestScope.user" value="externalContext.requestMap._user"/>
      <set name="flashScope.community" value="community"/>
      <set name="flashScope.myCommunity" value="community.isMyCommunity(user)"/>
      <set name="flashScope._feedUrl" value="'/community/' + community.code + '/index.xml'"/>
      <evaluate expression="communityViewAction.putTitle"/>
    </on-entry>
    <if test="community.class.simpleName == 'SingleThreadCommunity'" then="singleThreadView"/>
    <if test="community.class.simpleName == 'MultiThreadCommunity'" then="multiThreadView"/>
  </decision-state>

  <end-state id="singleThreadView" view="community.SingleThreadView">
    <on-entry>
      <set name="requestScope.displayCount" value="5" type="int"/>
      <set name="requestScope.page" value="requestParameters.page" type="int"/>
      <evaluate expression="community.retrieveEntries(page * displayCount, displayCount)"/>
    </on-entry>
  </end-state>

  <end-state id="multiThreadView" view="community.MultiThreadView"/>

</flow>
