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

Thu, 23 May 2013 12:50:40 +0100

author
chegar
date
Thu, 23 May 2013 12:50:40 +0100
changeset 1833
f1b90ea7d402
parent 1747
df4f44800923
child 1981
7fb27bc201cc
permissions
-rw-r--r--

Merge

     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     public Content getHyperLink(DocPath link, String label) {
    75         return getHyperLink(link, new StringContent(label), false, "", "", "");
    76     }
    78     /**
    79      * Get Html Hyper Link string.
    80      *
    81      * @param where      Position of the link in the file. Character '#' is not
    82      *                   needed.
    83      * @param label      Tag for the link.
    84      * @return a content tree for the hyper link
    85      */
    86     public Content getHyperLink(String where,
    87                                Content label) {
    88         return getHyperLink(DocLink.fragment(where), label, "", "");
    89     }
    91     /**
    92      * Get Html hyperlink.
    93      *
    94      * @param link       path of the file.
    95      * @param label      Tag for the link.
    96      * @return a content tree for the hyper link
    97      */
    98     public Content getHyperLink(DocPath link, Content label) {
    99         return getHyperLink(link, label, "", "");
   100     }
   102     public Content getHyperLink(DocLink link, Content label) {
   103         return getHyperLink(link, label, "", "");
   104     }
   106     public Content getHyperLink(DocPath link,
   107                                Content label, boolean strong,
   108                                String stylename, String title, String target) {
   109         return getHyperLink(new DocLink(link), label, strong,
   110                 stylename, title, target);
   111     }
   113     public Content getHyperLink(DocLink link,
   114                                Content label, boolean strong,
   115                                String stylename, String title, String target) {
   116         Content body = label;
   117         if (strong) {
   118             body = HtmlTree.SPAN(HtmlStyle.strong, body);
   119         }
   120         if (stylename != null && stylename.length() != 0) {
   121             HtmlTree t = new HtmlTree(HtmlTag.FONT, body);
   122             t.addAttr(HtmlAttr.CLASS, stylename);
   123             body = t;
   124         }
   125         HtmlTree l = HtmlTree.A(link.toString(), body);
   126         if (title != null && title.length() != 0) {
   127             l.addAttr(HtmlAttr.TITLE, title);
   128         }
   129         if (target != null && target.length() != 0) {
   130             l.addAttr(HtmlAttr.TARGET, target);
   131         }
   132         return l;
   133     }
   135     /**
   136      * Get Html Hyper Link.
   137      *
   138      * @param link       String name of the file.
   139      * @param label      Tag for the link.
   140      * @param title      String that describes the link's content for accessibility.
   141      * @param target     Target frame.
   142      * @return a content tree for the hyper link.
   143      */
   144     public Content getHyperLink(DocPath link,
   145             Content label, String title, String target) {
   146         return getHyperLink(new DocLink(link), label, title, target);
   147     }
   149     public Content getHyperLink(DocLink link,
   150             Content label, String title, String target) {
   151         HtmlTree anchor = HtmlTree.A(link.toString(), label);
   152         if (title != null && title.length() != 0) {
   153             anchor.addAttr(HtmlAttr.TITLE, title);
   154         }
   155         if (target != null && target.length() != 0) {
   156             anchor.addAttr(HtmlAttr.TARGET, target);
   157         }
   158         return anchor;
   159     }
   161     /**
   162      * Get the name of the package, this class is in.
   163      *
   164      * @param cd    ClassDoc.
   165      */
   166     public String getPkgName(ClassDoc cd) {
   167         String pkgName = cd.containingPackage().name();
   168         if (pkgName.length() > 0) {
   169             pkgName += ".";
   170             return pkgName;
   171         }
   172         return "";
   173     }
   175     public boolean getMemberDetailsListPrinted() {
   176         return memberDetailsListPrinted;
   177     }
   179     /**
   180      * Print the frameset version of the Html file header.
   181      * Called only when generating an HTML frameset file.
   182      *
   183      * @param title Title of this HTML document
   184      * @param noTimeStamp If true, don't print time stamp in header
   185      * @param frameset the frameset to be added to the HTML document
   186      */
   187     public void printFramesetDocument(String title, boolean noTimeStamp,
   188             Content frameset) throws IOException {
   189         Content htmlDocType = DocType.FRAMESET;
   190         Content htmlComment = new Comment(configuration.getText("doclet.New_Page"));
   191         Content head = new HtmlTree(HtmlTag.HEAD);
   192         if (! noTimeStamp) {
   193             Content headComment = new Comment(getGeneratedByString());
   194             head.addContent(headComment);
   195         }
   196         if (configuration.charset.length() > 0) {
   197             Content meta = HtmlTree.META("Content-Type", "text/html",
   198                     configuration.charset);
   199             head.addContent(meta);
   200         }
   201         Content windowTitle = HtmlTree.TITLE(new StringContent(title));
   202         head.addContent(windowTitle);
   203         head.addContent(getFramesetJavaScript());
   204         Content htmlTree = HtmlTree.HTML(configuration.getLocale().getLanguage(),
   205                 head, frameset);
   206         Content htmlDocument = new HtmlDocument(htmlDocType,
   207                 htmlComment, htmlTree);
   208         write(htmlDocument);
   209     }
   211     protected String getGeneratedByString() {
   212         Calendar calendar = new GregorianCalendar(TimeZone.getDefault());
   213         Date today = calendar.getTime();
   214         return "Generated by javadoc ("+ ConfigurationImpl.BUILD_DATE + ") on " + today;
   215     }
   216 }

mercurial