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, String relpath,
061: IndexBuilder indexbuilder) throws IOException {
062: super (configuration, path, filename, relpath);
063: this .indexbuilder = indexbuilder;
064: }
065:
066: /**
067: * This Constructor will be used by {@link SingleIndexWriter}.
068: *
069: * @param filename Name of the file which is getting genrated.
070: * @param indexbuilder Unicode based Index form {@link IndexBuilder}
071: */
072: protected AbstractIndexWriter(ConfigurationImpl configuration,
073: String filename, IndexBuilder indexbuilder)
074: throws IOException {
075: super (configuration, filename);
076: this .indexbuilder = indexbuilder;
077: }
078:
079: /**
080: * Print the text "Index" in bold format in the navigation bar.
081: */
082: protected void navLinkIndex() {
083: navCellRevStart();
084: fontStyle("NavBarFont1Rev");
085: boldText("doclet.Index");
086: fontEnd();
087: navCellEnd();
088: }
089:
090: /**
091: * Generate the member information for the unicode character along with the
092: * list of the members.
093: *
094: * @param unicode Unicode for which member list information to be generated.
095: * @param memberlist List of members for the unicode character.
096: */
097: protected void generateContents(Character unicode, List memberlist) {
098: anchor("_" + unicode + "_");
099: h2();
100: bold(unicode.toString());
101: h2End();
102: dl();
103: for (int i = 0; i < memberlist.size(); i++) {
104: Doc element = (Doc) memberlist.get(i);
105: if (element instanceof MemberDoc) {
106: printDescription((MemberDoc) element);
107: } else if (element instanceof ClassDoc) {
108: printDescription((ClassDoc) element);
109: } else if (element instanceof PackageDoc) {
110: printDescription((PackageDoc) element);
111: }
112: }
113: dlEnd();
114: hr();
115: }
116:
117: /**
118: * Print one line summary comment for the package.
119: *
120: * @param pkg PackageDoc passed.
121: */
122: protected void printDescription(PackageDoc pkg) {
123: dt();
124: printPackageLink(pkg, Util.getPackageName(pkg), true);
125: print(" - ");
126: print(configuration.getText("doclet.package") + " "
127: + pkg.name());
128: dd();
129: printSummaryComment(pkg);
130: }
131:
132: /**
133: * Print one line summary comment for the class.
134: *
135: * @param cd ClassDoc passed.
136: */
137: protected void printDescription(ClassDoc cd) {
138: dt();
139: printLink(new LinkInfoImpl(LinkInfoImpl.CONTEXT_INDEX, cd, true));
140: print(" - ");
141: printClassInfo(cd);
142: dd();
143: printComment(cd);
144: }
145:
146: /**
147: * Print the classkind(class, interface, exception, error of the class
148: * passed.
149: *
150: * @param cd ClassDoc.
151: */
152: protected void printClassInfo(ClassDoc cd) {
153: print(configuration.getText("doclet.in", Util.getTypeName(
154: configuration, cd, false), getPackageLink(cd
155: .containingPackage(), Util.getPackageName(cd
156: .containingPackage()), false)));
157: }
158:
159: /**
160: * Generate Description for Class, Field, Method or Constructor.
161: * for Java.* Packages Class Members.
162: *
163: * @param member MemberDoc for the member of the Class Kind.
164: * @see com.sun.javadoc.MemberDoc
165: */
166: protected void printDescription(MemberDoc member) {
167: String name = (member instanceof ExecutableMemberDoc) ? member
168: .name()
169: + ((ExecutableMemberDoc) member).flatSignature()
170: : member.name();
171: if (name.indexOf("<") != -1 || name.indexOf(">") != -1) {
172: name = Util.escapeHtmlChars(name);
173: }
174: ClassDoc containing = member.containingClass();
175: dt();
176: printDocLink(LinkInfoImpl.CONTEXT_INDEX, member, name, true);
177: println(" - ");
178: printMemberDesc(member);
179: println();
180: dd();
181: printComment(member);
182: println();
183: }
184:
185: /**
186: * Print comment for each element in the index. If the element is deprecated
187: * and it has a @deprecated tag, use that comment. Else if the containing
188: * class for this element is deprecated, then add the word "Deprecated." at
189: * the start and then print the normal comment.
190: *
191: * @param element Index element.
192: */
193: protected void printComment(ProgramElementDoc element) {
194: Tag[] tags;
195: if (Util.isDeprecated(element)) {
196: boldText("doclet.Deprecated");
197: space();
198: if ((tags = element.tags("deprecated")).length > 0)
199: printInlineDeprecatedComment(element, tags[0]);
200: } else {
201: ClassDoc cont = element.containingClass();
202: while (cont != null) {
203: if (Util.isDeprecated(cont)) {
204: boldText("doclet.Deprecated");
205: 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,
224: true)
225: + " "
226: + getPreQualifiedClassLink(LinkInfoImpl.CONTEXT_INDEX,
227: containing, false);
228: if (member.isField()) {
229: if (member.isStatic()) {
230: printText("doclet.Static_variable_in", classdesc);
231: } else {
232: printText("doclet.Variable_in", classdesc);
233: }
234: } else if (member.isConstructor()) {
235: printText("doclet.Constructor_for", classdesc);
236: } else if (member.isMethod()) {
237: if (member.isStatic()) {
238: printText("doclet.Static_method_in", classdesc);
239: } else {
240: printText("doclet.Method_in", classdesc);
241: }
242: }
243: }
244: }
|