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

Tue, 23 Oct 2012 13:20:37 -0700

author
jjg
date
Tue, 23 Oct 2012 13:20:37 -0700
changeset 1372
78962d89f283
parent 1365
2013982bee34
child 1373
4a1c57a1c410
permissions
-rw-r--r--

8000741: refactor javadoc to use abstraction to handle relative paths
Reviewed-by: darcy

     1 /*
     2  * Copyright (c) 1997, 2012, 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.DocPath;
    35 import com.sun.tools.doclets.internal.toolkit.util.DocPaths;
    38 /**
    39  * Class for the Html Format Code Generation specific to JavaDoc.
    40  * This Class contains methods related to the Html Code Generation which
    41  * are used by the Sub-Classes in the package com.sun.tools.doclets.standard
    42  * and com.sun.tools.doclets.oneone.
    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  * @since 1.2
    50  * @author Atul M Dambalkar
    51  * @author Robert Field
    52  */
    53 public abstract class HtmlDocWriter extends HtmlWriter {
    55     /**
    56      * Constructor. Initializes the destination file name through the super
    57      * class HtmlWriter.
    58      *
    59      * @param filename String file name.
    60      */
    61     public HtmlDocWriter(Configuration configuration, DocPath filename)
    62             throws IOException {
    63         super(configuration, filename);
    64         configuration.message.notice("doclet.Generating_0",
    65             filename.resolveAgainst(configuration.destDirName));
    66     }
    68     /**
    69      * Accessor for configuration.
    70      */
    71     public abstract Configuration configuration();
    73     /**
    74      * Return Html Hyper Link string.
    75      *
    76      * @param link       String name of the file.
    77      * @param where      Position of the link in the file. Character '#' is not
    78      * needed.
    79      * @param label      Tag for the link.
    80      * @param strong       Boolean that sets label to strong.
    81      * @return String    Hyper Link.
    82      */
    83     public String getHyperLinkString(DocPath link, String where,
    84                                String label, boolean strong) {
    85         return getHyperLinkString(link, where, label, strong, "", "", "");
    86     }
    88     /**
    89      * Get Html Hyper Link string.
    90      *
    91      * @param link       String name of the file.
    92      * @param where      Position of the link in the file. Character '#' is not
    93      *                   needed.
    94      * @param label      Tag for the link.
    95      * @param strong       Boolean that sets label to strong.
    96      * @param stylename  String style of text defined in style sheet.
    97      * @return String    Hyper Link.
    98      */
    99     public String getHyperLinkString(DocPath link, String where,
   100                                String label, boolean strong,
   101                                String stylename) {
   102         return getHyperLinkString(link, where, label, strong, stylename, "", "");
   103     }
   105     /**
   106      * Get Html Hyper Link string.
   107      *
   108      * @param where      Position of the link in the file. Character '#' is not
   109      *                   needed.
   110      * @param label      Tag for the link.
   111      * @return a content tree for the hyper link
   112      */
   113     public Content getHyperLink(String where,
   114                                Content label) {
   115         return getHyperLink(DocPath.empty, where, label, "", "");
   116     }
   118     /**
   119      * Get Html Hyper Link string.
   120      *
   121      * @param link       String name of the file.
   122      * @param where      Position of the link in the file. Character '#' is not
   123      *                   needed.
   124      * @param label      Tag for the link.
   125      * @return a content tree for the hyper link
   126      */
   127     public Content getHyperLink(DocPath link, String where,
   128                                Content label) {
   129         return getHyperLink(link, where, label, "", "");
   130     }
   132     /**
   133      * Get Html Hyper Link string.
   134      *
   135      * @param link       String name of the file.
   136      * @param where      Position of the link in the file. Character '#' is not
   137      *                   needed.
   138      * @param label      Tag for the link.
   139      * @param strong       Boolean that sets label to strong.
   140      * @param stylename  String style of text defined in style sheet.
   141      * @param title      String that describes the link's content for accessibility.
   142      * @param target     Target frame.
   143      * @return String    Hyper Link.
   144      */
   145     public String getHyperLinkString(DocPath link, String where,
   146                                String label, boolean strong,
   147                                String stylename, String title, String target) {
   148         return getHyperLinkString(link.getPath(), where, label, strong,
   149                 stylename, title, target);
   150     }
   152     public String getHyperLinkString(String link, String where,
   153                                String label, boolean strong,
   154                                String stylename, String title, String target) {
   155         StringBuilder retlink = new StringBuilder();
   156         retlink.append("<a href=\"");
   157         retlink.append(link);
   158         if (where != null && where.length() != 0) {
   159             retlink.append("#");
   160             retlink.append(where);
   161         }
   162         retlink.append("\"");
   163         if (title != null && title.length() != 0) {
   164             retlink.append(" title=\"").append(title).append("\"");
   165         }
   166         if (target != null && target.length() != 0) {
   167             retlink.append(" target=\"").append(target).append("\"");
   168         }
   169         retlink.append(">");
   170         if (stylename != null && stylename.length() != 0) {
   171             retlink.append("<FONT CLASS=\"");
   172             retlink.append(stylename);
   173             retlink.append("\">");
   174         }
   175         if (strong) {
   176             retlink.append("<span class=\"strong\">");
   177         }
   178         retlink.append(label);
   179         if (strong) {
   180             retlink.append("</span>");
   181         }
   182         if (stylename != null && stylename.length() != 0) {
   183             retlink.append("</FONT>");
   184         }
   185         retlink.append("</a>");
   186         return retlink.toString();
   187     }
   189     /**
   190      * Get Html Hyper Link.
   191      *
   192      * @param link       String name of the file.
   193      * @param where      Position of the link in the file. Character '#' is not
   194      *                   needed.
   195      * @param label      Tag for the link.
   196      * @param title      String that describes the link's content for accessibility.
   197      * @param target     Target frame.
   198      * @return a content tree for the hyper link.
   199      */
   200     public Content getHyperLink(DocPath link, String where,
   201             Content label, String title, String target) {
   202         return getHyperLink(link.getPath(), where, label, title, target);
   203     }
   204     public Content getHyperLink(String link, String where,
   205             Content label, String title, String target) {
   206         if (link.startsWith("/")) Thread.dumpStack();
   207         if (where != null && where.length() != 0) {
   208             link += "#" + where;
   209         }
   210         HtmlTree anchor = HtmlTree.A(link, label);
   211         if (title != null && title.length() != 0) {
   212             anchor.addAttr(HtmlAttr.TITLE, title);
   213         }
   214         if (target != null && target.length() != 0) {
   215             anchor.addAttr(HtmlAttr.TARGET, target);
   216         }
   217         return anchor;
   218     }
   220     /**
   221      * Get a hyperlink to a file.
   222      *
   223      * @param link String name of the file
   224      * @param label Label for the link
   225      * @return a content for the hyperlink to the file
   226      */
   227     public Content getHyperLink(DocPath link, Content label) {
   228         return getHyperLink(link, "", label);
   229     }
   231     /**
   232      * Get link string without positioning in the file.
   233      *
   234      * @param link       String name of the file.
   235      * @param label      Tag for the link.
   236      * @return Strign    Hyper link.
   237      */
   238     public String getHyperLinkString(DocPath link, String label) {
   239         return getHyperLinkString(link, "", label, false);
   240     }
   242     /**
   243      * Get the name of the package, this class is in.
   244      *
   245      * @param cd    ClassDoc.
   246      */
   247     public String getPkgName(ClassDoc cd) {
   248         String pkgName = cd.containingPackage().name();
   249         if (pkgName.length() > 0) {
   250             pkgName += ".";
   251             return pkgName;
   252         }
   253         return "";
   254     }
   256     public boolean getMemberDetailsListPrinted() {
   257         return memberDetailsListPrinted;
   258     }
   260     /**
   261      * Print the frameset version of the Html file header.
   262      * Called only when generating an HTML frameset file.
   263      *
   264      * @param title Title of this HTML document
   265      * @param noTimeStamp If true, don't print time stamp in header
   266      * @param frameset the frameset to be added to the HTML document
   267      */
   268     public void printFramesetDocument(String title, boolean noTimeStamp,
   269             Content frameset) throws IOException {
   270         Content htmlDocType = DocType.Frameset();
   271         Content htmlComment = new Comment(configuration.getText("doclet.New_Page"));
   272         Content head = new HtmlTree(HtmlTag.HEAD);
   273         if (! noTimeStamp) {
   274             Content headComment = new Comment(getGeneratedByString());
   275             head.addContent(headComment);
   276         }
   277         if (configuration.charset.length() > 0) {
   278             Content meta = HtmlTree.META("Content-Type", "text/html",
   279                     configuration.charset);
   280             head.addContent(meta);
   281         }
   282         Content windowTitle = HtmlTree.TITLE(new StringContent(title));
   283         head.addContent(windowTitle);
   284         head.addContent(getFramesetJavaScript());
   285         Content htmlTree = HtmlTree.HTML(configuration.getLocale().getLanguage(),
   286                 head, frameset);
   287         Content htmlDocument = new HtmlDocument(htmlDocType,
   288                 htmlComment, htmlTree);
   289         write(htmlDocument);
   290     }
   292     /**
   293      * Print the appropriate spaces to format the class tree in the class page.
   294      *
   295      * @param len   Number of spaces.
   296      */
   297     public String spaces(int len) {
   298         String space = "";
   300         for (int i = 0; i < len; i++) {
   301             space += " ";
   302         }
   303         return space;
   304     }
   306     protected String getGeneratedByString() {
   307         Calendar calendar = new GregorianCalendar(TimeZone.getDefault());
   308         Date today = calendar.getTime();
   309         return "Generated by javadoc ("+ ConfigurationImpl.BUILD_DATE + ") on " + today;
   310     }
   311 }

mercurial