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 26 package jdk.javadoc.internal.doclets.formats.html; 27 28 import java.io.IOException; 29 import java.util.Collection; 30 31 import javax.lang.model.element.PackageElement; 32 33 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlConstants; 34 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle; 35 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag; 36 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; 37 import jdk.javadoc.internal.doclets.formats.html.markup.RawHtml; 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.DocPath; 41 import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; 42 import jdk.javadoc.internal.doclets.toolkit.util.DocletAbortException; 43 44 45 /** 46 * Generate the package index for the left-hand frame in the generated output. 47 * A click on the package name in this frame will update the page in the bottom 48 * left hand frame with the listing of contents of the clicked package. 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 Atul M Dambalkar 56 */ 57 public class PackageIndexFrameWriter extends AbstractPackageIndexWriter { 58 59 /** 60 * Construct the PackageIndexFrameWriter object. 61 * 62 * @param filename Name of the package index file to be generated. 63 */ 64 public PackageIndexFrameWriter(ConfigurationImpl configuration, 65 DocPath filename) throws IOException { 66 super(configuration, filename); 67 } 68 69 /** 70 * Generate the package index file named "overview-frame.html". 71 * @throws DocletAbortException 72 */ 73 public static void generate(ConfigurationImpl configuration) { 74 PackageIndexFrameWriter packgen; 75 DocPath filename = DocPaths.OVERVIEW_FRAME; 76 try { 77 packgen = new PackageIndexFrameWriter(configuration, filename); 78 packgen.buildPackageIndexFile("doclet.Window_Overview", false); 79 packgen.close(); 80 } catch (IOException exc) { 81 configuration.standardmessage.error( 82 "doclet.exception_encountered", 83 exc.toString(), filename); 84 throw new DocletAbortException(exc); 85 } 86 } 87 88 /** 89 * {@inheritDoc} 90 */ 91 protected void addPackagesList(Collection<PackageElement> packages, String text, 92 String tableSummary, Content body) { 93 Content heading = HtmlTree.HEADING(HtmlConstants.PACKAGE_HEADING, true, 94 packagesLabel); 95 HtmlTree htmlTree = (configuration.allowTag(HtmlTag.MAIN)) 96 ? HtmlTree.MAIN(HtmlStyle.indexContainer, heading) 97 : HtmlTree.DIV(HtmlStyle.indexContainer, heading); 98 HtmlTree ul = new HtmlTree(HtmlTag.UL); 99 ul.setTitle(packagesLabel); 100 for (PackageElement aPackage : packages) { 101 // Do not list the package if -nodeprecated option is set and the 102 // package is marked as deprecated. 103 if (aPackage != null && 104 (!(configuration.nodeprecated && utils.isDeprecated(aPackage)))) { 105 ul.addContent(getPackage(aPackage)); 106 } 107 } 108 htmlTree.addContent(ul); 109 body.addContent(htmlTree); 110 } 111 112 /** 113 * Returns each package name as a separate link. 114 * 115 * @param pe PackageElement 116 * @return content for the package link 117 */ 118 protected Content getPackage(PackageElement pe) { 119 Content packageLinkContent; 120 Content packageLabel; 121 if (pe.isUnnamed()) { 122 packageLabel = new StringContent("<unnamed package>"); 123 packageLinkContent = getHyperLink(DocPaths.PACKAGE_FRAME, 124 packageLabel, "", "packageFrame"); 125 } else { 126 packageLabel = getPackageLabel(pe.getQualifiedName().toString()); 127 packageLinkContent = getHyperLink(pathString(pe, 128 DocPaths.PACKAGE_FRAME), packageLabel, "", 129 "packageFrame"); 130 } 131 Content li = HtmlTree.LI(packageLinkContent); 132 return li; 133 } 134 135 /** 136 * {@inheritDoc} 137 */ 138 protected void addNavigationBarHeader(Content body) { 139 Content headerContent; 140 if (configuration.packagesheader.length() > 0) { 141 headerContent = new RawHtml(replaceDocRootDir(configuration.packagesheader)); 142 } else { 143 headerContent = new RawHtml(replaceDocRootDir(configuration.header)); 144 } 145 Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true, 146 HtmlStyle.bar, headerContent); 147 body.addContent(heading); 148 } 149 150 /** 151 * Do nothing as there is no overview information in this page. 152 */ 153 protected void addOverviewHeader(Content body) { 154 } 155 156 /** 157 * Adds "All Classes" link for the top of the left-hand frame page to the 158 * documentation tree. 159 * 160 * @param ul the Content object to which the "All Classes" link should be added 161 */ 162 protected void addAllClassesLink(Content ul) { 163 Content linkContent = getHyperLink(DocPaths.ALLCLASSES_FRAME, 164 allclassesLabel, "", "packageFrame"); 165 Content li = HtmlTree.LI(linkContent); 166 ul.addContent(li); 167 } 168 169 /** 170 * {@inheritDoc} 171 */ 172 protected void addNavigationBarFooter(Content body) { 173 Content p = HtmlTree.P(getSpace()); 174 body.addContent(p); 175 } 176 }