<?xml version="1.0"?>
<!-- 
/*
 * Copyright 2001-2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 -->


<project xmlns:define="jelly:define"
  xmlns:j="jelly:core"
  xmlns:jsl="jelly:jsl"
  xmlns:log="jelly:log"
  xmlns:maven="jelly:maven"
  xmlns:pom="pom"
  xmlns:util="jelly:util"
  xmlns:x="jelly:xml"
  xmlns:velocity="jelly:velocity"
  xmlns:doc="doc">

  <j:new var="reports" className="java.util.ArrayList"/>


  <define:taglib uri="doc">
    <define:tag name="deregisterReport">
      <!-- @name : Report to deregister, must be same as name used to register -->
      
      <maven:pluginVar var="reports" plugin="maven-xdoc-plugin" property="reports" />
      
      <j:set var="removeRpt" value="null"/>
      <j:forEach var="rpt" items="${reports}">
        <j:if test="${rpt.get('name').equals(name)}">
          <j:set var="removeRpt" value="${rpt}"/>  
        </j:if>
      </j:forEach>
      <j:if test="${removeRpt != null}">
        <j:set var="dummy" value="${reports.remove(removeRpt)}"/>
      </j:if>
    </define:tag>
    
    <define:tag name="registerReport">
      <!--
      @name the name of this report. Used for navigation items
      @pluginName the name of the plugin.  @plugin:report goal must exist
      @description text description of report
      @link the nav-bar link for this report
      -->
      <maven:pluginVar var="reports" plugin="maven-xdoc-plugin" property="reports" />

      <!-- check if the given name is in the list already -->      
      <j:set var="add" value="true"/>
      <j:forEach var="rpt" items="${reports}">
        <j:if test="${rpt.get('name').equals(name)}">
          <j:set var="add" value="false"/>  
        </j:if>
      </j:forEach>
      
      <j:if test="${add.equals('true')}">
        <j:new var="report" className="java.util.HashMap"/>
        <j:set var="dummy">
          ${report.put('name', name)}
          ${report.put('pluginName', pluginName)}
          ${report.put('description', description)}
          ${report.put('link', link)}
          ${reports.add(report)}
        </j:set>
      </j:if>

    </define:tag>
    
    <define:tag name="formatAsNumber">
      <!--
       | @string
       | @pattern
      -->
      
      <!-- This appears to need to be here which is no good. Need
           more of a global tool box.
      -->
      
      <j:useBean var="formatter" class="org.apache.maven.util.DVSLFormatter"/>
      ${formatter.formatNumber(string,pattern)}
    </define:tag>

    <define:tag name="jslFile">
      <!--
       | Basic tag for performing arbitrary jsl transformations
       | on arbitrary jsl inputs.
       | @input
       | @output
       | @stylesheet
       | @encoding
       | @omitXmlDeclaration
       | @outputMode
       | @prettyPrint
      -->
 
      <!-- Set default encoding if not set. -->
      <j:if test="${encoding == null}">
        <j:set var="encoding" 
               value="${plugin.getVariable('maven.docs.outputencoding')}"/>
      </j:if>
      
      <util:file name="${input}" var="inputFile" />
      <x:parse var="doc" xml="${inputFile}"/>
      
      <j:set var="stylesheetURI" value="file:${stylesheet}"/>
      <j:file
        name="${output}"
        encoding="${encoding}"
        omitXmlDeclaration="${omitXmlDeclaration}"
        outputMode="${outputMode}"
        prettyPrint="${prettyPrint}">
        <j:include uri="${stylesheetURI.toString()}"/>
      </j:file>
    
    </define:tag>
    
    
    <define:tag name="jsl">
      <!--
       | This tag has a lot of defaults suitable for transforming
       | documents easily. See jslCore for a tag suitable for
       | transforming documents how you want.
       | @input
       | @outputDirectory - Will be placed under ${maven.gen.docs}
       | @stylesheet
       | @encoding           - defaults to ${maven.docs.outputencoding}
       | @omitXmlDeclaration - defaults to ${maven.docs.omitXmlDeclaration}
       | @outputMode
       | @prettyPrint
      -->
    
      <!-- 
      @todo make sure the output directory exists.
      -->        
      
      <!-- Set default outputDirectory if not set. -->
      <j:if test="${empty(outputDirectory)}">
        <j:set var="outputDirectory"  value="${maven.gen.docs}"
        />
      </j:if>

      <!-- Set default encoding if not set. -->
      <j:if test="${encoding == null}">
        <j:set var="encoding" value="${maven.docs.outputencoding}" />
      </j:if>
      
      <j:if test="${omitXmlDeclaration == null}">
        <j:set var="omitXmlDeclaration" value="${maven.docs.omitXmlDeclaration}"/>
      </j:if>
      
      <mkdir dir="${outputDirectory}"/>

      <doc:jslFile
        input="${input}"
        output="${outputDirectory}/${output}"
        stylesheet="${stylesheet}"
        encoding="${encoding}"
        omitXmlDeclaration="${omitXmlDeclaration}"
        outputMode="${outputMode}"
        prettyPrint="${prettyPrint}"/>
    </define:tag>


      <!--
        @link
        @relativePath
        @name
        @img
        @state - expanded / collapsed / none
        -->
    <define:tag name="itemLink">
      <a href="${pathTool.calculateLink(link,relativePath)}">
        <j:if test="${empty(state)}"><j:set var="state" value="none"/></j:if>
        <j:if test="${empty(img)}">${name}</j:if>
        <j:if test="${!empty(img)}"><img style="border: 1px" src="${img}" title="${name}" alt="${name}"/></j:if>
      </a>
    </define:tag>
    
    <define:tag name="text-xdoc">
      <!--
        @output - The output file
        @title - Title for page
        @section - Section heading
        @encoding - The XML encoding
        @preamble - Placed in paragraph block prior to text
        @inputText - Will be wrapped in a CDATA, will not escape CDATA tags (as yet)
        @inputFile - Will be read in and wrapped in CDATA. Overrides inputText if set
        -->
      <j:set var="inputFile">${inputFile}</j:set>
      <j:if test="${inputFile != ''}">
        <util:file name="${inputFile}" var="inputFileObject"/>
        <util:loadText var="inputText" file="${inputFileObject}"/>
       </j:if>
        
      <!-- Set default encoding if not set. -->
        <j:if test="${encoding == null}">
          <j:set var="encoding" 
                 value="${plugin.getVariable('maven.docs.outputencoding')}"/>
        </j:if>
      
      
      <j:file name="${output}" prettyPrint="false" encoding="${encoding}">         
            <document>
              <properties><title>${title}</title></properties>
              <body>
                <section name="${section}">
                <p>${preamble}</p>
                  <source>
                    <![CDATA[${inputText}]]>
                  </source>
                </section>
              </body>
            </document>
    </j:file>  
    </define:tag>

    <!-- Alternator for row style in a table -->
    <define:tag name="printRow">
      <j:if test="${(count % 2) gt 0}">
        <x:element name="tr">
          <x:attribute name="class">a</x:attribute>
        </x:element>
      </j:if>
      <j:if test="${(count % 2) le 0}">
        <x:element name="tr">
          <x:attribute name="class">b</x:attribute>
        </x:element>
      </j:if>
    </define:tag>

    <!-- Generates the JSL files on the given srcdir attribute -->
    <define:tag name="performJSL">
      <util:file var="srcdirFile" name="${srcdir}"/>
      <j:set var="srcdir" value="${srcdirFile.getCanonicalPath()}"/>
      <util:file var="destdirFile" name="${destdir}"/>
      <j:set var="destdir" value="${destdirFile.getCanonicalPath()}"/>
       
      <util:replace var="fromPattern" oldChar="\" newChar="/" value="${srcdir}/*.xml"/>
      <util:replace var="toPattern" oldChar="\" newChar="/" value="${destdir}/*.html"/>
      <j:if test="${mapper == null}">
        <j:new var="mapper" className="org.apache.maven.util.CaseInsensitiveGlobPatternMapper"/>
      </j:if>
      <j:setProperties object="${mapper}" from="${fromPattern}" to="${toPattern}"/>

      <util:replace var="fromDirPattern" oldChar="\" newChar="/" value="${srcdir}*"/>
      <util:replace var="toDirPattern" oldChar="\" newChar="/" value="${destdir}*"/>
      <j:new var="dirMapper" className="org.apache.maven.util.CaseInsensitiveGlobPatternMapper"/>
      <j:setProperties object="${dirMapper}" from="${fromDirPattern}" to="${toDirPattern}"/>

      <fileScanner var="docFiles">
        <fileset dir="${srcdir}">
          <patternset>
            <exclude name="**/project.xml"/>
            <exclude name="**/template.xml"/>
            <exclude name="**/navigation.xml"/>
            <exclude name="changes.xml"/>
            <include name="**/*.xml"/>
          </patternset>
        </fileset>
      </fileScanner>

      <!-- determine nav file to be used:- 1. check for sitewide nav files -->
      <!-- supplied nav file as project.xml in stylesheets dir -->
      <util:available file="${maven.docs.src}/stylesheets/project.xml">
        <util:file var="siteNavFile" name="${maven.docs.src}/stylesheets/project.xml"/>
      </util:available>
      <!-- supplied nav file as project.xml in root of xdocs source tree -->
      <util:available file="${maven.docs.src}/project.xml">
        <util:file var="siteNavFile" name="${maven.docs.src}/project.xml"/>
      </util:available>
      <!-- supplied navigation file in root of xdocs source tree -->
      <util:available file="${maven.docs.src}/navigation.xml">
        <util:file var="siteNavFile" name="${maven.docs.src}/navigation.xml"/>
      </util:available>
      <!-- navigation file that was generated -->
      <util:available file="${maven.gen.docs}/navigation.xml"> 
        <util:file var="siteNavFile" name="${maven.gen.docs}/navigation.xml"/> 
      </util:available> 
      <!-- hold onto maven.docs.src for later -->
      <util:file var="docsSrcFile" name="${maven.docs.src}"/>

      <!-- parse the project nav. Someone jellier than me can remove the temp file requirement -->
      <maven:pluginVar var="reports" plugin="maven-xdoc-plugin" property="reports" />

      <util:file var="tempnav" name="${maven.build.dir}/project-nav.xml"/>
    
      <j:file name="${tempnav.toString()}" outputMode="xml">
        <j:import file="${plugin.resources}/navigation.jelly" inherit="true"/>    
      </j:file>
  
      <x:parse var="projectNavRoot" xml="${tempnav}"/>
      <x:set var="projectNav" select="$projectNavRoot/project"/>

      <j:forEach var="file" items="${docFiles.iterator()}">

        <util:replace var="inDirForward" oldChar="\" newChar="/" value="${file.parent}"/>
        <j:set var="outDir" value="${dirMapper.mapFileName(inDirForward).0}"/>
        <mkdir dir="${outDir}"/>

        <!-- generate output file name -->
        <util:replace var="outFileForward" oldChar="\" newChar="/" value="${file.toString()}"/>
        <j:set var="outFile" value="${mapper.mapFileName(outFileForward).0}"/>

        <echo>Generating ${outFile} from ${file}</echo>
        <!-- work out relative path -->
        <util:replace var="docsForward" oldChar="\" newChar="/" value="${srcdir}"/>
        <j:if test="${pathTool == null}">
            <j:useBean var="pathTool" class="org.apache.maven.util.DVSLPathTool"/>
        </j:if>
        <j:set var="relativePath" value="${pathTool.getRelativePath(docsForward, outFileForward)}"/>

        <!-- determine nav file to be used: 2. check for nav file -->
        <!-- in the same directory as xml file being processed -->
        <!-- if no such nav file available use sitewide nav file -->
        <j:set var="navFile" value="${siteNavFile}" />
        <util:available file="${file.parentFile.absoluteFile}/navigation.xml">
          <!-- dont use current directory navigation.xml if it's in maven.docs.src -->
          <j:if test="${!(file.parentFile.equals(docsSrcFile))}">
            <util:file var="navFile" name="${file.parentFile.absoluteFile}/navigation.xml"/>
          </j:if>
        </util:available>

        <!-- parse nav and make it available to the stylesheet -->
        <x:parse var="navXML" xml="${navFile}"/>
        <x:set var="nav" select="$navXML/project"/>
        <!-- parse the doc and pass it to the stylesheet -->
        <x:parse var="doc" xml="${file}"/>
        
        <j:file name="${outFile}" encoding="${outputencoding}"
          omitXmlDeclaration="true" outputMode="xml"
          prettyPrint="no">
          <j:include uri="${stylesheet.toString()}"/>
        </j:file>
      </j:forEach>

    </define:tag>
    
    
    <define:tag name="jslToSite">
        <!--
         | transforms files in the given dir using the site stylesheet and navigation and place them
         | in maven.docs.dest (typically target/docs)
         | @srcdir source directory
        -->
  
      <maven:param-check value="${srcdir}" fail="true" message="'srcdir' must be specified"/>

      <maven:pluginVar var="maven.xdoc.jsl" 
        plugin='maven-xdoc-plugin' property='maven.xdoc.jsl' />
      
      <!-- copy old value for restoring it later -->
      <j:set var="previous.plugin.resources" value="${plugin.resources}" />

      <maven:pluginVar var="plugin.resources" 
        plugin='maven-xdoc-plugin' property='plugin.resources' />
        
      <maven:pluginVar var="includeProjectDocumentation" 
        plugin='maven-xdoc-plugin' property='maven.xdoc.includeProjectDocumentation' />
        
      <maven:pluginVar var="maven.xdoc.poweredby.image" 
        plugin='maven-xdoc-plugin' property='maven.xdoc.poweredby.image' />
        
      <maven:pluginVar var="maven.xdoc.poweredby.title" 
        plugin='maven-xdoc-plugin' property='maven.xdoc.poweredby.title' />
        
      <maven:pluginVar var="maven.xdoc.poweredby.url" 
        plugin='maven-xdoc-plugin' property='maven.xdoc.poweredby.url' />
        
      <maven:pluginVar var="maven.xdoc.crumb.separator" 
        plugin='maven-xdoc-plugin' property='maven.xdoc.crumb.separator' />
      
      <j:set var="outputDirectory" value="${maven.gen.docs}" />
      <j:set var="stylesheet" value="file:${plugin.resources}/site.jsl" />
  
      <j:set var="outputencoding" value="${maven.docs.outputencoding}" />
  
      <doc:performJSL srcdir="${srcdir}" destdir="${maven.docs.dest}" />

      <!-- restore plugin.resources -->
      <j:set var="plugin.resources" value="${previous.plugin.resources}" />

    </define:tag>
    
    <!--
     | escapes a string for generating a valid name token (need for "name" attribute in html anchors)
     | @value given token
    --> 
     <define:tag name="escapeNameToken">
     <j:invokeStatic var="escapedtoken" className="org.apache.commons.lang.StringUtils" method="replaceChars">
        <j:arg type="java.lang.String" value="${value}" useContextClassLoader="true"/>
        <j:arg type="java.lang.String" value=" .,;!?/'\()[]{}+*°" useContextClassLoader="true"/>
        <j:arg type="java.lang.String" value="__________________" useContextClassLoader="true"/>
     </j:invokeStatic>${escapedtoken}</define:tag>

  </define:taglib>

  <!-- ================================================================== -->
  <!-- P R O J E C T  D O C U M E N T A T I O N                           -->
  <!-- ================================================================== -->

  <goal name="xdoc"
    prereqs="xdoc:generate-from-pom, xdoc:transform"
    description="Generate html project documentation xdoc sources"/>

  <goal name="xdoc:init"
    description="Generates the directory structure required for xdocs">

    <mkdir dir="${maven.gen.docs}"/>
    <mkdir dir="${maven.docs.dest}"/>

  </goal>

  <goal
    name="xdoc:generate-from-pom"
    prereqs="xdoc:init, xdoc:register-reports"
    description="Generates xdocs for site based on project descriptor">
    
    <echo>Generating xdocs from POM ... </echo>
    
    <util:tokenize var="pomDocuments" delim=",">${maven.xdoc.pomDocuments}</util:tokenize>
    
    <!-- All the templates use $project for now. -->
    <j:set var="project" value="${pom}"/>
    <maven:pluginVar var="reports" plugin="maven-xdoc-plugin" property="reports" />

    <!-- Does the user want the maven-generated docs on their site? -->
    <j:set 
      var="includeProjectDocumentation" 
      value="${maven.xdoc.includeProjectDocumentation}"/>
    
    <!-- Need the escaper to html output. -->
    <j:useBean var="escape" class="org.apache.velocity.anakia.Escape"/>
    <j:useBean var="files" class="org.apache.velocity.texen.util.FileUtil"/>
    
    <!-- Need to enrich information about dependency by taking some information from its POM. -->
    <j:useBean var="dependencyDescriber" class="org.apache.maven.DependencyDescriberBean"/>
     ${dependencyDescriber.build(pom)}
    
    
    <j:if test="${encoding == null}">
         <j:set 
           var="encoding" 
           value="${maven.docs.outputencoding}"
         />
    </j:if>
    
    <j:forEach var="pomDocument" items="${pomDocuments}">
      <velocity:merge 
        name="${maven.gen.docs}/${pomDocument}"
        basedir="${plugin.resources}/templates"
        template="${pomDocument}"
        inputEncoding="${encoding}"
        outputEncoding="${encoding}" 
      />

    </j:forEach>

  </goal>

  <!-- ================================================================== -->
  <!-- V A L I D A T E  X D O C S                                         -->
  <!-- ================================================================== -->

  <!-- validate xdocs -->
  <goal name="xdoc:validate" prereqs="pom:taglib"
    description="Validate xdocs match the schema">

    <available file="${maven.docs.src}" type="dir"
      property="maven.docs.src.available"/>

    <j:if test="${maven.docs.src.available}">
      <fileScanner var="navFiles">
        <fileset dir="${maven.docs.src}">
          <patternset>
            <include name="**/navigation.xml"/>
          </patternset>
        </fileset>
      </fileScanner>

      <j:forEach var="file" items="${navFiles.iterator()}">
        <echo>Validating ${file}</echo>
        <pom:validate validator="${maven.home}/maven-navigation-1.0.xsd"
          projectDescriptor="${file}"/>
      </j:forEach>
    </j:if>
  </goal>

  <!-- ================================================================== -->
  <!-- C O P Y  R E S O U R C E S                                         -->
  <!-- ================================================================== -->

  <!-- copy resources needed for xdocs -->
  <goal name="xdoc:copy-resources"
    prereqs="xdoc:init"
    description="copy static resources for use in xdocs generated html">
    
    <!-- Read in the ui properties. -->
    <util:properties uri="file:${plugin.resources}/ui.properties" var="uiProperties"/>

    <!-- Copy maven supplied stylesheets.  -->
    <copy todir="${maven.docs.dest}/style" overwrite="yes" filtering="yes">
      <fileset dir="${plugin.resources}/css">
        <include name="**/*.css"/>
      </fileset>
      
      <filterset>
        <j:forEach var="uiProperty" items="${uiProperties.keys()}">
          <util:replace var="token" oldChar="." newChar="_" value="${uiProperty}"/>
          <j:set var="token" value="${token.substring(6).toUpperCase()}"/>
           <!-- Check if User has overidden this property -->
           <j:set var="propertyName" value="${uiProperty}" />
           <j:set var="propertyValue" value="${context.getVariable(propertyName)}"/>
           <j:choose>
             <j:when test="${propertyValue != null}">
               <!-- Use user's properties -->
               <filter token="${token}" value="${propertyValue}"/>
             </j:when>
             <j:otherwise>
               <!-- Use plugin's default properties -->
               <filter token="${token}" value="${uiProperties.getProperty(uiProperty)}"/>
             </j:otherwise>
           </j:choose>
        </j:forEach>
      </filterset>
    </copy>

    <!-- Copy maven supplied images.  -->
    <copy todir="${maven.docs.dest}/images" overwrite="yes" filtering="no">
      <fileset dir="${plugin.resources}/images">
        <include name="**/*.gif"/>
        <include name="**/*.jpeg"/>
        <include name="**/*.jpg"/>
        <include name="**/*.png"/>
      </fileset>
    </copy>

  </goal>

  <!-- ================================================================== -->
  <!-- C O P Y  U S E R  S U P P L I E D  R E S O U R C E S               -->
  <!-- ================================================================== -->

  <!-- copy user resources -->
  <goal name="xdoc:copy-user-resources"
    prereqs="xdoc:init"
    description="Copy user provided resources to docs destination">

    <j:if test="${maven.docs.src.available}">

      <!-- Copy user supplied resources -->
      <copy todir="${maven.docs.dest}" filtering="no">
        <fileset dir="${maven.docs.src}">
          <exclude name="**/*.xml"/>
          <exclude name="**/CVS/*"/>
          <exclude name="stylesheets/*"/>
        </fileset>
        <!-- copy file in generated docs folder: this allows for reporting plugins to add images -->
        <fileset dir="${maven.gen.docs}">
          <exclude name="**/*.xml"/>
          <exclude name="**/CVS/*"/>
          <exclude name="stylesheets/*"/>
        </fileset>
      </copy>

      <util:available file="${maven.docs.src}/stylesheets">
        <!-- Copy user supplied stylesheets, can override maven -->
        <copy todir="${maven.docs.dest}/style" overwrite="true" filtering="no">
          <fileset dir="${maven.docs.src}/stylesheets">
            <include name="**/*.css"/>
          </fileset>
        </copy>
      </util:available>
 
    </j:if>
  </goal>

  <!-- ================================================================== -->
  <!-- D V S L  D O C U M E N T A T I O N                                 -->
  <!-- ================================================================== -->
  
  <goal name="xdoc:transform"
    prereqs="xdoc:init"
    description="Generate html project documentation xdoc sources">

    <tstamp>
      <format property="mavenCurrentYear" pattern="yyyy"/>
    </tstamp>

    <!-- Use jelly utils here -->

    <available
      file="${maven.gen.docs}"
      type="dir"
      property="maven.gen.docs.available"
    />

    <available
      file="${maven.docs.src}"
      type="dir"
      property="maven.docs.src.available"
    />

    <!-- use JSL in Jelly to build the documenation -->
    <attainGoal name="xdoc:copy-resources"/>
    <attainGoal name="xdoc:copy-user-resources"/>
    <attainGoal name="xdoc:jelly-transform"/>

  </goal>

  <!-- ================================================================== -->
  <!-- J E L L Y   D O C U M E N T A T I O N                              -->
  <!-- ================================================================== -->

  <goal name="xdoc:jelly-init" description="Set up jelly xdoc requirements">
    <!-- moving here temporarily -->
    <tstamp>
      <format property="mavenCurrentYear" pattern="yyyy"/>
    </tstamp>
    <tstamp>
      <format property="build.date" pattern="${maven.xdoc.date.format}"
        locale="${maven.xdoc.date.locale}"/>
    </tstamp>
  </goal>
  
  

  <goal name="xdoc:register-reports">
    <!--
     | We need to have each <report> register itself with us so we can
     | build up our navbar.  To do this, we call the plugin:register
     | goal on each report plugin.
     |-->
     
    <j:if test="${!pom.reports.isEmpty()}">
      <j:forEach var="report" items="${pom.reports}">
        <attainGoal name="${report}:register"/>
      </j:forEach>
    </j:if>
    
    <!-- If the descriptor is empty, use these as defaults -->
    <j:if test="${pom.reports.isEmpty()}">
      <attainGoal name="maven-jdepend-plugin:register"/>
      <attainGoal name="maven-checkstyle-plugin:register"/>
      <attainGoal name="maven-changes-plugin:register"/>
      <attainGoal name="maven-changelog-plugin:register"/>
      <attainGoal name="maven-developer-activity-plugin:register"/>
      <attainGoal name="maven-file-activity-plugin:register"/>
      <attainGoal name="maven-license-plugin:register"/>
      <attainGoal name="maven-javadoc-plugin:register"/>
      <attainGoal name="maven-jxr-plugin:register"/>
      <attainGoal name="maven-junit-report-plugin:register"/>
      <attainGoal name="maven-linkcheck-plugin:register"/>
      <attainGoal name="maven-tasklist-plugin:register"/>
    </j:if>
  </goal>

  <goal name="xdoc:jelly-transform" 
    prereqs="xdoc:init, xdoc:jelly-init, xdoc:register-reports"
    description="transform xdocs using jelly/jsl rather than dvsl">

    <j:set var="destdir" value="${maven.docs.dest}"/>
    <j:set var="outputencoding" value="${maven.docs.outputencoding}"/>

    <!-- need to parse navigation into $nav -->

    <!-- mapper for determining output file name -->
    <j:new var="mapper" className="org.apache.maven.util.CaseInsensitiveGlobPatternMapper"/>
    

    <!-- path tool for relative processing -->
    <j:useBean var="pathTool" class="org.apache.maven.util.DVSLPathTool"/>

    <!-- tool for loading resources from the class loader -->
    <j:useBean class="org.apache.maven.util.ResourceBean" var="resourceTool"/>

    <!-- determine which stylesheet to use -->
    <j:set var="stylesheet" value="${maven.xdoc.jsl}"/>
    <j:if test="${empty(stylesheet)}">
      <j:set var="stylesheet" value="${resourceTool.findResource('plugin-resources/site.jsl')}"/>
      <j:if test="${empty(stylesheet)}">
        <log:warn>Could not load the JSL stylesheet 'site.jsl' on the classpath</log:warn>
        <j:set var="stylesheet" value="./site.jsl"/>
      </j:if>
    </j:if>

    <util:available file="${maven.gen.docs}">
      <log:info>About to use JSL stylesheet ${stylesheet}</log:info>

      <!-- perform JSL on generated docs -->
      <doc:performJSL srcdir="${maven.gen.docs}" destdir="${maven.docs.dest}"/>
    </util:available>
    
    <!-- perform JSL on user provided docs -->
    <j:if test="${maven.docs.src.available}">
      <log:info>
        Transforming user supplied documentation.
      </log:info>
      <doc:performJSL srcdir="${maven.docs.src}" destdir="${maven.docs.dest}"/>
    </j:if>

  </goal>
  
  
  <!-- 
   ! This is required as the linkchecker runs as a final pass over the generated
   ! document tree.
   ! FIXME: Why isn't this in linkcheck?
   !-->
  <goal name="xdoc:performJSL"
      description="Allows the LinkCheck plugin to xdoc a single directory">

    <maven:pluginVar var="maven.xdoc.src" plugin="maven-linkcheck-plugin" property="maven.xdoc.src" />
    <doc:performJSL 
      srcdir="${maven.xdoc.src}" 
      destdir="${maven.docs.dest}"/>
  </goal>
  
  <goal name="xdoc:dump-report-settings">
    <echo>Dumping report settings</echo>
    <maven:pluginVar var="reports" plugin="maven-xdoc-plugin" property="reports" />
       
    <j:forEach var="report" items="${reports}">
      <echo>Report: ${report}</echo>  
    </j:forEach>
  </goal>

</project>
