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