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