001 /*
002 * CSVFormatterMappingTaglet.java
003 *
004 * Copyright (C) 2005 Anupam Sengupta (anupamsg@users.sourceforge.net)
005 *
006 * This program is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU General Public License
008 * as published by the Free Software Foundation; either version 2
009 * of the License, or (at your option) any later version.
010 *
011 * This program is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with this program; if not, write to the Free Software
018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
019 *
020 * Version: $Revision: 1.2 $
021 */
022 package net.sf.anupam.csv.taglets;
023
024 import com.sun.javadoc.Tag;
025 import com.sun.tools.doclets.internal.toolkit.taglets.LegacyTaglet;
026 import com.sun.tools.doclets.internal.toolkit.taglets.Taglet;
027
028 import java.util.Map;
029 import java.util.StringTokenizer;
030
031 /**
032 * Taglet for outputting the CSV Formatter tag's name attribute. The
033 * <code>@csv.formatter-mapping</code> tags will be displayed for classes
034 * that have the formatter mapping set in the type documentation. This tag
035 * can only be used on the formatter class' type Javadoc.
036 *
037 * @author Anupam Sengupta
038 * @version $Revision: 1.2 $
039 * @since 1.5
040 */
041 public class CSVFormatterMappingTaglet
042 implements com.sun.tools.doclets.Taglet {
043
044 /**
045 * name of the tag.
046 */
047 private static final String NAME = "csv.formatter-mapping";
048
049 /**
050 * The Javadoc header to print.
051 */
052 private static final String HEADER = "CSV Formatter Mapping:";
053
054 /**
055 * Constructor for CSVBeanMappingTaglet.
056 */
057 public CSVFormatterMappingTaglet() {
058 super();
059 }
060
061 /**
062 * Returns the name of this Javadoc tag.
063 *
064 * @return the name of this tag
065 * @see com.sun.tools.doclets.internal.toolkit.taglets.Taglet#getName()
066 */
067 public String getName() {
068 return NAME;
069 }
070
071 /**
072 * Indicates whether this tag can be used in a constructor Javadoc.
073 *
074 * @return <code>false</code>
075 * @see com.sun.tools.doclets.internal.toolkit.taglets.Taglet#inConstructor()
076 */
077 public boolean inConstructor() {
078 return false;
079 }
080
081 /**
082 * Indicates whether this tag can be used in a field Javadoc.
083 *
084 * @return <code>false</code>
085 * @see com.sun.tools.doclets.internal.toolkit.taglets.Taglet#inField()
086 */
087 public boolean inField() {
088 return false;
089 }
090
091 /**
092 * Indicates whether this tag can be used in a method Javadoc.
093 *
094 * @return <code>false</code>
095 * @see com.sun.tools.doclets.internal.toolkit.taglets.Taglet#inMethod()
096 */
097 public boolean inMethod() {
098 return false;
099 }
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<String, Taglet> tagletMap) {
147 if (tagletMap.containsKey(NAME)) {
148 tagletMap.remove(NAME);
149 }
150 tagletMap.put(NAME, new LegacyTaglet(new CSVFormatterMappingTaglet()));
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 toString(final Tag tag) {
161
162 final StringTokenizer tokenizer = new StringTokenizer(tag.text());
163 String name = "Unknown";
164
165 while (tokenizer.hasMoreTokens()) {
166
167 final String [] nameValuePair = tokenizer.nextToken().split("=");
168
169 if (nameValuePair != null) {
170
171 if (nameValuePair[0].equalsIgnoreCase("name")) {
172 name = nameValuePair[1];
173 }
174 }
175 }
176 return "<DT><B>"
177 + HEADER + "</B><DD>" + "<table>" + "<tr>" + "<td>"
178 + "CSV Formatter Name: " + name + "</td>" + "</tr>"
179 + "</table>" + "</DD>\n";
180 }
181
182 /**
183 * Returns the string to be included the the output Javadoc for the specified tags.
184 *
185 * @param tags the tags for which the string representation should be returned
186 * @return the string representation to include in the output Javadoc
187 * @see com.sun.tools.doclets.Taglet#toString(com.sun.javadoc.Tag[])
188 */
189 public String toString(final Tag [] tags) {
190 if (tags.length == 0) {
191 return null;
192 }
193 final StringBuffer strBuffer = new StringBuffer();
194 for (Tag tag : tags) {
195 strBuffer.append(this.toString(tag));
196 }
197 return strBuffer.toString();
198 }
199 }