KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > doc > info > InfoSubTask


1 /*
2  * Copyright (c) 2001, 2002 The XDoclet team
3  * All rights reserved.
4  */

5 package xdoclet.modules.doc.info;
6
7 import java.io.File JavaDoc;
8 import java.util.*;
9
10 import xjavadoc.XClass;
11 import xjavadoc.XPackage;
12
13 import xdoclet.TemplateSubTask;
14 import xdoclet.XDocletException;
15 import xdoclet.modules.doc.XDocletModulesDocMessages;
16 import xdoclet.tagshandler.PackageTagsHandler;
17 import xdoclet.util.FileManager;
18 import xdoclet.util.Translator;
19
20 /**
21  * Extracts tag values from classes and method docs and generates an HTML report that summarizes all occurrences of this
22  * tag in a source tree. This task can be used to generate TODO lists or any list with metrics about the occurrence of a
23  * certain tag.
24  *
25  * @author <a HREF="mailto:aslak.nospam@users.sf.net">Aslak Hellesøy</a>
26  * @created September 18, 2001
27  * @ant.element display-name="Info/Todo" name="info" parent="xdoclet.modules.doc.DocumentDocletTask"
28  * @todo use DocletTask as parent instead. should be enough.
29  * @version $Revision: 1.14 $
30  */

31 public class InfoSubTask extends TemplateSubTask
32 {
33     private final Properties properties = new Properties();
34
35     private String JavaDoc header = null;
36
37     private String JavaDoc projectName = null;
38
39     /**
40      * @todo blabla (this is yet another test)
41      */

42     public InfoSubTask()
43     {
44         // Set default values
45
setHeader("Todo list");
46         setTag("todo");
47
48         // Use the Ant project's name
49
// setProjectname(documentDocletTask.getProject().getName());
50

51         // Don't want tags from superclasses
52
properties.setProperty("superclasses", "false");
53     }
54
55     /**
56      * Gets the Header attribute of the InfoSubTask object
57      *
58      * @return The Header value
59      */

60     public String JavaDoc getHeader()
61     {
62         return header;
63     }
64
65     /**
66      * Gets the Projectname attribute of the InfoSubTask object
67      *
68      * @return The Projectname value
69      */

70     public String JavaDoc getProjectname()
71     {
72         return projectName;
73     }
74
75     /**
76      * Sets the Header attribute of the InfoSubTask object
77      *
78      * @param header The new Header value
79      */

80     public void setHeader(String JavaDoc header)
81     {
82         this.header = header;
83     }
84
85     /**
86      * Sets the Tag attribute of the InfoSubTask object
87      *
88      * @param tag The new Tag value
89      */

90     public void setTag(String JavaDoc tag)
91     {
92         properties.setProperty("tagName", tag);
93     }
94
95     /**
96      * Sets the Projectname attribute of the InfoSubTask object
97      *
98      * @param projectname The new Projectname value
99      */

100     public void setProjectname(String JavaDoc projectname)
101     {
102         this.projectName = projectname;
103     }
104
105     /**
106      * @exception XDocletException Description of Exception
107      * @todo generate an overview summary html too? (the default right page). It could be the old
108      * todo file, a bit modified.
109      */

110     public void execute() throws XDocletException
111     {
112         System.out.println(Translator.getString(XDocletModulesDocMessages.class, XDocletModulesDocMessages.CREATE_INFO_LISTS_FOR,
113             new String JavaDoc[]{properties.getProperty("tagName")}));
114
115         // first, generate the general stuff on the root.
116

117         // copy the static stuff
118
try {
119             FileManager.writeURLContent(getClass().getResource("resources/class.gif"), new File JavaDoc(getDestDir(), "class.gif"));
120             FileManager.writeURLContent(getClass().getResource("resources/field.gif"), new File JavaDoc(getDestDir(), "field.gif"));
121             FileManager.writeURLContent(getClass().getResource("resources/constructor.gif"), new File JavaDoc(getDestDir(), "constructor.gif"));
122             FileManager.writeURLContent(getClass().getResource("resources/method.gif"), new File JavaDoc(getDestDir(), "method.gif"));
123         }
124         catch (Throwable JavaDoc e) {
125             e.printStackTrace();
126         }
127
128         // Although stylesheet could be copied out with above method, use template engine.
129
// We might want to parameterise colors/fonts with tags
130
setTemplateURL(getClass().getResource("resources/info.css"));
131         setDestinationFile("info.css");
132         startProcess();
133
134         setTemplateURL(getClass().getResource("resources/index.xdt"));
135         setDestinationFile("index.html");
136         startProcess();
137
138         setTemplateURL(getClass().getResource("resources/all-classes.xdt"));
139         setDestinationFile("all-classes.html");
140         startProcess();
141
142         setTemplateURL(getClass().getResource("resources/all-packages.xdt"));
143         setDestinationFile("all-packages.html");
144         startProcess();
145
146         setTemplateURL(getClass().getResource("resources/overview-packages.xdt"));
147         setDestinationFile("overview-packages.html");
148         startProcess();
149
150         // now loop over all packages and classes
151
Collection classes = getXJavaDoc().getSourceClasses();
152         SortedSet packages = new TreeSet();
153
154         for (Iterator i = classes.iterator(); i.hasNext(); ) {
155             packages.add(((XClass) i.next()).getContainingPackage());
156         }
157
158         XPackage currentPackage = null;
159
160         for (Iterator packageIterator = packages.iterator(); packageIterator.hasNext(); ) {
161             currentPackage = (XPackage) packageIterator.next();
162             setCurrentPackage(currentPackage);
163
164             File JavaDoc oldDestDir = getDestDir();
165             File JavaDoc dir = new File JavaDoc(getDestDir(), PackageTagsHandler.packageNameAsPathFor(currentPackage));
166
167             setDestDir(dir);
168             setTemplateURL(getClass().getResource("resources/classes-list.xdt"));
169             setDestinationFile("classes-list.html");
170             startProcess();
171
172             classes = currentPackage.getClasses();
173             setTemplateURL(getClass().getResource("resources/class-details.xdt"));
174             for (Iterator i = classes.iterator(); i.hasNext(); ) {
175                 setCurrentClass((XClass) i.next());
176                 setDestinationFile(getCurrentClass().getName() + "-details.html");
177                 startProcess();
178             }
179
180             setDestDir(oldDestDir);
181         }
182
183         // restore current package to null, so subsequent class iterations can
184
// perform outside the context of a current packages
185
setCurrentPackage(null);
186     }
187
188     /**
189      * validate options - noop here
190      *
191      * @exception XDocletException
192      */

193     public void validateOptions() throws XDocletException
194     {
195     }
196
197     /**
198      * Gets the Properties attribute of the InfoSubTask object
199      *
200      * @return The Properties value
201      */

202     protected Properties getProperties()
203     {
204         return properties;
205     }
206
207     /**
208      * Describe what the method does
209      *
210      * @exception XDocletException Describe the exception
211      */

212     protected void engineStarted() throws XDocletException
213     {
214     }
215
216 }
217
Popular Tags