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

Wed, 01 Dec 2010 11:02:38 -0800

author
bpatel
date
Wed, 01 Dec 2010 11:02:38 -0800
changeset 766
90af8d87741f
parent 554
9d9f26857129
child 798
4868a36f6fd8
permissions
-rw-r--r--

6851834: Javadoc doclet needs a structured approach to generate the output HTML.
Reviewed-by: jjg

duke@1 1 /*
ohair@554 2 * Copyright (c) 1997, 2004, 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.*;
duke@1 29 import com.sun.tools.doclets.internal.toolkit.util.*;
bpatel@766 30 import com.sun.tools.doclets.internal.toolkit.*;
bpatel@766 31 import com.sun.tools.doclets.formats.html.markup.*;
duke@1 32
duke@1 33 /**
duke@1 34 * Generate the documentation in the Html "frame" format in the browser. The
duke@1 35 * generated documentation will have two or three frames depending upon the
duke@1 36 * number of packages on the command line. In general there will be three frames
duke@1 37 * in the output, a left-hand top frame will have a list of all packages with
duke@1 38 * links to target left-hand bottom frame. The left-hand bottom frame will have
duke@1 39 * the particular package contents or the all-classes list, where as the single
duke@1 40 * right-hand frame will have overview or package summary or class file. Also
duke@1 41 * take care of browsers which do not support Html frames.
duke@1 42 *
duke@1 43 * @author Atul M Dambalkar
duke@1 44 */
duke@1 45 public class FrameOutputWriter extends HtmlDocletWriter {
duke@1 46
duke@1 47 /**
duke@1 48 * Number of packages specified on the command line.
duke@1 49 */
duke@1 50 int noOfPackages;
duke@1 51
bpatel@766 52 private final String SCROLL_YES = "yes";
bpatel@766 53
duke@1 54 /**
duke@1 55 * Constructor to construct FrameOutputWriter object.
duke@1 56 *
duke@1 57 * @param filename File to be generated.
duke@1 58 */
duke@1 59 public FrameOutputWriter(ConfigurationImpl configuration,
duke@1 60 String filename) throws IOException {
duke@1 61 super(configuration, filename);
duke@1 62 noOfPackages = configuration.packages.length;
duke@1 63 }
duke@1 64
duke@1 65 /**
duke@1 66 * Construct FrameOutputWriter object and then use it to generate the Html
duke@1 67 * file which will have the description of all the frames in the
duke@1 68 * documentation. The name of the generated file is "index.html" which is
duke@1 69 * the default first file for Html documents.
duke@1 70 * @throws DocletAbortException
duke@1 71 */
duke@1 72 public static void generate(ConfigurationImpl configuration) {
duke@1 73 FrameOutputWriter framegen;
duke@1 74 String filename = "";
duke@1 75 try {
duke@1 76 filename = "index.html";
duke@1 77 framegen = new FrameOutputWriter(configuration, filename);
duke@1 78 framegen.generateFrameFile();
duke@1 79 framegen.close();
duke@1 80 } catch (IOException exc) {
duke@1 81 configuration.standardmessage.error(
duke@1 82 "doclet.exception_encountered",
duke@1 83 exc.toString(), filename);
duke@1 84 throw new DocletAbortException();
duke@1 85 }
duke@1 86 }
duke@1 87
duke@1 88 /**
duke@1 89 * Generate the contants in the "index.html" file. Print the frame details
duke@1 90 * as well as warning if browser is not supporting the Html frames.
duke@1 91 */
duke@1 92 protected void generateFrameFile() {
bpatel@766 93 Content frameset = getFrameDetails();
duke@1 94 if (configuration.windowtitle.length() > 0) {
bpatel@766 95 printFramesetDocument(configuration.windowtitle, configuration.notimestamp,
bpatel@766 96 frameset);
duke@1 97 } else {
bpatel@766 98 printFramesetDocument(configuration.getText("doclet.Generated_Docs_Untitled"),
bpatel@766 99 configuration.notimestamp, frameset);
duke@1 100 }
duke@1 101 }
duke@1 102
duke@1 103 /**
bpatel@766 104 * Add the code for issueing the warning for a non-frame capable web
duke@1 105 * client. Also provide links to the non-frame version documentation.
bpatel@766 106 *
bpatel@766 107 * @param contentTree the content tree to which the non-frames information will be added
duke@1 108 */
bpatel@766 109 protected void addFrameWarning(Content contentTree) {
bpatel@766 110 Content noframes = new HtmlTree(HtmlTag.NOFRAMES);
bpatel@766 111 Content noScript = HtmlTree.NOSCRIPT(
bpatel@766 112 HtmlTree.DIV(getResource("doclet.No_Script_Message")));
bpatel@766 113 noframes.addContent(noScript);
bpatel@766 114 Content noframesHead = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING,
bpatel@766 115 getResource("doclet.Frame_Alert"));
bpatel@766 116 noframes.addContent(noframesHead);
bpatel@766 117 Content p = HtmlTree.P(getResource("doclet.Frame_Warning_Message"));
bpatel@766 118 noframes.addContent(p);
bpatel@766 119 noframes.addContent(new HtmlTree(HtmlTag.BR));
bpatel@766 120 noframes.addContent(getResource("doclet.Link_To"));
bpatel@766 121 Content link = getHyperLink(configuration.topFile,
bpatel@766 122 getResource("doclet.Non_Frame_Version"));
bpatel@766 123 noframes.addContent(link);
bpatel@766 124 contentTree.addContent(noframes);
duke@1 125 }
duke@1 126
duke@1 127 /**
bpatel@766 128 * Get the frame sizes and their contents.
bpatel@766 129 *
bpatel@766 130 * @return a content tree for the frame details
duke@1 131 */
bpatel@766 132 protected Content getFrameDetails() {
bpatel@766 133 HtmlTree frameset = HtmlTree.FRAMESET("20%,80%", null, "Documentation frame",
bpatel@766 134 "top.loadFrames()");
duke@1 135 if (noOfPackages <= 1) {
bpatel@766 136 addAllClassesFrameTag(frameset);
duke@1 137 } else if (noOfPackages > 1) {
bpatel@766 138 HtmlTree leftFrameset = HtmlTree.FRAMESET(null, "30%,70%", "Left frames",
bpatel@766 139 "top.loadFrames()");
bpatel@766 140 addAllPackagesFrameTag(leftFrameset);
bpatel@766 141 addAllClassesFrameTag(leftFrameset);
bpatel@766 142 frameset.addContent(leftFrameset);
duke@1 143 }
bpatel@766 144 addClassFrameTag(frameset);
bpatel@766 145 addFrameWarning(frameset);
bpatel@766 146 return frameset;
duke@1 147 }
duke@1 148
duke@1 149 /**
bpatel@766 150 * Add the FRAME tag for the frame that lists all packages.
bpatel@766 151 *
bpatel@766 152 * @param contentTree the content tree to which the information will be added
duke@1 153 */
bpatel@766 154 private void addAllPackagesFrameTag(Content contentTree) {
bpatel@766 155 HtmlTree frame = HtmlTree.FRAME("overview-frame.html", "packageListFrame",
bpatel@766 156 configuration.getText("doclet.All_Packages"));
bpatel@766 157 contentTree.addContent(frame);
duke@1 158 }
duke@1 159
duke@1 160 /**
bpatel@766 161 * Add the FRAME tag for the frame that lists all classes.
bpatel@766 162 *
bpatel@766 163 * @param contentTree the content tree to which the information will be added
duke@1 164 */
bpatel@766 165 private void addAllClassesFrameTag(Content contentTree) {
bpatel@766 166 HtmlTree frame = HtmlTree.FRAME("allclasses-frame.html", "packageFrame",
bpatel@766 167 configuration.getText("doclet.All_classes_and_interfaces"));
bpatel@766 168 contentTree.addContent(frame);
duke@1 169 }
duke@1 170
duke@1 171 /**
bpatel@766 172 * Add the FRAME tag for the frame that describes the class in detail.
bpatel@766 173 *
bpatel@766 174 * @param contentTree the content tree to which the information will be added
duke@1 175 */
bpatel@766 176 private void addClassFrameTag(Content contentTree) {
bpatel@766 177 HtmlTree frame = HtmlTree.FRAME(configuration.topFile, "classFrame",
bpatel@766 178 configuration.getText("doclet.Package_class_and_interface_descriptions"),
bpatel@766 179 SCROLL_YES);
bpatel@766 180 contentTree.addContent(frame);
duke@1 181 }
duke@1 182 }

mercurial