1 /* 2 * Copyright (c) 1998, 2015, 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 26 package com.sun.tools.doclets.formats.html; 27 28 import java.io.*; 29 30 import com.sun.javadoc.*; 31 import com.sun.tools.doclets.formats.html.markup.*; 32 import com.sun.tools.doclets.internal.toolkit.*; 33 import com.sun.tools.doclets.internal.toolkit.util.*; 34 35 /** 36 * Class to generate Tree page for a package. The name of the file generated is 37 * "package-tree.html" and it is generated in the respective package directory. 38 * 39 * <p><b>This is NOT part of any supported API. 40 * If you write code that depends on this, you do so at your own risk. 41 * This code and its internal interfaces are subject to change or 42 * deletion without notice.</b> 43 * 44 * @author Atul M Dambalkar 45 * @author Bhavesh Patel (Modified) 46 */ 47 public class PackageTreeWriter extends AbstractTreeWriter { 48 49 /** 50 * Package for which tree is to be generated. 51 */ 52 protected PackageDoc packagedoc; 53 54 /** 55 * The previous package name in the alpha-order list. 56 */ 57 protected PackageDoc prev; 58 59 /** 60 * The next package name in the alpha-order list. 61 */ 62 protected PackageDoc next; 63 64 /** 65 * Constructor. 66 * @throws IOException 67 * @throws DocletAbortException 68 */ 69 public PackageTreeWriter(ConfigurationImpl configuration, 70 DocPath path, 71 PackageDoc packagedoc, 72 PackageDoc prev, PackageDoc next) 73 throws IOException { 74 super(configuration, path, 75 new ClassTree( 76 configuration.classDocCatalog.allClasses(packagedoc), 77 configuration)); 78 this.packagedoc = packagedoc; 79 this.prev = prev; 80 this.next = next; 81 } 82 83 /** 84 * Construct a PackageTreeWriter object and then use it to generate the 85 * package tree page. 86 * 87 * @param pkg Package for which tree file is to be generated. 88 * @param prev Previous package in the alpha-ordered list. 89 * @param next Next package in the alpha-ordered list. 90 * @param noDeprecated If true, do not generate any information for 91 * deprecated classe or interfaces. 92 * @throws DocletAbortException 93 */ 94 public static void generate(ConfigurationImpl configuration, 95 PackageDoc pkg, PackageDoc prev, 96 PackageDoc next, boolean noDeprecated) { 97 PackageTreeWriter packgen; 98 DocPath path = DocPath.forPackage(pkg).resolve(DocPaths.PACKAGE_TREE); 99 try { 100 packgen = new PackageTreeWriter(configuration, path, pkg, 101 prev, next); 102 packgen.generatePackageTreeFile(); 103 packgen.close(); 104 } catch (IOException exc) { 105 configuration.standardmessage.error( 106 "doclet.exception_encountered", 107 exc.toString(), path.getPath()); 108 throw new DocletAbortException(exc); 109 } 110 } 111 112 /** 113 * Generate a separate tree file for each package. 114 */ 115 protected void generatePackageTreeFile() throws IOException { 116 HtmlTree body = getPackageTreeHeader(); 117 HtmlTree htmlTree = (configuration.allowTag(HtmlTag.MAIN)) 118 ? HtmlTree.MAIN() 119 : body; 120 Content headContent = getResource("doclet.Hierarchy_For_Package", 121 utils.getPackageName(packagedoc)); 122 Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, false, 123 HtmlStyle.title, headContent); 124 Content div = HtmlTree.DIV(HtmlStyle.header, heading); 125 if (configuration.packages.size() > 1) { 126 addLinkToMainTree(div); 127 } 128 htmlTree.addContent(div); 129 HtmlTree divTree = new HtmlTree(HtmlTag.DIV); 130 divTree.addStyle(HtmlStyle.contentContainer); 131 addTree(classtree.baseclasses(), "doclet.Class_Hierarchy", divTree); 132 addTree(classtree.baseinterfaces(), "doclet.Interface_Hierarchy", divTree); 133 addTree(classtree.baseAnnotationTypes(), "doclet.Annotation_Type_Hierarchy", divTree); 134 addTree(classtree.baseEnums(), "doclet.Enum_Hierarchy", divTree); 135 htmlTree.addContent(divTree); 136 if (configuration.allowTag(HtmlTag.MAIN)) { 137 body.addContent(htmlTree); 138 } 139 HtmlTree tree = (configuration.allowTag(HtmlTag.FOOTER)) 140 ? HtmlTree.FOOTER() 141 : body; 142 addNavLinks(false, tree); 143 addBottom(tree); 144 if (configuration.allowTag(HtmlTag.FOOTER)) { 145 body.addContent(tree); 146 } 147 printHtmlDocument(null, true, body); 148 } 149 150 /** 151 * Get the package tree header. 152 * 153 * @return a content tree for the header 154 */ 155 protected HtmlTree getPackageTreeHeader() { 156 String title = packagedoc.name() + " " + 157 configuration.getText("doclet.Window_Class_Hierarchy"); 158 HtmlTree bodyTree = getBody(true, getWindowTitle(title)); 159 HtmlTree htmlTree = (configuration.allowTag(HtmlTag.HEADER)) 160 ? HtmlTree.HEADER() 161 : bodyTree; 162 addTop(htmlTree); 163 addNavLinks(true, htmlTree); 164 if (configuration.allowTag(HtmlTag.HEADER)) { 165 bodyTree.addContent(htmlTree); 166 } 167 return bodyTree; 168 } 169 170 /** 171 * Add a link to the tree for all the packages. 172 * 173 * @param div the content tree to which the link will be added 174 */ 175 protected void addLinkToMainTree(Content div) { 176 Content span = HtmlTree.SPAN(HtmlStyle.packageHierarchyLabel, 177 getResource("doclet.Package_Hierarchies")); 178 div.addContent(span); 179 HtmlTree ul = new HtmlTree (HtmlTag.UL); 180 ul.addStyle(HtmlStyle.horizontal); 181 ul.addContent(getNavLinkMainTree(configuration.getText("doclet.All_Packages"))); 182 div.addContent(ul); 183 } 184 185 /** 186 * Get link for the previous package tree file. 187 * 188 * @return a content tree for the link 189 */ 190 protected Content getNavLinkPrevious() { 191 if (prev == null) { 192 return getNavLinkPrevious(null); 193 } else { 194 DocPath path = DocPath.relativePath(packagedoc, 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 protected Content getNavLinkNext() { 205 if (next == null) { 206 return getNavLinkNext(null); 207 } else { 208 DocPath path = DocPath.relativePath(packagedoc, next); 209 return getNavLinkNext(path.resolve(DocPaths.PACKAGE_TREE)); 210 } 211 } 212 213 /** 214 * Get link to the package summary page for the package of this tree. 215 * 216 * @return a content tree for the package link 217 */ 218 protected Content getNavLinkPackage() { 219 Content linkContent = getHyperLink(DocPaths.PACKAGE_SUMMARY, 220 packageLabel); 221 Content li = HtmlTree.LI(linkContent); 222 return li; 223 } 224 }