0N/A/*
797N/A * Copyright (c) 1997, 2010, 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) {
765N/A print(getHyperLinkString(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) {
765N/A print(getHyperLinkString(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 */
765N/A public String getHyperLinkString(String link, String where,
181N/A String label, boolean strong) {
765N/A return getHyperLinkString(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 */
765N/A public String getHyperLinkString(String link, String where,
181N/A String label, boolean strong,
0N/A String stylename) {
765N/A return getHyperLinkString(link, where, label, strong, stylename, "", "");
765N/A }
765N/A
765N/A /**
765N/A * Get Html Hyper Link string.
765N/A *
765N/A * @param link String name of the file.
765N/A * @param where Position of the link in the file. Character '#' is not
765N/A * needed.
765N/A * @param label Tag for the link.
765N/A * @return a content tree for the hyper link
765N/A */
765N/A public Content getHyperLink(String link, String where,
765N/A Content label) {
765N/A return getHyperLink(link, where, label, "", "");
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 */
765N/A public String getHyperLinkString(String link, String where,
181N/A String label, boolean strong,
0N/A String stylename, String title, String target) {
0N/A StringBuffer retlink = new StringBuffer();
765N/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) {
765N/A retlink.append("<span class=\"strong\">");
0N/A }
0N/A retlink.append(label);
181N/A if (strong) {
765N/A retlink.append("</span>");
0N/A }
0N/A if (stylename != null && stylename.length() != 0) {
0N/A retlink.append("</FONT>");
0N/A }
765N/A retlink.append("</a>");
0N/A return retlink.toString();
0N/A }
0N/A
0N/A /**
765N/A * Get Html Hyper Link.
0N/A *
0N/A * @param link String name of the file.
765N/A * @param where Position of the link in the file. Character '#' is not
765N/A * needed.
0N/A * @param label Tag for the link.
765N/A * @param title String that describes the link's content for accessibility.
765N/A * @param target Target frame.
765N/A * @return a content tree for the hyper link.
0N/A */
765N/A public Content getHyperLink(String link, String where,
765N/A Content label, String title, String target) {
765N/A if (where != null && where.length() != 0) {
765N/A link += "#" + where;
765N/A }
765N/A HtmlTree anchor = HtmlTree.A(link, label);
765N/A if (title != null && title.length() != 0) {
765N/A anchor.addAttr(HtmlAttr.TITLE, title);
765N/A }
765N/A if (target != null && target.length() != 0) {
765N/A anchor.addAttr(HtmlAttr.TARGET, target);
765N/A }
765N/A return anchor;
765N/A }
765N/A
765N/A /**
765N/A * Get a hyperlink to a file.
765N/A *
765N/A * @param link String name of the file
765N/A * @param label Label for the link
765N/A * @return a content for the hyperlink to the file
765N/A */
765N/A public Content getHyperLink(String link, Content label) {
765N/A return getHyperLink(link, "", label);
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 */
765N/A public String getHyperLinkString(String link, String label) {
765N/A return getHyperLinkString(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 *
765N/A * @param title Title of this HTML document
765N/A * @param noTimeStamp If true, don't print time stamp in header
765N/A * @param frameset the frameset to be added to the HTML document
0N/A */
765N/A public void printFramesetDocument(String title, boolean noTimeStamp,
765N/A Content frameset) {
765N/A Content htmlDocType = DocType.Frameset();
765N/A Content htmlComment = new Comment(configuration.getText("doclet.New_Page"));
765N/A Content head = new HtmlTree(HtmlTag.HEAD);
0N/A if (! noTimeStamp) {
765N/A Content headComment = new Comment("Generated by javadoc on " + today());
765N/A head.addContent(headComment);
0N/A }
0N/A if (configuration.charset.length() > 0) {
765N/A Content meta = HtmlTree.META("Content-Type", "text/html",
765N/A configuration.charset);
765N/A head.addContent(meta);
0N/A }
765N/A Content windowTitle = HtmlTree.TITLE(new StringContent(title));
765N/A head.addContent(windowTitle);
765N/A head.addContent(getFramesetJavaScript());
765N/A Content htmlTree = HtmlTree.HTML(configuration.getLocale().getLanguage(),
765N/A head, frameset);
765N/A Content htmlDocument = new HtmlDocument(htmlDocType,
765N/A htmlComment, htmlTree);
765N/A print(htmlDocument.toString());
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}