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

Tue, 14 May 2013 10:14:53 -0700

author
jjg
date
Tue, 14 May 2013 10:14:53 -0700
changeset 1741
4c43e51433ba
parent 1740
ce4f0769b4b2
child 1746
bd51ca92c013
permissions
-rw-r--r--

8011288: Erratic/inconsistent indentation of signatures
Reviewed-by: darcy

     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.markup;
    28 import java.io.*;
    29 import java.util.*;
    31 import com.sun.javadoc.*;
    32 import com.sun.tools.doclets.formats.html.ConfigurationImpl;
    33 import com.sun.tools.doclets.internal.toolkit.*;
    34 import com.sun.tools.doclets.internal.toolkit.util.DocFile;
    35 import com.sun.tools.doclets.internal.toolkit.util.DocLink;
    36 import com.sun.tools.doclets.internal.toolkit.util.DocPath;
    39 /**
    40  * Class for the Html Format Code Generation specific to JavaDoc.
    41  * This Class contains methods related to the Html Code Generation which
    42  * are used by the Sub-Classes in the package com.sun.tools.doclets.standard
    43  * and com.sun.tools.doclets.oneone.
    44  *
    45  *  <p><b>This is NOT part of any supported API.
    46  *  If you write code that depends on this, you do so at your own risk.
    47  *  This code and its internal interfaces are subject to change or
    48  *  deletion without notice.</b>
    49  *
    50  * @since 1.2
    51  * @author Atul M Dambalkar
    52  * @author Robert Field
    53  */
    54 public abstract class HtmlDocWriter extends HtmlWriter {
    56     /**
    57      * Constructor. Initializes the destination file name through the super
    58      * class HtmlWriter.
    59      *
    60      * @param filename String file name.
    61      */
    62     public HtmlDocWriter(Configuration configuration, DocPath filename)
    63             throws IOException {
    64         super(configuration, filename);
    65         configuration.message.notice("doclet.Generating_0",
    66             DocFile.createFileForOutput(configuration, filename).getPath());
    67     }
    69     /**
    70      * Accessor for configuration.
    71      */
    72     public abstract Configuration configuration();
    74     /**
    75      * Return Html hyperlink string.
    76      *
    77      * @param link       String name of the file.
    78      * @param label      Tag for the link.
    79      * @return String    Hyper Link.
    80      */
    81     public String getHyperLinkString(DocPath link, String label) {
    82         return getHyperLinkString(link, label, false, "", "", "");
    83     }
    85     public Content getHyperLink(DocPath link, String label) {
    86         return getHyperLink(link, new StringContent(label), false, "", "", "");
    87     }
    89     public String getHyperLinkString(DocLink link, String label) {
    90         return getHyperLinkString(link, label, false, "", "", "");
    91     }
    93     /**
    94      * Get Html Hyper Link string.
    95      *
    96      * @param link       String name of the file.
    97      * @param label      Tag for the link.
    98      * @param strong       Boolean that sets label to strong.
    99      * @param stylename  String style of text defined in style sheet.
   100      * @return String    Hyper Link.
   101      */
   102     public String getHyperLinkString(DocPath link,
   103                                String label, boolean strong,
   104                                String stylename) {
   105         return getHyperLinkString(link, label, strong, stylename, "", "");
   106     }
   108     public String getHyperLinkString(DocLink link,
   109                                String label, boolean strong,
   110                                String stylename) {
   111         return getHyperLinkString(link, label, strong, stylename, "", "");
   112     }
   114     /**
   115      * Get Html Hyper Link string.
   116      *
   117      * @param where      Position of the link in the file. Character '#' is not
   118      *                   needed.
   119      * @param label      Tag for the link.
   120      * @return a content tree for the hyper link
   121      */
   122     public Content getHyperLink(String where,
   123                                Content label) {
   124         return getHyperLink(DocLink.fragment(where), label, "", "");
   125     }
   127     /**
   128      * Get Html hyperlink.
   129      *
   130      * @param link       path of the file.
   131      * @param label      Tag for the link.
   132      * @return a content tree for the hyper link
   133      */
   134     public Content getHyperLink(DocPath link, Content label) {
   135         return getHyperLink(link, label, "", "");
   136     }
   138     public Content getHyperLink(DocLink link, Content label) {
   139         return getHyperLink(link, label, "", "");
   140     }
   142     /**
   143      * Get Html Hyper Link string.
   144      *
   145      * @param link       String name of the file.
   146      * @param label      Tag for the link.
   147      * @param strong       Boolean that sets label to strong.
   148      * @param stylename  String style of text defined in style sheet.
   149      * @param title      String that describes the links content for accessibility.
   150      * @param target     Target frame.
   151      * @return String    Hyper Link.
   152      */
   153     public String getHyperLinkString(DocPath link,
   154                                String label, boolean strong,
   155                                String stylename, String title, String target) {
   156         return getHyperLinkString(new DocLink(link), label, strong,
   157                 stylename, title, target);
   158     }
   160     public String getHyperLinkString(DocLink link,
   161                                String label, boolean strong,
   162                                String stylename, String title, String target) {
   163         StringBuilder retlink = new StringBuilder();
   164         retlink.append("<a href=\"").append(link).append('"');
   165         if (title != null && title.length() != 0) {
   166             retlink.append(" title=\"").append(title).append('"');
   167         }
   168         if (target != null && target.length() != 0) {
   169             retlink.append(" target=\"").append(target).append('"');
   170         }
   171         retlink.append(">");
   172         if (stylename != null && stylename.length() != 0) {
   173             retlink.append("<FONT CLASS=\"");
   174             retlink.append(stylename);
   175             retlink.append("\">");
   176         }
   177         if (strong) {
   178             retlink.append("<span class=\"strong\">");
   179         }
   180         retlink.append(label);
   181         if (strong) {
   182             retlink.append("</span>");
   183         }
   184         if (stylename != null && stylename.length() != 0) {
   185             retlink.append("</FONT>");
   186         }
   187         retlink.append("</a>");
   188         return retlink.toString();
   189     }
   191     public Content getHyperLink(DocPath link,
   192                                Content label, boolean strong,
   193                                String stylename, String title, String target) {
   194         return getHyperLink(new DocLink(link), label, strong,
   195                 stylename, title, target);
   196     }
   198     public Content getHyperLink(DocLink link,
   199                                Content label, boolean strong,
   200                                String stylename, String title, String target) {
   201         Content body = label;
   202         if (strong) {
   203             body = HtmlTree.SPAN(HtmlStyle.strong, body);
   204         }
   205         if (stylename != null && stylename.length() != 0) {
   206             HtmlTree t = new HtmlTree(HtmlTag.FONT, body);
   207             t.addAttr(HtmlAttr.CLASS, stylename);
   208             body = t;
   209         }
   210         HtmlTree l = HtmlTree.A(link.toString(), body);
   211         if (title != null && title.length() != 0) {
   212             l.addAttr(HtmlAttr.TITLE, title);
   213         }
   214         if (target != null && target.length() != 0) {
   215             l.addAttr(HtmlAttr.TARGET, target);
   216         }
   217         return l;
   218     }
   220     /**
   221      * Get Html Hyper Link.
   222      *
   223      * @param link       String name of the file.
   224      * @param label      Tag for the link.
   225      * @param title      String that describes the link's content for accessibility.
   226      * @param target     Target frame.
   227      * @return a content tree for the hyper link.
   228      */
   229     public Content getHyperLink(DocPath link,
   230             Content label, String title, String target) {
   231         return getHyperLink(new DocLink(link), label, title, target);
   232     }
   234     public Content getHyperLink(DocLink link,
   235             Content label, String title, String target) {
   236         HtmlTree anchor = HtmlTree.A(link.toString(), label);
   237         if (title != null && title.length() != 0) {
   238             anchor.addAttr(HtmlAttr.TITLE, title);
   239         }
   240         if (target != null && target.length() != 0) {
   241             anchor.addAttr(HtmlAttr.TARGET, target);
   242         }
   243         return anchor;
   244     }
   246     /**
   247      * Get the name of the package, this class is in.
   248      *
   249      * @param cd    ClassDoc.
   250      */
   251     public String getPkgName(ClassDoc cd) {
   252         String pkgName = cd.containingPackage().name();
   253         if (pkgName.length() > 0) {
   254             pkgName += ".";
   255             return pkgName;
   256         }
   257         return "";
   258     }
   260     public boolean getMemberDetailsListPrinted() {
   261         return memberDetailsListPrinted;
   262     }
   264     /**
   265      * Print the frameset version of the Html file header.
   266      * Called only when generating an HTML frameset file.
   267      *
   268      * @param title Title of this HTML document
   269      * @param noTimeStamp If true, don't print time stamp in header
   270      * @param frameset the frameset to be added to the HTML document
   271      */
   272     public void printFramesetDocument(String title, boolean noTimeStamp,
   273             Content frameset) throws IOException {
   274         Content htmlDocType = DocType.FRAMESET;
   275         Content htmlComment = new Comment(configuration.getText("doclet.New_Page"));
   276         Content head = new HtmlTree(HtmlTag.HEAD);
   277         if (! noTimeStamp) {
   278             Content headComment = new Comment(getGeneratedByString());
   279             head.addContent(headComment);
   280         }
   281         if (configuration.charset.length() > 0) {
   282             Content meta = HtmlTree.META("Content-Type", "text/html",
   283                     configuration.charset);
   284             head.addContent(meta);
   285         }
   286         Content windowTitle = HtmlTree.TITLE(new StringContent(title));
   287         head.addContent(windowTitle);
   288         head.addContent(getFramesetJavaScript());
   289         Content htmlTree = HtmlTree.HTML(configuration.getLocale().getLanguage(),
   290                 head, frameset);
   291         Content htmlDocument = new HtmlDocument(htmlDocType,
   292                 htmlComment, htmlTree);
   293         write(htmlDocument);
   294     }
   296     protected String getGeneratedByString() {
   297         Calendar calendar = new GregorianCalendar(TimeZone.getDefault());
   298         Date today = calendar.getTime();
   299         return "Generated by javadoc ("+ ConfigurationImpl.BUILD_DATE + ") on " + today;
   300     }
   301 }

mercurial