duke@1: /* jjg@1736: * 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: bpatel@233: 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: * Class to generate Tree page for a package. The name of the file generated is duke@1: * "package-tree.html" and it is generated in the respective package directory. 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: * @author Atul M Dambalkar bpatel@766: * @author Bhavesh Patel (Modified) duke@1: */ duke@1: public class PackageTreeWriter extends AbstractTreeWriter { duke@1: duke@1: /** duke@1: * Package for which tree is to be generated. duke@1: */ duke@1: protected PackageDoc packagedoc; duke@1: duke@1: /** duke@1: * The previous package name in the alpha-order list. duke@1: */ duke@1: protected PackageDoc prev; duke@1: duke@1: /** duke@1: * The next package name in the alpha-order list. duke@1: */ duke@1: protected PackageDoc next; duke@1: duke@1: /** duke@1: * Constructor. duke@1: * @throws IOException duke@1: * @throws DocletAbortException duke@1: */ duke@1: public PackageTreeWriter(ConfigurationImpl configuration, jjg@1372: DocPath path, duke@1: PackageDoc packagedoc, duke@1: PackageDoc prev, PackageDoc next) duke@1: throws IOException { jjg@1372: super(configuration, path, duke@1: new ClassTree( duke@1: configuration.classDocCatalog.allClasses(packagedoc), jjg@1372: configuration)); duke@1: this.packagedoc = packagedoc; duke@1: this.prev = prev; duke@1: this.next = next; duke@1: } duke@1: duke@1: /** duke@1: * Construct a PackageTreeWriter object and then use it to generate the duke@1: * package tree page. duke@1: * duke@1: * @param pkg Package for which tree file is to be generated. duke@1: * @param prev Previous package in the alpha-ordered list. duke@1: * @param next Next package in the alpha-ordered list. duke@1: * @param noDeprecated If true, do not generate any information for duke@1: * deprecated classe or interfaces. duke@1: * @throws DocletAbortException duke@1: */ duke@1: public static void generate(ConfigurationImpl configuration, duke@1: PackageDoc pkg, PackageDoc prev, duke@1: PackageDoc next, boolean noDeprecated) { duke@1: PackageTreeWriter packgen; jjg@1372: DocPath path = DocPath.forPackage(pkg).resolve(DocPaths.PACKAGE_TREE); duke@1: try { jjg@1372: packgen = new PackageTreeWriter(configuration, path, pkg, duke@1: prev, next); duke@1: packgen.generatePackageTreeFile(); duke@1: packgen.close(); duke@1: } catch (IOException exc) { duke@1: configuration.standardmessage.error( duke@1: "doclet.exception_encountered", jjg@1372: exc.toString(), path.getPath()); jjg@1985: throw new DocletAbortException(exc); duke@1: } duke@1: } duke@1: duke@1: /** duke@1: * Generate a separate tree file for each package. duke@1: */ duke@1: protected void generatePackageTreeFile() throws IOException { bpatel@766: Content body = getPackageTreeHeader(); bpatel@766: Content headContent = getResource("doclet.Hierarchy_For_Package", jjg@1740: Util.getPackageName(packagedoc)); bpatel@766: Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, false, bpatel@766: HtmlStyle.title, headContent); bpatel@766: Content div = HtmlTree.DIV(HtmlStyle.header, heading); duke@1: if (configuration.packages.length > 1) { bpatel@766: addLinkToMainTree(div); duke@1: } bpatel@766: body.addContent(div); bpatel@766: HtmlTree divTree = new HtmlTree(HtmlTag.DIV); bpatel@766: divTree.addStyle(HtmlStyle.contentContainer); bpatel@766: addTree(classtree.baseclasses(), "doclet.Class_Hierarchy", divTree); bpatel@766: addTree(classtree.baseinterfaces(), "doclet.Interface_Hierarchy", divTree); bpatel@766: addTree(classtree.baseAnnotationTypes(), "doclet.Annotation_Type_Hierarchy", divTree); bpatel@766: addTree(classtree.baseEnums(), "doclet.Enum_Hierarchy", divTree); bpatel@766: body.addContent(divTree); bpatel@766: addNavLinks(false, body); bpatel@766: addBottom(body); bpatel@766: printHtmlDocument(null, true, body); duke@1: } duke@1: duke@1: /** bpatel@766: * Get the package tree header. bpatel@766: * bpatel@766: * @return a content tree for the header duke@1: */ bpatel@766: protected Content getPackageTreeHeader() { bpatel@766: String title = packagedoc.name() + " " + bpatel@766: configuration.getText("doclet.Window_Class_Hierarchy"); bpatel@766: Content bodyTree = getBody(true, getWindowTitle(title)); bpatel@766: addTop(bodyTree); bpatel@766: addNavLinks(true, bodyTree); bpatel@766: return bodyTree; duke@1: } duke@1: duke@1: /** bpatel@766: * Add a link to the tree for all the packages. bpatel@766: * bpatel@766: * @param div the content tree to which the link will be added duke@1: */ bpatel@766: protected void addLinkToMainTree(Content div) { bpatel@2147: Content span = HtmlTree.SPAN(HtmlStyle.packageHierarchyLabel, bpatel@766: getResource("doclet.Package_Hierarchies")); bpatel@766: div.addContent(span); bpatel@766: HtmlTree ul = new HtmlTree (HtmlTag.UL); bpatel@766: ul.addStyle(HtmlStyle.horizontal); bpatel@766: ul.addContent(getNavLinkMainTree(configuration.getText("doclet.All_Packages"))); bpatel@766: div.addContent(ul); duke@1: } duke@1: duke@1: /** bpatel@766: * Get link for the previous package tree file. bpatel@766: * bpatel@766: * @return a content tree for the link duke@1: */ bpatel@766: protected Content getNavLinkPrevious() { duke@1: if (prev == null) { bpatel@766: return getNavLinkPrevious(null); duke@1: } else { jjg@1372: DocPath path = DocPath.relativePath(packagedoc, prev); jjg@1372: return getNavLinkPrevious(path.resolve(DocPaths.PACKAGE_TREE)); duke@1: } duke@1: } duke@1: duke@1: /** bpatel@766: * Get link for the next package tree file. bpatel@766: * bpatel@766: * @return a content tree for the link duke@1: */ bpatel@766: protected Content getNavLinkNext() { duke@1: if (next == null) { bpatel@766: return getNavLinkNext(null); duke@1: } else { jjg@1372: DocPath path = DocPath.relativePath(packagedoc, next); jjg@1372: return getNavLinkNext(path.resolve(DocPaths.PACKAGE_TREE)); duke@1: } duke@1: } duke@1: duke@1: /** bpatel@766: * Get link to the package summary page for the package of this tree. bpatel@766: * bpatel@766: * @return a content tree for the package link duke@1: */ bpatel@766: protected Content getNavLinkPackage() { jjg@1373: Content linkContent = getHyperLink(DocPaths.PACKAGE_SUMMARY, bpatel@766: packageLabel); bpatel@766: Content li = HtmlTree.LI(linkContent); bpatel@766: return li; duke@1: } duke@1: }