Tue, 03 Dec 2013 14:21:45 -0800
8025416: doclet not substituting {@docRoot} in some cases
Reviewed-by: jjg
duke@1 | 1 | /* |
jjg@1606 | 2 | * Copyright (c) 1998, 2013, Oracle and/or its affiliates. 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 |
ohair@554 | 7 | * published by the Free Software Foundation. Oracle designates this |
duke@1 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@554 | 9 | * by Oracle 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 | * |
ohair@554 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 23 | * questions. |
duke@1 | 24 | */ |
duke@1 | 25 | |
duke@1 | 26 | package com.sun.tools.doclets.formats.html; |
duke@1 | 27 | |
bpatel@766 | 28 | import java.io.*; |
bpatel@766 | 29 | import java.util.*; |
jjg@1357 | 30 | |
bpatel@766 | 31 | import com.sun.javadoc.*; |
jjg@1357 | 32 | import com.sun.tools.doclets.formats.html.markup.*; |
jjg@1357 | 33 | import com.sun.tools.doclets.internal.toolkit.*; |
duke@1 | 34 | import com.sun.tools.doclets.internal.toolkit.util.*; |
duke@1 | 35 | |
duke@1 | 36 | /** |
duke@1 | 37 | * Class to generate file for each package contents in the left-hand bottom |
duke@1 | 38 | * frame. This will list all the Class Kinds in the package. A click on any |
duke@1 | 39 | * class-kind will update the right-hand frame with the clicked class-kind page. |
duke@1 | 40 | * |
jjg@1359 | 41 | * <p><b>This is NOT part of any supported API. |
jjg@1359 | 42 | * If you write code that depends on this, you do so at your own risk. |
jjg@1359 | 43 | * This code and its internal interfaces are subject to change or |
jjg@1359 | 44 | * deletion without notice.</b> |
jjg@1359 | 45 | * |
duke@1 | 46 | * @author Atul M Dambalkar |
bpatel@766 | 47 | * @author Bhavesh Patel (Modified) |
duke@1 | 48 | */ |
duke@1 | 49 | public class PackageFrameWriter extends HtmlDocletWriter { |
duke@1 | 50 | |
duke@1 | 51 | /** |
duke@1 | 52 | * The package being documented. |
duke@1 | 53 | */ |
duke@1 | 54 | private PackageDoc packageDoc; |
duke@1 | 55 | |
duke@1 | 56 | /** |
duke@1 | 57 | * The classes to be documented. Use this to filter out classes |
duke@1 | 58 | * that will not be documented. |
duke@1 | 59 | */ |
mcimadamore@184 | 60 | private Set<ClassDoc> documentedClasses; |
duke@1 | 61 | |
duke@1 | 62 | /** |
duke@1 | 63 | * Constructor to construct PackageFrameWriter object and to generate |
duke@1 | 64 | * "package-frame.html" file in the respective package directory. |
duke@1 | 65 | * For example for package "java.lang" this will generate file |
duke@1 | 66 | * "package-frame.html" file in the "java/lang" directory. It will also |
duke@1 | 67 | * create "java/lang" directory in the current or the destination directory |
jjg@1372 | 68 | * if it doesn't exist. |
duke@1 | 69 | * |
duke@1 | 70 | * @param configuration the configuration of the doclet. |
duke@1 | 71 | * @param packageDoc PackageDoc under consideration. |
duke@1 | 72 | */ |
duke@1 | 73 | public PackageFrameWriter(ConfigurationImpl configuration, |
duke@1 | 74 | PackageDoc packageDoc) |
duke@1 | 75 | throws IOException { |
jjg@1372 | 76 | super(configuration, DocPath.forPackage(packageDoc).resolve(DocPaths.PACKAGE_FRAME)); |
duke@1 | 77 | this.packageDoc = packageDoc; |
duke@1 | 78 | if (configuration.root.specifiedPackages().length == 0) { |
jjg@74 | 79 | documentedClasses = new HashSet<ClassDoc>(Arrays.asList(configuration.root.classes())); |
duke@1 | 80 | } |
duke@1 | 81 | } |
duke@1 | 82 | |
duke@1 | 83 | /** |
duke@1 | 84 | * Generate a package summary page for the left-hand bottom frame. Construct |
duke@1 | 85 | * the PackageFrameWriter object and then uses it generate the file. |
duke@1 | 86 | * |
duke@1 | 87 | * @param configuration the current configuration of the doclet. |
duke@1 | 88 | * @param packageDoc The package for which "pacakge-frame.html" is to be generated. |
duke@1 | 89 | */ |
duke@1 | 90 | public static void generate(ConfigurationImpl configuration, |
bpatel@766 | 91 | PackageDoc packageDoc) { |
duke@1 | 92 | PackageFrameWriter packgen; |
duke@1 | 93 | try { |
duke@1 | 94 | packgen = new PackageFrameWriter(configuration, packageDoc); |
duke@1 | 95 | String pkgName = Util.getPackageName(packageDoc); |
bpatel@766 | 96 | Content body = packgen.getBody(false, packgen.getWindowTitle(pkgName)); |
jjg@1737 | 97 | Content pkgNameContent = new StringContent(pkgName); |
bpatel@766 | 98 | Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, HtmlStyle.bar, |
bpatel@766 | 99 | packgen.getTargetPackageLink(packageDoc, "classFrame", pkgNameContent)); |
bpatel@766 | 100 | body.addContent(heading); |
bpatel@766 | 101 | HtmlTree div = new HtmlTree(HtmlTag.DIV); |
bpatel@766 | 102 | div.addStyle(HtmlStyle.indexContainer); |
bpatel@766 | 103 | packgen.addClassListing(div); |
bpatel@766 | 104 | body.addContent(div); |
bpatel@766 | 105 | packgen.printHtmlDocument( |
bpatel@766 | 106 | configuration.metakeywords.getMetaKeywords(packageDoc), false, body); |
duke@1 | 107 | packgen.close(); |
duke@1 | 108 | } catch (IOException exc) { |
duke@1 | 109 | configuration.standardmessage.error( |
bpatel@766 | 110 | "doclet.exception_encountered", |
jjg@1372 | 111 | exc.toString(), DocPaths.PACKAGE_FRAME.getPath()); |
jjg@1985 | 112 | throw new DocletAbortException(exc); |
duke@1 | 113 | } |
duke@1 | 114 | } |
duke@1 | 115 | |
duke@1 | 116 | /** |
bpatel@766 | 117 | * Add class listing for all the classes in this package. Divide class |
duke@1 | 118 | * listing as per the class kind and generate separate listing for |
duke@1 | 119 | * Classes, Interfaces, Exceptions and Errors. |
bpatel@766 | 120 | * |
bpatel@766 | 121 | * @param contentTree the content tree to which the listing will be added |
duke@1 | 122 | */ |
bpatel@766 | 123 | protected void addClassListing(Content contentTree) { |
jjg@1410 | 124 | Configuration config = configuration; |
duke@1 | 125 | if (packageDoc.isIncluded()) { |
bpatel@766 | 126 | addClassKindListing(packageDoc.interfaces(), |
bpatel@766 | 127 | getResource("doclet.Interfaces"), contentTree); |
bpatel@766 | 128 | addClassKindListing(packageDoc.ordinaryClasses(), |
bpatel@766 | 129 | getResource("doclet.Classes"), contentTree); |
bpatel@766 | 130 | addClassKindListing(packageDoc.enums(), |
bpatel@766 | 131 | getResource("doclet.Enums"), contentTree); |
bpatel@766 | 132 | addClassKindListing(packageDoc.exceptions(), |
bpatel@766 | 133 | getResource("doclet.Exceptions"), contentTree); |
bpatel@766 | 134 | addClassKindListing(packageDoc.errors(), |
bpatel@766 | 135 | getResource("doclet.Errors"), contentTree); |
bpatel@766 | 136 | addClassKindListing(packageDoc.annotationTypes(), |
bpatel@766 | 137 | getResource("doclet.AnnotationTypes"), contentTree); |
duke@1 | 138 | } else { |
duke@1 | 139 | String name = Util.getPackageName(packageDoc); |
bpatel@766 | 140 | addClassKindListing(config.classDocCatalog.interfaces(name), |
bpatel@766 | 141 | getResource("doclet.Interfaces"), contentTree); |
bpatel@766 | 142 | addClassKindListing(config.classDocCatalog.ordinaryClasses(name), |
bpatel@766 | 143 | getResource("doclet.Classes"), contentTree); |
bpatel@766 | 144 | addClassKindListing(config.classDocCatalog.enums(name), |
bpatel@766 | 145 | getResource("doclet.Enums"), contentTree); |
bpatel@766 | 146 | addClassKindListing(config.classDocCatalog.exceptions(name), |
bpatel@766 | 147 | getResource("doclet.Exceptions"), contentTree); |
bpatel@766 | 148 | addClassKindListing(config.classDocCatalog.errors(name), |
bpatel@766 | 149 | getResource("doclet.Errors"), contentTree); |
bpatel@766 | 150 | addClassKindListing(config.classDocCatalog.annotationTypes(name), |
bpatel@766 | 151 | getResource("doclet.AnnotationTypes"), contentTree); |
duke@1 | 152 | } |
duke@1 | 153 | } |
duke@1 | 154 | |
duke@1 | 155 | /** |
bpatel@766 | 156 | * Add specific class kind listing. Also add label to the listing. |
duke@1 | 157 | * |
bpatel@766 | 158 | * @param arr Array of specific class kinds, namely Class or Interface or Exception or Error |
bpatel@766 | 159 | * @param labelContent content tree of the label to be added |
bpatel@766 | 160 | * @param contentTree the content tree to which the class kind listing will be added |
duke@1 | 161 | */ |
bpatel@766 | 162 | protected void addClassKindListing(ClassDoc[] arr, Content labelContent, |
bpatel@766 | 163 | Content contentTree) { |
jjg@1606 | 164 | arr = Util.filterOutPrivateClasses(arr, configuration.javafx); |
duke@1 | 165 | if(arr.length > 0) { |
duke@1 | 166 | Arrays.sort(arr); |
duke@1 | 167 | boolean printedHeader = false; |
bpatel@766 | 168 | HtmlTree ul = new HtmlTree(HtmlTag.UL); |
jjg@1747 | 169 | ul.setTitle(labelContent); |
duke@1 | 170 | for (int i = 0; i < arr.length; i++) { |
duke@1 | 171 | if (documentedClasses != null && |
bpatel@766 | 172 | !documentedClasses.contains(arr[i])) { |
duke@1 | 173 | continue; |
duke@1 | 174 | } |
duke@1 | 175 | if (!Util.isCoreClass(arr[i]) || ! |
bpatel@766 | 176 | configuration.isGeneratedDoc(arr[i])) { |
duke@1 | 177 | continue; |
duke@1 | 178 | } |
duke@1 | 179 | if (!printedHeader) { |
bpatel@766 | 180 | Content heading = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, |
bpatel@766 | 181 | true, labelContent); |
bpatel@766 | 182 | contentTree.addContent(heading); |
duke@1 | 183 | printedHeader = true; |
duke@1 | 184 | } |
jjg@1737 | 185 | Content arr_i_name = new StringContent(arr[i].name()); |
bpatel@2147 | 186 | if (arr[i].isInterface()) arr_i_name = HtmlTree.SPAN(HtmlStyle.interfaceName, arr_i_name); |
jjg@1736 | 187 | Content link = getLink(new LinkInfoImpl(configuration, |
jjg@1738 | 188 | LinkInfoImpl.Kind.PACKAGE_FRAME, arr[i]).label(arr_i_name).target("classFrame")); |
bpatel@766 | 189 | Content li = HtmlTree.LI(link); |
bpatel@766 | 190 | ul.addContent(li); |
duke@1 | 191 | } |
bpatel@766 | 192 | contentTree.addContent(ul); |
duke@1 | 193 | } |
duke@1 | 194 | } |
duke@1 | 195 | } |