1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/AbstractIndexWriter.java Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,242 @@ 1.4 +/* 1.5 + * Copyright 1998-2004 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Sun designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Sun in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.26 + * have any questions. 1.27 + */ 1.28 + 1.29 +package com.sun.tools.doclets.formats.html; 1.30 + 1.31 +import com.sun.tools.doclets.internal.toolkit.util.*; 1.32 + 1.33 +import com.sun.javadoc.*; 1.34 +import java.io.*; 1.35 +import java.util.*; 1.36 + 1.37 +/** 1.38 + * Generate Index for all the Member Names with Indexing in 1.39 + * Unicode Order. This class is a base class for {@link SingleIndexWriter} and 1.40 + * {@link SplitIndexWriter}. It uses the functionality from 1.41 + * {@link HtmlDocletWriter} to generate the Index Contents. 1.42 + * 1.43 + * @see IndexBuilder 1.44 + * @author Atul M Dambalkar 1.45 + */ 1.46 +public class AbstractIndexWriter extends HtmlDocletWriter { 1.47 + 1.48 + /** 1.49 + * The index of all the members with unicode character. 1.50 + */ 1.51 + protected IndexBuilder indexbuilder; 1.52 + 1.53 + /** 1.54 + * This constructor will be used by {@link SplitIndexWriter}. Initialises 1.55 + * path to this file and relative path from this file. 1.56 + * 1.57 + * @param path Path to the file which is getting generated. 1.58 + * @param filename Name of the file which is getting genrated. 1.59 + * @param relpath Relative path from this file to the current directory. 1.60 + * @param indexbuilder Unicode based Index from {@link IndexBuilder} 1.61 + */ 1.62 + protected AbstractIndexWriter(ConfigurationImpl configuration, 1.63 + String path, String filename, 1.64 + String relpath, IndexBuilder indexbuilder) 1.65 + throws IOException { 1.66 + super(configuration, path, filename, relpath); 1.67 + this.indexbuilder = indexbuilder; 1.68 + } 1.69 + 1.70 + /** 1.71 + * This Constructor will be used by {@link SingleIndexWriter}. 1.72 + * 1.73 + * @param filename Name of the file which is getting genrated. 1.74 + * @param indexbuilder Unicode based Index form {@link IndexBuilder} 1.75 + */ 1.76 + protected AbstractIndexWriter(ConfigurationImpl configuration, 1.77 + String filename, IndexBuilder indexbuilder) 1.78 + throws IOException { 1.79 + super(configuration, filename); 1.80 + this.indexbuilder = indexbuilder; 1.81 + } 1.82 + 1.83 + /** 1.84 + * Print the text "Index" in bold format in the navigation bar. 1.85 + */ 1.86 + protected void navLinkIndex() { 1.87 + navCellRevStart(); 1.88 + fontStyle("NavBarFont1Rev"); 1.89 + boldText("doclet.Index"); 1.90 + fontEnd(); 1.91 + navCellEnd(); 1.92 + } 1.93 + 1.94 + /** 1.95 + * Generate the member information for the unicode character along with the 1.96 + * list of the members. 1.97 + * 1.98 + * @param unicode Unicode for which member list information to be generated. 1.99 + * @param memberlist List of members for the unicode character. 1.100 + */ 1.101 + protected void generateContents(Character unicode, List memberlist) { 1.102 + anchor("_" + unicode + "_"); 1.103 + h2(); 1.104 + bold(unicode.toString()); 1.105 + h2End(); 1.106 + dl(); 1.107 + for (int i = 0; i < memberlist.size(); i++) { 1.108 + Doc element = (Doc)memberlist.get(i); 1.109 + if (element instanceof MemberDoc) { 1.110 + printDescription((MemberDoc)element); 1.111 + } else if (element instanceof ClassDoc) { 1.112 + printDescription((ClassDoc)element); 1.113 + } else if (element instanceof PackageDoc) { 1.114 + printDescription((PackageDoc)element); 1.115 + } 1.116 + } 1.117 + dlEnd(); 1.118 + hr(); 1.119 + } 1.120 + 1.121 + 1.122 + /** 1.123 + * Print one line summary comment for the package. 1.124 + * 1.125 + * @param pkg PackageDoc passed. 1.126 + */ 1.127 + protected void printDescription(PackageDoc pkg) { 1.128 + dt(); 1.129 + printPackageLink(pkg, Util.getPackageName(pkg), true); 1.130 + print(" - "); 1.131 + print(configuration.getText("doclet.package") + " " + pkg.name()); 1.132 + dd(); 1.133 + printSummaryComment(pkg); 1.134 + } 1.135 + 1.136 + /** 1.137 + * Print one line summary comment for the class. 1.138 + * 1.139 + * @param cd ClassDoc passed. 1.140 + */ 1.141 + protected void printDescription(ClassDoc cd) { 1.142 + dt(); 1.143 + printLink(new LinkInfoImpl(LinkInfoImpl.CONTEXT_INDEX, cd, true)); 1.144 + print(" - "); 1.145 + printClassInfo(cd); 1.146 + dd(); 1.147 + printComment(cd); 1.148 + } 1.149 + 1.150 + /** 1.151 + * Print the classkind(class, interface, exception, error of the class 1.152 + * passed. 1.153 + * 1.154 + * @param cd ClassDoc. 1.155 + */ 1.156 + protected void printClassInfo(ClassDoc cd) { 1.157 + print(configuration.getText("doclet.in", 1.158 + Util.getTypeName(configuration, cd, false), 1.159 + getPackageLink(cd.containingPackage(), 1.160 + Util.getPackageName(cd.containingPackage()), false))); 1.161 + } 1.162 + 1.163 + 1.164 + /** 1.165 + * Generate Description for Class, Field, Method or Constructor. 1.166 + * for Java.* Packages Class Members. 1.167 + * 1.168 + * @param member MemberDoc for the member of the Class Kind. 1.169 + * @see com.sun.javadoc.MemberDoc 1.170 + */ 1.171 + protected void printDescription(MemberDoc member) { 1.172 + String name = (member instanceof ExecutableMemberDoc)? 1.173 + member.name() + ((ExecutableMemberDoc)member).flatSignature() : 1.174 + member.name(); 1.175 + if (name.indexOf("<") != -1 || name.indexOf(">") != -1) { 1.176 + name = Util.escapeHtmlChars(name); 1.177 + } 1.178 + ClassDoc containing = member.containingClass(); 1.179 + dt(); 1.180 + printDocLink(LinkInfoImpl.CONTEXT_INDEX, member, name, true); 1.181 + println(" - "); 1.182 + printMemberDesc(member); 1.183 + println(); 1.184 + dd(); 1.185 + printComment(member); 1.186 + println(); 1.187 + } 1.188 + 1.189 + 1.190 + /** 1.191 + * Print comment for each element in the index. If the element is deprecated 1.192 + * and it has a @deprecated tag, use that comment. Else if the containing 1.193 + * class for this element is deprecated, then add the word "Deprecated." at 1.194 + * the start and then print the normal comment. 1.195 + * 1.196 + * @param element Index element. 1.197 + */ 1.198 + protected void printComment(ProgramElementDoc element) { 1.199 + Tag[] tags; 1.200 + if (Util.isDeprecated(element)) { 1.201 + boldText("doclet.Deprecated"); space(); 1.202 + if ((tags = element.tags("deprecated")).length > 0) 1.203 + printInlineDeprecatedComment(element, tags[0]); 1.204 + } else { 1.205 + ClassDoc cont = element.containingClass(); 1.206 + while (cont != null) { 1.207 + if (Util.isDeprecated(cont)) { 1.208 + boldText("doclet.Deprecated"); space(); 1.209 + break; 1.210 + } 1.211 + cont = cont.containingClass(); 1.212 + } 1.213 + printSummaryComment(element); 1.214 + } 1.215 + } 1.216 + 1.217 + /** 1.218 + * Print description about the Static Varible/Method/Constructor for a 1.219 + * member. 1.220 + * 1.221 + * @param member MemberDoc for the member within the Class Kind. 1.222 + * @see com.sun.javadoc.MemberDoc 1.223 + */ 1.224 + protected void printMemberDesc(MemberDoc member) { 1.225 + ClassDoc containing = member.containingClass(); 1.226 + String classdesc = Util.getTypeName(configuration, containing, true) + " " + 1.227 + getPreQualifiedClassLink(LinkInfoImpl.CONTEXT_INDEX, containing, 1.228 + false); 1.229 + if (member.isField()) { 1.230 + if (member.isStatic()) { 1.231 + printText("doclet.Static_variable_in", classdesc); 1.232 + } else { 1.233 + printText("doclet.Variable_in", classdesc); 1.234 + } 1.235 + } else if (member.isConstructor()) { 1.236 + printText("doclet.Constructor_for", classdesc); 1.237 + } else if (member.isMethod()) { 1.238 + if (member.isStatic()) { 1.239 + printText("doclet.Static_method_in", classdesc); 1.240 + } else { 1.241 + printText("doclet.Method_in", classdesc); 1.242 + } 1.243 + } 1.244 + } 1.245 +}