1 /* 2 * Copyright (c) 2013, 2018, 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.Map; 29 import java.util.Set; 30 31 import javax.lang.model.element.ModuleElement; 32 import javax.lang.model.element.PackageElement; 33 34 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlAttr; 35 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlConstants; 36 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle; 37 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag; 38 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; 39 import jdk.javadoc.internal.doclets.formats.html.markup.RawHtml; 40 import jdk.javadoc.internal.doclets.formats.html.markup.StringContent; 41 import jdk.javadoc.internal.doclets.toolkit.Content; 42 import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; 43 import jdk.javadoc.internal.doclets.toolkit.util.DocLink; 44 import jdk.javadoc.internal.doclets.toolkit.util.DocPath; 45 import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; 46 47 /** 48 * Generate the module index for the left-hand frame in the generated output. 49 * A click on the module name in this frame will update the page in the top 50 * left hand frame with the listing of packages of the clicked module. 51 * 52 * <p><b>This is NOT part of any supported API. 53 * If you write code that depends on this, you do so at your own risk. 54 * This code and its internal interfaces are subject to change or 55 * deletion without notice.</b> 56 * 57 * @author Bhavesh Patel 58 */ 59 public class ModuleIndexFrameWriter extends AbstractModuleIndexWriter { 60 61 /** 62 * Construct the ModuleIndexFrameWriter object. 63 * 64 * @param configuration the configuration object 65 * @param filename Name of the module index file to be generated. 66 */ ModuleIndexFrameWriter(HtmlConfiguration configuration, DocPath filename)67 public ModuleIndexFrameWriter(HtmlConfiguration configuration, 68 DocPath filename) { 69 super(configuration, filename); 70 } 71 72 /** 73 * Generate the module index file named "module-overview-frame.html". 74 * @throws DocFileIOException 75 * @param configuration the configuration object 76 */ generate(HtmlConfiguration configuration)77 public static void generate(HtmlConfiguration configuration) throws DocFileIOException { 78 DocPath filename = DocPaths.MODULE_OVERVIEW_FRAME; 79 ModuleIndexFrameWriter modulegen = new ModuleIndexFrameWriter(configuration, filename); 80 modulegen.buildModuleIndexFile("doclet.Window_Overview", false); 81 } 82 83 /** 84 * {@inheritDoc} 85 */ addModulesList(Content body)86 protected void addModulesList(Content body) { 87 Content heading = HtmlTree.HEADING(HtmlConstants.MODULE_HEADING, true, 88 contents.modulesLabel); 89 HtmlTree htmlTree = (configuration.allowTag(HtmlTag.MAIN)) 90 ? HtmlTree.MAIN(HtmlStyle.indexContainer, heading) 91 : HtmlTree.DIV(HtmlStyle.indexContainer, heading); 92 HtmlTree ul = new HtmlTree(HtmlTag.UL); 93 ul.setTitle(contents.modulesLabel); 94 for (ModuleElement mdle: configuration.modules) { 95 ul.addContent(getModuleLink(mdle)); 96 } 97 htmlTree.addContent(ul); 98 body.addContent(htmlTree); 99 } 100 101 /** 102 * Returns each module name as a separate link. 103 * 104 * @param mdle the module being documented 105 * @return content for the module link 106 */ getModuleLink(ModuleElement mdle)107 protected Content getModuleLink(ModuleElement mdle) { 108 Content moduleLinkContent; 109 Content mdlLabel = new StringContent(mdle.getQualifiedName()); 110 moduleLinkContent = getModuleFramesHyperLink(mdle, mdlLabel, "packageListFrame"); 111 Content li = HtmlTree.LI(moduleLinkContent); 112 return li; 113 } 114 getModuleFramesHyperLink(ModuleElement mdle, Content label, String target)115 private Content getModuleFramesHyperLink(ModuleElement mdle, Content label, String target) { 116 DocLink mdlLink = new DocLink(docPaths.moduleFrame(mdle)); 117 DocLink mtFrameLink = new DocLink(docPaths.moduleTypeFrame(mdle)); 118 DocLink cFrameLink = new DocLink(docPaths.moduleSummary(mdle)); 119 HtmlTree anchor = HtmlTree.A(mdlLink.toString(), label); 120 String onclickStr = "updateModuleFrame('" + mtFrameLink + "','" + cFrameLink + "');"; 121 anchor.addAttr(HtmlAttr.TARGET, target); 122 anchor.addAttr(HtmlAttr.ONCLICK, onclickStr); 123 return anchor; 124 } 125 126 /** 127 * {@inheritDoc} 128 */ addNavigationBarHeader(Content body)129 protected void addNavigationBarHeader(Content body) { 130 Content headerContent; 131 if (configuration.packagesheader.length() > 0) { 132 headerContent = new RawHtml(replaceDocRootDir(configuration.packagesheader)); 133 } else { 134 headerContent = new RawHtml(replaceDocRootDir(configuration.header)); 135 } 136 Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true, 137 HtmlStyle.bar, headerContent); 138 body.addContent(heading); 139 } 140 141 /** 142 * Do nothing as there is no overview information in this page. 143 */ addOverviewHeader(Content body)144 protected void addOverviewHeader(Content body) { 145 } 146 147 /** 148 * Adds "All Classes" link for the top of the left-hand frame page to the 149 * documentation tree. 150 * 151 * @param ul the Content object to which the all classes link should be added 152 */ addAllClassesLink(Content ul)153 protected void addAllClassesLink(Content ul) { 154 Content linkContent = links.createLink(DocPaths.ALLCLASSES_FRAME, 155 contents.allClassesLabel, "", "packageFrame"); 156 Content li = HtmlTree.LI(linkContent); 157 ul.addContent(li); 158 } 159 160 /** 161 * Adds "All Packages" link for the top of the left-hand frame page to the 162 * documentation tree. 163 * 164 * @param ul the Content object to which the all packages link should be added 165 */ addAllPackagesLink(Content ul)166 protected void addAllPackagesLink(Content ul) { 167 Content linkContent = links.createLink(DocPaths.OVERVIEW_FRAME, 168 contents.allPackagesLabel, "", "packageListFrame"); 169 Content li = HtmlTree.LI(linkContent); 170 ul.addContent(li); 171 } 172 173 /** 174 * {@inheritDoc} 175 */ addNavigationBarFooter(Content body)176 protected void addNavigationBarFooter(Content body) { 177 Content p = HtmlTree.P(Contents.SPACE); 178 body.addContent(p); 179 } 180 addModulePackagesList(Map<ModuleElement, Set<PackageElement>> modules, String text, String tableSummary, Content body, ModuleElement mdle)181 protected void addModulePackagesList(Map<ModuleElement, Set<PackageElement>> modules, String text, 182 String tableSummary, Content body, ModuleElement mdle) { 183 } 184 } 185