src/share/classes/com/sun/tools/doclets/formats/html/FrameOutputWriter.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 947
442b1366cfdf
permissions
-rw-r--r--

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

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

mercurial