KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > anupam > csv > taglets > CSVBeanMappingTaglet


1 /*
2  * CSVBeanMappingTaglet.java
3  *
4  * Copyright (C) 2005 Anupam Sengupta (anupamsg@users.sourceforge.net)
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * Version: $Revision: 1.2 $
21  */

22 package net.sf.anupam.csv.taglets;
23
24 import com.sun.javadoc.Tag;
25 import com.sun.tools.doclets.internal.toolkit.taglets.LegacyTaglet;
26 import com.sun.tools.doclets.internal.toolkit.taglets.Taglet;
27
28 import java.util.Map JavaDoc;
29 import java.util.StringTokenizer JavaDoc;
30
31 /**
32  * Taglet for outputting the CSV bean mapping information. The
33  * <code>@csv.bean-mapping</code> tags will be displayed for classes
34  * that have CSV bean mapping set in the type Javadoc comment. The tag can
35  * only be specified in the type Javadoc.
36  *
37  * @author Anupam Sengupta
38  * @version $Revision: 1.2 $
39  * @since 1.5
40  */

41 public class CSVBeanMappingTaglet
42         implements com.sun.tools.doclets.Taglet {
43
44     /**
45      * name of the tag.
46      */

47     private static final String JavaDoc NAME = "csv.bean-mapping";
48
49     /**
50      * The Javadoc header to print.
51      */

52     private static final String JavaDoc HEADER = "CSV Mapping:";
53
54     /**
55      * Constructor for CSVBeanMappingTaglet.
56      */

57     public CSVBeanMappingTaglet() {
58         super();
59     }
60
61     /**
62      * Returns the name of this Javadoc tag.
63      *
64      * @return the name of this tag
65      * @see com.sun.tools.doclets.internal.toolkit.taglets.Taglet#getName()
66      */

67     public String JavaDoc getName() {
68         return NAME;
69     }
70
71     /**
72      * Indicates whether this tag can be used in a constructor Javadoc.
73      *
74      * @return <code>false</code>
75      * @see com.sun.tools.doclets.internal.toolkit.taglets.Taglet#inConstructor()
76      */

77     public boolean inConstructor() {
78         return false;
79     }
80
81     /**
82      * Indicates whether this tag can be used in a field Javadoc.
83      *
84      * @return <code>false</code>
85      * @see com.sun.tools.doclets.internal.toolkit.taglets.Taglet#inField()
86      */

87     public boolean inField() {
88         return false;
89     }
90
91     /**
92      * Indicates whether this tag can be used in a method Javadoc.
93      *
94      * @return <code>false</code>
95      * @see com.sun.tools.doclets.internal.toolkit.taglets.Taglet#inMethod()
96      */

97     public boolean inMethod() {
98         return false;
99     }
100
101     /**
102      * Indicates whether this tag can be used in the overview Javadoc.
103      *
104      * @return <code>false</code>
105      * @see com.sun.tools.doclets.internal.toolkit.taglets.Taglet#inOverview()
106      */

107     public boolean inOverview() {
108         return false;
109     }
110
111     /**
112      * Indicates whether this tag can be used in the package Javadoc.
113      *
114      * @return <code>false</code>
115      * @see com.sun.tools.doclets.internal.toolkit.taglets.Taglet#inPackage()
116      */

117     public boolean inPackage() {
118         return false;
119     }
120
121     /**
122      * Indicates whether this tag can be used in a Type Javadoc.
123      *
124      * @return <code>true</code>
125      * @see com.sun.tools.doclets.internal.toolkit.taglets.Taglet#inType()
126      */

127     public boolean inType() {
128         return true;
129     }
130
131     /**
132      * Indicates whether this is an inline tag.
133      *
134      * @return <code>false</code>
135      * @see com.sun.tools.doclets.internal.toolkit.taglets.Taglet#isInlineTag()
136      */

137     public boolean isInlineTag() {
138         return false;
139     }
140
141     /**
142      * Register a new instance of this taglet to the Javadoc taglet set.
143      *
144      * @param tagletMap the Javadoc taglet set.
145      */

146     public static void register(final Map JavaDoc<String JavaDoc, Taglet> tagletMap) {
147         if (tagletMap.containsKey(NAME)) {
148             tagletMap.remove(NAME);
149         }
150         tagletMap.put(NAME, new LegacyTaglet(new CSVBeanMappingTaglet()));
151     }
152
153     /**
154      * Given the <code>Tag</code> representation of this custom tag, return
155      * its string representation.
156      *
157      * @param tag the <code>Tag</code> representation of this custom tag.
158      * @return String representation of the tag
159      */

160     public String JavaDoc toString(final Tag tag) {
161
162         final StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(tag.text());
163         String JavaDoc beanName = "Unknown";
164         String JavaDoc hasCVSHeader = "False";
165         while (tokenizer.hasMoreTokens()) {
166
167             final String JavaDoc [] nameValuePair = tokenizer.nextToken().split("=");
168
169             if (nameValuePair != null) {
170
171                 if (nameValuePair[0].equalsIgnoreCase("bean-name")) {
172                     beanName = nameValuePair[1];
173                 } else if (nameValuePair[0].equalsIgnoreCase("csv-header")) {
174                     hasCVSHeader = nameValuePair[1];
175                 }
176             }
177         }
178         return "<DT><B>"
179                 + HEADER + "</B><DD>" + "<table>" + "<tr>" + "<td>"
180                 + "Mapped Bean Name: " + beanName + "<BR>Has CSV Header: "
181                 + hasCVSHeader + "</td>" + "</tr>" + "</table>" + "</DD>\n";
182     }
183
184     /**
185      * Returns the string to be displayed on the Javadoc for the specified tags.
186      *
187      * @param tags the list of tags for which the string representation should be returned
188      * @return the string to display on the Javadoc
189      * @see com.sun.tools.doclets.Taglet#toString(com.sun.javadoc.Tag[])
190      */

191     public String JavaDoc toString(final Tag [] tags) {
192         if (tags.length == 0) {
193             return null;
194         }
195         final StringBuffer JavaDoc strBuffer = new StringBuffer JavaDoc();
196         for (Tag tag : tags) {
197             strBuffer.append(this.toString(tag));
198         }
199         return strBuffer.toString();
200     }
201 }
202
Popular Tags