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