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

changeset 1
9a66ca7c79fa
child 182
47a62d8d98b4
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlDocWriter.java	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,357 @@
     1.4 +/*
     1.5 + * Copyright 1997-2007 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Sun designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Sun in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.26 + * have any questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.tools.doclets.formats.html.markup;
    1.30 +
    1.31 +import com.sun.tools.doclets.internal.toolkit.*;
    1.32 +
    1.33 +import com.sun.javadoc.*;
    1.34 +import java.io.*;
    1.35 +import java.util.*;
    1.36 +import com.sun.tools.doclets.internal.toolkit.util.*;
    1.37 +
    1.38 +
    1.39 +/**
    1.40 + * Class for the Html Format Code Generation specific to JavaDoc.
    1.41 + * This Class contains methods related to the Html Code Generation which
    1.42 + * are used by the Sub-Classes in the package com.sun.tools.doclets.standard
    1.43 + * and com.sun.tools.doclets.oneone.
    1.44 + *
    1.45 + * @since 1.2
    1.46 + * @author Atul M Dambalkar
    1.47 + * @author Robert Field
    1.48 + */
    1.49 +public abstract class HtmlDocWriter extends HtmlWriter {
    1.50 +
    1.51 +    /**
    1.52 +     * Constructor. Initializes the destination file name through the super
    1.53 +     * class HtmlWriter.
    1.54 +     *
    1.55 +     * @param filename String file name.
    1.56 +     */
    1.57 +    public HtmlDocWriter(Configuration configuration,
    1.58 +                         String filename) throws IOException {
    1.59 +        super(configuration,
    1.60 +              null, configuration.destDirName + filename,
    1.61 +              configuration.docencoding);
    1.62 +        configuration.message.notice("doclet.Generating_0",
    1.63 +                                     configuration.destDirName + filename);
    1.64 +    }
    1.65 +
    1.66 +    public HtmlDocWriter(Configuration configuration,
    1.67 +                         String path, String filename) throws IOException {
    1.68 +        super(configuration,
    1.69 +              configuration.destDirName + path, filename,
    1.70 +              configuration.docencoding);
    1.71 +        configuration.message.notice("doclet.Generating_0",
    1.72 +                                     configuration.destDirName +
    1.73 +                                         ((path.length() > 0)?
    1.74 +                                              path + File.separator: "") + filename);
    1.75 +    }
    1.76 +
    1.77 +    /**
    1.78 +     * Accessor for configuration.
    1.79 +     */
    1.80 +    public abstract Configuration configuration();
    1.81 +
    1.82 +    /**
    1.83 +     * Print Html Hyper Link.
    1.84 +     *
    1.85 +     * @param link String name of the file.
    1.86 +     * @param where Position of the link in the file. Character '#' is not
    1.87 +     * needed.
    1.88 +     * @param label Tag for the link.
    1.89 +     * @param bold  Boolean that sets label to bold.
    1.90 +     */
    1.91 +    public void printHyperLink(String link, String where,
    1.92 +                               String label, boolean bold) {
    1.93 +        print(getHyperLink(link, where, label, bold, "", "", ""));
    1.94 +    }
    1.95 +
    1.96 +    /**
    1.97 +     * Print Html Hyper Link.
    1.98 +     *
    1.99 +     * @param link String name of the file.
   1.100 +     * @param where Position of the link in the file. Character '#' is not
   1.101 +     * needed.
   1.102 +     * @param label Tag for the link.
   1.103 +     */
   1.104 +    public void printHyperLink(String link, String where, String label) {
   1.105 +        printHyperLink(link, where, label, false);
   1.106 +    }
   1.107 +
   1.108 +    /**
   1.109 +     * Print Html Hyper Link.
   1.110 +     *
   1.111 +     * @param link       String name of the file.
   1.112 +     * @param where      Position of the link in the file. Character '#' is not
   1.113 +     * needed.
   1.114 +     * @param label      Tag for the link.
   1.115 +     * @param bold       Boolean that sets label to bold.
   1.116 +     * @param stylename  String style of text defined in style sheet.
   1.117 +     */
   1.118 +    public void printHyperLink(String link, String where,
   1.119 +                               String label, boolean bold,
   1.120 +                               String stylename) {
   1.121 +        print(getHyperLink(link, where, label, bold, stylename, "", ""));
   1.122 +    }
   1.123 +
   1.124 +    /**
   1.125 +     * Return Html Hyper Link string.
   1.126 +     *
   1.127 +     * @param link       String name of the file.
   1.128 +     * @param where      Position of the link in the file. Character '#' is not
   1.129 +     * needed.
   1.130 +     * @param label      Tag for the link.
   1.131 +     * @param bold       Boolean that sets label to bold.
   1.132 +     * @return String    Hyper Link.
   1.133 +     */
   1.134 +    public String getHyperLink(String link, String where,
   1.135 +                               String label, boolean bold) {
   1.136 +        return getHyperLink(link, where, label, bold, "", "", "");
   1.137 +    }
   1.138 +
   1.139 +    /**
   1.140 +     * Get Html Hyper Link string.
   1.141 +     *
   1.142 +     * @param link       String name of the file.
   1.143 +     * @param where      Position of the link in the file. Character '#' is not
   1.144 +     *                   needed.
   1.145 +     * @param label      Tag for the link.
   1.146 +     * @param bold       Boolean that sets label to bold.
   1.147 +     * @param stylename  String style of text defined in style sheet.
   1.148 +     * @return String    Hyper Link.
   1.149 +     */
   1.150 +    public String getHyperLink(String link, String where,
   1.151 +                               String label, boolean bold,
   1.152 +                               String stylename) {
   1.153 +        return getHyperLink(link, where, label, bold, stylename, "", "");
   1.154 +    }
   1.155 +
   1.156 +    /**
   1.157 +     * Get Html Hyper Link string.
   1.158 +     *
   1.159 +     * @param link       String name of the file.
   1.160 +     * @param where      Position of the link in the file. Character '#' is not
   1.161 +     *                   needed.
   1.162 +     * @param label      Tag for the link.
   1.163 +     * @param bold       Boolean that sets label to bold.
   1.164 +     * @param stylename  String style of text defined in style sheet.
   1.165 +     * @param title      String that describes the link's content for accessibility.
   1.166 +     * @param target     Target frame.
   1.167 +     * @return String    Hyper Link.
   1.168 +     */
   1.169 +    public String getHyperLink(String link, String where,
   1.170 +                               String label, boolean bold,
   1.171 +                               String stylename, String title, String target) {
   1.172 +        StringBuffer retlink = new StringBuffer();
   1.173 +        retlink.append("<A HREF=\"");
   1.174 +        retlink.append(link);
   1.175 +        if (where != null && where.length() != 0) {
   1.176 +            retlink.append("#");
   1.177 +            retlink.append(where);
   1.178 +        }
   1.179 +        retlink.append("\"");
   1.180 +        if (title != null && title.length() != 0) {
   1.181 +            retlink.append(" title=\"" + title + "\"");
   1.182 +        }
   1.183 +        if (target != null && target.length() != 0) {
   1.184 +            retlink.append(" target=\"" + target + "\"");
   1.185 +        }
   1.186 +        retlink.append(">");
   1.187 +        if (stylename != null && stylename.length() != 0) {
   1.188 +            retlink.append("<FONT CLASS=\"");
   1.189 +            retlink.append(stylename);
   1.190 +            retlink.append("\">");
   1.191 +        }
   1.192 +        if (bold) {
   1.193 +            retlink.append("<B>");
   1.194 +        }
   1.195 +        retlink.append(label);
   1.196 +        if (bold) {
   1.197 +            retlink.append("</B>");
   1.198 +        }
   1.199 +        if (stylename != null && stylename.length() != 0) {
   1.200 +            retlink.append("</FONT>");
   1.201 +        }
   1.202 +        retlink.append("</A>");
   1.203 +        return retlink.toString();
   1.204 +    }
   1.205 +
   1.206 +    /**
   1.207 +     * Print link without positioning in the file.
   1.208 +     *
   1.209 +     * @param link       String name of the file.
   1.210 +     * @param label      Tag for the link.
   1.211 +     */
   1.212 +    public void printHyperLink(String link, String label) {
   1.213 +        print(getHyperLink(link, "", label, false));
   1.214 +    }
   1.215 +
   1.216 +    /**
   1.217 +     * Get link string without positioning in the file.
   1.218 +     *
   1.219 +     * @param link       String name of the file.
   1.220 +     * @param label      Tag for the link.
   1.221 +     * @return Strign    Hyper link.
   1.222 +     */
   1.223 +    public String getHyperLink(String link, String label) {
   1.224 +        return getHyperLink(link, "", label, false);
   1.225 +    }
   1.226 +
   1.227 +    /**
   1.228 +     * Print the name of the package, this class is in.
   1.229 +     *
   1.230 +     * @param cd    ClassDoc.
   1.231 +     */
   1.232 +    public void printPkgName(ClassDoc cd) {
   1.233 +        print(getPkgName(cd));
   1.234 +    }
   1.235 +
   1.236 +    /**
   1.237 +     * Get the name of the package, this class is in.
   1.238 +     *
   1.239 +     * @param cd    ClassDoc.
   1.240 +     */
   1.241 +    public String getPkgName(ClassDoc cd) {
   1.242 +        String pkgName = cd.containingPackage().name();
   1.243 +        if (pkgName.length() > 0) {
   1.244 +            pkgName += ".";
   1.245 +            return pkgName;
   1.246 +        }
   1.247 +        return "";
   1.248 +    }
   1.249 +
   1.250 +    /**
   1.251 +     * Print the frameset version of the Html file header.
   1.252 +     * Called only when generating an HTML frameset file.
   1.253 +     *
   1.254 +     * @param title    Title of this HTML document.
   1.255 +     */
   1.256 +    public void printFramesetHeader(String title) {
   1.257 +        printFramesetHeader(title, false);
   1.258 +    }
   1.259 +
   1.260 +    /**
   1.261 +     * Print the frameset version of the Html file header.
   1.262 +     * Called only when generating an HTML frameset file.
   1.263 +     *
   1.264 +     * @param title        Title of this HTML document.
   1.265 +     * @param noTimeStamp  If true, don't print time stamp in header.
   1.266 +     */
   1.267 +    public void printFramesetHeader(String title, boolean noTimeStamp) {
   1.268 +        println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 " +
   1.269 +                    "Frameset//EN\" " +
   1.270 +                    "\"http://www.w3.org/TR/html4/frameset.dtd\">");
   1.271 +        println("<!--NewPage-->");
   1.272 +        html();
   1.273 +        head();
   1.274 +        if (! noTimeStamp) {
   1.275 +            print("<!-- Generated by javadoc on ");
   1.276 +            print(today());
   1.277 +            println("-->");
   1.278 +        }
   1.279 +        if (configuration.charset.length() > 0) {
   1.280 +            println("<META http-equiv=\"Content-Type\" content=\"text/html; "
   1.281 +                        + "charset=" + configuration.charset + "\">");
   1.282 +        }
   1.283 +        title();
   1.284 +        println(title);
   1.285 +        titleEnd();
   1.286 +        //Script to set the classFrame if necessary.
   1.287 +        script();
   1.288 +        println("    targetPage = \"\" + window.location.search;");
   1.289 +        println("    if (targetPage != \"\" && targetPage != \"undefined\")");
   1.290 +        println("        targetPage = targetPage.substring(1);");
   1.291 +        println("    if (targetPage.indexOf(\":\") != -1)");
   1.292 +        println("        targetPage = \"undefined\";");
   1.293 +
   1.294 +        println("    function loadFrames() {");
   1.295 +        println("        if (targetPage != \"\" && targetPage != \"undefined\")");
   1.296 +        println("             top.classFrame.location = top.targetPage;");
   1.297 +        println("    }");
   1.298 +        scriptEnd();
   1.299 +        noScript();
   1.300 +        noScriptEnd();
   1.301 +        headEnd();
   1.302 +    }
   1.303 +
   1.304 +    /**
   1.305 +     * Print the appropriate spaces to format the class tree in the class page.
   1.306 +     *
   1.307 +     * @param len   Number of spaces.
   1.308 +     */
   1.309 +    public String spaces(int len) {
   1.310 +        String space = "";
   1.311 +
   1.312 +        for (int i = 0; i < len; i++) {
   1.313 +            space += " ";
   1.314 +        }
   1.315 +        return space;
   1.316 +    }
   1.317 +
   1.318 +    /**
   1.319 +     * Print the closing &lt;/body&gt; and &lt;/html&gt; tags.
   1.320 +     */
   1.321 +    public void printBodyHtmlEnd() {
   1.322 +        println();
   1.323 +        bodyEnd();
   1.324 +        htmlEnd();
   1.325 +    }
   1.326 +
   1.327 +    /**
   1.328 +     * Calls {@link #printBodyHtmlEnd()} method.
   1.329 +     */
   1.330 +    public void printFooter() {
   1.331 +        printBodyHtmlEnd();
   1.332 +    }
   1.333 +
   1.334 +    /**
   1.335 +     * Print closing &lt;/html&gt; tag.
   1.336 +     */
   1.337 +    public void printFrameFooter() {
   1.338 +        htmlEnd();
   1.339 +    }
   1.340 +
   1.341 +    /**
   1.342 +     * Print ten non-breaking spaces("&#38;nbsp;").
   1.343 +     */
   1.344 +    public void printNbsps() {
   1.345 +        print("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
   1.346 +    }
   1.347 +
   1.348 +    /**
   1.349 +     * Get the day and date information for today, depending upon user option.
   1.350 +     *
   1.351 +     * @return String Today.
   1.352 +     * @see java.util.Calendar
   1.353 +     * @see java.util.GregorianCalendar
   1.354 +     * @see java.util.TimeZone
   1.355 +     */
   1.356 +    public String today() {
   1.357 +        Calendar calendar = new GregorianCalendar(TimeZone.getDefault());
   1.358 +        return calendar.getTime().toString();
   1.359 +    }
   1.360 +}

mercurial