HtmlDocWriter.java revision 553
0N/A/*
553N/A * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
553N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
553N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
553N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
553N/A * or visit www.oracle.com if you need additional information or have any
553N/A * questions.
0N/A */
0N/A
0N/Apackage com.sun.tools.doclets.formats.html.markup;
0N/A
196N/Aimport java.io.*;
196N/Aimport java.util.*;
0N/A
0N/Aimport com.sun.javadoc.*;
196N/Aimport com.sun.tools.doclets.internal.toolkit.*;
0N/A
0N/A
0N/A/**
0N/A * Class for the Html Format Code Generation specific to JavaDoc.
0N/A * This Class contains methods related to the Html Code Generation which
0N/A * are used by the Sub-Classes in the package com.sun.tools.doclets.standard
0N/A * and com.sun.tools.doclets.oneone.
0N/A *
0N/A * @since 1.2
0N/A * @author Atul M Dambalkar
0N/A * @author Robert Field
0N/A */
0N/Apublic abstract class HtmlDocWriter extends HtmlWriter {
0N/A
0N/A /**
0N/A * Constructor. Initializes the destination file name through the super
0N/A * class HtmlWriter.
0N/A *
0N/A * @param filename String file name.
0N/A */
0N/A public HtmlDocWriter(Configuration configuration,
0N/A String filename) throws IOException {
0N/A super(configuration,
0N/A null, configuration.destDirName + filename,
0N/A configuration.docencoding);
196N/A // use File to normalize file separators
0N/A configuration.message.notice("doclet.Generating_0",
196N/A new File(configuration.destDirName, filename));
0N/A }
0N/A
0N/A public HtmlDocWriter(Configuration configuration,
0N/A String path, String filename) throws IOException {
0N/A super(configuration,
0N/A configuration.destDirName + path, filename,
0N/A configuration.docencoding);
196N/A // use File to normalize file separators
0N/A configuration.message.notice("doclet.Generating_0",
196N/A new File(configuration.destDirName,
196N/A ((path.length() > 0)? path + File.separator: "") + filename));
0N/A }
0N/A
0N/A /**
0N/A * Accessor for configuration.
0N/A */
0N/A public abstract Configuration configuration();
0N/A
0N/A /**
0N/A * Print Html Hyper Link.
0N/A *
0N/A * @param link String name of the file.
0N/A * @param where Position of the link in the file. Character '#' is not
0N/A * needed.
0N/A * @param label Tag for the link.
181N/A * @param strong Boolean that sets label to strong.
0N/A */
0N/A public void printHyperLink(String link, String where,
181N/A String label, boolean strong) {
181N/A print(getHyperLink(link, where, label, strong, "", "", ""));
0N/A }
0N/A
0N/A /**
0N/A * Print Html Hyper Link.
0N/A *
0N/A * @param link String name of the file.
0N/A * @param where Position of the link in the file. Character '#' is not
0N/A * needed.
0N/A * @param label Tag for the link.
0N/A */
0N/A public void printHyperLink(String link, String where, String label) {
0N/A printHyperLink(link, where, label, false);
0N/A }
0N/A
0N/A /**
0N/A * Print Html Hyper Link.
0N/A *
0N/A * @param link String name of the file.
0N/A * @param where Position of the link in the file. Character '#' is not
0N/A * needed.
0N/A * @param label Tag for the link.
181N/A * @param strong Boolean that sets label to strong.
0N/A * @param stylename String style of text defined in style sheet.
0N/A */
0N/A public void printHyperLink(String link, String where,
181N/A String label, boolean strong,
0N/A String stylename) {
181N/A print(getHyperLink(link, where, label, strong, stylename, "", ""));
0N/A }
0N/A
0N/A /**
0N/A * Return Html Hyper Link string.
0N/A *
0N/A * @param link String name of the file.
0N/A * @param where Position of the link in the file. Character '#' is not
0N/A * needed.
0N/A * @param label Tag for the link.
181N/A * @param strong Boolean that sets label to strong.
0N/A * @return String Hyper Link.
0N/A */
0N/A public String getHyperLink(String link, String where,
181N/A String label, boolean strong) {
181N/A return getHyperLink(link, where, label, strong, "", "", "");
0N/A }
0N/A
0N/A /**
0N/A * Get Html Hyper Link string.
0N/A *
0N/A * @param link String name of the file.
0N/A * @param where Position of the link in the file. Character '#' is not
0N/A * needed.
0N/A * @param label Tag for the link.
181N/A * @param strong Boolean that sets label to strong.
0N/A * @param stylename String style of text defined in style sheet.
0N/A * @return String Hyper Link.
0N/A */
0N/A public String getHyperLink(String link, String where,
181N/A String label, boolean strong,
0N/A String stylename) {
181N/A return getHyperLink(link, where, label, strong, stylename, "", "");
0N/A }
0N/A
0N/A /**
0N/A * Get Html Hyper Link string.
0N/A *
0N/A * @param link String name of the file.
0N/A * @param where Position of the link in the file. Character '#' is not
0N/A * needed.
0N/A * @param label Tag for the link.
181N/A * @param strong Boolean that sets label to strong.
0N/A * @param stylename String style of text defined in style sheet.
0N/A * @param title String that describes the link's content for accessibility.
0N/A * @param target Target frame.
0N/A * @return String Hyper Link.
0N/A */
0N/A public String getHyperLink(String link, String where,
181N/A String label, boolean strong,
0N/A String stylename, String title, String target) {
0N/A StringBuffer retlink = new StringBuffer();
0N/A retlink.append("<A HREF=\"");
0N/A retlink.append(link);
0N/A if (where != null && where.length() != 0) {
0N/A retlink.append("#");
0N/A retlink.append(where);
0N/A }
0N/A retlink.append("\"");
0N/A if (title != null && title.length() != 0) {
0N/A retlink.append(" title=\"" + title + "\"");
0N/A }
0N/A if (target != null && target.length() != 0) {
0N/A retlink.append(" target=\"" + target + "\"");
0N/A }
0N/A retlink.append(">");
0N/A if (stylename != null && stylename.length() != 0) {
0N/A retlink.append("<FONT CLASS=\"");
0N/A retlink.append(stylename);
0N/A retlink.append("\">");
0N/A }
181N/A if (strong) {
181N/A retlink.append("<STRONG>");
0N/A }
0N/A retlink.append(label);
181N/A if (strong) {
181N/A retlink.append("</STRONG>");
0N/A }
0N/A if (stylename != null && stylename.length() != 0) {
0N/A retlink.append("</FONT>");
0N/A }
0N/A retlink.append("</A>");
0N/A return retlink.toString();
0N/A }
0N/A
0N/A /**
0N/A * Print link without positioning in the file.
0N/A *
0N/A * @param link String name of the file.
0N/A * @param label Tag for the link.
0N/A */
0N/A public void printHyperLink(String link, String label) {
0N/A print(getHyperLink(link, "", label, false));
0N/A }
0N/A
0N/A /**
0N/A * Get link string without positioning in the file.
0N/A *
0N/A * @param link String name of the file.
0N/A * @param label Tag for the link.
0N/A * @return Strign Hyper link.
0N/A */
0N/A public String getHyperLink(String link, String label) {
0N/A return getHyperLink(link, "", label, false);
0N/A }
0N/A
0N/A /**
0N/A * Print the name of the package, this class is in.
0N/A *
0N/A * @param cd ClassDoc.
0N/A */
0N/A public void printPkgName(ClassDoc cd) {
0N/A print(getPkgName(cd));
0N/A }
0N/A
0N/A /**
0N/A * Get the name of the package, this class is in.
0N/A *
0N/A * @param cd ClassDoc.
0N/A */
0N/A public String getPkgName(ClassDoc cd) {
0N/A String pkgName = cd.containingPackage().name();
0N/A if (pkgName.length() > 0) {
0N/A pkgName += ".";
0N/A return pkgName;
0N/A }
0N/A return "";
0N/A }
0N/A
0N/A /**
232N/A * Keep track of member details list. Print the definition list start tag
232N/A * if it is not printed yet.
232N/A */
232N/A public void printMemberDetailsListStartTag () {
232N/A if (!getMemberDetailsListPrinted()) {
232N/A dl();
232N/A memberDetailsListPrinted = true;
232N/A }
232N/A }
232N/A
232N/A /**
232N/A * Print the definition list end tag if the list start tag was printed.
232N/A */
232N/A public void printMemberDetailsListEndTag () {
232N/A if (getMemberDetailsListPrinted()) {
232N/A dlEnd();
232N/A memberDetailsListPrinted = false;
232N/A }
232N/A }
232N/A
232N/A public boolean getMemberDetailsListPrinted() {
232N/A return memberDetailsListPrinted;
232N/A }
232N/A
232N/A /**
0N/A * Print the frameset version of the Html file header.
0N/A * Called only when generating an HTML frameset file.
0N/A *
0N/A * @param title Title of this HTML document.
0N/A */
0N/A public void printFramesetHeader(String title) {
0N/A printFramesetHeader(title, false);
0N/A }
0N/A
0N/A /**
0N/A * Print the frameset version of the Html file header.
0N/A * Called only when generating an HTML frameset file.
0N/A *
0N/A * @param title Title of this HTML document.
0N/A * @param noTimeStamp If true, don't print time stamp in header.
0N/A */
0N/A public void printFramesetHeader(String title, boolean noTimeStamp) {
0N/A println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 " +
0N/A "Frameset//EN\" " +
0N/A "\"http://www.w3.org/TR/html4/frameset.dtd\">");
0N/A println("<!--NewPage-->");
0N/A html();
0N/A head();
0N/A if (! noTimeStamp) {
0N/A print("<!-- Generated by javadoc on ");
0N/A print(today());
0N/A println("-->");
0N/A }
0N/A if (configuration.charset.length() > 0) {
0N/A println("<META http-equiv=\"Content-Type\" content=\"text/html; "
0N/A + "charset=" + configuration.charset + "\">");
0N/A }
0N/A title();
0N/A println(title);
0N/A titleEnd();
0N/A //Script to set the classFrame if necessary.
0N/A script();
0N/A println(" targetPage = \"\" + window.location.search;");
0N/A println(" if (targetPage != \"\" && targetPage != \"undefined\")");
0N/A println(" targetPage = targetPage.substring(1);");
0N/A println(" if (targetPage.indexOf(\":\") != -1)");
0N/A println(" targetPage = \"undefined\";");
0N/A
0N/A println(" function loadFrames() {");
0N/A println(" if (targetPage != \"\" && targetPage != \"undefined\")");
0N/A println(" top.classFrame.location = top.targetPage;");
0N/A println(" }");
0N/A scriptEnd();
0N/A noScript();
0N/A noScriptEnd();
0N/A headEnd();
0N/A }
0N/A
0N/A /**
0N/A * Print the appropriate spaces to format the class tree in the class page.
0N/A *
0N/A * @param len Number of spaces.
0N/A */
0N/A public String spaces(int len) {
0N/A String space = "";
0N/A
0N/A for (int i = 0; i < len; i++) {
0N/A space += " ";
0N/A }
0N/A return space;
0N/A }
0N/A
0N/A /**
0N/A * Print the closing &lt;/body&gt; and &lt;/html&gt; tags.
0N/A */
0N/A public void printBodyHtmlEnd() {
0N/A println();
0N/A bodyEnd();
0N/A htmlEnd();
0N/A }
0N/A
0N/A /**
0N/A * Calls {@link #printBodyHtmlEnd()} method.
0N/A */
0N/A public void printFooter() {
0N/A printBodyHtmlEnd();
0N/A }
0N/A
0N/A /**
0N/A * Print closing &lt;/html&gt; tag.
0N/A */
0N/A public void printFrameFooter() {
0N/A htmlEnd();
0N/A }
0N/A
0N/A /**
0N/A * Print ten non-breaking spaces("&#38;nbsp;").
0N/A */
0N/A public void printNbsps() {
0N/A print("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
0N/A }
0N/A
0N/A /**
0N/A * Get the day and date information for today, depending upon user option.
0N/A *
0N/A * @return String Today.
0N/A * @see java.util.Calendar
0N/A * @see java.util.GregorianCalendar
0N/A * @see java.util.TimeZone
0N/A */
0N/A public String today() {
0N/A Calendar calendar = new GregorianCalendar(TimeZone.getDefault());
0N/A return calendar.getTime().toString();
0N/A }
0N/A}