<?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="blogEntry" class="org.unitedfront2.domain.communication.BlogEntry"/>

  <on-start>
    <set name="flowScope.blogCode" value="requestParameters.blogCode"/>
  </on-start>

  <subflow-state id="form" subflow="message.form-sub-flow">
    <input name="pageTitleCode" value="'blog.EntryCreateForm'"/>
    <input name="formSubmitCode" value="'doPost'"/>
    <input name="subjectRequired" value="true"/>
    <output name="message" value="blogEntry.entry" required="true"/>
    <transition on="finish" to="post"/>
  </subflow-state>

  <end-state id="post" view="externalRedirect:contextRelative:/blog/${flowScope.blogCode}/index.html">
    <on-entry>
      <set name="requestScope.user" value="externalContext.requestMap._user"/>
      <set name="requestScope.blog" value="blogTable.findByCodeForWrite(blogCode, user)"/>
      <set name="blogEntry.entry.ownerId" value="user.id"/>
      <set name="blogEntry.entry.authorId" value="user.id"/>
      <set name="blogEntry.entry.readAccessControl" value="blog.readAccessControl"/>
      <set name="blogEntry.entry.writeAccessControl" value="blog.writeAccessControl"/>
      <evaluate expression="domainFactory.prototype(blog).post(domainFactory.prototype(blogEntry))"/>
    </on-entry>
  </end-state>

</flow>
