<?xml version="1.0"?>

<project xmlns:j="jelly:core" xmlns:u="jelly:util">

  <goal 
    name="pdf:init"
    prereqs="xdoc:init">

    <j:set var="docsDest"
      value="${pom.getPluginContext('maven-xdoc-plugin').getVariable('maven.docs.dest')}"/>
    <j:set var="docsSrc"
      value="${pom.getPluginContext('maven-xdoc-plugin').getVariable('maven.docs.src')}"/>

  </goal>

  <goal
    name="fo"
    prereqs="fo:fo"
    description="Generate XSL:FO project documentation"/>

  <goal name="fo:fo" 
    prereqs="pdf:init"
    description="Generate XSL:FO project documentation">
    
    <echo>Generating ${docsDest}/project.fo ...</echo>
    <available file="${docsSrc}/navigation.xml" 
      property="maven.fo.navigation.available"/>
    <fail message="PDF generation cannot complete as ${docsSrc}/navigation.xml is missing"
      unless="maven.fo.navigation.available"/>
    <u:file name="${plugin.resources}/project2fo.xslt" var="stylesheetFile" />
    <u:file name="${docsSrc}/navigation.xml" var="navigationFile" />
    <java classname="org.apache.xalan.xslt.Process" fork="yes" failonerror="true">
      <classpath>
        <pathelement location="${plugin.getDependencyPath('xerces')}"/>
        <pathelement location="${plugin.getDependencyPath('xml-apis')}"/>
        <pathelement location="${plugin.getDependencyPath('xalan')}"/>
      </classpath>
      <sysproperty key="user.language" value="en"/>
      <arg value="-in"/>
      <arg value="${navigationFile.toURL().toExternalForm()}"/>
      <arg value="-out"/>
      <arg value="${docsDest}/project.fo"/>
      <arg value="-xsl"/>
      <arg value="${stylesheetFile.toURL().toExternalForm()}"/>
      <arg value="-param"/>
      <arg value="basePath"/>
      <arg value="${docsSrc}"/>
    </java>

  </goal>

  <goal
    name="pdf"
    prereqs="pdf:pdf"
    description="Generate PDF project documentation"/>

  <goal name="pdf:pdf" description="Generate PDF project documentation"
     prereqs="pdf:init, fo">

    <echo>Generating ${docsDest}/project.pdf ...</echo>
    <java classname="org.apache.fop.apps.Fop" fork="yes" failonerror="true">
      <classpath>
        <pathelement location="${plugin.getDependencyPath('fop')}"/>
        <pathelement location="${plugin.getDependencyPath('batik')}"/>
        <pathelement location="${plugin.getDependencyPath('logkit')}"/>
        <pathelement location="${plugin.getDependencyPath('avalon-framework')}"/>
        <pathelement location="${plugin.getDependencyPath('xerces')}"/>
        <pathelement location="${plugin.getDependencyPath('xml-apis')}"/>
      </classpath>
      <arg value="-d" />
      <arg value="-fo" />
      <arg value="${docsDest}/project.fo" />
      <arg value="-pdf" />
      <arg value="${docsDest}/project.pdf"/>
    </java>

  </goal>

</project>
