1/* 2 * Copyright (c) 1998, 2016, 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 26package jdk.javadoc.internal.doclets.formats.html; 27 28import java.util.Collection; 29 30import javax.lang.model.element.PackageElement; 31 32import jdk.javadoc.internal.doclets.formats.html.markup.HtmlConstants; 33import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle; 34import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag; 35import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; 36import jdk.javadoc.internal.doclets.formats.html.markup.RawHtml; 37import jdk.javadoc.internal.doclets.formats.html.markup.StringContent; 38import jdk.javadoc.internal.doclets.toolkit.Content; 39import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; 40import jdk.javadoc.internal.doclets.toolkit.util.DocPath; 41import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; 42 43 44/** 45 * Generate the package index for the left-hand frame in the generated output. 46 * A click on the package name in this frame will update the page in the bottom 47 * left hand frame with the listing of contents of the clicked package. 48 * 49 * <p><b>This is NOT part of any supported API. 50 * If you write code that depends on this, you do so at your own risk. 51 * This code and its internal interfaces are subject to change or 52 * deletion without notice.</b> 53 * 54 * @author Atul M Dambalkar 55 */ 56public class PackageIndexFrameWriter extends AbstractPackageIndexWriter { 57 58 /** 59 * Construct the PackageIndexFrameWriter object. 60 * 61 * @param filename Name of the package index file to be generated. 62 */ 63 public PackageIndexFrameWriter(ConfigurationImpl configuration, DocPath filename) { 64 super(configuration, filename); 65 } 66 67 /** 68 * Generate the package index file named "overview-frame.html". 69 * @throws DocFileIOException 70 */ 71 public static void generate(ConfigurationImpl configuration) throws DocFileIOException { 72 DocPath filename = DocPaths.OVERVIEW_FRAME; 73 PackageIndexFrameWriter packgen = new PackageIndexFrameWriter(configuration, filename); 74 packgen.buildPackageIndexFile("doclet.Window_Overview", false); 75 } 76 77 /** 78 * {@inheritDoc} 79 */ 80 @Override 81 protected void addPackagesList(Collection<PackageElement> packages, String text, 82 String tableSummary, Content body) { 83 Content heading = HtmlTree.HEADING(HtmlConstants.PACKAGE_HEADING, true, 84 contents.packagesLabel); 85 HtmlTree htmlTree = (configuration.allowTag(HtmlTag.MAIN)) 86 ? HtmlTree.MAIN(HtmlStyle.indexContainer, heading) 87 : HtmlTree.DIV(HtmlStyle.indexContainer, heading); 88 HtmlTree ul = new HtmlTree(HtmlTag.UL); 89 ul.setTitle(contents.packagesLabel); 90 for (PackageElement aPackage : packages) { 91 // Do not list the package if -nodeprecated option is set and the 92 // package is marked as deprecated. 93 if (aPackage != null && 94 (!(configuration.nodeprecated && utils.isDeprecated(aPackage)))) { 95 ul.addContent(getPackage(aPackage)); 96 } 97 } 98 htmlTree.addContent(ul); 99 body.addContent(htmlTree); 100 } 101 102 /** 103 * Returns each package name as a separate link. 104 * 105 * @param pe PackageElement 106 * @return content for the package link 107 */ 108 protected Content getPackage(PackageElement pe) { 109 Content packageLinkContent; 110 Content packageLabel; 111 if (pe.isUnnamed()) { 112 packageLabel = new StringContent("<unnamed package>"); 113 packageLinkContent = getHyperLink(DocPaths.PACKAGE_FRAME, 114 packageLabel, "", "packageFrame"); 115 } else { 116 packageLabel = getPackageLabel(pe.getQualifiedName()); 117 packageLinkContent = getHyperLink(pathString(pe, 118 DocPaths.PACKAGE_FRAME), packageLabel, "", 119 "packageFrame"); 120 } 121 Content li = HtmlTree.LI(packageLinkContent); 122 return li; 123 } 124 125 /** 126 * {@inheritDoc} 127 */ 128 @Override 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 */ 144 @Override 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 @Override 155 protected void addAllClassesLink(Content ul) { 156 Content linkContent = getHyperLink(DocPaths.ALLCLASSES_FRAME, 157 contents.allClassesLabel, "", "packageFrame"); 158 Content li = HtmlTree.LI(linkContent); 159 ul.addContent(li); 160 } 161 162 /** 163 * Adds "All Modules" link for the top of the left-hand frame page to the 164 * documentation tree. 165 * 166 * @param ul the Content object to which the "All Modules" link should be added 167 */ 168 @Override 169 protected void addAllModulesLink(Content ul) { 170 Content linkContent = getHyperLink(DocPaths.MODULE_OVERVIEW_FRAME, 171 contents.allModulesLabel, "", "packageListFrame"); 172 Content li = HtmlTree.LI(linkContent); 173 ul.addContent(li); 174 } 175 176 /** 177 * {@inheritDoc} 178 */ 179 @Override 180 protected void addNavigationBarFooter(Content body) { 181 Content p = HtmlTree.P(Contents.SPACE); 182 body.addContent(p); 183 } 184} 185