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