Thu, 08 Jan 2009 16:26:59 -0800
6786028: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - Bold tags should be strong
Reviewed-by: jjg
duke@1 | 1 | /* |
xdono@117 | 2 | * Copyright 1998-2008 Sun Microsystems, Inc. All Rights Reserved. |
duke@1 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@1 | 4 | * |
duke@1 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@1 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@1 | 7 | * published by the Free Software Foundation. Sun designates this |
duke@1 | 8 | * particular file as subject to the "Classpath" exception as provided |
duke@1 | 9 | * by Sun in the LICENSE file that accompanied this code. |
duke@1 | 10 | * |
duke@1 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@1 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@1 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@1 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@1 | 15 | * accompanied this code). |
duke@1 | 16 | * |
duke@1 | 17 | * You should have received a copy of the GNU General Public License version |
duke@1 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@1 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@1 | 20 | * |
duke@1 | 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@1 | 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@1 | 23 | * have any questions. |
duke@1 | 24 | */ |
duke@1 | 25 | |
duke@1 | 26 | package com.sun.tools.doclets.formats.html; |
duke@1 | 27 | |
duke@1 | 28 | import com.sun.tools.doclets.internal.toolkit.util.*; |
duke@1 | 29 | import com.sun.tools.doclets.internal.toolkit.*; |
duke@1 | 30 | |
duke@1 | 31 | import com.sun.javadoc.*; |
duke@1 | 32 | import java.io.*; |
duke@1 | 33 | import java.util.*; |
duke@1 | 34 | /** |
duke@1 | 35 | * Class to generate file for each package contents in the left-hand bottom |
duke@1 | 36 | * frame. This will list all the Class Kinds in the package. A click on any |
duke@1 | 37 | * class-kind will update the right-hand frame with the clicked class-kind page. |
duke@1 | 38 | * |
duke@1 | 39 | * @author Atul M Dambalkar |
duke@1 | 40 | */ |
duke@1 | 41 | public class PackageFrameWriter extends HtmlDocletWriter { |
duke@1 | 42 | |
duke@1 | 43 | /** |
duke@1 | 44 | * The package being documented. |
duke@1 | 45 | */ |
duke@1 | 46 | private PackageDoc packageDoc; |
duke@1 | 47 | |
duke@1 | 48 | /** |
duke@1 | 49 | * The classes to be documented. Use this to filter out classes |
duke@1 | 50 | * that will not be documented. |
duke@1 | 51 | */ |
duke@1 | 52 | private Set documentedClasses; |
duke@1 | 53 | |
duke@1 | 54 | /** |
duke@1 | 55 | * The name of the output file. |
duke@1 | 56 | */ |
duke@1 | 57 | public static final String OUTPUT_FILE_NAME = "package-frame.html"; |
duke@1 | 58 | |
duke@1 | 59 | /** |
duke@1 | 60 | * Constructor to construct PackageFrameWriter object and to generate |
duke@1 | 61 | * "package-frame.html" file in the respective package directory. |
duke@1 | 62 | * For example for package "java.lang" this will generate file |
duke@1 | 63 | * "package-frame.html" file in the "java/lang" directory. It will also |
duke@1 | 64 | * create "java/lang" directory in the current or the destination directory |
duke@1 | 65 | * if it doesen't exist. |
duke@1 | 66 | * |
duke@1 | 67 | * @param configuration the configuration of the doclet. |
duke@1 | 68 | * @param packageDoc PackageDoc under consideration. |
duke@1 | 69 | */ |
duke@1 | 70 | public PackageFrameWriter(ConfigurationImpl configuration, |
duke@1 | 71 | PackageDoc packageDoc) |
duke@1 | 72 | throws IOException { |
duke@1 | 73 | super(configuration, DirectoryManager.getDirectoryPath(packageDoc), OUTPUT_FILE_NAME, DirectoryManager.getRelativePath(packageDoc)); |
duke@1 | 74 | this.packageDoc = packageDoc; |
duke@1 | 75 | if (configuration.root.specifiedPackages().length == 0) { |
jjg@74 | 76 | documentedClasses = new HashSet<ClassDoc>(Arrays.asList(configuration.root.classes())); |
duke@1 | 77 | } |
duke@1 | 78 | } |
duke@1 | 79 | |
duke@1 | 80 | /** |
duke@1 | 81 | * Generate a package summary page for the left-hand bottom frame. Construct |
duke@1 | 82 | * the PackageFrameWriter object and then uses it generate the file. |
duke@1 | 83 | * |
duke@1 | 84 | * @param configuration the current configuration of the doclet. |
duke@1 | 85 | * @param packageDoc The package for which "pacakge-frame.html" is to be generated. |
duke@1 | 86 | */ |
duke@1 | 87 | public static void generate(ConfigurationImpl configuration, |
duke@1 | 88 | PackageDoc packageDoc) { |
duke@1 | 89 | PackageFrameWriter packgen; |
duke@1 | 90 | try { |
duke@1 | 91 | packgen = new PackageFrameWriter(configuration, packageDoc); |
duke@1 | 92 | String pkgName = Util.getPackageName(packageDoc); |
duke@1 | 93 | packgen.printHtmlHeader(pkgName, configuration.metakeywords.getMetaKeywords(packageDoc), false); |
duke@1 | 94 | packgen.printPackageHeader(pkgName); |
duke@1 | 95 | packgen.generateClassListing(); |
duke@1 | 96 | packgen.printBodyHtmlEnd(); |
duke@1 | 97 | packgen.close(); |
duke@1 | 98 | } catch (IOException exc) { |
duke@1 | 99 | configuration.standardmessage.error( |
duke@1 | 100 | "doclet.exception_encountered", |
duke@1 | 101 | exc.toString(), OUTPUT_FILE_NAME); |
duke@1 | 102 | throw new DocletAbortException(); |
duke@1 | 103 | } |
duke@1 | 104 | } |
duke@1 | 105 | |
duke@1 | 106 | /** |
duke@1 | 107 | * Generate class listing for all the classes in this package. Divide class |
duke@1 | 108 | * listing as per the class kind and generate separate listing for |
duke@1 | 109 | * Classes, Interfaces, Exceptions and Errors. |
duke@1 | 110 | */ |
duke@1 | 111 | protected void generateClassListing() { |
duke@1 | 112 | Configuration config = configuration(); |
duke@1 | 113 | if (packageDoc.isIncluded()) { |
duke@1 | 114 | generateClassKindListing(packageDoc.interfaces(), |
duke@1 | 115 | configuration.getText("doclet.Interfaces")); |
duke@1 | 116 | generateClassKindListing(packageDoc.ordinaryClasses(), |
duke@1 | 117 | configuration.getText("doclet.Classes")); |
duke@1 | 118 | generateClassKindListing(packageDoc.enums(), |
duke@1 | 119 | configuration.getText("doclet.Enums")); |
duke@1 | 120 | generateClassKindListing(packageDoc.exceptions(), |
duke@1 | 121 | configuration.getText("doclet.Exceptions")); |
duke@1 | 122 | generateClassKindListing(packageDoc.errors(), |
duke@1 | 123 | configuration.getText("doclet.Errors")); |
duke@1 | 124 | generateClassKindListing(packageDoc.annotationTypes(), |
duke@1 | 125 | configuration.getText("doclet.AnnotationTypes")); |
duke@1 | 126 | } else { |
duke@1 | 127 | String name = Util.getPackageName(packageDoc); |
duke@1 | 128 | generateClassKindListing(config.classDocCatalog.interfaces(name), |
duke@1 | 129 | configuration.getText("doclet.Interfaces")); |
duke@1 | 130 | generateClassKindListing(config.classDocCatalog.ordinaryClasses(name), |
duke@1 | 131 | configuration.getText("doclet.Classes")); |
duke@1 | 132 | generateClassKindListing(config.classDocCatalog.enums(name), |
duke@1 | 133 | configuration.getText("doclet.Enums")); |
duke@1 | 134 | generateClassKindListing(config.classDocCatalog.exceptions(name), |
duke@1 | 135 | configuration.getText("doclet.Exceptions")); |
duke@1 | 136 | generateClassKindListing(config.classDocCatalog.errors(name), |
duke@1 | 137 | configuration.getText("doclet.Errors")); |
duke@1 | 138 | generateClassKindListing(config.classDocCatalog.annotationTypes(name), |
duke@1 | 139 | configuration.getText("doclet.AnnotationTypes")); |
duke@1 | 140 | } |
duke@1 | 141 | } |
duke@1 | 142 | |
duke@1 | 143 | /** |
duke@1 | 144 | * Generate specific class kind listing. Also add label to the listing. |
duke@1 | 145 | * |
duke@1 | 146 | * @param arr Array of specific class kinds, namely Class or Interface or |
duke@1 | 147 | * Exception or Error. |
duke@1 | 148 | * @param label Label for the listing |
duke@1 | 149 | */ |
duke@1 | 150 | protected void generateClassKindListing(ClassDoc[] arr, String label) { |
duke@1 | 151 | if(arr.length > 0) { |
duke@1 | 152 | Arrays.sort(arr); |
duke@1 | 153 | printPackageTableHeader(); |
duke@1 | 154 | fontSizeStyle("+1", "FrameHeadingFont"); |
duke@1 | 155 | boolean printedHeader = false; |
duke@1 | 156 | for (int i = 0; i < arr.length; i++) { |
duke@1 | 157 | if (documentedClasses != null && |
duke@1 | 158 | !documentedClasses.contains(arr[i])) { |
duke@1 | 159 | continue; |
duke@1 | 160 | } |
duke@1 | 161 | if (!Util.isCoreClass(arr[i]) || ! |
duke@1 | 162 | configuration.isGeneratedDoc(arr[i])) { |
duke@1 | 163 | continue; |
duke@1 | 164 | } |
duke@1 | 165 | if (!printedHeader) { |
duke@1 | 166 | print(label); |
duke@1 | 167 | fontEnd(); |
duke@1 | 168 | println(" "); |
duke@1 | 169 | fontStyle("FrameItemFont"); |
duke@1 | 170 | printedHeader = true; |
duke@1 | 171 | } |
duke@1 | 172 | br(); |
duke@1 | 173 | printLink(new LinkInfoImpl( |
duke@1 | 174 | LinkInfoImpl.PACKAGE_FRAME, |
duke@1 | 175 | arr[i], |
duke@1 | 176 | (arr[i].isInterface() ? |
duke@1 | 177 | italicsText(arr[i].name()) : |
duke@1 | 178 | arr[i].name()),"classFrame") |
duke@1 | 179 | ); |
duke@1 | 180 | } |
duke@1 | 181 | fontEnd(); |
duke@1 | 182 | printPackageTableFooter(); |
duke@1 | 183 | println(); |
duke@1 | 184 | } |
duke@1 | 185 | } |
duke@1 | 186 | |
duke@1 | 187 | /** |
duke@1 | 188 | * Print the package link at the top of the class kind listing. Clicking |
duke@1 | 189 | * this link, package-summary page will appear in the right hand frame. |
duke@1 | 190 | * |
duke@1 | 191 | * @param heading Top Heading to be used for the class kind listing. |
duke@1 | 192 | */ |
duke@1 | 193 | protected void printPackageHeader(String heading) { |
duke@1 | 194 | fontSizeStyle("+1", "FrameTitleFont"); |
duke@1 | 195 | printTargetPackageLink(packageDoc, "classFrame", heading); |
duke@1 | 196 | fontEnd(); |
duke@1 | 197 | } |
duke@1 | 198 | |
duke@1 | 199 | /** |
duke@1 | 200 | * The table for the class kind listing. |
duke@1 | 201 | */ |
duke@1 | 202 | protected void printPackageTableHeader() { |
duke@1 | 203 | table(); |
duke@1 | 204 | tr(); |
duke@1 | 205 | tdNowrap(); |
duke@1 | 206 | } |
duke@1 | 207 | |
duke@1 | 208 | /** |
duke@1 | 209 | * Closing Html tags for table of class kind listing. |
duke@1 | 210 | */ |
duke@1 | 211 | protected void printPackageTableFooter() { |
duke@1 | 212 | tdEnd(); |
duke@1 | 213 | trEnd(); |
duke@1 | 214 | tableEnd(); |
duke@1 | 215 | } |
duke@1 | 216 | } |