PackageIndexFrameWriter.java revision 3294:9adfb22ff08f
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 com.sun.tools.doclets.formats.html; 27 28import java.io.IOException; 29import java.util.Collection; 30 31import com.sun.javadoc.*; 32import com.sun.tools.doclets.formats.html.markup.*; 33import com.sun.tools.doclets.internal.toolkit.*; 34import com.sun.tools.doclets.internal.toolkit.util.*; 35 36/** 37 * Generate the package index for the left-hand frame in the generated output. 38 * A click on the package name in this frame will update the page in the bottom 39 * left hand frame with the listing of contents of the clicked package. 40 * 41 * <p><b>This is NOT part of any supported API. 42 * If you write code that depends on this, you do so at your own risk. 43 * This code and its internal interfaces are subject to change or 44 * deletion without notice.</b> 45 * 46 * @author Atul M Dambalkar 47 */ 48public class PackageIndexFrameWriter extends AbstractPackageIndexWriter { 49 50 /** 51 * Construct the PackageIndexFrameWriter object. 52 * 53 * @param filename Name of the package index file to be generated. 54 */ 55 public PackageIndexFrameWriter(ConfigurationImpl configuration, 56 DocPath filename) throws IOException { 57 super(configuration, filename); 58 } 59 60 /** 61 * Generate the package index file named "overview-frame.html". 62 * @throws DocletAbortException 63 */ 64 public static void generate(ConfigurationImpl configuration) { 65 PackageIndexFrameWriter packgen; 66 DocPath filename = DocPaths.OVERVIEW_FRAME; 67 try { 68 packgen = new PackageIndexFrameWriter(configuration, filename); 69 packgen.buildPackageIndexFile("doclet.Window_Overview", false); 70 packgen.close(); 71 } catch (IOException exc) { 72 configuration.standardmessage.error( 73 "doclet.exception_encountered", 74 exc.toString(), filename); 75 throw new DocletAbortException(exc); 76 } 77 } 78 79 /** 80 * {@inheritDoc} 81 */ 82 protected void addPackagesList(Collection<PackageDoc> packages, String text, 83 String tableSummary, Content body) { 84 Content heading = HtmlTree.HEADING(HtmlConstants.PACKAGE_HEADING, true, 85 packagesLabel); 86 HtmlTree htmlTree = (configuration.allowTag(HtmlTag.MAIN)) 87 ? HtmlTree.MAIN(HtmlStyle.indexContainer, heading) 88 : HtmlTree.DIV(HtmlStyle.indexContainer, heading); 89 HtmlTree ul = new HtmlTree(HtmlTag.UL); 90 ul.setTitle(packagesLabel); 91 for (PackageDoc aPackage : packages) { 92 // Do not list the package if -nodeprecated option is set and the 93 // package is marked as deprecated. 94 if (aPackage != null && 95 (!(configuration.nodeprecated && utils.isDeprecated(aPackage)))) { 96 ul.addContent(getPackage(aPackage)); 97 } 98 } 99 htmlTree.addContent(ul); 100 body.addContent(htmlTree); 101 } 102 103 /** 104 * Returns each package name as a separate link. 105 * 106 * @param pd PackageDoc 107 * @return content for the package link 108 */ 109 protected Content getPackage(PackageDoc pd) { 110 Content packageLinkContent; 111 Content packageLabel; 112 if (!pd.name().isEmpty()) { 113 packageLabel = getPackageLabel(pd.name()); 114 packageLinkContent = getHyperLink(pathString(pd, 115 DocPaths.PACKAGE_FRAME), packageLabel, "", 116 "packageFrame"); 117 } else { 118 packageLabel = new StringContent("<unnamed package>"); 119 packageLinkContent = getHyperLink(DocPaths.PACKAGE_FRAME, 120 packageLabel, "", "packageFrame"); 121 } 122 Content li = HtmlTree.LI(packageLinkContent); 123 return li; 124 } 125 126 /** 127 * {@inheritDoc} 128 */ 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 protected void addOverviewHeader(Content body) { 145 } 146 147 /** 148 * Adds "All Classes" 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 Classes" link should be added 152 */ 153 protected void addAllClassesLink(Content ul) { 154 Content linkContent = getHyperLink(DocPaths.ALLCLASSES_FRAME, 155 allclassesLabel, "", "packageFrame"); 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(getSpace()); 165 body.addContent(p); 166 } 167} 168