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