duke@1: /* ohair@798: * Copyright (c) 1998, 2010, 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: duke@1: import java.io.*; duke@1: import java.util.*; bpatel@766: import com.sun.tools.doclets.internal.toolkit.util.*; bpatel@766: import com.sun.tools.doclets.internal.toolkit.*; bpatel@766: import com.sun.tools.doclets.formats.html.markup.*; bpatel@766: import com.sun.javadoc.*; duke@1: duke@1: /** duke@1: * Abstract class to print the class hierarchy page for all the Classes. This duke@1: * is sub-classed by {@link PackageTreeWriter} and {@link TreeWriter} to duke@1: * generate the Package Tree and global Tree(for all the classes and packages) duke@1: * pages. duke@1: * duke@1: * @author Atul M Dambalkar duke@1: */ duke@1: public abstract class AbstractTreeWriter extends HtmlDocletWriter { duke@1: duke@1: /** duke@1: * The class and interface tree built by using {@link ClassTree} duke@1: */ duke@1: protected final ClassTree classtree; duke@1: bpatel@766: private static final String LI_CIRCLE = "circle"; bpatel@766: duke@1: /** duke@1: * Constructor initilises classtree variable. This constructor will be used duke@1: * while generating global tree file "overview-tree.html". duke@1: * duke@1: * @param filename File to be generated. duke@1: * @param classtree Tree built by {@link ClassTree}. duke@1: * @throws IOException duke@1: * @throws DocletAbortException duke@1: */ duke@1: protected AbstractTreeWriter(ConfigurationImpl configuration, duke@1: String filename, ClassTree classtree) duke@1: throws IOException { duke@1: super(configuration, filename); duke@1: this.classtree = classtree; duke@1: } duke@1: duke@1: /** duke@1: * Create appropriate directory for the package and also initilise the duke@1: * relative path from this generated file to the current or duke@1: * the destination directory. This constructor will be used while duke@1: * generating "package tree" file. duke@1: * duke@1: * @param path Directories in this path will be created if they are not duke@1: * already there. duke@1: * @param filename Name of the package tree file to be generated. duke@1: * @param classtree The tree built using {@link ClassTree}. duke@1: * for the package pkg. duke@1: * @param pkg PackageDoc for which tree file will be generated. duke@1: * @throws IOException duke@1: * @throws DocletAbortException duke@1: */ duke@1: protected AbstractTreeWriter(ConfigurationImpl configuration, duke@1: String path, String filename, duke@1: ClassTree classtree, PackageDoc pkg) duke@1: throws IOException { duke@1: super(configuration, duke@1: path, filename, DirectoryManager.getRelativePath(pkg.name())); duke@1: this.classtree = classtree; duke@1: } duke@1: duke@1: /** bpatel@766: * Add each level of the class tree. For each sub-class or duke@1: * sub-interface indents the next level information. bpatel@766: * Recurses itself to add subclasses info. duke@1: * bpatel@766: * @param parent the superclass or superinterface of the list bpatel@766: * @param list list of the sub-classes at this level bpatel@766: * @param isEnum true if we are generating a tree for enums bpatel@766: * @param contentTree the content tree to which the level information will be added duke@1: */ bpatel@766: protected void addLevelInfo(ClassDoc parent, List list, bpatel@766: boolean isEnum, Content contentTree) { bpatel@766: int size = list.size(); bpatel@766: if (size > 0) { bpatel@766: Content ul = new HtmlTree(HtmlTag.UL); bpatel@766: for (int i = 0; i < size; i++) { mcimadamore@184: ClassDoc local = list.get(i); bpatel@766: HtmlTree li = new HtmlTree(HtmlTag.LI); bpatel@766: li.addAttr(HtmlAttr.TYPE, LI_CIRCLE); bpatel@766: addPartialInfo(local, li); bpatel@766: addExtendsImplements(parent, local, li); bpatel@766: addLevelInfo(local, classtree.subs(local, isEnum), bpatel@766: isEnum, li); // Recurse bpatel@766: ul.addContent(li); duke@1: } bpatel@766: contentTree.addContent(ul); duke@1: } duke@1: } duke@1: duke@1: /** bpatel@766: * Add the heading for the tree depending upon tree type if it's a bpatel@766: * Class Tree or Interface tree. duke@1: * duke@1: * @param list List of classes which are at the most base level, all the bpatel@766: * other classes in this run will derive from these classes bpatel@766: * @param heading heading for the tree bpatel@766: * @param div the content tree to which the tree will be added duke@1: */ bpatel@766: protected void addTree(List list, String heading, Content div) { duke@1: if (list.size() > 0) { mcimadamore@184: ClassDoc firstClassDoc = list.get(0); bpatel@766: Content headingContent = getResource(heading); bpatel@766: div.addContent(HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, true, bpatel@766: headingContent)); bpatel@766: addLevelInfo(!firstClassDoc.isInterface()? firstClassDoc : null, bpatel@766: list, list == classtree.baseEnums(), div); duke@1: } duke@1: } duke@1: duke@1: /** bpatel@766: * Add information regarding the classes which this class extends or duke@1: * implements. duke@1: * bpatel@766: * @param parent the parent class of the class being documented bpatel@766: * @param cd the classdoc under consideration bpatel@766: * @param contentTree the content tree to which the information will be added duke@1: */ bpatel@766: protected void addExtendsImplements(ClassDoc parent, ClassDoc cd, bpatel@766: Content contentTree) { duke@1: ClassDoc[] interfaces = cd.interfaces(); duke@1: if (interfaces.length > (cd.isInterface()? 1 : 0)) { duke@1: Arrays.sort(interfaces); duke@1: int counter = 0; duke@1: for (int i = 0; i < interfaces.length; i++) { duke@1: if (parent != interfaces[i]) { duke@1: if (! (interfaces[i].isPublic() || duke@1: Util.isLinkable(interfaces[i], configuration()))) { duke@1: continue; duke@1: } duke@1: if (counter == 0) { duke@1: if (cd.isInterface()) { bpatel@766: contentTree.addContent(" ("); bpatel@766: contentTree.addContent(getResource("doclet.also")); bpatel@766: contentTree.addContent(" extends "); duke@1: } else { bpatel@766: contentTree.addContent(" (implements "); duke@1: } duke@1: } else { bpatel@766: contentTree.addContent(", "); duke@1: } bpatel@766: addPreQualifiedClassLink(LinkInfoImpl.CONTEXT_TREE, bpatel@766: interfaces[i], contentTree); duke@1: counter++; duke@1: } duke@1: } duke@1: if (counter > 0) { bpatel@766: contentTree.addContent(")"); duke@1: } duke@1: } duke@1: } duke@1: duke@1: /** bpatel@766: * Add information about the class kind, if it's a "class" or "interface". duke@1: * bpatel@766: * @param cd the class being documented bpatel@766: * @param contentTree the content tree to which the information will be added duke@1: */ bpatel@766: protected void addPartialInfo(ClassDoc cd, Content contentTree) { bpatel@766: addPreQualifiedStrongClassLink(LinkInfoImpl.CONTEXT_TREE, cd, contentTree); duke@1: } duke@1: duke@1: /** bpatel@766: * Get the tree label for the navigation bar. duke@1: * bpatel@766: * @return a content tree for the tree label duke@1: */ bpatel@766: protected Content getNavLinkTree() { bpatel@766: Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, treeLabel); bpatel@766: return li; duke@1: } duke@1: }