Fork me on GitHub

Transform files metadata to download pages for files list

This example shows how use the transformMetadata goal to generate download pages for all files from src/main/webapp/files. Pages will be saved in ${project.build.directory}/${project.artifactId}-${project.version}/download directory.

<project>
   ...
   <build>
      <plugins>
         ...
         <plugin>
            <groupId>biz.gabrys.maven.plugins</groupId>
            <artifactId>directory-content-maven-plugin</artifactId>
            <version>1.0.2</version>
            <executions>
               <execution>
                  <goals>
                     <goal>transformMetadata</goal>
                  </goals>
                  <configuration>
                     <sourceDirectory>src/main/webapp/files</sourceDirectory>
                     <includes>
                        <include>**/*</include>
                     </includes>
                     <outputFileFormat>{fileName}.html</outputFileFormat>
                     <outputDirectory>${project.build.directory}/${project.artifactId}-${project.version}/download</outputDirectory>
                     <xsltFile>download-page.xsl</xsltFile>
                     <separator>/</separator>
                  </configuration>
               </execution>
            </executions>
         </plugin>
      </plugins>
   </build>
<project>

download-page.xsl content:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <!-- use xml, because html insert META tag: http://stackoverflow.com/q/4408725/4944847 -->
   <xsl:output method="xml" omit-xml-declaration="yes" indent="yes" />

   <xsl:template match="file">
      <xsl:text disable-output-escaping="yes"><![CDATA[<!doctype html>]]>&#10;</xsl:text>
      <html lang="en">
         <head>
            <meta charset="UTF-8" />
            <title>Download <xsl:value-of select="fullName" /></title>
            <link href="/style.css" rel="stylesheet" />
         </head>
         <body>
            <div class="ads">Space for advertisement</div>
            <div class="download">
               <a>
                  <xsl:attribute name="href">
                     <xsl:text>/files/</xsl:text>
                     <xsl:value-of select="fullPath" />
                  </xsl:attribute>
                  <xsl:text>Download </xsl:text>
                  <xsl:value-of select="name" />
                  <xsl:if test="extension != ''">
                     <xsl:text> (type: </xsl:text>
                     <xsl:value-of select="extension" />
                     <xsl:text>)</xsl:text>
                  </xsl:if>
               </a>
            </div>
            <div class="ads">Space for advertisement</div>
         </body>
      </html>
   </xsl:template>
</xsl:stylesheet>