/* * @(#)HtmlStandardWriter.java 1.13 98/04/30 * * Copyright 1998 by Sun Microsystems, Inc., * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. * All rights reserved. * * This software is the confidential and proprietary information * of Sun Microsystems, Inc. ("Confidential Information"). You * shall not disclose such Confidential Information and shall use * it only in accordance with the terms of the license agreement * you entered into with Sun. */ package com.sun.tools.doclets.standard; import com.sun.tools.doclets.*; import com.sun.javadoc.*; import java.io.*; import java.util.*; import java.lang.*; import java.text.MessageFormat; /** * Class for the Html Format Code Generation specific to JavaDoc. * This Class contains methods related to the Html Code Generation which * are used by the Sub-Classes: PackageIndexWriter, PackageWriter, * ClassWriter which are Standard Doclets. * Super-Class is HtmlWriter. * * @since JDK1.2 * @author Atul M Dambalkar * @author Robert Field */ public class HtmlStandardWriter extends HtmlDocWriter { public static final String destdir = Standard.configuration().destdirname; public String relativepath = ""; public String path = ""; public String filename = ""; /** * Constructor. Initializes the destination file name through the super * class HtmlWriter. * * @param filename String file name. */ public HtmlStandardWriter(String filename) throws IOException { super(filename); this.filename = filename; } public HtmlStandardWriter(String path, String filename, String relativepath) throws IOException { super(path, filename); this.path = path; this.relativepath = relativepath; this.filename = filename; } /** * Print Html Hyper Link, with target frame. * * @param link String name of the file. * @param where Position in the file * @param target Position of the link in the file. * @param label Tag for the link. */ public void printTargetHyperLink(String link, String where, String target, String label) { println("" + label + ""); } /** * Print Html Hyper Link, with target frame. * * @param link String name of the file. * @param target Position of the link in the file. * @param label Tag for the link. */ public void printTargetHyperLink(String link, String target, String label) { println("" + label + ""); } /** * Print Class link, with target frame. */ public void printTargetClassLink(ClassDoc cd, String target) { String filename = cd.name() + ".html"; printTargetHyperLink(filename, target, (cd.isInterface())? italicsText(cd.name()): cd.name()); } /** * Print the html file header. * * @param title String title for the generated html file. */ public void printHeader(String title) { println(""); println(""); html(); head(); print(""); title(); println(title); titleEnd(); printStyleSheetProperties(); headEnd(); body("white"); println(); } /** * Print user specified header and the footer. * * @param header boolean if true print the header else footer. */ public void printUserHeaderFooter(boolean header) { em(); if (header) { print(Standard.configuration().header); } else { print(Standard.configuration().footer); } emEnd(); } /** * Print the user specified bottom. */ public void printBottom() { hr(); print(Standard.configuration().bottom); // usually empty } protected void navGap() { space(); print('|'); print(' '); } protected void navLinks(boolean header) { if (!Standard.configuration().nonavbar) { if (header) { anchor("navbar_top"); } else { anchor("navbar_bottom"); } table(); tr(); td(); tdEnd(); td(); tdEnd(); td(); tdEnd(); td(); tdEnd(); trEnd(); tr(); tdColspan(3); if (Standard.configuration().packages.length > 0) { navLinkContents(); navGap(); navLinkPackage(); navGap(); } navLinkClass(); if(Standard.configuration().createtree) { navGap(); navLinkTree(); } if(!Standard.configuration().nodeprecatedlist) { navGap(); navLinkDeprecated(); } if(Standard.configuration().createindex) { navGap(); navLinkIndex(); } if (!Standard.configuration().nohelp) { navGap(); navLinkHelp(); } tdEnd(); tdAlignVAlignRowspan("right", "top", 2); printUserHeaderFooter(header); tdEnd(); trEnd(); tr(); td(); font("-2"); navLinkPrevious(); navGap(); navLinkNext(); fontEnd(); tdEnd(); td(); font("-2"); navShowLists(); navGap(); navHideLists(); fontEnd(); tdEnd(); td(); tdEnd(); td(); tdEnd(); trEnd(); printSummaryDetailLinks(); tableEnd(); } } protected void printSummaryDetailLinks() { } /** * Print packages contents link */ protected void navLinkContents() { printHyperLink(relativepath + "overview-summary.html", getText("doclet.Overview")); } /** * Print this package link */ protected void navLinkPackage(PackageDoc pkg) { printPackageLink(pkg, getText("doclet.Package")); } /** * Print this package link */ protected void navLinkPackage() { printText("doclet.Package"); } /** * Print link for previous file. * * @param next String previous link name */ public void navLinkPrevious(String prev) { String tag = getText("doclet.Prev"); if (prev != null) { printHyperLink(prev, tag) ; } else { print(tag); } } /** * Print previous item link */ protected void navLinkPrevious() { navLinkPrevious(null); } /** * Print link for next file. * * @param next String next link name */ public void navLinkNext(String next) { String tag = getText("doclet.Next"); if (next != null) { printHyperLink(next, tag) ; } else { print(tag); } } /** * Print next item link */ protected void navLinkNext() { navLinkNext(null); } /** * Print show lists switch */ protected void navShowLists(String link) { printTargetHyperLink(link, "_top", getText("doclet.FRAMES")); } /** * Print show lists switch */ protected void navShowLists() { navShowLists(relativepath + "index.html"); } /** * Print hide lists switch */ protected void navHideLists(String link) { printTargetHyperLink(link, "_top", getText("doclet.NO_FRAMES")); } /** * Print hide lists switch */ protected void navHideLists() { navHideLists(filename); } protected void navLinkTree() { printHyperLink(relativepath + "tree.html", "", getText("doclet.Tree")); } /** * Print class/interface hierarchy link */ protected void navLinkMainTree(String label) { printHyperLink(relativepath + "tree.html", label); } /** * Print class page indicator */ protected void navLinkClass() { printText("doclet.Class"); } /** * Print deprecated API link */ protected void navLinkDeprecated() { printHyperLink(relativepath + "deprecatedlist.html", getText("doclet.navDeprecated")); } /** * Print link for generated index file, * depending upon the user option. */ protected void navLinkIndex() { printHyperLink(relativepath + (Standard.configuration().splitindex? "index-1.html" : "index-all.html"), getText("doclet.Index")); } /** * Print help file link, considering the user options. */ protected void navLinkHelp() { String helpfilenm = Standard.configuration().helpfile; if (helpfilenm.equals("")) { helpfilenm = "help.html"; } else { int lastsep; if ((lastsep = helpfilenm.lastIndexOf(File.separatorChar)) != -1) { helpfilenm = helpfilenm.substring(lastsep + 1); } } printHyperLink(relativepath + helpfilenm, getText("doclet.Help")); } protected void navDetail() { printText("doclet.Detail"); } protected void navSummary() { printText("doclet.Summary"); } public void tableIndexSummary() { println("\n"); } public void tableIndexDetail() { println("\n
"); } public void tdIndex() { print("
"); } public void tableHeaderStart(String color, int span) { trBgcolorClass(color, "TableSummaryHeadingColor"); tdColspan(span); font("+2"); } public void tableInheritedHeaderStart(String color) { trBgcolorClass(color, "TableInheritedHeadingColor"); tdColspan(2); } public void tableHeaderStart(String color) { tableHeaderStart(color, 2); } public void tableHeaderStart(int span) { tableHeaderStart("#CCCCFF", span); } public void tableHeaderStart() { tableHeaderStart(2); } public void tableHeaderEnd() { fontEnd(); tdEnd(); trEnd(); } public void tableInheritedHeaderEnd() { tdEnd(); trEnd(); } public void summaryRow(int width) { if (width != 0) { tdWidth("" + width + "%"); } else { td(); } } public void summaryRowEnd() { tdEnd(); } public void printIndexHeading(String str) { h2(); print(str); h2End(); } public void frameSet(String arg) { println(""); } public void frameSetEnd() { println(""); } public void frame(String arg) { println(""); } public void frameEnd() { println(""); } /** * Print link for individual package file. */ public void printPackageLink(PackageDoc pkg, String linklabel) { String pathstr = DirectoryManager.createPathString(pkg); String filename = relativepath + ((pathstr.length() > 0)? pathstr + fileseparator: "") + "package-summary.html"; printHyperLink(filename, linklabel); } /** * Print link for individual package file. */ public void printPackageLink(PackageDoc pkg) { printPackageLink(pkg, pkg.name()); } public String italicsClassName(ClassDoc cd, boolean qual) { String name = (qual)? cd.qualifiedName(): cd.name(); return (cd.isInterface())? italicsText(name): name; } public void printClassLinkForSameDir(ClassDoc cd) { if (Standard.configuration().linkall || cd.isIncluded()) { printHyperLink(cd.name() + ".html", "", italicsClassName(cd, false)); } else { print(italicsClassName(cd, true)); } } public void printClassLink(ClassDoc cd) { printClassLink(cd, false); } public void printClassLink(ClassDoc cd, String label) { printClassLink(cd, "", label, false); } public void printClassLink(ClassDoc cd, String where, String label) { printClassLink(cd, where, label, false); } public void printClassLink(ClassDoc cd, boolean bold) { if (Standard.configuration().linkall || cd.isIncluded()) { printClassLink(cd, "", cd.name(), bold); } else { printClassLink(cd, "", cd.qualifiedName(), bold); } } public void printClassLink(ClassDoc cd, String where, String label, boolean bold) { if (Standard.configuration().linkall || cd.isIncluded()) { String pathstr = DirectoryManager.createPathString(cd. containingPackage()); String filename = relativepath + ((pathstr.length() > 0)? pathstr + fileseparator: "") + cd.name() + ".html"; printHyperLink(filename, where, label, bold); } else { print(label); } } public void printQualifiedClassLink(ClassDoc cd) { printClassLink(cd, "", cd.qualifiedName()); } /** * Print Class link, with only class name as the link and prefixing * plain package name. */ public void printPreQualifiedClassLink(ClassDoc cd) { printPkgName(cd); if (Standard.configuration().linkall || cd.isIncluded()) { printClassLink(cd); } else { print(cd.name()); } } /** * Print Class link, with only class name as the bold link and prefixing * plain package name. */ public void printPreQualifiedBoldClassLink(ClassDoc cd) { printPkgName(cd); if (Standard.configuration().linkall || cd.isIncluded()) { printClassLink(cd, true); } else { print(cd.name()); } } public void printText(String key) { print(Standard.configuration().standardmessage.getText(key)); } public void printText(String key, String a1) { print(Standard.configuration().standardmessage.getText(key, a1)); } public void boldText(String key) { bold(Standard.configuration().standardmessage.getText(key)); } public void boldText(String key, String a1) { bold(Standard.configuration().standardmessage.getText(key, a1)); } public String getText(String key) { return Standard.configuration().standardmessage.getText(key); } public void notice(String key, String a1) { Standard.configuration().standardmessage.notice(key, a1); } public void notice(String key, String a1, String a2) { Standard.configuration().standardmessage.notice(key, a1, a2); } public void error(String key, String a1) { Standard.configuration().standardmessage.notice(key, a1); } public void error(String key, String a1, String a2) { Standard.configuration().standardmessage.notice(key, a1, a2); } /** * Print link for any doc element. */ public void printDocLink(Doc doc, String label, boolean bold) { if (doc instanceof PackageDoc) { printPackageLink((PackageDoc)doc, label); } else if (doc instanceof ClassDoc) { printClassLink((ClassDoc)doc, "", label, bold); } else if (doc instanceof ExecutableMemberDoc) { ExecutableMemberDoc emd = (ExecutableMemberDoc)doc; printClassLink(emd.containingClass(), emd.name()+emd.signature(), label, bold); } else if (doc instanceof MemberDoc) { MemberDoc md = (MemberDoc)doc; printClassLink(md.containingClass(), md.name(), label, bold); } else if (doc instanceof RootDoc) { printHyperLink("overview-summary.html", label); } else { print(label); } } public void printDocLink(Doc doc, String label) { printDocLink(doc, label, false); } /** * Print the see tags information given the doc comment. * * @param doc Doc doc * @see com.sun.javadoc.Doc */ public void printSeeTags(Doc doc) { SeeTag[] sees = doc.seeTags(); if (sees.length > 0) { dt(); boldText("doclet.See_Also"); dd(); for (int i = 0; i < sees.length; ++i) { if (i > 0) { print(", "); } printSeeTag(sees[i]); } } if (doc.isClass() && ((ClassDoc)doc).isSerializable()) { if (sees.length > 0) { print(", "); } else { dt(); boldText("doclet.See_Also"); dd(); } printHyperLink(relativepath + "serializedform.html", ((ClassDoc)(doc)).qualifiedName(), getText("doclet.Serialized_Form")); } } public void printSeeTag(SeeTag see) { ClassDoc refClass = see.referencedClass(); MemberDoc refMem = see.referencedMember(); String refMemName = see.referencedMemberName(); String label = see.label(); String text = see.text(); if (refClass == null) { // nothing to link to, just use text print((label.length() == 0)? text: label); } else if (refMemName == null) { // class reference if (label.length() == 0) { printClassLink(refClass); } else { printClassLink(refClass, (label.length() == 0)? text: label); } } else if (refMem == null) { // can't find the member reference print((label.length() == 0)? text: label); } else { // member reference printDocLink(refMem, (label.length() == 0)? refMemName: label); } } /** * Print tag information */ public void generateTagInfo(Doc doc) { Tag[] sinces = doc.tags("since"); Tag[] sees = doc.seeTags(); Tag[] authors; Tag[] versions; if (configuration.showauthor) { authors = doc.tags("author"); } else { authors = new Tag[0]; } if (configuration.showversion) { versions = doc.tags("version"); } else { versions = new Tag[0]; } if (sinces.length > 0 || sees.length > 0 || authors.length > 0 || versions.length > 0 || (doc.isClass() && ((ClassDoc)doc).isSerializable())) { dl(); if (sinces.length > 0) { // There is going to be only one Since tag. dt(); boldText("doclet.Since"); print(' '); dd(); printCommentTags(sinces[0].inlineTags()); ddEnd(); } if (versions.length > 0) { // There is going to be only one Version tag. dt(); boldText("doclet.Version"); print(' '); dd(); printCommentTags(versions[0].inlineTags()); ddEnd(); } for (int i = 0; i < authors.length; ++i) { dt(); boldText("doclet.Author"); print(' '); dd(); printCommentTags(authors[0].inlineTags()); ddEnd(); } printSeeTags(doc); dlEnd(); } } public void printCommentTags(Tag[] commenttags, boolean deprecated) { if (deprecated) { italic(); } for (int i = 0; i < commenttags.length; i++) { Tag tagelem = commenttags[i]; if (tagelem instanceof SeeTag) { printSeeTag((SeeTag)tagelem); } else { print(tagelem.text()); } } if (deprecated) { italicEnd(); } if (commenttags.length == 0) { space(); } } public void printCommentTags(Tag[] commenttags) { printCommentTags(commenttags, false); } public void printStyleSheetProperties() { String filename = Standard.configuration().stylesheetfile; if (filename.length() > 0) { File stylefile = new File(filename); String parent = stylefile.getParent(); filename = (parent == null)? filename: filename.substring(parent.length() + 1); } else { filename = "stylesheet.css"; } filename = relativepath + filename; link("rel =\"stylesheet\" type=\"text/css\" href=\"" + filename + "\" " + "title=\"Style\""); } }