1 /***
2 * Copyright 2004 Fabrizio Giustina.
3 *
4 * Licensed under the Artistic License; you may not use this file
5 * except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://maven-taglib.sourceforge.net/license.html
9 *
10 * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
11 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
12 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13 */
14 package net.sf.maventaglib;
15
16 import java.io.File;
17
18 import javax.xml.transform.TransformerFactoryConfigurationError;
19
20 import com.sun.tlddoc.TLDDocGenerator;
21
22
23 /***
24 * Plugins which generates taglibdoc documentation.
25 * @author Fabrizio Giustina
26 * @version $Id: TaglibTaglibdocPlugin.java,v 1.8 2005/08/23 12:29:52 fgiust Exp $
27 */
28 public class TaglibTaglibdocPlugin extends TaglibPlugin
29 {
30
31 /***
32 * title for tlddoc generated documentation.
33 */
34 protected String title;
35
36 /***
37 * TldDoc output dir.
38 */
39 protected String tldDocDir;
40
41 /***
42 * Sets the title for tlddoc generated docs.
43 * @param docTitle title for tlddoc generated documentation.
44 */
45 public void setTitle(String docTitle)
46 {
47 this.title = docTitle;
48 }
49
50 /***
51 * Sets the TldDoc output dir.
52 * @param dir output directory for tlddoc documentation
53 */
54 public void setTldDocDir(String dir)
55 {
56 this.tldDocDir = dir;
57 }
58
59 /***
60 * @see net.sf.maventaglib.TaglibPlugin#execute()
61 */
62 public void execute() throws Exception
63 {
64 File srcDirFile = new File(this.srcDir);
65 File tldOutDir = new File(this.tldDocDir);
66 echo("Generating tlddoc doc from files in " + srcDirFile.getAbsolutePath());
67 TLDDocGenerator generator = new TLDDocGenerator();
68 generator.setOutputDirectory(tldOutDir);
69 generator.setQuiet(true);
70 generator.setWindowTitle(this.title);
71
72 if (!srcDirFile.isDirectory())
73 {
74 throw new IllegalArgumentException("Not a directory: " + srcDirFile.getAbsolutePath());
75 }
76
77 File[] files = srcDirFile.listFiles();
78 for (int i = 0; i < files.length; i++)
79 {
80 File current = files[i];
81 if (!current.isDirectory() && current.getName().toLowerCase().endsWith(".tld"))
82 {
83 generator.addTLD(current);
84 }
85 }
86
87 try
88 {
89 generator.generate();
90 }
91 catch (TransformerFactoryConfigurationError e)
92 {
93 this.echo("Unable to run tlddodc due to a TransformerFactoryConfigurationError: " + e.getMessage());
94 }
95 }
96
97 }