1 /* 2 * Copyright (c) 2016, 2019, 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 jdk.javadoc.internal.doclets.formats.html.markup.Table; 29 import jdk.javadoc.internal.doclets.formats.html.markup.TableHeader; 30 31 import java.util.*; 32 33 import javax.lang.model.element.ModuleElement; 34 35 import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder; 36 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle; 37 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; 38 import jdk.javadoc.internal.doclets.formats.html.markup.StringContent; 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 import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; 43 44 /** 45 * Generate the module index page "index.html". 46 * 47 * <p><b>This is NOT part of any supported API. 48 * If you write code that depends on this, you do so at your own risk. 49 * This code and its internal interfaces are subject to change or 50 * deletion without notice.</b> 51 */ 52 public class ModuleIndexWriter extends AbstractOverviewIndexWriter { 53 54 /** 55 * Modules to be documented. 56 */ 57 protected SortedSet<ModuleElement> modules; 58 59 /** 60 * Construct the ModuleIndexWriter. 61 * 62 * @param configuration the configuration object 63 * @param filename the name of the generated file 64 */ 65 public ModuleIndexWriter(HtmlConfiguration configuration, DocPath filename) { 66 super(configuration, filename); 67 modules = configuration.modules; 68 } 69 70 /** 71 * Generate the module index page. 72 * 73 * @param configuration the current configuration of the doclet. 74 * @throws DocFileIOException if there is a problem generating the module index page 75 */ 76 public static void generate(HtmlConfiguration configuration) throws DocFileIOException { 77 DocPath filename = DocPaths.INDEX; 78 ModuleIndexWriter mdlgen = new ModuleIndexWriter(configuration, filename); 79 mdlgen.buildOverviewIndexFile("doclet.Window_Overview_Summary", "module index"); 80 } 81 82 /** 83 * Adds the list of modules. 84 * 85 * @param main the documentation tree to which the modules list will be added 86 */ 87 @Override 88 protected void addIndex(Content main) { 89 Map<String, SortedSet<ModuleElement>> groupModuleMap 90 = configuration.group.groupModules(modules); 91 92 if (!groupModuleMap.keySet().isEmpty()) { 93 TableHeader tableHeader = new TableHeader(contents.moduleLabel, contents.descriptionLabel); 94 Table table = new Table(HtmlStyle.overviewSummary) 95 .setHeader(tableHeader) 96 .setColumnStyles(HtmlStyle.colFirst, HtmlStyle.colLast) 97 .setDefaultTab(resources.getText("doclet.All_Modules")) 98 .setTabScript(i -> "show(" + i + ");") 99 .setTabId(i -> (i == 0) ? "t0" : ("t" + (1 << (i - 1)))); 100 101 // add the tabs in command-line order 102 for (String groupName : configuration.group.getGroupList()) { 103 Set<ModuleElement> groupModules = groupModuleMap.get(groupName); 104 if (groupModules != null) { 105 table.addTab(groupName, groupModules::contains); 106 } 107 } 108 109 for (ModuleElement mdle : modules) { 110 if (!mdle.isUnnamed()) { 111 if (!(options.noDeprecated && utils.isDeprecated(mdle))) { 112 Content moduleLinkContent = getModuleLink(mdle, new StringContent(mdle.getQualifiedName().toString())); 113 Content summaryContent = new ContentBuilder(); 114 addSummaryComment(mdle, summaryContent); 115 table.addRow(mdle, moduleLinkContent, summaryContent); 116 } 117 } 118 } 119 120 Content div = HtmlTree.DIV(HtmlStyle.contentContainer, table.toContent()); 121 main.add(div); 122 123 if (table.needsScript()) { 124 mainBodyScript.append(table.getScript()); 125 } 126 } 127 } 128 }