001 /*
002 * Copyright 1998-2004 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package com.sun.tools.doclets.formats.html;
027
028 import com.sun.tools.doclets.internal.toolkit.util.*;
029
030 import com.sun.javadoc.*;
031 import java.io.*;
032 import java.util.*;
033
034 /**
035 * Generate Index for all the Member Names with Indexing in
036 * Unicode Order. This class is a base class for {@link SingleIndexWriter} and
037 * {@link SplitIndexWriter}. It uses the functionality from
038 * {@link HtmlDocletWriter} to generate the Index Contents.
039 *
040 * @see IndexBuilder
041 * @author Atul M Dambalkar
042 */
043 public class AbstractIndexWriter extends HtmlDocletWriter {
044
045 /**
046 * The index of all the members with unicode character.
047 */
048 protected IndexBuilder indexbuilder;
049
050 /**
051 * This constructor will be used by {@link SplitIndexWriter}. Initialises
052 * path to this file and relative path from this file.
053 *
054 * @param path Path to the file which is getting generated.
055 * @param filename Name of the file which is getting genrated.
056 * @param relpath Relative path from this file to the current directory.
057 * @param indexbuilder Unicode based Index from {@link IndexBuilder}
058 */
059 protected AbstractIndexWriter(ConfigurationImpl configuration,
060 String path, String filename,
061 String relpath, IndexBuilder indexbuilder)
062 throws IOException {
063 super(configuration, path, filename, relpath);
064 this.indexbuilder = indexbuilder;
065 }
066
067 /**
068 * This Constructor will be used by {@link SingleIndexWriter}.
069 *
070 * @param filename Name of the file which is getting genrated.
071 * @param indexbuilder Unicode based Index form {@link IndexBuilder}
072 */
073 protected AbstractIndexWriter(ConfigurationImpl configuration,
074 String filename, IndexBuilder indexbuilder)
075 throws IOException {
076 super(configuration, filename);
077 this.indexbuilder = indexbuilder;
078 }
079
080 /**
081 * Print the text "Index" in strong format in the navigation bar.
082 */
083 protected void navLinkIndex() {
084 navCellRevStart();
085 fontStyle("NavBarFont1Rev");
086 strongText("doclet.Index");
087 fontEnd();
088 navCellEnd();
089 }
090
091 /**
092 * Generate the member information for the unicode character along with the
093 * list of the members.
094 *
095 * @param unicode Unicode for which member list information to be generated.
096 * @param memberlist List of members for the unicode character.
097 */
098 protected void generateContents(Character unicode, List<? extends Doc> memberlist) {
099 anchor("_" + unicode + "_");
100 h2();
101 strong(unicode.toString());
102 h2End();
103 dl();
104 for (int i = 0; i < memberlist.size(); i++) {
105 Doc element = memberlist.get(i);
106 if (element instanceof MemberDoc) {
107 printDescription((MemberDoc)element);
108 } else if (element instanceof ClassDoc) {
109 printDescription((ClassDoc)element);
110 } else if (element instanceof PackageDoc) {
111 printDescription((PackageDoc)element);
112 }
113 }
114 dlEnd();
115 hr();
116 }
117
118
119 /**
120 * Print one line summary comment for the package.
121 *
122 * @param pkg PackageDoc passed.
123 */
124 protected void printDescription(PackageDoc pkg) {
125 dt();
126 printPackageLink(pkg, Util.getPackageName(pkg), true);
127 print(" - ");
128 print(configuration.getText("doclet.package") + " " + pkg.name());
129 dd();
130 printSummaryComment(pkg);
131 }
132
133 /**
134 * Print one line summary comment for the class.
135 *
136 * @param cd ClassDoc passed.
137 */
138 protected void printDescription(ClassDoc cd) {
139 dt();
140 printLink(new LinkInfoImpl(LinkInfoImpl.CONTEXT_INDEX, cd, true));
141 print(" - ");
142 printClassInfo(cd);
143 dd();
144 printComment(cd);
145 }
146
147 /**
148 * Print the classkind(class, interface, exception, error of the class
149 * passed.
150 *
151 * @param cd ClassDoc.
152 */
153 protected void printClassInfo(ClassDoc cd) {
154 print(configuration.getText("doclet.in",
155 Util.getTypeName(configuration, cd, false),
156 getPackageLink(cd.containingPackage(),
157 Util.getPackageName(cd.containingPackage()), false)));
158 }
159
160
161 /**
162 * Generate Description for Class, Field, Method or Constructor.
163 * for Java.* Packages Class Members.
164 *
165 * @param member MemberDoc for the member of the Class Kind.
166 * @see com.sun.javadoc.MemberDoc
167 */
168 protected void printDescription(MemberDoc member) {
169 String name = (member instanceof ExecutableMemberDoc)?
170 member.name() + ((ExecutableMemberDoc)member).flatSignature() :
171 member.name();
172 if (name.indexOf("<") != -1 || name.indexOf(">") != -1) {
173 name = Util.escapeHtmlChars(name);
174 }
175 ClassDoc containing = member.containingClass();
176 dt();
177 printDocLink(LinkInfoImpl.CONTEXT_INDEX, member, name, true);
178 println(" - ");
179 printMemberDesc(member);
180 println();
181 dd();
182 printComment(member);
183 println();
184 }
185
186
187 /**
188 * Print comment for each element in the index. If the element is deprecated
189 * and it has a @deprecated tag, use that comment. Else if the containing
190 * class for this element is deprecated, then add the word "Deprecated." at
191 * the start and then print the normal comment.
192 *
193 * @param element Index element.
194 */
195 protected void printComment(ProgramElementDoc element) {
196 Tag[] tags;
197 if (Util.isDeprecated(element)) {
198 strongText("doclet.Deprecated"); space();
199 if ((tags = element.tags("deprecated")).length > 0)
200 printInlineDeprecatedComment(element, tags[0]);
201 } else {
202 ClassDoc cont = element.containingClass();
203 while (cont != null) {
204 if (Util.isDeprecated(cont)) {
205 strongText("doclet.Deprecated"); space();
206 break;
207 }
208 cont = cont.containingClass();
209 }
210 printSummaryComment(element);
211 }
212 }
213
214 /**
215 * Print description about the Static Varible/Method/Constructor for a
216 * member.
217 *
218 * @param member MemberDoc for the member within the Class Kind.
219 * @see com.sun.javadoc.MemberDoc
220 */
221 protected void printMemberDesc(MemberDoc member) {
222 ClassDoc containing = member.containingClass();
223 String classdesc = Util.getTypeName(configuration, containing, true) + " " +
224 getPreQualifiedClassLink(LinkInfoImpl.CONTEXT_INDEX, containing,
225 false);
226 if (member.isField()) {
227 if (member.isStatic()) {
228 printText("doclet.Static_variable_in", classdesc);
229 } else {
230 printText("doclet.Variable_in", classdesc);
231 }
232 } else if (member.isConstructor()) {
233 printText("doclet.Constructor_for", classdesc);
234 } else if (member.isMethod()) {
235 if (member.isStatic()) {
236 printText("doclet.Static_method_in", classdesc);
237 } else {
238 printText("doclet.Method_in", classdesc);
239 }
240 }
241 }
242 }