AbstractPackageIndexWriter.java revision 3294:9adfb22ff08f
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 26package jdk.javadoc.internal.doclets.formats.html; 27 28import java.io.*; 29import java.util.*; 30 31import javax.lang.model.element.PackageElement; 32 33import jdk.javadoc.internal.doclets.formats.html.markup.HtmlConstants; 34import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle; 35import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag; 36import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; 37import jdk.javadoc.internal.doclets.formats.html.markup.RawHtml; 38import jdk.javadoc.internal.doclets.toolkit.Content; 39import jdk.javadoc.internal.doclets.toolkit.util.DocPath; 40 41/** 42 * Abstract class to generate the overview files in 43 * Frame and Non-Frame format. This will be sub-classed by to 44 * generate overview-frame.html as well as overview-summary.html. 45 * 46 * <p><b>This is NOT part of any supported API. 47 * If you write code that depends on this, you do so at your own risk. 48 * This code and its internal interfaces are subject to change or 49 * deletion without notice.</b> 50 * 51 * @author Atul M Dambalkar 52 * @author Bhavesh Patel (Modified) 53 */ 54public abstract class AbstractPackageIndexWriter extends HtmlDocletWriter { 55 56 /** 57 * A Set of Packages to be documented. 58 */ 59 protected SortedSet<PackageElement> packages; 60 61 /** 62 * Constructor. Also initializes the packages variable. 63 * 64 * @param configuration The current configuration 65 * @param filename Name of the package index file to be generated. 66 */ 67 public AbstractPackageIndexWriter(ConfigurationImpl configuration, 68 DocPath filename) throws IOException { 69 super(configuration, filename); 70 packages = configuration.packages; 71 } 72 73 /** 74 * Adds the navigation bar header to the documentation tree. 75 * 76 * @param body the document tree to which the navigation bar header will be added 77 */ 78 protected abstract void addNavigationBarHeader(Content body); 79 80 /** 81 * Adds the navigation bar footer to the documentation tree. 82 * 83 * @param body the document tree to which the navigation bar footer will be added 84 */ 85 protected abstract void addNavigationBarFooter(Content body); 86 87 /** 88 * Adds the overview header to the documentation tree. 89 * 90 * @param body the document tree to which the overview header will be added 91 */ 92 protected abstract void addOverviewHeader(Content body); 93 94 /** 95 * Adds the packages list to the documentation tree. 96 * 97 * @param packages a collection of packagedoc objects 98 * @param text caption for the table 99 * @param tableSummary summary for the table 100 * @param body the document tree to which the packages list will be added 101 */ 102 protected abstract void addPackagesList(Collection<PackageElement> packages, String text, 103 String tableSummary, Content body); 104 105 /** 106 * Generate and prints the contents in the package index file. Call appropriate 107 * methods from the sub-class in order to generate Frame or Non 108 * Frame format. 109 * 110 * @param title the title of the window. 111 * @param includeScript boolean set true if windowtitle script is to be included 112 */ 113 protected void buildPackageIndexFile(String title, boolean includeScript) throws IOException { 114 String windowOverview = configuration.getText(title); 115 Content body = getBody(includeScript, getWindowTitle(windowOverview)); 116 addNavigationBarHeader(body); 117 addOverviewHeader(body); 118 addIndex(body); 119 addOverview(body); 120 addNavigationBarFooter(body); 121 printHtmlDocument(configuration.metakeywords.getOverviewMetaKeywords(title, 122 configuration.doctitle), includeScript, body); 123 } 124 125 /** 126 * Default to no overview, override to add overview. 127 * 128 * @param body the document tree to which the overview will be added 129 */ 130 protected void addOverview(Content body) throws IOException { 131 } 132 133 /** 134 * Adds the frame or non-frame package index to the documentation tree. 135 * 136 * @param body the document tree to which the index will be added 137 */ 138 protected void addIndex(Content body) { 139 addIndexContents(packages, "doclet.Package_Summary", 140 configuration.getText("doclet.Member_Table_Summary", 141 configuration.getText("doclet.Package_Summary"), 142 configuration.getText("doclet.packages")), body); 143 } 144 145 /** 146 * Adds package index contents. Call appropriate methods from 147 * the sub-classes. Adds it to the body HtmlTree 148 * 149 * @param packages a collection of packages to be documented 150 * @param text string which will be used as the heading 151 * @param tableSummary summary for the table 152 * @param body the document tree to which the index contents will be added 153 */ 154 protected void addIndexContents(Collection<PackageElement> packages, String text, 155 String tableSummary, Content body) { 156 if (!packages.isEmpty()) { 157 HtmlTree htmlTree = (configuration.allowTag(HtmlTag.NAV)) 158 ? HtmlTree.NAV() 159 : new HtmlTree(HtmlTag.DIV); 160 htmlTree.addStyle(HtmlStyle.indexNav); 161 HtmlTree ul = new HtmlTree(HtmlTag.UL); 162 addAllClassesLink(ul); 163 if (configuration.showModules) { 164 addAllModulesLink(ul); 165 } 166 htmlTree.addContent(ul); 167 body.addContent(htmlTree); 168 addPackagesList(packages, text, tableSummary, body); 169 } 170 } 171 172 /** 173 * Adds the doctitle to the documentation tree, if it is specified on the command line. 174 * 175 * @param body the document tree to which the title will be added 176 */ 177 protected void addConfigurationTitle(Content body) { 178 if (configuration.doctitle.length() > 0) { 179 Content title = new RawHtml(configuration.doctitle); 180 Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, 181 HtmlStyle.title, title); 182 Content div = HtmlTree.DIV(HtmlStyle.header, heading); 183 body.addContent(div); 184 } 185 } 186 187 /** 188 * Returns highlighted "Overview", in the navigation bar as this is the 189 * overview page. 190 * 191 * @return a Content object to be added to the documentation tree 192 */ 193 protected Content getNavLinkContents() { 194 Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, overviewLabel); 195 return li; 196 } 197 198 /** 199 * Do nothing. This will be overridden. 200 * 201 * @param div the document tree to which the all classes link will be added 202 */ 203 protected void addAllClassesLink(Content div) { 204 } 205 206 /** 207 * Do nothing. This will be overridden. 208 * 209 * @param div the document tree to which the all modules link will be added 210 */ 211 protected void addAllModulesLink(Content div) { 212 } 213} 214