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

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