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

Mon, 13 Dec 2010 13:44:47 -0800

author
bpatel
date
Mon, 13 Dec 2010 13:44:47 -0800
changeset 793
ffbf2b2a8611
parent 766
90af8d87741f
child 798
4868a36f6fd8
permissions
-rw-r--r--

7006270: Several javadoc regression tests are failing on windows
Reviewed-by: jjg

     1 /*
     2  * Copyright (c) 1997, 2009, 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.markup;
    28 import java.io.*;
    29 import java.util.*;
    31 import com.sun.javadoc.*;
    32 import com.sun.tools.doclets.internal.toolkit.*;
    35 /**
    36  * Class for the Html Format Code Generation specific to JavaDoc.
    37  * This Class contains methods related to the Html Code Generation which
    38  * are used by the Sub-Classes in the package com.sun.tools.doclets.standard
    39  * and com.sun.tools.doclets.oneone.
    40  *
    41  * @since 1.2
    42  * @author Atul M Dambalkar
    43  * @author Robert Field
    44  */
    45 public abstract class HtmlDocWriter extends HtmlWriter {
    47     /**
    48      * Constructor. Initializes the destination file name through the super
    49      * class HtmlWriter.
    50      *
    51      * @param filename String file name.
    52      */
    53     public HtmlDocWriter(Configuration configuration,
    54                          String filename) throws IOException {
    55         super(configuration,
    56               null, configuration.destDirName + filename,
    57               configuration.docencoding);
    58         // use File to normalize file separators
    59         configuration.message.notice("doclet.Generating_0",
    60             new File(configuration.destDirName, filename));
    61     }
    63     public HtmlDocWriter(Configuration configuration,
    64                          String path, String filename) throws IOException {
    65         super(configuration,
    66               configuration.destDirName + path, filename,
    67               configuration.docencoding);
    68         // use File to normalize file separators
    69         configuration.message.notice("doclet.Generating_0",
    70             new File(configuration.destDirName,
    71                     ((path.length() > 0)? path + File.separator: "") + filename));
    72     }
    74     /**
    75      * Accessor for configuration.
    76      */
    77     public abstract Configuration configuration();
    79     /**
    80      * Print Html Hyper Link.
    81      *
    82      * @param link String name of the file.
    83      * @param where Position of the link in the file. Character '#' is not
    84      * needed.
    85      * @param label Tag for the link.
    86      * @param strong  Boolean that sets label to strong.
    87      */
    88     public void printHyperLink(String link, String where,
    89                                String label, boolean strong) {
    90         print(getHyperLinkString(link, where, label, strong, "", "", ""));
    91     }
    93     /**
    94      * Print Html Hyper Link.
    95      *
    96      * @param link String name of the file.
    97      * @param where Position of the link in the file. Character '#' is not
    98      * needed.
    99      * @param label Tag for the link.
   100      */
   101     public void printHyperLink(String link, String where, String label) {
   102         printHyperLink(link, where, label, false);
   103     }
   105     /**
   106      * Print Html Hyper Link.
   107      *
   108      * @param link       String name of the file.
   109      * @param where      Position of the link in the file. Character '#' is not
   110      * needed.
   111      * @param label      Tag for the link.
   112      * @param strong       Boolean that sets label to strong.
   113      * @param stylename  String style of text defined in style sheet.
   114      */
   115     public void printHyperLink(String link, String where,
   116                                String label, boolean strong,
   117                                String stylename) {
   118         print(getHyperLinkString(link, where, label, strong, stylename, "", ""));
   119     }
   121     /**
   122      * Return Html Hyper Link string.
   123      *
   124      * @param link       String name of the file.
   125      * @param where      Position of the link in the file. Character '#' is not
   126      * needed.
   127      * @param label      Tag for the link.
   128      * @param strong       Boolean that sets label to strong.
   129      * @return String    Hyper Link.
   130      */
   131     public String getHyperLinkString(String link, String where,
   132                                String label, boolean strong) {
   133         return getHyperLinkString(link, where, label, strong, "", "", "");
   134     }
   136     /**
   137      * Get Html Hyper Link string.
   138      *
   139      * @param link       String name of the file.
   140      * @param where      Position of the link in the file. Character '#' is not
   141      *                   needed.
   142      * @param label      Tag for the link.
   143      * @param strong       Boolean that sets label to strong.
   144      * @param stylename  String style of text defined in style sheet.
   145      * @return String    Hyper Link.
   146      */
   147     public String getHyperLinkString(String link, String where,
   148                                String label, boolean strong,
   149                                String stylename) {
   150         return getHyperLinkString(link, where, label, strong, stylename, "", "");
   151     }
   153     /**
   154      * Get Html Hyper Link string.
   155      *
   156      * @param link       String name of the file.
   157      * @param where      Position of the link in the file. Character '#' is not
   158      *                   needed.
   159      * @param label      Tag for the link.
   160      * @return a content tree for the hyper link
   161      */
   162     public Content getHyperLink(String link, String where,
   163                                Content label) {
   164         return getHyperLink(link, where, label, "", "");
   165     }
   167     /**
   168      * Get Html Hyper Link string.
   169      *
   170      * @param link       String name of the file.
   171      * @param where      Position of the link in the file. Character '#' is not
   172      *                   needed.
   173      * @param label      Tag for the link.
   174      * @param strong       Boolean that sets label to strong.
   175      * @param stylename  String style of text defined in style sheet.
   176      * @param title      String that describes the link's content for accessibility.
   177      * @param target     Target frame.
   178      * @return String    Hyper Link.
   179      */
   180     public String getHyperLinkString(String link, String where,
   181                                String label, boolean strong,
   182                                String stylename, String title, String target) {
   183         StringBuffer retlink = new StringBuffer();
   184         retlink.append("<a href=\"");
   185         retlink.append(link);
   186         if (where != null && where.length() != 0) {
   187             retlink.append("#");
   188             retlink.append(where);
   189         }
   190         retlink.append("\"");
   191         if (title != null && title.length() != 0) {
   192             retlink.append(" title=\"" + title + "\"");
   193         }
   194         if (target != null && target.length() != 0) {
   195             retlink.append(" target=\"" + target + "\"");
   196         }
   197         retlink.append(">");
   198         if (stylename != null && stylename.length() != 0) {
   199             retlink.append("<FONT CLASS=\"");
   200             retlink.append(stylename);
   201             retlink.append("\">");
   202         }
   203         if (strong) {
   204             retlink.append("<span class=\"strong\">");
   205         }
   206         retlink.append(label);
   207         if (strong) {
   208             retlink.append("</span>");
   209         }
   210         if (stylename != null && stylename.length() != 0) {
   211             retlink.append("</FONT>");
   212         }
   213         retlink.append("</a>");
   214         return retlink.toString();
   215     }
   217     /**
   218      * Get Html Hyper Link.
   219      *
   220      * @param link       String name of the file.
   221      * @param where      Position of the link in the file. Character '#' is not
   222      *                   needed.
   223      * @param label      Tag for the link.
   224      * @param title      String that describes the link's content for accessibility.
   225      * @param target     Target frame.
   226      * @return a content tree for the hyper link.
   227      */
   228     public Content getHyperLink(String link, String where,
   229             Content label, String title, String target) {
   230         if (where != null && where.length() != 0) {
   231             link += "#" + where;
   232         }
   233         HtmlTree anchor = HtmlTree.A(link, label);
   234         if (title != null && title.length() != 0) {
   235             anchor.addAttr(HtmlAttr.TITLE, title);
   236         }
   237         if (target != null && target.length() != 0) {
   238             anchor.addAttr(HtmlAttr.TARGET, target);
   239         }
   240         return anchor;
   241     }
   243     /**
   244      * Get a hyperlink to a file.
   245      *
   246      * @param link String name of the file
   247      * @param label Label for the link
   248      * @return a content for the hyperlink to the file
   249      */
   250     public Content getHyperLink(String link, Content label) {
   251         return getHyperLink(link, "", label);
   252     }
   254     /**
   255      * Get link string without positioning in the file.
   256      *
   257      * @param link       String name of the file.
   258      * @param label      Tag for the link.
   259      * @return Strign    Hyper link.
   260      */
   261     public String getHyperLinkString(String link, String label) {
   262         return getHyperLinkString(link, "", label, false);
   263     }
   265     /**
   266      * Print the name of the package, this class is in.
   267      *
   268      * @param cd    ClassDoc.
   269      */
   270     public void printPkgName(ClassDoc cd) {
   271         print(getPkgName(cd));
   272     }
   274     /**
   275      * Get the name of the package, this class is in.
   276      *
   277      * @param cd    ClassDoc.
   278      */
   279     public String getPkgName(ClassDoc cd) {
   280         String pkgName = cd.containingPackage().name();
   281         if (pkgName.length() > 0) {
   282             pkgName += ".";
   283             return pkgName;
   284         }
   285         return "";
   286     }
   288     /**
   289      * Keep track of member details list. Print the definition list start tag
   290      * if it is not printed yet.
   291      */
   292     public void printMemberDetailsListStartTag () {
   293         if (!getMemberDetailsListPrinted()) {
   294             dl();
   295             memberDetailsListPrinted = true;
   296         }
   297     }
   299     /**
   300      * Print the definition list end tag if the list start tag was printed.
   301      */
   302     public void printMemberDetailsListEndTag () {
   303         if (getMemberDetailsListPrinted()) {
   304             dlEnd();
   305             memberDetailsListPrinted = false;
   306         }
   307     }
   309     public boolean getMemberDetailsListPrinted() {
   310         return memberDetailsListPrinted;
   311     }
   313     /**
   314      * Print the frameset version of the Html file header.
   315      * Called only when generating an HTML frameset file.
   316      *
   317      * @param title Title of this HTML document
   318      * @param noTimeStamp If true, don't print time stamp in header
   319      * @param frameset the frameset to be added to the HTML document
   320      */
   321     public void printFramesetDocument(String title, boolean noTimeStamp,
   322             Content frameset) {
   323         Content htmlDocType = DocType.Frameset();
   324         Content htmlComment = new Comment(configuration.getText("doclet.New_Page"));
   325         Content head = new HtmlTree(HtmlTag.HEAD);
   326         if (! noTimeStamp) {
   327             Content headComment = new Comment("Generated by javadoc on " + today());
   328             head.addContent(headComment);
   329         }
   330         if (configuration.charset.length() > 0) {
   331             Content meta = HtmlTree.META("Content-Type", "text/html",
   332                     configuration.charset);
   333             head.addContent(meta);
   334         }
   335         Content windowTitle = HtmlTree.TITLE(new StringContent(title));
   336         head.addContent(windowTitle);
   337         head.addContent(getFramesetJavaScript());
   338         Content htmlTree = HtmlTree.HTML(configuration.getLocale().getLanguage(),
   339                 head, frameset);
   340         Content htmlDocument = new HtmlDocument(htmlDocType,
   341                 htmlComment, htmlTree);
   342         print(htmlDocument.toString());
   343     }
   345     /**
   346      * Print the appropriate spaces to format the class tree in the class page.
   347      *
   348      * @param len   Number of spaces.
   349      */
   350     public String spaces(int len) {
   351         String space = "";
   353         for (int i = 0; i < len; i++) {
   354             space += " ";
   355         }
   356         return space;
   357     }
   359     /**
   360      * Print the closing &lt;/body&gt; and &lt;/html&gt; tags.
   361      */
   362     public void printBodyHtmlEnd() {
   363         println();
   364         bodyEnd();
   365         htmlEnd();
   366     }
   368     /**
   369      * Calls {@link #printBodyHtmlEnd()} method.
   370      */
   371     public void printFooter() {
   372         printBodyHtmlEnd();
   373     }
   375     /**
   376      * Print closing &lt;/html&gt; tag.
   377      */
   378     public void printFrameFooter() {
   379         htmlEnd();
   380     }
   382     /**
   383      * Print ten non-breaking spaces("&#38;nbsp;").
   384      */
   385     public void printNbsps() {
   386         print("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
   387     }
   389     /**
   390      * Get the day and date information for today, depending upon user option.
   391      *
   392      * @return String Today.
   393      * @see java.util.Calendar
   394      * @see java.util.GregorianCalendar
   395      * @see java.util.TimeZone
   396      */
   397     public String today() {
   398         Calendar calendar = new GregorianCalendar(TimeZone.getDefault());
   399         return calendar.getTime().toString();
   400     }
   401 }

mercurial