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