src/share/classes/com/sun/tools/doclets/formats/html/PackageTreeWriter.java

Thu, 31 Aug 2017 15:17:03 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:17:03 +0800
changeset 2525
2eb010b6cb22
parent 2147
130b8c0e570e
parent 0
959103a6100f
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 package com.sun.tools.doclets.formats.html;
aoqi@0 27
aoqi@0 28 import java.io.*;
aoqi@0 29
aoqi@0 30 import com.sun.javadoc.*;
aoqi@0 31 import com.sun.tools.doclets.formats.html.markup.*;
aoqi@0 32 import com.sun.tools.doclets.internal.toolkit.*;
aoqi@0 33 import com.sun.tools.doclets.internal.toolkit.util.*;
aoqi@0 34
aoqi@0 35 /**
aoqi@0 36 * Class to generate Tree page for a package. The name of the file generated is
aoqi@0 37 * "package-tree.html" and it is generated in the respective package directory.
aoqi@0 38 *
aoqi@0 39 * <p><b>This is NOT part of any supported API.
aoqi@0 40 * If you write code that depends on this, you do so at your own risk.
aoqi@0 41 * This code and its internal interfaces are subject to change or
aoqi@0 42 * deletion without notice.</b>
aoqi@0 43 *
aoqi@0 44 * @author Atul M Dambalkar
aoqi@0 45 * @author Bhavesh Patel (Modified)
aoqi@0 46 */
aoqi@0 47 public class PackageTreeWriter extends AbstractTreeWriter {
aoqi@0 48
aoqi@0 49 /**
aoqi@0 50 * Package for which tree is to be generated.
aoqi@0 51 */
aoqi@0 52 protected PackageDoc packagedoc;
aoqi@0 53
aoqi@0 54 /**
aoqi@0 55 * The previous package name in the alpha-order list.
aoqi@0 56 */
aoqi@0 57 protected PackageDoc prev;
aoqi@0 58
aoqi@0 59 /**
aoqi@0 60 * The next package name in the alpha-order list.
aoqi@0 61 */
aoqi@0 62 protected PackageDoc next;
aoqi@0 63
aoqi@0 64 /**
aoqi@0 65 * Constructor.
aoqi@0 66 * @throws IOException
aoqi@0 67 * @throws DocletAbortException
aoqi@0 68 */
aoqi@0 69 public PackageTreeWriter(ConfigurationImpl configuration,
aoqi@0 70 DocPath path,
aoqi@0 71 PackageDoc packagedoc,
aoqi@0 72 PackageDoc prev, PackageDoc next)
aoqi@0 73 throws IOException {
aoqi@0 74 super(configuration, path,
aoqi@0 75 new ClassTree(
aoqi@0 76 configuration.classDocCatalog.allClasses(packagedoc),
aoqi@0 77 configuration));
aoqi@0 78 this.packagedoc = packagedoc;
aoqi@0 79 this.prev = prev;
aoqi@0 80 this.next = next;
aoqi@0 81 }
aoqi@0 82
aoqi@0 83 /**
aoqi@0 84 * Construct a PackageTreeWriter object and then use it to generate the
aoqi@0 85 * package tree page.
aoqi@0 86 *
aoqi@0 87 * @param pkg Package for which tree file is to be generated.
aoqi@0 88 * @param prev Previous package in the alpha-ordered list.
aoqi@0 89 * @param next Next package in the alpha-ordered list.
aoqi@0 90 * @param noDeprecated If true, do not generate any information for
aoqi@0 91 * deprecated classe or interfaces.
aoqi@0 92 * @throws DocletAbortException
aoqi@0 93 */
aoqi@0 94 public static void generate(ConfigurationImpl configuration,
aoqi@0 95 PackageDoc pkg, PackageDoc prev,
aoqi@0 96 PackageDoc next, boolean noDeprecated) {
aoqi@0 97 PackageTreeWriter packgen;
aoqi@0 98 DocPath path = DocPath.forPackage(pkg).resolve(DocPaths.PACKAGE_TREE);
aoqi@0 99 try {
aoqi@0 100 packgen = new PackageTreeWriter(configuration, path, pkg,
aoqi@0 101 prev, next);
aoqi@0 102 packgen.generatePackageTreeFile();
aoqi@0 103 packgen.close();
aoqi@0 104 } catch (IOException exc) {
aoqi@0 105 configuration.standardmessage.error(
aoqi@0 106 "doclet.exception_encountered",
aoqi@0 107 exc.toString(), path.getPath());
aoqi@0 108 throw new DocletAbortException(exc);
aoqi@0 109 }
aoqi@0 110 }
aoqi@0 111
aoqi@0 112 /**
aoqi@0 113 * Generate a separate tree file for each package.
aoqi@0 114 */
aoqi@0 115 protected void generatePackageTreeFile() throws IOException {
aoqi@0 116 Content body = getPackageTreeHeader();
aoqi@0 117 Content headContent = getResource("doclet.Hierarchy_For_Package",
aoqi@0 118 Util.getPackageName(packagedoc));
aoqi@0 119 Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, false,
aoqi@0 120 HtmlStyle.title, headContent);
aoqi@0 121 Content div = HtmlTree.DIV(HtmlStyle.header, heading);
aoqi@0 122 if (configuration.packages.length > 1) {
aoqi@0 123 addLinkToMainTree(div);
aoqi@0 124 }
aoqi@0 125 body.addContent(div);
aoqi@0 126 HtmlTree divTree = new HtmlTree(HtmlTag.DIV);
aoqi@0 127 divTree.addStyle(HtmlStyle.contentContainer);
aoqi@0 128 addTree(classtree.baseclasses(), "doclet.Class_Hierarchy", divTree);
aoqi@0 129 addTree(classtree.baseinterfaces(), "doclet.Interface_Hierarchy", divTree);
aoqi@0 130 addTree(classtree.baseAnnotationTypes(), "doclet.Annotation_Type_Hierarchy", divTree);
aoqi@0 131 addTree(classtree.baseEnums(), "doclet.Enum_Hierarchy", divTree);
aoqi@0 132 body.addContent(divTree);
aoqi@0 133 addNavLinks(false, body);
aoqi@0 134 addBottom(body);
aoqi@0 135 printHtmlDocument(null, true, body);
aoqi@0 136 }
aoqi@0 137
aoqi@0 138 /**
aoqi@0 139 * Get the package tree header.
aoqi@0 140 *
aoqi@0 141 * @return a content tree for the header
aoqi@0 142 */
aoqi@0 143 protected Content getPackageTreeHeader() {
aoqi@0 144 String title = packagedoc.name() + " " +
aoqi@0 145 configuration.getText("doclet.Window_Class_Hierarchy");
aoqi@0 146 Content bodyTree = getBody(true, getWindowTitle(title));
aoqi@0 147 addTop(bodyTree);
aoqi@0 148 addNavLinks(true, bodyTree);
aoqi@0 149 return bodyTree;
aoqi@0 150 }
aoqi@0 151
aoqi@0 152 /**
aoqi@0 153 * Add a link to the tree for all the packages.
aoqi@0 154 *
aoqi@0 155 * @param div the content tree to which the link will be added
aoqi@0 156 */
aoqi@0 157 protected void addLinkToMainTree(Content div) {
aoqi@0 158 Content span = HtmlTree.SPAN(HtmlStyle.packageHierarchyLabel,
aoqi@0 159 getResource("doclet.Package_Hierarchies"));
aoqi@0 160 div.addContent(span);
aoqi@0 161 HtmlTree ul = new HtmlTree (HtmlTag.UL);
aoqi@0 162 ul.addStyle(HtmlStyle.horizontal);
aoqi@0 163 ul.addContent(getNavLinkMainTree(configuration.getText("doclet.All_Packages")));
aoqi@0 164 div.addContent(ul);
aoqi@0 165 }
aoqi@0 166
aoqi@0 167 /**
aoqi@0 168 * Get link for the previous package tree file.
aoqi@0 169 *
aoqi@0 170 * @return a content tree for the link
aoqi@0 171 */
aoqi@0 172 protected Content getNavLinkPrevious() {
aoqi@0 173 if (prev == null) {
aoqi@0 174 return getNavLinkPrevious(null);
aoqi@0 175 } else {
aoqi@0 176 DocPath path = DocPath.relativePath(packagedoc, prev);
aoqi@0 177 return getNavLinkPrevious(path.resolve(DocPaths.PACKAGE_TREE));
aoqi@0 178 }
aoqi@0 179 }
aoqi@0 180
aoqi@0 181 /**
aoqi@0 182 * Get link for the next package tree file.
aoqi@0 183 *
aoqi@0 184 * @return a content tree for the link
aoqi@0 185 */
aoqi@0 186 protected Content getNavLinkNext() {
aoqi@0 187 if (next == null) {
aoqi@0 188 return getNavLinkNext(null);
aoqi@0 189 } else {
aoqi@0 190 DocPath path = DocPath.relativePath(packagedoc, next);
aoqi@0 191 return getNavLinkNext(path.resolve(DocPaths.PACKAGE_TREE));
aoqi@0 192 }
aoqi@0 193 }
aoqi@0 194
aoqi@0 195 /**
aoqi@0 196 * Get link to the package summary page for the package of this tree.
aoqi@0 197 *
aoqi@0 198 * @return a content tree for the package link
aoqi@0 199 */
aoqi@0 200 protected Content getNavLinkPackage() {
aoqi@0 201 Content linkContent = getHyperLink(DocPaths.PACKAGE_SUMMARY,
aoqi@0 202 packageLabel);
aoqi@0 203 Content li = HtmlTree.LI(linkContent);
aoqi@0 204 return li;
aoqi@0 205 }
aoqi@0 206 }

mercurial