KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > taglet > ToDoTaglet


1 package jodd.taglet;
2
3 import java.util.Map;
4
5 import com.sun.javadoc.Tag;
6 import com.sun.tools.doclets.Taglet;
7
8 /**
9  * A sample To Do Taglet. This tag can be used in any kind of {@link
10  * com.sun.javadoc.Doc}. It is not an inline tag. Every generated html text
11  * element has its own CSS "to do" class.
12  */

13 public class ToDoTaglet implements Taglet {
14     
15     private static final String NAME = "2do";
16     private static final String HEADER = "To Do:";
17     private static final String CSS_CLASS = "todo";
18     
19     /**
20      * Return the name of this custom tag.
21      */

22     public String getName() {
23         return NAME;
24     }
25     
26     /**
27      * Will return true since <code>@2do</code> can be used in field
28      * documentation.
29      *
30      * @return true since <code>@2do</code> can be used in field documentation and false
31      * otherwise.
32      */

33     public boolean inField() {
34         return true;
35     }
36     
37     /**
38      * Will return true since <code>@2do</code> can be used in constructor
39      * documentation.
40      *
41      * @return true since <code>@2do</code> can be used in constructor documentation and
42      * false otherwise.
43      */

44     public boolean inConstructor() {
45         return true;
46     }
47     
48     /**
49      * Will return true since <code>@2do</code> can be used in method
50      * documentation.
51      *
52      * @return true since <code>@2do</code> can be used in method documentation and
53      * false otherwise.
54      */

55     public boolean inMethod() {
56         return true;
57     }
58     
59     /**
60      * Will return true since <code>@2do</code> can be used in method
61      * documentation.
62      *
63      * @return true since <code>@2do</code> can be used in overview documentation and
64      * false otherwise.
65      */

66     public boolean inOverview() {
67         return true;
68     }
69     
70     /**
71      * Will return true since <code>@2do</code> can be used in package
72      * documentation.
73      *
74      * @return true since <code>@2do</code> can be used in package documentation and
75      * false otherwise.
76      */

77     public boolean inPackage() {
78         return true;
79     }
80     
81     /**
82      * Will return true since <code>@2do</code> can be used in type
83      * documentation (classes or interfaces).
84      *
85      * @return true since <code>@2do</code> can be used in type documentation and false
86      * otherwise.
87      */

88     public boolean inType() {
89         return true;
90     }
91     
92     /**
93      * Will return false since <code>@2do</code> is not an inline tag.
94      *
95      * @return false since <code>@2do</code> is not an inline tag.
96      */

97
98     public boolean isInlineTag() {
99         return false;
100     }
101     
102     /**
103      * Register this Taglet.
104      *
105      * @param tagletMap the map to register this tag to.
106      */

107     public static void register(Map tagletMap) {
108         ToDoTaglet tag = new ToDoTaglet();
109         Taglet t = (Taglet) tagletMap.get(tag.getName());
110         if (t != null) {
111             tagletMap.remove(tag.getName());
112         }
113         tagletMap.put(tag.getName(), tag);
114     }
115
116
117     /**
118      * Given the <code>Tag</code> representation of this custom tag, return its
119      * string representation.
120      *
121      * @param tag the <code>Tag</code> representation of this custom tag.
122      */

123     public String toString(Tag tag) {
124         return getString(tag.text());
125     }
126
127     /**
128      * Given an array of <code>Tag</code>s representing this custom tag, return
129      * its string representation.
130      *
131      * @param tags the array of <code>Tag</code>s representing of this custom tag.
132      */

133     public String toString(Tag[] tags) {
134         if (tags.length == 0) {
135             return null;
136         }
137         String result = new String();
138         for (int i = 0; i < tags.length; i++) {
139             if (i > 0) {
140                 result += "</dd>\n<dd class=\"" + CSS_CLASS + "\">";
141             }
142             result += tags[i].text();
143         }
144         return getString(result);
145     }
146
147
148     /**
149      * Formats the output.
150      *
151      * @param tagtext
152      */

153     private String getString(String tagtext) {
154         String result = "\n<dt class=\"" + CSS_CLASS + "\">" + HEADER;
155         result += "<dd class=\"" + CSS_CLASS + "\">";
156         result += "<span class=\"" + CSS_CLASS + "\">";
157         result += tagtext;
158         result += "</span></dd></dt>\n";
159         return result;
160     }
161
162 }
163
Popular Tags