1/*
2 * Copyright (c) 1997, 2017, 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 */
25
26package jdk.javadoc.internal.doclets.formats.html;
27
28import jdk.javadoc.internal.doclets.formats.html.markup.HtmlAttr;
29import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
30import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
31import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
32import jdk.javadoc.internal.doclets.formats.html.markup.RawHtml;
33import jdk.javadoc.internal.doclets.toolkit.Content;
34import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException;
35import jdk.javadoc.internal.doclets.toolkit.util.DocPath;
36import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
37import jdk.javadoc.internal.doclets.toolkit.util.DocletConstants;
38
39
40/**
41 * Generate the documentation in the Html "frame" format in the browser. The
42 * generated documentation will have two or three frames depending upon the
43 * number of packages on the command line. In general there will be three frames
44 * in the output, a left-hand top frame will have a list of all packages with
45 * links to target left-hand bottom frame. The left-hand bottom frame will have
46 * the particular package contents or the all-classes list, where as the single
47 * right-hand frame will have overview or package summary or class file. Also
48 * take care of browsers which do not support Html frames.
49 *
50 *  <p><b>This is NOT part of any supported API.
51 *  If you write code that depends on this, you do so at your own risk.
52 *  This code and its internal interfaces are subject to change or
53 *  deletion without notice.</b>
54 *
55 * @author Atul M Dambalkar
56 */
57public class FrameOutputWriter extends HtmlDocletWriter {
58
59    /**
60     * Number of packages specified on the command line.
61     */
62    int noOfPackages;
63
64    /**
65     * Constructor to construct FrameOutputWriter object.
66     *
67     * @param configuration for this run
68     * @param filename File to be generated.
69     */
70    public FrameOutputWriter(ConfigurationImpl configuration, DocPath filename) {
71        super(configuration, filename);
72        noOfPackages = configuration.packages.size();
73    }
74
75    /**
76     * Construct FrameOutputWriter object and then use it to generate the Html
77     * file which will have the description of all the frames in the
78     * documentation. The name of the generated file is "index.html" which is
79     * the default first file for Html documents.
80     * @param configuration the configuration for this doclet
81     * @throws DocFileIOException if there is a problem generating the frame file
82     */
83    public static void generate(ConfigurationImpl configuration) throws DocFileIOException {
84        FrameOutputWriter framegen = new FrameOutputWriter(configuration, DocPaths.INDEX);
85        framegen.generateFrameFile();
86    }
87
88    /**
89     * Generate the constants in the "index.html" file. Print the frame details
90     * as well as warning if browser is not supporting the Html frames.
91     * @throws DocFileIOException if there is a problem generating the frame file
92     */
93    protected void generateFrameFile() throws DocFileIOException {
94        Content frame = getFrameDetails();
95        HtmlTree body = new HtmlTree(HtmlTag.BODY);
96        body.addAttr(HtmlAttr.ONLOAD, "loadFrames()");
97        String topFilePath = configuration.topFile.getPath();
98        String javaScriptRefresh = "\nif (targetPage == \"\" || targetPage == \"undefined\")\n" +
99                "     window.location.replace('" + topFilePath + "');\n";
100        RawHtml scriptContent = new RawHtml(javaScriptRefresh.replace("\n", DocletConstants.NL));
101        HtmlTree scriptTree = HtmlTree.SCRIPT();
102        scriptTree.addContent(scriptContent);
103        body.addContent(scriptTree);
104        Content noScript = HtmlTree.NOSCRIPT(contents.noScriptMessage);
105        body.addContent(noScript);
106        if (configuration.allowTag(HtmlTag.MAIN)) {
107            HtmlTree main = HtmlTree.MAIN(frame);
108            body.addContent(main);
109        } else {
110            body.addContent(frame);
111        }
112        if (configuration.windowtitle.length() > 0) {
113            printFramesDocument(configuration.windowtitle, configuration,
114                    body);
115        } else {
116            printFramesDocument(configuration.getText("doclet.Generated_Docs_Untitled"),
117                    configuration, body);
118        }
119    }
120
121    /**
122     * Get the frame sizes and their contents.
123     *
124     * @return a content tree for the frame details
125     */
126    protected Content getFrameDetails() {
127        HtmlTree leftContainerDiv = new HtmlTree(HtmlTag.DIV);
128        HtmlTree rightContainerDiv = new HtmlTree(HtmlTag.DIV);
129        leftContainerDiv.addStyle(HtmlStyle.leftContainer);
130        rightContainerDiv.addStyle(HtmlStyle.rightContainer);
131        if (configuration.showModules && configuration.modules.size() > 1) {
132            addAllModulesFrameTag(leftContainerDiv);
133        } else if (noOfPackages > 1) {
134            addAllPackagesFrameTag(leftContainerDiv);
135        }
136        addAllClassesFrameTag(leftContainerDiv);
137        addClassFrameTag(rightContainerDiv);
138        HtmlTree mainContainer = HtmlTree.DIV(HtmlStyle.mainContainer, leftContainerDiv);
139        mainContainer.addContent(rightContainerDiv);
140        return mainContainer;
141    }
142
143    /**
144     * Add the IFRAME tag for the frame that lists all modules.
145     *
146     * @param contentTree to which the information will be added
147     */
148    private void addAllModulesFrameTag(Content contentTree) {
149        HtmlTree frame = HtmlTree.IFRAME(DocPaths.MODULE_OVERVIEW_FRAME.getPath(),
150                "packageListFrame", configuration.getText("doclet.All_Modules"));
151        HtmlTree leftTop = HtmlTree.DIV(HtmlStyle.leftTop, frame);
152        contentTree.addContent(leftTop);
153    }
154
155    /**
156     * Add the IFRAME tag for the frame that lists all packages.
157     *
158     * @param contentTree the content tree to which the information will be added
159     */
160    private void addAllPackagesFrameTag(Content contentTree) {
161        HtmlTree frame = HtmlTree.IFRAME(DocPaths.OVERVIEW_FRAME.getPath(),
162                "packageListFrame", configuration.getText("doclet.All_Packages"));
163        HtmlTree leftTop = HtmlTree.DIV(HtmlStyle.leftTop, frame);
164        contentTree.addContent(leftTop);
165    }
166
167    /**
168     * Add the IFRAME tag for the frame that lists all classes.
169     *
170     * @param contentTree the content tree to which the information will be added
171     */
172    private void addAllClassesFrameTag(Content contentTree) {
173        HtmlTree frame = HtmlTree.IFRAME(DocPaths.ALLCLASSES_FRAME.getPath(),
174                "packageFrame", configuration.getText("doclet.All_classes_and_interfaces"));
175        HtmlTree leftBottom = HtmlTree.DIV(HtmlStyle.leftBottom, frame);
176        contentTree.addContent(leftBottom);
177    }
178
179    /**
180     * Add the IFRAME tag for the frame that describes the class in detail.
181     *
182     * @param contentTree the content tree to which the information will be added
183     */
184    private void addClassFrameTag(Content contentTree) {
185        HtmlTree frame = HtmlTree.IFRAME(configuration.topFile.getPath(), "classFrame",
186                configuration.getText("doclet.Package_class_and_interface_descriptions"));
187        frame.addStyle(HtmlStyle.rightIframe);
188        contentTree.addContent(frame);
189    }
190}
191