1 /* 2 * Copyright (c) 1997, 2012, 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 com.sun.tools.doclets.formats.html; 27 28 import java.io.*; 29 import java.util.*; 30 31 import com.sun.javadoc.*; 32 import com.sun.tools.doclets.formats.html.markup.*; 33 import com.sun.tools.doclets.internal.toolkit.*; 34 import com.sun.tools.doclets.internal.toolkit.util.*; 35 36 /** 37 * Generate the package index page "overview-summary.html" for the right-hand 38 * frame. A click on the package name on this page will update the same frame 39 * with the "package-summary.html" file for 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 * @author Bhavesh Patel (Modified) 48 */ 49 public class PackageIndexWriter extends AbstractPackageIndexWriter { 50 51 /** 52 * Root of the program structure. Used for "overview" documentation. 53 */ 54 private RootDoc root; 55 56 /** 57 * Map representing the group of packages as specified on the command line. 58 * 59 * @see Group 60 */ 61 private Map<String,List<PackageDoc>> groupPackageMap; 62 63 /** 64 * List to store the order groups as specified on the command line. 65 */ 66 private List<String> groupList; 67 68 /** 69 * Construct the PackageIndexWriter. Also constructs the grouping 70 * information as provided on the command line by "-group" option. Stores 71 * the order of groups specified by the user. 72 * 73 * @see Group 74 */ 75 public PackageIndexWriter(ConfigurationImpl configuration, 76 DocPath filename) 77 throws IOException { 78 super(configuration, filename); 79 this.root = configuration.root; 80 groupPackageMap = configuration.group.groupPackages(packages); 81 groupList = configuration.group.getGroupList(); 82 } 83 84 /** 85 * Generate the package index page for the right-hand frame. 86 * 87 * @param configuration the current configuration of the doclet. 88 */ 89 public static void generate(ConfigurationImpl configuration) { 90 PackageIndexWriter packgen; 91 DocPath filename = DocPaths.OVERVIEW_SUMMARY; 92 try { 93 packgen = new PackageIndexWriter(configuration, filename); 94 packgen.buildPackageIndexFile("doclet.Window_Overview_Summary", true); 95 packgen.close(); 96 } catch (IOException exc) { 97 configuration.standardmessage.error( 98 "doclet.exception_encountered", 99 exc.toString(), filename); 100 throw new DocletAbortException(); 101 } 102 } 103 104 /** 105 * Depending upon the grouping information and their titles, add 106 * separate table indices for each package group. 107 * 108 * @param body the documentation tree to which the index will be added 109 */ 110 protected void addIndex(Content body) { 111 for (int i = 0; i < groupList.size(); i++) { 112 String groupname = groupList.get(i); 113 List<PackageDoc> list = groupPackageMap.get(groupname); 114 if (list != null && list.size() > 0) { 115 addIndexContents(list.toArray(new PackageDoc[list.size()]), 116 groupname, configuration.getText("doclet.Member_Table_Summary", 117 groupname, configuration.getText("doclet.packages")), body); 118 } 119 } 120 } 121 122 /** 123 * {@inheritDoc} 124 */ 125 protected void addPackagesList(PackageDoc[] packages, String text, 126 String tableSummary, Content body) { 127 Content table = HtmlTree.TABLE(HtmlStyle.overviewSummary, 0, 3, 0, tableSummary, 128 getTableCaption(text)); 129 table.addContent(getSummaryTableHeader(packageTableHeader, "col")); 130 Content tbody = new HtmlTree(HtmlTag.TBODY); 131 addPackagesList(packages, tbody); 132 table.addContent(tbody); 133 Content div = HtmlTree.DIV(HtmlStyle.contentContainer, table); 134 body.addContent(div); 135 } 136 137 /** 138 * Adds list of packages in the index table. Generate link to each package. 139 * 140 * @param packages Packages to which link is to be generated 141 * @param tbody the documentation tree to which the list will be added 142 */ 143 protected void addPackagesList(PackageDoc[] packages, Content tbody) { 144 for (int i = 0; i < packages.length; i++) { 145 if (packages[i] != null && packages[i].name().length() > 0) { 146 if (configuration.nodeprecated && Util.isDeprecated(packages[i])) 147 continue; 148 Content packageLinkContent = getPackageLink(packages[i], 149 getPackageName(packages[i])); 150 Content tdPackage = HtmlTree.TD(HtmlStyle.colFirst, packageLinkContent); 151 HtmlTree tdSummary = new HtmlTree(HtmlTag.TD); 152 tdSummary.addStyle(HtmlStyle.colLast); 153 addSummaryComment(packages[i], tdSummary); 154 HtmlTree tr = HtmlTree.TR(tdPackage); 155 tr.addContent(tdSummary); 156 if (i%2 == 0) 157 tr.addStyle(HtmlStyle.altColor); 158 else 159 tr.addStyle(HtmlStyle.rowColor); 160 tbody.addContent(tr); 161 } 162 } 163 } 164 165 /** 166 * Adds the overview summary comment for this documentation. Add one line 167 * summary at the top of the page and generate a link to the description, 168 * which is added at the end of this page. 169 * 170 * @param body the documentation tree to which the overview header will be added 171 */ 172 protected void addOverviewHeader(Content body) { 173 if (root.inlineTags().length > 0) { 174 HtmlTree subTitleDiv = new HtmlTree(HtmlTag.DIV); 175 subTitleDiv.addStyle(HtmlStyle.subTitle); 176 addSummaryComment(root, subTitleDiv); 177 Content div = HtmlTree.DIV(HtmlStyle.header, subTitleDiv); 178 Content see = seeLabel; 179 see.addContent(" "); 180 Content descPara = HtmlTree.P(see); 181 Content descLink = getHyperLink(DocLink.fragment("overview_description"), 182 descriptionLabel, "", ""); 183 descPara.addContent(descLink); 184 div.addContent(descPara); 185 body.addContent(div); 186 } 187 } 188 189 /** 190 * Adds the overview comment as provided in the file specified by the 191 * "-overview" option on the command line. 192 * 193 * @param htmltree the documentation tree to which the overview comment will 194 * be added 195 */ 196 protected void addOverviewComment(Content htmltree) { 197 if (root.inlineTags().length > 0) { 198 htmltree.addContent(getMarkerAnchor("overview_description")); 199 HtmlTree div = new HtmlTree(HtmlTag.DIV); 200 div.addStyle(HtmlStyle.subTitle); 201 addInlineComment(root, div); 202 htmltree.addContent(div); 203 } 204 } 205 206 /** 207 * Adds the tag information as provided in the file specified by the 208 * "-overview" option on the command line. 209 * 210 * @param body the documentation tree to which the overview will be added 211 */ 212 protected void addOverview(Content body) throws IOException { 213 HtmlTree div = new HtmlTree(HtmlTag.DIV); 214 div.addStyle(HtmlStyle.footer); 215 addOverviewComment(div); 216 addTagsInfo(root, div); 217 body.addContent(div); 218 } 219 220 /** 221 * Adds the top text (from the -top option), the upper 222 * navigation bar, and then the title (from the"-title" 223 * option), at the top of page. 224 * 225 * @body the documentation tree to which the navigation bar header will be added 226 */ 227 protected void addNavigationBarHeader(Content body) { 228 addTop(body); 229 addNavLinks(true, body); 230 addConfigurationTitle(body); 231 } 232 233 /** 234 * Adds the lower navigation bar and the bottom text 235 * (from the -bottom option) at the bottom of page. 236 * 237 * @param body the documentation tree to which the navigation bar footer will be added 238 */ 239 protected void addNavigationBarFooter(Content body) { 240 addNavLinks(false, body); 241 addBottom(body); 242 } 243 }