duke@1: /* jjg@1735: * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as ohair@554: * published by the Free Software Foundation. Oracle designates this duke@1: * particular file as subject to the "Classpath" exception as provided ohair@554: * by Oracle in the LICENSE file that accompanied this code. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. duke@1: */ duke@1: duke@1: package com.sun.tools.doclets.formats.html; duke@1: bpatel@233: import java.io.*; bpatel@233: import java.util.*; duke@1: duke@1: import com.sun.javadoc.*; bpatel@766: import com.sun.tools.doclets.formats.html.markup.*; bpatel@766: import com.sun.tools.doclets.internal.toolkit.*; jjg@1357: import com.sun.tools.doclets.internal.toolkit.util.*; duke@1: duke@1: /** duke@1: * Generate Index for all the Member Names with Indexing in duke@1: * Unicode Order. This class is a base class for {@link SingleIndexWriter} and duke@1: * {@link SplitIndexWriter}. It uses the functionality from duke@1: * {@link HtmlDocletWriter} to generate the Index Contents. duke@1: * jjg@1359: *

This is NOT part of any supported API. jjg@1359: * If you write code that depends on this, you do so at your own risk. jjg@1359: * This code and its internal interfaces are subject to change or jjg@1359: * deletion without notice. jjg@1359: * duke@1: * @see IndexBuilder duke@1: * @author Atul M Dambalkar bpatel@766: * @author Bhavesh Patel (Modified) duke@1: */ duke@1: public class AbstractIndexWriter extends HtmlDocletWriter { duke@1: duke@1: /** duke@1: * The index of all the members with unicode character. duke@1: */ duke@1: protected IndexBuilder indexbuilder; duke@1: duke@1: /** jjg@1372: * This constructor will be used by {@link SplitIndexWriter}. Initializes duke@1: * path to this file and relative path from this file. duke@1: * jjg@1372: * @param configuration The current configuration duke@1: * @param path Path to the file which is getting generated. duke@1: * @param indexbuilder Unicode based Index from {@link IndexBuilder} duke@1: */ duke@1: protected AbstractIndexWriter(ConfigurationImpl configuration, jjg@1372: DocPath path, jjg@1372: IndexBuilder indexbuilder) duke@1: throws IOException { jjg@1372: super(configuration, path); duke@1: this.indexbuilder = indexbuilder; duke@1: } duke@1: duke@1: /** bpatel@766: * Get the index label for navigation bar. bpatel@766: * bpatel@766: * @return a content tree for the tree label duke@1: */ bpatel@766: protected Content getNavLinkIndex() { bpatel@766: Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, indexLabel); bpatel@766: return li; duke@1: } duke@1: duke@1: /** bpatel@766: * Add the member information for the unicode character along with the duke@1: * list of the members. duke@1: * bpatel@766: * @param unicode Unicode for which member list information to be generated bpatel@766: * @param memberlist List of members for the unicode character bpatel@766: * @param contentTree the content tree to which the information will be added duke@1: */ bpatel@2101: protected void addContents(Character uc, List memberlist, bpatel@766: Content contentTree) { bpatel@2101: String unicode = uc.toString(); bpatel@2101: contentTree.addContent(getMarkerAnchorForIndex(unicode)); bpatel@2101: Content headContent = new StringContent(unicode); bpatel@766: Content heading = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, false, bpatel@766: HtmlStyle.title, headContent); bpatel@766: contentTree.addContent(heading); bpatel@233: int memberListSize = memberlist.size(); bpatel@233: // Display the list only if there are elements to be displayed. bpatel@233: if (memberListSize > 0) { bpatel@766: Content dl = new HtmlTree(HtmlTag.DL); bpatel@233: for (int i = 0; i < memberListSize; i++) { bpatel@233: Doc element = memberlist.get(i); bpatel@233: if (element instanceof MemberDoc) { bpatel@766: addDescription((MemberDoc)element, dl); bpatel@233: } else if (element instanceof ClassDoc) { bpatel@766: addDescription((ClassDoc)element, dl); bpatel@233: } else if (element instanceof PackageDoc) { bpatel@766: addDescription((PackageDoc)element, dl); bpatel@233: } duke@1: } bpatel@766: contentTree.addContent(dl); duke@1: } duke@1: } duke@1: duke@1: /** bpatel@766: * Add one line summary comment for the package. duke@1: * bpatel@766: * @param pkg the package to be documented bpatel@766: * @param dlTree the content tree to which the description will be added duke@1: */ bpatel@766: protected void addDescription(PackageDoc pkg, Content dlTree) { bpatel@766: Content link = getPackageLink(pkg, new StringContent(Util.getPackageName(pkg))); bpatel@766: Content dt = HtmlTree.DT(link); bpatel@766: dt.addContent(" - "); bpatel@766: dt.addContent(getResource("doclet.package")); bpatel@766: dt.addContent(" " + pkg.name()); bpatel@766: dlTree.addContent(dt); bpatel@766: Content dd = new HtmlTree(HtmlTag.DD); bpatel@766: addSummaryComment(pkg, dd); bpatel@766: dlTree.addContent(dd); duke@1: } duke@1: duke@1: /** bpatel@766: * Add one line summary comment for the class. bpatel@766: * bpatel@766: * @param cd the class being documented bpatel@766: * @param dlTree the content tree to which the description will be added bpatel@766: */ bpatel@766: protected void addDescription(ClassDoc cd, Content dlTree) { jjg@1736: Content link = getLink(new LinkInfoImpl(configuration, jjg@1738: LinkInfoImpl.Kind.INDEX, cd).strong(true)); bpatel@766: Content dt = HtmlTree.DT(link); bpatel@766: dt.addContent(" - "); bpatel@766: addClassInfo(cd, dt); bpatel@766: dlTree.addContent(dt); bpatel@766: Content dd = new HtmlTree(HtmlTag.DD); bpatel@766: addComment(cd, dd); bpatel@766: dlTree.addContent(dd); bpatel@766: } bpatel@766: bpatel@766: /** jjg@1735: * Add the classkind (class, interface, exception), error of the class duke@1: * passed. duke@1: * bpatel@766: * @param cd the class being documented bpatel@766: * @param contentTree the content tree to which the class info will be added duke@1: */ bpatel@766: protected void addClassInfo(ClassDoc cd, Content contentTree) { bpatel@766: contentTree.addContent(getResource("doclet.in", bpatel@766: Util.getTypeName(configuration, cd, false), jjg@1740: getPackageLink(cd.containingPackage(), jjg@1740: Util.getPackageName(cd.containingPackage())) jjg@1740: )); duke@1: } duke@1: duke@1: /** bpatel@766: * Add description for Class, Field, Method or Constructor. duke@1: * bpatel@766: * @param member MemberDoc for the member of the Class Kind bpatel@766: * @param dlTree the content tree to which the description will be added duke@1: */ bpatel@766: protected void addDescription(MemberDoc member, Content dlTree) { duke@1: String name = (member instanceof ExecutableMemberDoc)? duke@1: member.name() + ((ExecutableMemberDoc)member).flatSignature() : duke@1: member.name(); bpatel@766: Content span = HtmlTree.SPAN(HtmlStyle.strong, jjg@1735: getDocLink(LinkInfoImpl.Kind.INDEX, member, name)); bpatel@766: Content dt = HtmlTree.DT(span); bpatel@766: dt.addContent(" - "); bpatel@766: addMemberDesc(member, dt); bpatel@766: dlTree.addContent(dt); bpatel@766: Content dd = new HtmlTree(HtmlTag.DD); bpatel@766: addComment(member, dd); bpatel@766: dlTree.addContent(dd); duke@1: } duke@1: duke@1: /** bpatel@766: * Add comment for each element in the index. If the element is deprecated duke@1: * and it has a @deprecated tag, use that comment. Else if the containing duke@1: * class for this element is deprecated, then add the word "Deprecated." at duke@1: * the start and then print the normal comment. duke@1: * bpatel@766: * @param element Index element bpatel@766: * @param contentTree the content tree to which the comment will be added duke@1: */ bpatel@766: protected void addComment(ProgramElementDoc element, Content contentTree) { duke@1: Tag[] tags; bpatel@766: Content span = HtmlTree.SPAN(HtmlStyle.strong, deprecatedPhrase); bpatel@766: HtmlTree div = new HtmlTree(HtmlTag.DIV); bpatel@766: div.addStyle(HtmlStyle.block); duke@1: if (Util.isDeprecated(element)) { bpatel@766: div.addContent(span); duke@1: if ((tags = element.tags("deprecated")).length > 0) bpatel@766: addInlineDeprecatedComment(element, tags[0], div); bpatel@766: contentTree.addContent(div); duke@1: } else { duke@1: ClassDoc cont = element.containingClass(); duke@1: while (cont != null) { duke@1: if (Util.isDeprecated(cont)) { bpatel@766: div.addContent(span); bpatel@766: contentTree.addContent(div); duke@1: break; duke@1: } duke@1: cont = cont.containingClass(); duke@1: } bpatel@766: addSummaryComment(element, contentTree); duke@1: } duke@1: } duke@1: duke@1: /** bpatel@766: * Add description about the Static Varible/Method/Constructor for a duke@1: * member. duke@1: * bpatel@766: * @param member MemberDoc for the member within the Class Kind bpatel@766: * @param contentTree the content tree to which the member description will be added duke@1: */ bpatel@766: protected void addMemberDesc(MemberDoc member, Content contentTree) { duke@1: ClassDoc containing = member.containingClass(); bpatel@766: String classdesc = Util.getTypeName( bpatel@766: configuration, containing, true) + " "; duke@1: if (member.isField()) { duke@1: if (member.isStatic()) { bpatel@766: contentTree.addContent( bpatel@766: getResource("doclet.Static_variable_in", classdesc)); duke@1: } else { bpatel@766: contentTree.addContent( bpatel@766: getResource("doclet.Variable_in", classdesc)); duke@1: } duke@1: } else if (member.isConstructor()) { bpatel@766: contentTree.addContent( bpatel@766: getResource("doclet.Constructor_for", classdesc)); duke@1: } else if (member.isMethod()) { duke@1: if (member.isStatic()) { bpatel@766: contentTree.addContent( bpatel@766: getResource("doclet.Static_method_in", classdesc)); duke@1: } else { bpatel@766: contentTree.addContent( bpatel@766: getResource("doclet.Method_in", classdesc)); duke@1: } duke@1: } jjg@1735: addPreQualifiedClassLink(LinkInfoImpl.Kind.INDEX, containing, bpatel@766: false, contentTree); duke@1: } bpatel@2101: bpatel@2101: /** bpatel@2101: * Get the marker anchor which will be added to the index documentation tree. bpatel@2101: * bpatel@2101: * @param anchorNameForIndex the anchor name attribute for index page bpatel@2101: * @return a content tree for the marker anchor bpatel@2101: */ bpatel@2101: public Content getMarkerAnchorForIndex(String anchorNameForIndex) { bpatel@2101: return getMarkerAnchor(getNameForIndex(anchorNameForIndex), null); bpatel@2101: } bpatel@2101: bpatel@2101: /** bpatel@2101: * Generate a valid HTML name for member index page. bpatel@2101: * bpatel@2101: * @param unicode the string that needs to be converted to valid HTML name. bpatel@2101: * @return a valid HTML name string. bpatel@2101: */ bpatel@2101: public String getNameForIndex(String unicode) { bpatel@2101: return "I:" + getName(unicode); bpatel@2101: } duke@1: }