ModulePackageIndexFrameWriter.java revision 3294:9adfb22ff08f
1/* 2 * Copyright (c) 2013, 2016, 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.IOException; 29import java.util.ArrayList; 30import java.util.List; 31import java.util.Map; 32import java.util.Set; 33 34import javax.lang.model.element.ModuleElement; 35import javax.lang.model.element.PackageElement; 36 37import jdk.javadoc.internal.doclets.formats.html.markup.HtmlConstants; 38import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle; 39import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag; 40import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; 41import jdk.javadoc.internal.doclets.formats.html.markup.RawHtml; 42import jdk.javadoc.internal.doclets.formats.html.markup.StringContent; 43import jdk.javadoc.internal.doclets.toolkit.Content; 44import jdk.javadoc.internal.doclets.toolkit.util.DocPath; 45import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; 46import jdk.javadoc.internal.doclets.toolkit.util.DocletAbortException; 47 48/** 49 * Generate the module package index for the left-hand frame in the generated output. 50 * A click on the package name in this frame will update the page in the bottom 51 * left hand frame with the listing of contents of the clicked module package. 52 * 53 * <p><b>This is NOT part of any supported API. 54 * If you write code that depends on this, you do so at your own risk. 55 * This code and its internal interfaces are subject to change or 56 * deletion without notice.</b> 57 * 58 * @author Bhavesh Patel 59 */ 60public class ModulePackageIndexFrameWriter extends AbstractModuleIndexWriter { 61 62 /** 63 * Construct the ModulePackageIndexFrameWriter object. 64 * 65 * @param configuration the configuration object 66 * @param filename Name of the package index file to be generated. 67 */ 68 public ModulePackageIndexFrameWriter(ConfigurationImpl configuration, 69 DocPath filename) throws IOException { 70 super(configuration, filename); 71 } 72 73 /** 74 * Generate the module package index file. 75 * @throws DocletAbortException 76 * @param configuration the configuration object 77 * @param mdle the module being documented 78 */ 79 public static void generate(ConfigurationImpl configuration, ModuleElement mdle) { 80 ModulePackageIndexFrameWriter modpackgen; 81 DocPath filename = DocPaths.moduleFrame(mdle); 82 try { 83 modpackgen = new ModulePackageIndexFrameWriter(configuration, filename); 84 modpackgen.buildModulePackagesIndexFile("doclet.Window_Overview", false, mdle); 85 modpackgen.close(); 86 } catch (IOException exc) { 87 configuration.standardmessage.error( 88 "doclet.exception_encountered", 89 exc.toString(), filename); 90 throw new DocletAbortException(exc); 91 } 92 } 93 94 /** 95 * {@inheritDoc} 96 */ 97 protected void addModulePackagesList(Map<ModuleElement, Set<PackageElement>> modules, String text, 98 String tableSummary, Content body, ModuleElement mdle) { 99 Content profNameContent = new StringContent(mdle.getQualifiedName().toString()); 100 Content heading = HtmlTree.HEADING(HtmlConstants.PACKAGE_HEADING, true, 101 getTargetModuleLink("classFrame", profNameContent, mdle)); 102 heading.addContent(getSpace()); 103 heading.addContent(packagesLabel); 104 HtmlTree htmlTree = (configuration.allowTag(HtmlTag.MAIN)) 105 ? HtmlTree.MAIN(HtmlStyle.indexContainer, heading) 106 : HtmlTree.DIV(HtmlStyle.indexContainer, heading); 107 HtmlTree ul = new HtmlTree(HtmlTag.UL); 108 ul.setTitle(packagesLabel); 109 List<PackageElement> packages = new ArrayList<>(modules.get(mdle)); 110 for (PackageElement pkg : packages) { 111 if ((!(configuration.nodeprecated && utils.isDeprecated(pkg)))) { 112 ul.addContent(getPackage(pkg, mdle)); 113 } 114 } 115 htmlTree.addContent(ul); 116 body.addContent(htmlTree); 117 } 118 119 /** 120 * {@inheritDoc} 121 */ 122 protected void addModulePackagesList(Set<ModuleElement> modules, String text, 123 String tableSummary, Content body, ModuleElement mdle) { 124 Content moduleNameContent = new StringContent(mdle.getQualifiedName().toString()); 125 Content heading = HtmlTree.HEADING(HtmlConstants.PACKAGE_HEADING, true, 126 getTargetModuleLink("classFrame", moduleNameContent, mdle)); 127 heading.addContent(getSpace()); 128 heading.addContent(packagesLabel); 129 HtmlTree htmlTree = (configuration.allowTag(HtmlTag.MAIN)) 130 ? HtmlTree.MAIN(HtmlStyle.indexContainer, heading) 131 : HtmlTree.DIV(HtmlStyle.indexContainer, heading); 132 HtmlTree ul = new HtmlTree(HtmlTag.UL); 133 ul.setTitle(packagesLabel); 134 Set<PackageElement> modulePackages = configuration.modulePackages.get(mdle); 135 for (PackageElement pkg: modulePackages) { 136 if ((!(configuration.nodeprecated && utils.isDeprecated(pkg)))) { 137 ul.addContent(getPackage(pkg, mdle)); 138 } 139 } 140 htmlTree.addContent(ul); 141 body.addContent(htmlTree); 142 } 143 144 /** 145 * Returns each package name as a separate link. 146 * 147 * @param pkg PackageElement 148 * @param mdle the module being documented 149 * @return content for the package link 150 */ 151 protected Content getPackage(PackageElement pkg, ModuleElement mdle) { 152 Content packageLinkContent; 153 Content pkgLabel; 154 if (!pkg.isUnnamed()) { 155 pkgLabel = getPackageLabel(utils.getPackageName(pkg)); 156 packageLinkContent = getHyperLink(pathString(pkg, 157 DocPaths.PACKAGE_FRAME), pkgLabel, "", 158 "packageFrame"); 159 } else { 160 pkgLabel = new StringContent("<unnamed package>"); 161 packageLinkContent = getHyperLink(DocPaths.PACKAGE_FRAME, 162 pkgLabel, "", "packageFrame"); 163 } 164 Content li = HtmlTree.LI(packageLinkContent); 165 return li; 166 } 167 168 /** 169 * {@inheritDoc} 170 */ 171 protected void addNavigationBarHeader(Content body) { 172 Content headerContent; 173 if (configuration.packagesheader.length() > 0) { 174 headerContent = new RawHtml(replaceDocRootDir(configuration.packagesheader)); 175 } else { 176 headerContent = new RawHtml(replaceDocRootDir(configuration.header)); 177 } 178 Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true, 179 HtmlStyle.bar, headerContent); 180 body.addContent(heading); 181 } 182 183 /** 184 * Do nothing as there is no overview information in this page. 185 */ 186 protected void addOverviewHeader(Content body) { 187 } 188 189 protected void addModulesList(Map<ModuleElement, Set<PackageElement>> modules, String text, 190 String tableSummary, Content body) { 191 } 192 193 /** 194 * Adds "All Classes" link for the top of the left-hand frame page to the 195 * documentation tree. 196 * 197 * @param ul the Content object to which the all classes link should be added 198 */ 199 protected void addAllClassesLink(Content ul) { 200 Content linkContent = getHyperLink(DocPaths.ALLCLASSES_FRAME, 201 allclassesLabel, "", "packageFrame"); 202 Content li = HtmlTree.LI(linkContent); 203 ul.addContent(li); 204 } 205 206 /** 207 * Adds "All Packages" link for the top of the left-hand frame page to the 208 * documentation tree. 209 * 210 * @param ul the Content object to which the all packages link should be added 211 */ 212 protected void addAllPackagesLink(Content ul) { 213 Content linkContent = getHyperLink(DocPaths.OVERVIEW_FRAME, 214 allpackagesLabel, "", "packageListFrame"); 215 Content li = HtmlTree.LI(linkContent); 216 ul.addContent(li); 217 } 218 219 /** 220 * Adds "All Modules" link for the top of the left-hand frame page to the 221 * documentation tree. 222 * 223 * @param ul the Content object to which the all modules link should be added 224 */ 225 protected void addAllModulesLink(Content ul) { 226 Content linkContent = getHyperLink(DocPaths.MODULE_OVERVIEW_FRAME, 227 allmodulesLabel, "", "packageListFrame"); 228 Content li = HtmlTree.LI(linkContent); 229 ul.addContent(li); 230 } 231 232 /** 233 * {@inheritDoc} 234 */ 235 protected void addNavigationBarFooter(Content body) { 236 Content p = HtmlTree.P(getSpace()); 237 body.addContent(p); 238 } 239} 240