<?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">

  <secured attributes="ROLE_USER, ROLE_ADMIN"/>

  <decision-state id="singleOrMultiple">
    <on-entry>
      <set name="requestScope.user" value="externalContext.requestMap._user"/>
      <evaluate expression="blogTable.findByOwnerId(user.id)" result="flashScope.blogs,flowScope.blogs"/>
      <set name="flashScope.blogNum" value="blogs.size()"/>
    </on-entry>
    <if test="flashScope.blogNum == 1" then="singleView" else="multipleView"/>
  </decision-state>

  <end-state id="singleView" view="externalRedirect:contextRelative:/blog/${flowScope.blogs[0].code}/index.html"/>

  <end-state id="multipleView" view="blog.Index"/>

</flow>
