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.IOException; 29 import java.util.SortedSet; 30 31 import com.sun.javadoc.*; 32 import com.sun.tools.doclets.formats.html.markup.*; 33 import com.sun.tools.doclets.internal.toolkit.*; 34 import com.sun.tools.doclets.internal.toolkit.util.*; 35 36 /** 37 * Generate Class Hierarchy page for all the Classes in this run. Use 38 * ClassTree for building the Tree. The name of 39 * the generated file is "overview-tree.html" and it is generated in the 40 * current or the destination directory. 41 * 42 * <p><b>This is NOT part of any supported API. 43 * If you write code that depends on this, you do so at your own risk. 44 * This code and its internal interfaces are subject to change or 45 * deletion without notice.</b> 46 * 47 * @author Atul M Dambalkar 48 * @author Bhavesh Patel (Modified) 49 */ 50 public class TreeWriter extends AbstractTreeWriter { 51 52 /** 53 * Packages in this run. 54 */ 55 SortedSet<PackageDoc> packages; 56 57 /** 58 * True if there are no packages specified on the command line, 59 * False otherwise. 60 */ 61 private boolean classesonly; 62 63 /** 64 * Constructor to construct TreeWriter object. 65 * 66 * @param configuration the current configuration of the doclet. 67 * @param filename String filename 68 * @param classtree the tree being built. 69 */ 70 public TreeWriter(ConfigurationImpl configuration, 71 DocPath filename, ClassTree classtree) throws IOException { 72 super(configuration, filename, classtree); 73 packages = configuration.packages; 74 classesonly = packages.isEmpty(); 75 } 96 throw new DocletAbortException(exc); 97 } 98 } 99 100 /** 101 * Generate the interface hierarchy and class hierarchy. 102 */ 103 public void generateTreeFile() throws IOException { 104 HtmlTree body = getTreeHeader(); 105 Content headContent = getResource("doclet.Hierarchy_For_All_Packages"); 106 Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, false, 107 HtmlStyle.title, headContent); 108 Content div = HtmlTree.DIV(HtmlStyle.header, heading); 109 addPackageTreeLinks(div); 110 HtmlTree htmlTree = (configuration.allowTag(HtmlTag.MAIN)) 111 ? HtmlTree.MAIN() 112 : body; 113 htmlTree.addContent(div); 114 HtmlTree divTree = new HtmlTree(HtmlTag.DIV); 115 divTree.addStyle(HtmlStyle.contentContainer); 116 addTree(classtree.baseclasses(), "doclet.Class_Hierarchy", divTree); 117 addTree(classtree.baseinterfaces(), "doclet.Interface_Hierarchy", divTree); 118 addTree(classtree.baseAnnotationTypes(), "doclet.Annotation_Type_Hierarchy", divTree); 119 addTree(classtree.baseEnums(), "doclet.Enum_Hierarchy", divTree); 120 htmlTree.addContent(divTree); 121 if (configuration.allowTag(HtmlTag.MAIN)) { 122 body.addContent(htmlTree); 123 } 124 if (configuration.allowTag(HtmlTag.FOOTER)) { 125 htmlTree = HtmlTree.FOOTER(); 126 } else { 127 htmlTree = body; 128 } 129 addNavLinks(false, htmlTree); 130 addBottom(htmlTree); 131 if (configuration.allowTag(HtmlTag.FOOTER)) { 132 body.addContent(htmlTree); 133 } 134 printHtmlDocument(null, true, body); 135 } 136 137 /** 138 * Add the links to all the package tree files. 139 * 140 * @param contentTree the content tree to which the links will be added 141 */ 142 protected void addPackageTreeLinks(Content contentTree) { 143 //Do nothing if only unnamed package is used 144 if (isUnnamedPackage()) { 145 return; 146 } 147 if (!classesonly) { 148 Content span = HtmlTree.SPAN(HtmlStyle.packageHierarchyLabel, 149 getResource("doclet.Package_Hierarchies")); 150 contentTree.addContent(span); 151 HtmlTree ul = new HtmlTree(HtmlTag.UL); 152 ul.addStyle(HtmlStyle.horizontal); 153 int i = 0; 154 for (PackageDoc pkg : packages) { 155 // If the package name length is 0 or if -nodeprecated option 156 // is set and the package is marked as deprecated, do not include 157 // the page in the list of package hierarchies. 158 if (pkg.name().isEmpty() || 159 (configuration.nodeprecated && utils.isDeprecated(pkg))) { 160 i++; 161 continue; 162 } 163 DocPath link = pathString(pkg, DocPaths.PACKAGE_TREE); 164 Content li = HtmlTree.LI(getHyperLink( 165 link, new StringContent(pkg.name()))); 166 if (i < packages.size() - 1) { 167 li.addContent(", "); 168 } 169 ul.addContent(li); 170 i++; 171 } 172 contentTree.addContent(ul); 173 } 174 } 175 176 /** 177 * Get the tree header. 178 * 179 * @return a content tree for the tree header 180 */ 181 protected HtmlTree getTreeHeader() { 182 String title = configuration.getText("doclet.Window_Class_Hierarchy"); 183 HtmlTree bodyTree = getBody(true, getWindowTitle(title)); 184 HtmlTree htmlTree = (configuration.allowTag(HtmlTag.HEADER)) 185 ? HtmlTree.HEADER() 186 : bodyTree; 187 addTop(htmlTree); 188 addNavLinks(true, htmlTree); 189 if (configuration.allowTag(HtmlTag.HEADER)) { 190 bodyTree.addContent(htmlTree); 191 } 192 return bodyTree; 193 } 194 195 private boolean isUnnamedPackage() { 196 return packages.size() == 1 && packages.first().name().isEmpty(); 197 } 198 } | 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 jdk.javadoc.internal.doclets.formats.html; 27 28 import java.io.IOException; 29 import java.util.SortedSet; 30 31 import javax.lang.model.element.PackageElement; 32 33 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlConstants; 34 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle; 35 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag; 36 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; 37 import jdk.javadoc.internal.doclets.formats.html.markup.StringContent; 38 import jdk.javadoc.internal.doclets.toolkit.Content; 39 import jdk.javadoc.internal.doclets.toolkit.util.ClassTree; 40 import jdk.javadoc.internal.doclets.toolkit.util.DocPath; 41 import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; 42 import jdk.javadoc.internal.doclets.toolkit.util.DocletAbortException; 43 44 /** 45 * Generate Class Hierarchy page for all the Classes in this run. Use 46 * ClassTree for building the Tree. The name of 47 * the generated file is "overview-tree.html" and it is generated in the 48 * current or the destination directory. 49 * 50 * <p><b>This is NOT part of any supported API. 51 * If you write code that depends on this, you do so at your own risk. 52 * This code and its internal interfaces are subject to change or 53 * deletion without notice.</b> 54 * 55 * @author Atul M Dambalkar 56 * @author Bhavesh Patel (Modified) 57 */ 58 public class TreeWriter extends AbstractTreeWriter { 59 60 /** 61 * Packages in this run. 62 */ 63 SortedSet<PackageElement> packages; 64 65 /** 66 * True if there are no packages specified on the command line, 67 * False otherwise. 68 */ 69 private boolean classesonly; 70 71 /** 72 * Constructor to construct TreeWriter object. 73 * 74 * @param configuration the current configuration of the doclet. 75 * @param filename String filename 76 * @param classtree the tree being built. 77 */ 78 public TreeWriter(ConfigurationImpl configuration, 79 DocPath filename, ClassTree classtree) throws IOException { 80 super(configuration, filename, classtree); 81 packages = configuration.packages; 82 classesonly = packages.isEmpty(); 83 } 104 throw new DocletAbortException(exc); 105 } 106 } 107 108 /** 109 * Generate the interface hierarchy and class hierarchy. 110 */ 111 public void generateTreeFile() throws IOException { 112 HtmlTree body = getTreeHeader(); 113 Content headContent = getResource("doclet.Hierarchy_For_All_Packages"); 114 Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, false, 115 HtmlStyle.title, headContent); 116 Content div = HtmlTree.DIV(HtmlStyle.header, heading); 117 addPackageTreeLinks(div); 118 HtmlTree htmlTree = (configuration.allowTag(HtmlTag.MAIN)) 119 ? HtmlTree.MAIN() 120 : body; 121 htmlTree.addContent(div); 122 HtmlTree divTree = new HtmlTree(HtmlTag.DIV); 123 divTree.addStyle(HtmlStyle.contentContainer); 124 addTree(classtree.baseClasses(), "doclet.Class_Hierarchy", divTree); 125 addTree(classtree.baseInterfaces(), "doclet.Interface_Hierarchy", divTree); 126 addTree(classtree.baseAnnotationTypes(), "doclet.Annotation_Type_Hierarchy", divTree); 127 addTree(classtree.baseEnums(), "doclet.Enum_Hierarchy", divTree, true); 128 htmlTree.addContent(divTree); 129 if (configuration.allowTag(HtmlTag.MAIN)) { 130 body.addContent(htmlTree); 131 } 132 if (configuration.allowTag(HtmlTag.FOOTER)) { 133 htmlTree = HtmlTree.FOOTER(); 134 } else { 135 htmlTree = body; 136 } 137 addNavLinks(false, htmlTree); 138 addBottom(htmlTree); 139 if (configuration.allowTag(HtmlTag.FOOTER)) { 140 body.addContent(htmlTree); 141 } 142 printHtmlDocument(null, true, body); 143 } 144 145 /** 146 * Add the links to all the package tree files. 147 * 148 * @param contentTree the content tree to which the links will be added 149 */ 150 protected void addPackageTreeLinks(Content contentTree) { 151 //Do nothing if only unnamed package is used 152 if (isUnnamedPackage()) { 153 return; 154 } 155 if (!classesonly) { 156 Content span = HtmlTree.SPAN(HtmlStyle.packageHierarchyLabel, 157 getResource("doclet.Package_Hierarchies")); 158 contentTree.addContent(span); 159 HtmlTree ul = new HtmlTree(HtmlTag.UL); 160 ul.addStyle(HtmlStyle.horizontal); 161 int i = 0; 162 for (PackageElement pkg : packages) { 163 // If the package name length is 0 or if -nodeprecated option 164 // is set and the package is marked as deprecated, do not include 165 // the page in the list of package hierarchies. 166 if (pkg.isUnnamed() || 167 (configuration.nodeprecated && utils.isDeprecated(pkg))) { 168 i++; 169 continue; 170 } 171 DocPath link = pathString(pkg, DocPaths.PACKAGE_TREE); 172 Content li = HtmlTree.LI(getHyperLink(link, 173 new StringContent(utils.getPackageName(pkg)))); 174 if (i < packages.size() - 1) { 175 li.addContent(", "); 176 } 177 ul.addContent(li); 178 i++; 179 } 180 contentTree.addContent(ul); 181 } 182 } 183 184 /** 185 * Get the tree header. 186 * 187 * @return a content tree for the tree header 188 */ 189 protected HtmlTree getTreeHeader() { 190 String title = configuration.getText("doclet.Window_Class_Hierarchy"); 191 HtmlTree bodyTree = getBody(true, getWindowTitle(title)); 192 HtmlTree htmlTree = (configuration.allowTag(HtmlTag.HEADER)) 193 ? HtmlTree.HEADER() 194 : bodyTree; 195 addTop(htmlTree); 196 addNavLinks(true, htmlTree); 197 if (configuration.allowTag(HtmlTag.HEADER)) { 198 bodyTree.addContent(htmlTree); 199 } 200 return bodyTree; 201 } 202 203 private boolean isUnnamedPackage() { 204 return packages.size() == 1 && packages.first().isUnnamed(); 205 } 206 } |