From: Morten K. <mor...@us...> - 2005-03-07 10:33:15
|
mortenkr 05/03/07 02:32:59 Added: files/files/somefolder exec1.bat web1.htm img5.bmp soffice3.sxc img1.gif img3.tif properties.properties unknown.unk text.txt exec2.sh img4.png soffice1.sxi soffice2.sxw img2.jpg winzip1.zip adobe1.pdf soffice4.sxd web2.html files/src/plugin-resources/images mp3.png java.png sql.png jar.png zip.png mov.png html.png xml.png ppt.png pdf.png avi.png folder.png txt.png sxd.png sxc.png doc.png rm.png sxw.png unknown.png bmp.png xls.png jpg.png class.png sh.png back.png mpg.png sxi.png gif.png wav.png png.png files/files winzip1.zip soffice1.sxi unknown.unk img5.bmp properties.properties web1.htm xmlfile.xml img1.gif exec2.sh text.txt soffice3.sxc adobe1.pdf img3.tif web2.html exec1.bat soffice2.sxw img4.png soffice4.sxd img2.jpg files/src/plugin-resources imgmap.properties rss.png files .cvsignore project.xml plugin.jelly plugin.properties project.properties files/xdocs index.xml goals.xml changes.xml navigation.xml customize.xml properties.xml files/src/main/org/apache/maven/files Generator.java Log: New Files plugin - initial commit Revision Changes Path 1.1 maven-plugins/files/files/somefolder/exec1.bat <<Binary file>> 1.1 maven-plugins/files/files/somefolder/web1.htm <<Binary file>> 1.1 maven-plugins/files/files/somefolder/img5.bmp <<Binary file>> 1.1 maven-plugins/files/files/somefolder/soffice3.sxc <<Binary file>> 1.1 maven-plugins/files/files/somefolder/img1.gif <<Binary file>> 1.1 maven-plugins/files/files/somefolder/img3.tif <<Binary file>> 1.1 maven-plugins/files/files/somefolder/properties.properties <<Binary file>> 1.1 maven-plugins/files/files/somefolder/unknown.unk <<Binary file>> 1.1 maven-plugins/files/files/somefolder/text.txt <<Binary file>> 1.1 maven-plugins/files/files/somefolder/exec2.sh <<Binary file>> 1.1 maven-plugins/files/files/somefolder/img4.png <<Binary file>> 1.1 maven-plugins/files/files/somefolder/soffice1.sxi <<Binary file>> 1.1 maven-plugins/files/files/somefolder/soffice2.sxw <<Binary file>> 1.1 maven-plugins/files/files/somefolder/img2.jpg <<Binary file>> 1.1 maven-plugins/files/files/somefolder/winzip1.zip <<Binary file>> 1.1 maven-plugins/files/files/somefolder/adobe1.pdf <<Binary file>> 1.1 maven-plugins/files/files/somefolder/soffice4.sxd <<Binary file>> 1.1 maven-plugins/files/files/somefolder/web2.html <<Binary file>> 1.1 maven-plugins/files/src/plugin-resources/images/mp3.png <<Binary file>> 1.1 maven-plugins/files/src/plugin-resources/images/java.png <<Binary file>> 1.1 maven-plugins/files/src/plugin-resources/images/sql.png <<Binary file>> 1.1 maven-plugins/files/src/plugin-resources/images/jar.png <<Binary file>> 1.1 maven-plugins/files/src/plugin-resources/images/zip.png <<Binary file>> 1.1 maven-plugins/files/src/plugin-resources/images/mov.png <<Binary file>> 1.1 maven-plugins/files/src/plugin-resources/images/html.png <<Binary file>> 1.1 maven-plugins/files/src/plugin-resources/images/xml.png <<Binary file>> 1.1 maven-plugins/files/src/plugin-resources/images/ppt.png <<Binary file>> 1.1 maven-plugins/files/src/plugin-resources/images/pdf.png <<Binary file>> 1.1 maven-plugins/files/src/plugin-resources/images/avi.png <<Binary file>> 1.1 maven-plugins/files/src/plugin-resources/images/folder.png <<Binary file>> 1.1 maven-plugins/files/src/plugin-resources/images/txt.png <<Binary file>> 1.1 maven-plugins/files/src/plugin-resources/images/sxd.png <<Binary file>> 1.1 maven-plugins/files/src/plugin-resources/images/sxc.png <<Binary file>> 1.1 maven-plugins/files/src/plugin-resources/images/doc.png <<Binary file>> 1.1 maven-plugins/files/src/plugin-resources/images/rm.png <<Binary file>> 1.1 maven-plugins/files/src/plugin-resources/images/sxw.png <<Binary file>> 1.1 maven-plugins/files/src/plugin-resources/images/unknown.png <<Binary file>> 1.1 maven-plugins/files/src/plugin-resources/images/bmp.png <<Binary file>> 1.1 maven-plugins/files/src/plugin-resources/images/xls.png <<Binary file>> 1.1 maven-plugins/files/src/plugin-resources/images/jpg.png <<Binary file>> 1.1 maven-plugins/files/src/plugin-resources/images/class.png <<Binary file>> 1.1 maven-plugins/files/src/plugin-resources/images/sh.png <<Binary file>> 1.1 maven-plugins/files/src/plugin-resources/images/back.png <<Binary file>> 1.1 maven-plugins/files/src/plugin-resources/images/mpg.png <<Binary file>> 1.1 maven-plugins/files/src/plugin-resources/images/sxi.png <<Binary file>> 1.1 maven-plugins/files/src/plugin-resources/images/gif.png <<Binary file>> 1.1 maven-plugins/files/src/plugin-resources/images/wav.png <<Binary file>> 1.1 maven-plugins/files/src/plugin-resources/images/png.png <<Binary file>> 1.1 maven-plugins/files/files/winzip1.zip <<Binary file>> 1.1 maven-plugins/files/files/soffice1.sxi <<Binary file>> 1.1 maven-plugins/files/files/unknown.unk <<Binary file>> 1.1 maven-plugins/files/files/img5.bmp <<Binary file>> 1.1 maven-plugins/files/files/properties.properties <<Binary file>> 1.1 maven-plugins/files/files/web1.htm <<Binary file>> 1.1 maven-plugins/files/files/xmlfile.xml <<Binary file>> 1.1 maven-plugins/files/files/img1.gif <<Binary file>> 1.1 maven-plugins/files/files/exec2.sh <<Binary file>> 1.1 maven-plugins/files/files/text.txt <<Binary file>> 1.1 maven-plugins/files/files/soffice3.sxc <<Binary file>> 1.1 maven-plugins/files/files/adobe1.pdf <<Binary file>> 1.1 maven-plugins/files/files/img3.tif <<Binary file>> 1.1 maven-plugins/files/files/web2.html <<Binary file>> 1.1 maven-plugins/files/files/exec1.bat <<Binary file>> 1.1 maven-plugins/files/files/soffice2.sxw <<Binary file>> 1.1 maven-plugins/files/files/img4.png <<Binary file>> 1.1 maven-plugins/files/files/soffice4.sxd <<Binary file>> 1.1 maven-plugins/files/files/img2.jpg <<Binary file>> 1.1 maven-plugins/files/src/plugin-resources/imgmap.properties Index: imgmap.properties =================================================================== .avi=avi.png .bmp=bmp.png .class=class.png .doc=doc.png .gif=gif.png .htm=html.png .html=html.png .jar=jar.png .java=java.png .jpg=jpg.png .mov=mov.png .mp3=mp3.png .mpg=mpg.png .pdf=pdf.png .png=png.png .ppt=ppt.png .rm=rm.png .ram=rm.png .sh=sh.png .bat=sh.png .sql=sql.png .sxw=sxw.png .sxc=sxc.png .sxd=sxd.png .sxi=sxi.png .txt=txt.png .properties=txt.png .wav=wav.png .xls=xls.png .xml=xml.png .zip=zip.png 1.1 maven-plugins/files/src/plugin-resources/rss.png <<Binary file>> 1.1 maven-plugins/files/.cvsignore Index: .cvsignore =================================================================== velocity* target 1.1 maven-plugins/files/project.xml Index: project.xml =================================================================== <?xml version="1.0" encoding="UTF-8"?> <project> <extend>${basedir}/../plugin-project.xml</extend> <!--pomVersion is in parent --> <id>maven-files-plugin</id> <name>Maven Files Plugin</name> <!-- groupId is in parent --> <currentVersion>1.0</currentVersion> <!-- organization is in parent --> <inceptionYear>2004</inceptionYear> <!-- package, logo are in parent. no gumpRepositoryId --> <description>Creates files report</description> <shortDescription>Creates files report</shortDescription> <!-- issue tracking url, siteAddress are in parent --> <url>http://maven-plugins.sourceforge.net/maven-files-plugin/</url> <siteDirectory>/home/groups/m/ma/maven-plugins/htdocs/maven-files-plugin/</siteDirectory> <repository> <connection>scm:cvs:pserver:ano...@cv...:/cvsroot/maven-plugins:maven-plugins/files</connection> <developerConnection>scm:cvs:ext:${maven.username}@cvs.sourceforge.net:/cvsroot/maven-plugins:maven-plugins/files</developerConnection> <url>http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/maven-plugins/maven-plugins/files/</url> </repository> <versions> <version> <id>1.0</id> <name>1.0</name> <tag>MAVEN_PLUGINS_FILES_1_0</tag> </version> </versions> <!-- mailingLists are in parent --> <developers> <developer> <name>Morten Kristiansen</name> <id>mortenkr</id> <email>mor...@us...</email> <roles> <role>Java Developer</role> </roles> <timezone>1</timezone> </developer> </developers> <dependencies> <dependency> <groupId>ant</groupId> <artifactId>ant</artifactId> <version>1.5.3-1</version> </dependency> <dependency> <groupId>xalan</groupId> <artifactId>xalan</artifactId> <version>2.5.1</version> </dependency> </dependencies> <reports> <report>maven-changes-plugin</report> <report>maven-changelog-plugin</report> <report>maven-developer-activity-plugin</report> <report>maven-file-activity-plugin</report> <report>maven-files-plugin</report> <report>maven-javadoc-plugin</report> <report>maven-license-plugin</report> </reports> </project> 1.1 maven-plugins/files/plugin.jelly Index: plugin.jelly =================================================================== <?xml version="1.0"?> <project xmlns:j="jelly:core" xmlns:ant="jelly:ant" xmlns:define="jelly:define" xmlns:util="jelly:util" xmlns:doc="doc"> <goal name="maven-files-plugin:register" description="Registers plugin as report"> <util:available file="${maven.files.src}"> <doc:registerReport name="Files" pluginName="files" link="files/index" description="Report on the project files." /> </util:available> </goal> <goal name="maven-files-plugin:deregister" description="Deregisters plugin as report"> <doc:deregisterReport name="Files" /> </goal> <goal name="files:init" description="Initialize Files Plugin"> <ant:delete dir="${maven.gen.docs}/files" /> <ant:delete dir="${maven.docs.dest}/files" /> <ant:mkdir dir="${maven.gen.docs}/files" /> <ant:mkdir dir="${maven.docs.dest}/files" /> <ant:mkdir dir="${maven.docs.dest}/images" /> </goal> <goal name="files:report" prereqs="files:init" description="Generates a files report"> <!-- Copy all files to docs dest --> <copy todir="${maven.docs.dest}/files" preservelastmodified="true" includeEmptyDirs="false" overwrite="true"> <fileset dir="${maven.files.src}" defaultexcludes="yes" excludes="${maven.files.excludes}" followsymlinks="false" /> </copy> <ant:taskdef name="files" classname="org.apache.maven.files.Generator"> <ant:classpath> <ant:pathelement path="${plugin.dir}" /> </ant:classpath> </ant:taskdef> <!-- The Generator task creates the same folder structure as the one found in ${maven.docs.dest}/files in ${maven.gen.docs}/files with an index.xml file in each folder. --> <ant:files gendocs="${maven.gen.docs}" docsDest="${maven.docs.dest}" url="${pom.url}" name="${pom.name}" logo="${pom.logo}" imgmap="${maven.files.imgmap}" unknownfile="${maven.files.unknownfile}" folderfile="${maven.files.folderfile}" backfile="${maven.files.backfile}" encoding="${maven.docs.outputencoding}" rss="${maven.files.rss}" dateformat="${maven.files.dateformat}" /> <!-- Copy all images to docs dest --> <copy todir="${maven.docs.dest}/images"> <fileset dir="${maven.files.images}" /> <fileset dir="${plugin.dir}/plugin-resources"> <include name="rss.png" /> </fileset> </copy> </goal> </project> 1.1 maven-plugins/files/plugin.properties Index: plugin.properties =================================================================== # Plugin default props maven.files.src=${basedir}/files maven.files.dateformat=dd.MM.yy HH:mm maven.files.imgmap=${plugin.dir}/plugin-resources/imgmap.properties maven.files.images=${plugin.dir}/plugin-resources/images maven.files.unknownfile=unknown.png maven.files.folderfile=folder.png maven.files.backfile=back.png maven.files.rss=true maven.files.excludes= 1.1 maven-plugins/files/project.properties Index: project.properties =================================================================== maven.license.licenseFile=${basedir}/../LICENSE.txt maven.xdoc.date=left maven.xdoc.version=${pom.currentVersion} 1.1 maven-plugins/files/xdocs/index.xml Index: index.xml =================================================================== <?xml version="1.0"?> <document> <body> <section name="Maven Files Plugin"> <p> This plugin provides functionality for adding additional files to the generated Maven site as a report. Default, all files under ${basedir}/files are added to site. To add report, simply put the following line in your POM: <br/> <pre> <reports> ... <report>maven-files-plugin</report> ... </reports> </pre> An example of the plugin result can be found under <a href="files/index.html">here</a>. <p/> For more information on the functionality provided by this plugin, please see the <a href="goals.html">Goals</a> document. <p /> For more information on how to customise the functionality provided by this plugin, please see the <a href="properties.html">Properties</a> document. </p> </section> </body> </document> 1.1 maven-plugins/files/xdocs/goals.xml Index: goals.xml =================================================================== <?xml version="1.0" encoding="UTF-8"?> <document> <properties> <title>Maven Files Plugin Goals</title> </properties> <body> <goals> <goal> <name>files:report</name> <description>For generating report directly</description> </goal> </goals> </body> </document> 1.1 maven-plugins/files/xdocs/changes.xml Index: changes.xml =================================================================== <?xml version="1.0"?> <document> <body> <release version="1.0" date="01.04.2005"> <action type="add" dev="mortenkr">Version 1.0 released</action> </release> </body> </document> 1.1 maven-plugins/files/xdocs/navigation.xml Index: navigation.xml =================================================================== <?xml version="1.0" encoding="UTF-8"?> <project name="Maven Files Plugin"> <title>Maven Files Plugin</title> <body> <links> <item href="http://maven.apache.org/" name="Maven"> </item> </links> <menu name="Overview"> <item href="/goals.html" name="Goals"> </item> <item href="/properties.html" name="Properties"> </item> <item href="/customize.html" name="Customize layout"> </item> </menu> </body> </project> 1.1 maven-plugins/files/xdocs/customize.xml Index: customize.xml =================================================================== <?xml version="1.0"?> <document> <body> <section name="Customize layout"> <p> If you'd like to customize the layout of plugin (meaning: add other/additional images), perform the following operations: <ul> <li>Copy the "images" folder from <b>${plugin.dir}/plugin-resources</b> and place it where you like.</li> <li>Copy the <b>${plugin.dir}/plugin-resources/imgmap.properties</b> file to the same place</li> <li>Add or modify images in you new "images" folder</li> <li>Modify your new <b>imgmap.properties</b> file to fit the new/modified images.</li> <li>Set property <b>maven.files.imgmap</b> and <b>maven.files.images</b> to new location</li> <li>Modify <b>maven.files.unknownfile</b>, <b>maven.files.backfile</b> and <b>maven.files.folderfile</b> if needed</li> <li>Have a look at <a href="properties.html">properties</a> for further information on properties.</li> </ul> </p> </section> </body> </document> 1.1 maven-plugins/files/xdocs/properties.xml Index: properties.xml =================================================================== <?xml version="1.0" encoding="UTF-8"?> <document> <properties> <title>Maven Files Plugin Properties</title> </properties> <body> <section name="Maven Files Plugin Settings"> <table> <tr> <th>Property</th> <th>Optional?</th> <th>Description</th> </tr> <tr> <td>maven.files.src</td> <td>Yes</td> <td> <p> Directory where plugin searches for files. Default value is <code>${basedir}/files</code> . </p> </td> </tr> <tr> <td>maven.files.excludes</td> <td>Yes</td> <td> <p> Patterns of files to exclude (uses Ant exclude patterns). Default value is blank. </p> </td> </tr> <tr> <td>maven.files.dateformat</td> <td>Yes</td> <td> <p> Date pattern to be used in the "Last Modified" column in report. Default value is <code>dd.MM.yy HH:mm</code>. </p> </td> </tr> <tr> <td>maven.files.imgmap</td> <td>Yes</td> <td> <p> Path to file which contains the mapping between filetypes and images. Default plugin provides images for the following filetypes: <p/> .avi, .bmp, .class, .doc, .gif, .htm, .html, .jar, .java, .jpg, .mov, .mp3, .mpg, .pdf, .png, .ppt, .rm, .ram, .sh, .bat, .sql, .sxw, .sxc, .sxd, .sxi, .txt, .properties, .wav, .xls, .xml, .zip <p/> All other files types will get image defined by property <code>maven.files.unknownfile</code> Default value is <code>${plugin.dir}/plugin-resources/imgmap.properties</code>. </p> </td> </tr> <tr> <td>maven.files.images</td> <td>Yes</td> <td> <p> Path to where the images used in report are located. Default value is <code>${plugin.dir}/plugin-resources/images</code>. </p> </td> </tr> <tr> <td>maven.files.unknownfile</td> <td>Yes</td> <td> <p> Name of image file used when displaying unknown filetypes. Default value is <code>txt.png</code>. </p> </td> </tr> <tr> <td>maven.files.backfile</td> <td>Yes</td> <td> <p> Name of image file used when displaying "back" link. Default value is <code>back.png</code>. </p> </td> </tr> <tr> <td>maven.files.folderfile</td> <td>Yes</td> <td> <p> Name of image file used when displaying a folder. Default value is <code>folder.png</code>. </p> </td> </tr> <tr> <td>maven.files.rss</td> <td>Yes</td> <td> <p> If RSS feed should be generated. Default value is <code>true</code> . </p> </td> </tr> </table> </section> </body> </document> 1.1 maven-plugins/files/src/main/org/apache/maven/files/Generator.java Index: Generator.java =================================================================== package org.apache.maven.files; /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Maven" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact ap...@ap.... * * 5. Products derived from this software may not be called "Apache", * "Apache Maven", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * ==================================================================== */ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.Iterator; import java.util.List; import java.util.Properties; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Task; import org.w3c.dom.Document; import org.w3c.dom.DocumentFragment; import org.w3c.dom.Element; import org.w3c.dom.Text; /** * Ant task that generates index.xml files for browsing the project files. * * @author <a href="mailto:mor...@us...">Morten Kristiansen</a> */ public class Generator extends Task { private static final String FILE_SEP = System.getProperty("file.separator"); private String myGendocs = null; private String myDocsDest = null; private String myImgmap = null; private String myDateFormat = null; private String myEncoding = null; private String myUnknownfile = null; private String myFolderfile = null; private String myBackfile = null; private String myRss = null; private String myUrl = null; private String myName = null; private String myLogo = null; private Properties myImgmapProps = new Properties(); private List myFiles = new ArrayList(); /** * Ant tasks execute method. * * @throws BuildException If errors occur. */ public void execute() throws BuildException { // TODO How should this be solved? System.setProperty("javax.xml.transform.TransformerFactory", "org.apache.xalan.processor.TransformerFactoryImpl"); File docsDestRoot = new File(myDocsDest + FILE_SEP + "files"); File genDocsRoot = new File(myGendocs + FILE_SEP + "files"); myImgmapProps = new Properties(); try { myImgmapProps.load(new FileInputStream(new File(myImgmap))); } catch (Throwable t) { throw new BuildException(t); } createIndexFile(docsDestRoot, genDocsRoot, 0); } /** * Creates an index.xml file to generated-xdocs/docs for the current folder in docs. * * @param docsDestFolder Folder where all files are copied to, used as master when generating index files. * @param genDocsFolder Folder where all index.xml files are generated. * @param level Which level in docs we're in (needed to be able to generate correct image links). */ private void createIndexFile(File docsDestFolder, File genDocsFolder, int level) { String imgPath = getImgPath(level); String indexFile = genDocsFolder.getAbsolutePath() + FILE_SEP + "index.xml"; try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document report = db.newDocument(); DocumentFragment document = report.createDocumentFragment(); Element rootElement = report.createElement("document"); Element table = createTableHeader(rootElement, report, imgPath, level); if (level > 0) { addBack(table, report, imgPath); } File[] children = docsDestFolder.listFiles(); // Assure that folder is not null. if (children != null) { // Folders first for (int i = 0; i < children.length; i++) { if (!children[i].isDirectory()) { continue; } // Create folder in gendocs tree String tmpPath = children[i].getAbsolutePath().substring(myDocsDest.length() + 1); File genDocsFolderCreated = new File(myGendocs + FILE_SEP + tmpPath); genDocsFolderCreated.mkdir(); createIndexFile(children[i], genDocsFolderCreated, level + 1); addFolder(table, report, imgPath, children[i].getName()); } // Then files for (int i = 0; i < children.length; i++) { if (children[i].isDirectory()) { continue; } addFile(table, report, imgPath, children[i]); if (rss()) { myFiles.add(children[i]); } } } if (rss()) { generateRssFile(); } document.appendChild(rootElement); DOMSource domSource = new DOMSource(document); StreamResult result = new StreamResult(new FileOutputStream(indexFile)); TransformerFactory tFact = TransformerFactory.newInstance(); Transformer trans = tFact.newTransformer(); trans.setOutputProperty(OutputKeys.INDENT, "yes"); trans.setOutputProperty(OutputKeys.METHOD, "xml"); trans.setOutputProperty(OutputKeys.ENCODING, myEncoding); trans.transform(domSource, result); } catch (Throwable t) { t.printStackTrace(); throw new BuildException(t); } } /** * Returns if rss report should be generated. * * @return boolean True if rss feed is to be generated. */ private boolean rss() { return myRss != null && myRss.trim().equals("true"); } /** * Generates rss file with content describing date of recent changed document. */ private void generateRssFile() { try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document report = db.newDocument(); DocumentFragment document = report.createDocumentFragment(); Element rootElement = report.createElement("rss"); rootElement.setAttribute("version", "0.92"); Element channelElement = report.createElement("channel"); rootElement.appendChild(channelElement); Element titleElement = report.createElement("title"); channelElement.appendChild(titleElement); Text titleText = report.createTextNode("Files for " + myName); titleElement.appendChild(titleText); Element descElement = report.createElement("description"); channelElement.appendChild(descElement); Text descText = report.createTextNode("Files for " + myName); descElement.appendChild(descText); Element linkElement = report.createElement("link"); channelElement.appendChild(linkElement); Text linkText = report.createTextNode(myUrl + "/files/index.html"); linkElement.appendChild(linkText); if(myLogo != null && !myLogo.trim().equals("")) { Element imageElement = report.createElement("image"); channelElement.appendChild(imageElement); Element imageTitleElement = report.createElement("title"); imageElement.appendChild(imageTitleElement); Text imageTitleText = report.createTextNode(myName); imageTitleElement.appendChild(imageTitleText); Element imageLinkElement = report.createElement("link"); imageElement.appendChild(imageLinkElement); Text imageLinkText = report.createTextNode(myUrl); imageLinkElement.appendChild(imageLinkText); Element imageUrlElement = report.createElement("url"); imageElement.appendChild(imageUrlElement); Text imageUrlText = report.createTextNode(myLogo); imageUrlElement.appendChild(imageUrlText); } Element itemElement = report.createElement("item"); channelElement.appendChild(itemElement); String myDesc = getDesc(); Element itemTitleElement = report.createElement("title"); itemElement.appendChild(itemTitleElement); Text itemTitleText = report.createTextNode(myDesc); itemTitleElement.appendChild(itemTitleText); Element itemDescElement = report.createElement("description"); itemElement.appendChild(itemDescElement); Text itemDescText = report.createTextNode(myDesc); itemDescElement.appendChild(itemDescText); Element itemLinkElement = report.createElement("link"); itemElement.appendChild(itemLinkElement); Text itemLinkText = report.createTextNode(myUrl + "/files/index.html"); itemLinkElement.appendChild(itemLinkText); document.appendChild(rootElement); DOMSource domSource = new DOMSource(document); StreamResult result = new StreamResult(new FileOutputStream(myDocsDest + FILE_SEP + "files/files.rss")); TransformerFactory tFact = TransformerFactory.newInstance(); Transformer trans = tFact.newTransformer(); trans.setOutputProperty(OutputKeys.INDENT, "yes"); trans.setOutputProperty(OutputKeys.METHOD, "xml"); trans.setOutputProperty(OutputKeys.ENCODING, myEncoding); trans.transform(domSource, result); } catch (Throwable t) { t.printStackTrace(); throw new BuildException(t); } } /** * Returns text to be displayed in RSS file. * * @return String "Documentation last updated: <date of recently updated file>" */ private String getDesc() { long high = 0; for (Iterator iter = myFiles.iterator(); iter.hasNext();) { File file = (File) iter.next(); if(file.lastModified() > high) { high = file.lastModified(); } } Date highest = new Date(high); return "Files last updated: " + new SimpleDateFormat(myDateFormat).format(highest); } /** * Creates new element for the root table in the index.xml file. * * @param root Root xml element. * @param document Document from which Elements are to created from. * @param imgPath Path to images to be used. * @param level Current level * * @return Element The table element. */ private Element createTableHeader(Element root, Document document, String imgPath, int level) { // BODY Element bodyElement = document.createElement("body"); root.appendChild(bodyElement); // SECTION Element sectionElement = document.createElement("section"); sectionElement.setAttribute("name", "Files"); bodyElement.appendChild(sectionElement); // P to SECTION Element pElement = document.createElement("p"); sectionElement.appendChild(pElement); Text pText = document.createTextNode("Generated report based on files found in the files src folder in this project"); pElement.appendChild(pText); // RSS P to SECTION if (rss()) { Element rsspElement = document.createElement("p"); sectionElement.appendChild(rsspElement); Text rsspText = document.createTextNode("Get the RSS feed of the last changes "); rsspElement.appendChild(rsspText); // A TO P Element aElement = document.createElement("a"); rsspElement.appendChild(aElement); aElement.setAttribute("href", getRootPath(level) + "files.rss"); // IMG to A Element imgElement = document.createElement("img"); imgElement.setAttribute("src", imgPath + "rss.png"); aElement.appendChild(imgElement); } // TABLE to SECTION Element tableElement = document.createElement("table"); sectionElement.appendChild(tableElement); // TR to TABLE Element trElement = document.createElement("tr"); tableElement.appendChild(trElement); // THs to TR Element th1Element = document.createElement("th"); Element th2Element = document.createElement("th"); Element th3Element = document.createElement("th"); trElement.appendChild(th1Element); trElement.appendChild(th2Element); trElement.appendChild(th3Element); Text th1Text = document.createTextNode("File"); Text th2Text = document.createTextNode("Type"); Text th3Text = document.createTextNode("Last Modified"); th1Element.appendChild(th1Text); th2Element.appendChild(th2Text); th3Element.appendChild(th3Text); return tableElement; } /** * Adds a row to tableElement with a "back link" to previous folder. * * @param tableElement The table element. * @param document Document from which Elements are to created from. * @param imgPath Path to images to be used. */ private void addBack(Element tableElement, Document document, String imgPath) { // TR Element trElement = document.createElement("tr"); tableElement.appendChild(trElement); // TD to TR Element tdElement = document.createElement("td"); tdElement.setAttribute("colspan", "3"); trElement.appendChild(tdElement); // IMG to TD Element imgElement = document.createElement("img"); imgElement.setAttribute("src", imgPath + myBackfile); tdElement.appendChild(imgElement); // A TO TD Element aElement = document.createElement("a"); aElement.setAttribute("href", "../"); Text aText = document.createTextNode("../"); aElement.appendChild(aText); tdElement.appendChild(aElement); } /** * Adds a row to tableElement with a "folder link" to a sub folder. * * @param tableElement The table element. * @param document Document from which Elements are to created from. * @param imgPath Path to images to be used. * @param folderName The folder name used in link. */ private void addFolder(Element tableElement, Document document, String imgPath, String folderName) { // TR Element trElement = document.createElement("tr"); tableElement.appendChild(trElement); // TD to TR Element tdElement = document.createElement("td"); tdElement.setAttribute("colspan", "3"); trElement.appendChild(tdElement); // IMG to TD Element imgElement = document.createElement("img"); imgElement.setAttribute("src", imgPath + myFolderfile); tdElement.appendChild(imgElement); // A TO TD Element aElement = document.createElement("a"); aElement.setAttribute("href", folderName); Text aText = document.createTextNode(folderName); aElement.appendChild(aText); tdElement.appendChild(aElement); } /** * Adds a row to tableElement with a "file link" to a file current folder. * * @param tableElement The table element. * @param document Document from which Elements are to created from. * @param imgPath Path to images to be used. * @param file The file to generate row in table for. */ private void addFile(Element tableElement, Document document, String imgPath, File file) { String fileName = file.getName(); String filetype = "-"; if (fileName.indexOf('.') != -1) { filetype = fileName.substring(fileName.lastIndexOf('.') + 1); } // TR Element trElement = document.createElement("tr"); tableElement.appendChild(trElement); // TD1 to TR Element tdElement1 = document.createElement("td"); trElement.appendChild(tdElement1); // IMG to TD1 Element imgElement = document.createElement("img"); imgElement.setAttribute("src", imgPath + getImgFilename(fileName)); tdElement1.appendChild(imgElement); // A TO TD1 Element aElement = document.createElement("a"); aElement.setAttribute("href", fileName); aElement.setAttribute("target", "_blank"); Text aText = null; if (fileName.indexOf('.') != -1) { aText = document.createTextNode(fileName.substring(0, fileName.lastIndexOf('.'))); } else { aText = document.createTextNode(fileName); } aElement.appendChild(aText); tdElement1.appendChild(aElement); // TD2 to TR Element tdElement2 = document.createElement("td"); Text td2Text = document.createTextNode(filetype); tdElement2.appendChild(td2Text); trElement.appendChild(tdElement2); // TD3 to TR Element tdElement3 = document.createElement("td"); Text td3Text = document.createTextNode(formatDate(file.lastModified())); tdElement3.appendChild(td3Text); trElement.appendChild(tdElement3); } /** * Returns path to images based on level. * * @param level The current level. * * @return String Path. */ private String getImgPath(int level) { StringBuffer result = new StringBuffer(getRootPath(level)); result.append("../images/"); return result.toString(); } /** * Returns path to root of files report. * * @param level The current level. * * @return String Path. */ private String getRootPath(int level) { StringBuffer result = new StringBuffer(""); for (int i = 0; i < level; i++) { result.append("../"); } return result.toString(); } /** * Returns name of image to be displayed for current file type. * * @param name Filename for current file. * * @return String Image name for file type. */ private String getImgFilename(String name) { for (Iterator iter = myImgmapProps.keySet().iterator(); iter.hasNext();) { String key = (String) iter.next(); if (name.endsWith(key)) { return myImgmapProps.getProperty(key); } } return myUnknownfile; } /** * Returns date as a formatted string. * * @param date The date for format. * * @return String Date as String. */ private String formatDate(long date) { return new SimpleDateFormat(myDateFormat).format(new Date(date)); } /** * @param string */ public void setDateFormat(String string) { myDateFormat = string; } /** * @param string */ public void setEncoding(String string) { myEncoding = string; } /** * @param string */ public void setGendocs(String string) { myGendocs = string; } /** * @param string */ public void setImgmap(String string) { myImgmap = string; } /** * @param string */ public void setBackfile(String string) { myBackfile = string; } /** * @param string */ public void setFolderfile(String string) { myFolderfile = string; } /** * @param string */ public void setUnknownfile(String string) { myUnknownfile = string; } /** * @param string */ public void setRss(String string) { myRss = string; } /** * @param string */ public void setDocsDest(String string) { myDocsDest = string; } /** * @param string */ public void setUrl(String string) { myUrl = string; } /** * @param string */ public void setLogo(String string) { myLogo = string; } /** * @param string */ public void setName(String string) { myName = string; } } |