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