src/share/classes/com/sun/tools/doclets/formats/html/PackageFrameWriter.java

Fri, 04 Mar 2011 19:53:03 -0800

author
jjg
date
Fri, 04 Mar 2011 19:53:03 -0800
changeset 910
ebf7c13df6c0
parent 798
4868a36f6fd8
child 995
62bc3775d5bb
permissions
-rw-r--r--

6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
Reviewed-by: bpatel

duke@1 1 /*
ohair@798 2 * Copyright (c) 1998, 2010, 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.*;
bpatel@766 30 import com.sun.javadoc.*;
duke@1 31 import com.sun.tools.doclets.internal.toolkit.util.*;
duke@1 32 import com.sun.tools.doclets.internal.toolkit.*;
bpatel@766 33 import com.sun.tools.doclets.formats.html.markup.*;
duke@1 34
duke@1 35 /**
duke@1 36 * Class to generate file for each package contents in the left-hand bottom
duke@1 37 * frame. This will list all the Class Kinds in the package. A click on any
duke@1 38 * class-kind will update the right-hand frame with the clicked class-kind page.
duke@1 39 *
duke@1 40 * @author Atul M Dambalkar
bpatel@766 41 * @author Bhavesh Patel (Modified)
duke@1 42 */
duke@1 43 public class PackageFrameWriter extends HtmlDocletWriter {
duke@1 44
duke@1 45 /**
duke@1 46 * The package being documented.
duke@1 47 */
duke@1 48 private PackageDoc packageDoc;
duke@1 49
duke@1 50 /**
duke@1 51 * The classes to be documented. Use this to filter out classes
duke@1 52 * that will not be documented.
duke@1 53 */
mcimadamore@184 54 private Set<ClassDoc> documentedClasses;
duke@1 55
duke@1 56 /**
duke@1 57 * The name of the output file.
duke@1 58 */
duke@1 59 public static final String OUTPUT_FILE_NAME = "package-frame.html";
duke@1 60
duke@1 61 /**
duke@1 62 * Constructor to construct PackageFrameWriter object and to generate
duke@1 63 * "package-frame.html" file in the respective package directory.
duke@1 64 * For example for package "java.lang" this will generate file
duke@1 65 * "package-frame.html" file in the "java/lang" directory. It will also
duke@1 66 * create "java/lang" directory in the current or the destination directory
duke@1 67 * if it doesen't exist.
duke@1 68 *
duke@1 69 * @param configuration the configuration of the doclet.
duke@1 70 * @param packageDoc PackageDoc under consideration.
duke@1 71 */
duke@1 72 public PackageFrameWriter(ConfigurationImpl configuration,
duke@1 73 PackageDoc packageDoc)
duke@1 74 throws IOException {
duke@1 75 super(configuration, DirectoryManager.getDirectoryPath(packageDoc), OUTPUT_FILE_NAME, DirectoryManager.getRelativePath(packageDoc));
duke@1 76 this.packageDoc = packageDoc;
duke@1 77 if (configuration.root.specifiedPackages().length == 0) {
jjg@74 78 documentedClasses = new HashSet<ClassDoc>(Arrays.asList(configuration.root.classes()));
duke@1 79 }
duke@1 80 }
duke@1 81
duke@1 82 /**
duke@1 83 * Generate a package summary page for the left-hand bottom frame. Construct
duke@1 84 * the PackageFrameWriter object and then uses it generate the file.
duke@1 85 *
duke@1 86 * @param configuration the current configuration of the doclet.
duke@1 87 * @param packageDoc The package for which "pacakge-frame.html" is to be generated.
duke@1 88 */
duke@1 89 public static void generate(ConfigurationImpl configuration,
bpatel@766 90 PackageDoc packageDoc) {
duke@1 91 PackageFrameWriter packgen;
duke@1 92 try {
duke@1 93 packgen = new PackageFrameWriter(configuration, packageDoc);
duke@1 94 String pkgName = Util.getPackageName(packageDoc);
bpatel@766 95 Content body = packgen.getBody(false, packgen.getWindowTitle(pkgName));
bpatel@766 96 Content pkgNameContent = new StringContent(pkgName);
bpatel@766 97 Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, HtmlStyle.bar,
bpatel@766 98 packgen.getTargetPackageLink(packageDoc, "classFrame", pkgNameContent));
bpatel@766 99 body.addContent(heading);
bpatel@766 100 HtmlTree div = new HtmlTree(HtmlTag.DIV);
bpatel@766 101 div.addStyle(HtmlStyle.indexContainer);
bpatel@766 102 packgen.addClassListing(div);
bpatel@766 103 body.addContent(div);
bpatel@766 104 packgen.printHtmlDocument(
bpatel@766 105 configuration.metakeywords.getMetaKeywords(packageDoc), false, body);
duke@1 106 packgen.close();
duke@1 107 } catch (IOException exc) {
duke@1 108 configuration.standardmessage.error(
bpatel@766 109 "doclet.exception_encountered",
bpatel@766 110 exc.toString(), OUTPUT_FILE_NAME);
duke@1 111 throw new DocletAbortException();
duke@1 112 }
duke@1 113 }
duke@1 114
duke@1 115 /**
bpatel@766 116 * Add class listing for all the classes in this package. Divide class
duke@1 117 * listing as per the class kind and generate separate listing for
duke@1 118 * Classes, Interfaces, Exceptions and Errors.
bpatel@766 119 *
bpatel@766 120 * @param contentTree the content tree to which the listing will be added
duke@1 121 */
bpatel@766 122 protected void addClassListing(Content contentTree) {
duke@1 123 Configuration config = configuration();
duke@1 124 if (packageDoc.isIncluded()) {
bpatel@766 125 addClassKindListing(packageDoc.interfaces(),
bpatel@766 126 getResource("doclet.Interfaces"), contentTree);
bpatel@766 127 addClassKindListing(packageDoc.ordinaryClasses(),
bpatel@766 128 getResource("doclet.Classes"), contentTree);
bpatel@766 129 addClassKindListing(packageDoc.enums(),
bpatel@766 130 getResource("doclet.Enums"), contentTree);
bpatel@766 131 addClassKindListing(packageDoc.exceptions(),
bpatel@766 132 getResource("doclet.Exceptions"), contentTree);
bpatel@766 133 addClassKindListing(packageDoc.errors(),
bpatel@766 134 getResource("doclet.Errors"), contentTree);
bpatel@766 135 addClassKindListing(packageDoc.annotationTypes(),
bpatel@766 136 getResource("doclet.AnnotationTypes"), contentTree);
duke@1 137 } else {
duke@1 138 String name = Util.getPackageName(packageDoc);
bpatel@766 139 addClassKindListing(config.classDocCatalog.interfaces(name),
bpatel@766 140 getResource("doclet.Interfaces"), contentTree);
bpatel@766 141 addClassKindListing(config.classDocCatalog.ordinaryClasses(name),
bpatel@766 142 getResource("doclet.Classes"), contentTree);
bpatel@766 143 addClassKindListing(config.classDocCatalog.enums(name),
bpatel@766 144 getResource("doclet.Enums"), contentTree);
bpatel@766 145 addClassKindListing(config.classDocCatalog.exceptions(name),
bpatel@766 146 getResource("doclet.Exceptions"), contentTree);
bpatel@766 147 addClassKindListing(config.classDocCatalog.errors(name),
bpatel@766 148 getResource("doclet.Errors"), contentTree);
bpatel@766 149 addClassKindListing(config.classDocCatalog.annotationTypes(name),
bpatel@766 150 getResource("doclet.AnnotationTypes"), contentTree);
duke@1 151 }
duke@1 152 }
duke@1 153
duke@1 154 /**
bpatel@766 155 * Add specific class kind listing. Also add label to the listing.
duke@1 156 *
bpatel@766 157 * @param arr Array of specific class kinds, namely Class or Interface or Exception or Error
bpatel@766 158 * @param labelContent content tree of the label to be added
bpatel@766 159 * @param contentTree the content tree to which the class kind listing will be added
duke@1 160 */
bpatel@766 161 protected void addClassKindListing(ClassDoc[] arr, Content labelContent,
bpatel@766 162 Content contentTree) {
duke@1 163 if(arr.length > 0) {
duke@1 164 Arrays.sort(arr);
duke@1 165 boolean printedHeader = false;
bpatel@766 166 HtmlTree ul = new HtmlTree(HtmlTag.UL);
bpatel@766 167 ul.addAttr(HtmlAttr.TITLE, labelContent.toString());
duke@1 168 for (int i = 0; i < arr.length; i++) {
duke@1 169 if (documentedClasses != null &&
bpatel@766 170 !documentedClasses.contains(arr[i])) {
duke@1 171 continue;
duke@1 172 }
duke@1 173 if (!Util.isCoreClass(arr[i]) || !
bpatel@766 174 configuration.isGeneratedDoc(arr[i])) {
duke@1 175 continue;
duke@1 176 }
duke@1 177 if (!printedHeader) {
bpatel@766 178 Content heading = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING,
bpatel@766 179 true, labelContent);
bpatel@766 180 contentTree.addContent(heading);
duke@1 181 printedHeader = true;
duke@1 182 }
bpatel@766 183 Content link = new RawHtml (getLink(new LinkInfoImpl(
bpatel@766 184 LinkInfoImpl.PACKAGE_FRAME, arr[i],
bpatel@766 185 (arr[i].isInterface() ? italicsText(arr[i].name()) :
bpatel@766 186 arr[i].name()),"classFrame")));
bpatel@766 187 Content li = HtmlTree.LI(link);
bpatel@766 188 ul.addContent(li);
duke@1 189 }
bpatel@766 190 contentTree.addContent(ul);
duke@1 191 }
duke@1 192 }
duke@1 193 }

mercurial