001/* 002 * Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. Oracle designates this 008 * particular file as subject to the "Classpath" exception as provided 009 * by Oracle in the LICENSE file that accompanied this code. 010 * 011 * This code is distributed in the hope that it will be useful, but WITHOUT 012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 014 * version 2 for more details (a copy is included in the LICENSE file that 015 * accompanied this code). 016 * 017 * You should have received a copy of the GNU General Public License version 018 * 2 along with this work; if not, write to the Free Software Foundation, 019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 020 * 021 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 022 * or visit www.oracle.com if you need additional information or have any 023 * questions. 024 */ 025 026package org.jdrupes.mdoclet.internal.doclets.formats.html; 027 028import java.util.Map; 029import java.util.Set; 030import java.util.SortedSet; 031 032import javax.lang.model.element.ModuleElement; 033 034import org.jdrupes.mdoclet.internal.doclets.formats.html.markup.ContentBuilder; 035import org.jdrupes.mdoclet.internal.doclets.formats.html.markup.HtmlStyle; 036import org.jdrupes.mdoclet.internal.doclets.formats.html.markup.Text; 037import org.jdrupes.mdoclet.internal.doclets.toolkit.Content; 038import org.jdrupes.mdoclet.internal.doclets.toolkit.util.DocFileIOException; 039import org.jdrupes.mdoclet.internal.doclets.toolkit.util.DocPath; 040import org.jdrupes.mdoclet.internal.doclets.toolkit.util.DocPaths; 041 042/** 043 * Generate the module index page "index.html". 044 */ 045public class ModuleIndexWriter extends AbstractOverviewIndexWriter { 046 047 /** 048 * Modules to be documented. 049 */ 050 protected SortedSet<ModuleElement> modules; 051 052 /** 053 * Construct the ModuleIndexWriter. 054 * 055 * @param configuration the configuration object 056 * @param filename the name of the generated file 057 */ 058 public ModuleIndexWriter(HtmlConfiguration configuration, 059 DocPath filename) { 060 super(configuration, filename); 061 modules = configuration.modules; 062 } 063 064 /** 065 * Generate the module index page. 066 * 067 * @param configuration the current configuration of the doclet. 068 * @throws DocFileIOException if there is a problem generating the module index page 069 */ 070 public static void generate(HtmlConfiguration configuration) 071 throws DocFileIOException { 072 DocPath filename = DocPaths.INDEX; 073 ModuleIndexWriter mdlgen 074 = new ModuleIndexWriter(configuration, filename); 075 mdlgen.buildOverviewIndexFile("doclet.Window_Overview_Summary", 076 "module index"); 077 } 078 079 /** 080 * Adds the list of modules. 081 * 082 * @param target the content to which the modules list will be added 083 */ 084 @Override 085 protected void addIndex(Content target) { 086 Map<String, SortedSet<ModuleElement>> groupModuleMap 087 = configuration.group.groupModules(modules); 088 089 if (!groupModuleMap.keySet().isEmpty()) { 090 TableHeader tableHeader = new TableHeader(contents.moduleLabel, 091 contents.descriptionLabel); 092 var table = new Table<ModuleElement>(HtmlStyle.summaryTable) 093 .setHeader(tableHeader) 094 .setColumnStyles(HtmlStyle.colFirst, HtmlStyle.colLast) 095 .setId(HtmlIds.ALL_MODULES_TABLE) 096 .setDefaultTab(contents.getContent("doclet.All_Modules")); 097 098 // add the tabs in command-line order 099 for (String groupName : configuration.group.getGroupList()) { 100 Set<ModuleElement> groupModules = groupModuleMap.get(groupName); 101 if (groupModules != null) { 102 table.addTab(Text.of(groupName), groupModules::contains); 103 } 104 } 105 106 for (ModuleElement mdle : modules) { 107 if (!mdle.isUnnamed()) { 108 if (!(options.noDeprecated() && utils.isDeprecated(mdle))) { 109 Content moduleLinkContent = getModuleLink(mdle, 110 Text.of(mdle.getQualifiedName().toString())); 111 Content summaryContent = new ContentBuilder(); 112 addPreviewSummary(mdle, summaryContent); 113 addSummaryComment(mdle, summaryContent); 114 table.addRow(mdle, moduleLinkContent, summaryContent); 115 } 116 } 117 } 118 119 target.add(table); 120 } 121 } 122}