KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > doc > DocumentTagsSubTask


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

5 package xdoclet.modules.doc;
6
7 import java.io.File JavaDoc;
8 import java.text.MessageFormat JavaDoc;
9 import java.util.*;
10
11 import xjavadoc.XClass;
12
13 import xdoclet.TemplateSubTask;
14 import xdoclet.XDocletException;
15 import xdoclet.template.TemplateEngine;
16 import xdoclet.template.TemplateException;
17 import xdoclet.template.TemplateTagHandler;
18 import xdoclet.util.Translator;
19
20 /**
21  * Extracts doc.blabla tags from xdoclet.* sources and generates an html file describing the tags and their parameters.
22  *
23  * @author Ara Abrahamian (ara_e@email.com)
24  * @created June 19, 2001
25  * @ant.element display-name="Tag documentation" name="documenttags" parent="xdoclet.modules.doc.DocumentDocletTask"
26  * @todo use DocletTask as parent instead. should be enough.
27  * @version $Revision: 1.10 $
28  */

29 public class DocumentTagsSubTask extends TemplateSubTask
30 {
31     private static String JavaDoc INDEX_TEMPLATE_FILE = "resources/index.xdt";
32
33     private static String JavaDoc GENERATED_INDEX_FILE_NAME = "index.html";
34
35     private static String JavaDoc NAMESPACES_TEMPLATE_FILE = "resources/namespaces.xdt";
36
37     private static String JavaDoc GENERATED_NAMESPACES_FILE_NAME = "namespaces.html";
38
39     private static String JavaDoc TAGS_MAIN_TEMPLATE_FILE = "resources/tags_main.xdt";
40
41     private static String JavaDoc GENERATED_TAGS_MAIN_FILE_NAME = "tags.html";
42
43     private static String JavaDoc TAGS_TOC_MAIN_TEMPLATE_FILE = "resources/tags_toc_main.xdt";
44
45     private static String JavaDoc GENERATED_TAGS_TOC_MAIN_FILE_NAME = "tags_toc.html";
46
47     private static String JavaDoc TAGS_TOC_TEMPLATE_FILE = "resources/tags_toc.xdt";
48
49     private static String JavaDoc GENERATED_TAGS_TOC_FILE_NAME = "{0}_toc.html";
50
51     private static String JavaDoc TAGS_TEMPLATE_FILE = "resources/tags.xdt";
52
53     private static String JavaDoc GENERATED_TAGS_FILE_NAME = "{0}.html";
54
55     private String JavaDoc currentNamespace;
56
57     /**
58      * Gets the CurrentNamespace attribute of the DocumentTagsSubTask object
59      *
60      * @return The CurrentNamespace value
61      */

62     public String JavaDoc getCurrentNamespace()
63     {
64         return currentNamespace;
65     }
66
67
68     /**
69      * Called to validate configuration parameters - really noop here
70      *
71      * @exception XDocletException thrown on failure
72      */

73     public void validateOptions() throws XDocletException
74     {
75     }
76
77     /**
78      * Describe what the method does
79      *
80      * @exception XDocletException Describe the exception
81      */

82     public void execute() throws XDocletException
83     {
84
85         setTemplateURL(getClass().getResource(INDEX_TEMPLATE_FILE));
86         setDestinationFile(GENERATED_INDEX_FILE_NAME);
87         startProcess();
88
89         System.out.println(Translator.getString(XDocletModulesDocMessages.class, XDocletModulesDocMessages.GENERATING_NAMESPACES));
90         setTemplateURL(getClass().getResource(NAMESPACES_TEMPLATE_FILE));
91         setDestinationFile(GENERATED_NAMESPACES_FILE_NAME);
92         startProcess();
93
94         System.out.println(Translator.getString(XDocletModulesDocMessages.class, XDocletModulesDocMessages.GENERATING_TAGS_MAIN));
95         setTemplateURL(getClass().getResource(TAGS_MAIN_TEMPLATE_FILE));
96         setDestinationFile(GENERATED_TAGS_MAIN_FILE_NAME);
97         startProcess();
98
99         System.out.println(Translator.getString(XDocletModulesDocMessages.class, XDocletModulesDocMessages.GENERATING_TAGS_TOC_MAIN));
100         setTemplateURL(getClass().getResource(TAGS_TOC_MAIN_TEMPLATE_FILE));
101         setDestinationFile(GENERATED_TAGS_TOC_MAIN_FILE_NAME);
102         startProcess();
103
104         System.out.println(Translator.getString(XDocletModulesDocMessages.class, XDocletModulesDocMessages.GENERATING_TAGS_MAIN));
105         setTemplateURL(getClass().getResource(TAGS_TOC_TEMPLATE_FILE));
106         setDestinationFile(GENERATED_TAGS_TOC_FILE_NAME);
107         addOfType("xdoclet.template.TemplateTagHandler");
108         //setExtentValue( "superclass" );
109
startProcess();
110
111         System.out.println(Translator.getString(XDocletModulesDocMessages.class, XDocletModulesDocMessages.GENERATING_TAGS_MAIN));
112         setTemplateURL(getClass().getResource(TAGS_TEMPLATE_FILE));
113         setDestinationFile(GENERATED_TAGS_FILE_NAME);
114         addOfType("xdoclet.template.TemplateTagHandler");
115         //setExtentValue( "superclass" );
116
startProcess();
117     }
118
119     /**
120      * Gets the GeneratedFileName attribute of the DocumentTagsSubTask object
121      *
122      * @param clazz Describe what the parameter does
123      * @return The GeneratedFileName value
124      * @exception XDocletException Describe the exception
125      */

126     protected String JavaDoc getGeneratedFileName(XClass clazz) throws XDocletException
127     {
128         String JavaDoc destinationFile = MessageFormat.format(getDestinationFile(), new Object JavaDoc[]{currentNamespace});
129
130         return new File JavaDoc(destinationFile).toString();
131     }
132
133     /**
134      * Processed template for clazz and generates output file for clazz.
135      *
136      * @param clazz Description of Parameter
137      * @exception XDocletException Description of Exception
138      */

139     protected void generateForClass(XClass clazz) throws XDocletException
140     {
141         setCurrentNamespace(clazz);
142
143         super.generateForClass(clazz);
144     }
145
146     /**
147      * Describe what the method does
148      *
149      * @exception XDocletException Describe the exception
150      */

151     protected void engineStarted() throws XDocletException
152     {
153     }
154
155     /**
156      * Sets the CurrentNamespace attribute of the DocumentTagsSubTask object
157      *
158      * @param clazz The new CurrentNamespace value
159      * @exception XDocletException Describe the exception
160      */

161     private void setCurrentNamespace(XClass clazz) throws XDocletException
162     {
163         for (Iterator namespaces = TemplateEngine.getEngineInstance().getNamespaces().iterator(); namespaces.hasNext(); ) {
164             String JavaDoc namespace = (String JavaDoc) namespaces.next();
165
166             try {
167                 TemplateTagHandler handler = TemplateEngine.getEngineInstance().getTagHandlerFor(namespace);
168
169                 if (handler.getClass().getName().equals(clazz.getQualifiedName())) {
170                     currentNamespace = namespace;
171                     break;
172                 }
173             }
174             catch (TemplateException e) {
175                 throw new XDocletException(e, "Error getting tag handler for " + namespace);
176             }
177         }
178         if (currentNamespace == null) {
179             // throw new XDocletException("No namespace found for class " + clazz.qualifiedName());
180
}
181     }
182 }
183
Popular Tags