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

  <var name="blog" class="org.unitedfront2.domain.communication.Blog"/>
  <var name="readAccessControl" class="org.unitedfront2.domain.accesscontrol.UserOnly"/>
  <var name="writeAccessControl" class="org.unitedfront2.domain.accesscontrol.OwnerOnly"/>
  <var name="commentAccessControl" class="org.unitedfront2.domain.accesscontrol.UserOnly"/>
  <var name="overview" class="org.unitedfront2.domain.communication.Message"/>

  <on-start>
    <set name="requestScope.user" value="externalContext.requestMap._user"/>
    <set name="overview.ownerId" value="user.id"/>
    <set name="overview.authorId" value="user.id"/>
    <set name="overview.readAccessControl" value="readAccessControl"/>
    <set name="overview.writeAccessControl" value="writeAccessControl"/>
    <set name="blog.ownerId" value="user.id"/>
    <set name="blog.readAccessControl" value="readAccessControl"/>
    <set name="blog.writeAccessControl" value="writeAccessControl"/>
    <set name="blog.commentAccessControl" value="commentAccessControl"/>
    <set name="blog.overview" value="overview"/>
  </on-start>

  <subflow-state subflow="blog.form-sub-flow" id="form">
    <input name="pageTitleCode" value="'blog.CreateForm'"/>
    <input name="lastSubmitCode" value="'doCreate'"/>
    <input name="blog" required="true"/>
    <output name="blog" required="true"/>
    <transition on="finish" to="finish"/>
  </subflow-state>

  <end-state id="finish" view="externalRedirect:contextRelative:/blog/${flowScope.blog.code}/index.html"/>

</flow>
