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