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

Tue, 20 Jan 2009 15:17:45 -0800

author
jjg
date
Tue, 20 Jan 2009 15:17:45 -0800
changeset 197
1bf037016426
parent 182
47a62d8d98b4
child 229
03bcd66bd8e7
child 233
5240b1120530
permissions
-rw-r--r--

6794582: javadoc should read files using a FileManager
Reviewed-by: darcy, bpatel

duke@1 1 /*
duke@1 2 * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
duke@1 7 * published by the Free Software Foundation. Sun designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
duke@1 9 * by Sun in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
duke@1 21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@1 22 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@1 23 * have any questions.
duke@1 24 */
duke@1 25
duke@1 26 package com.sun.tools.doclets.formats.html.markup;
duke@1 27
jjg@197 28 import java.io.*;
jjg@197 29 import java.util.*;
duke@1 30
duke@1 31 import com.sun.javadoc.*;
jjg@197 32 import com.sun.tools.doclets.internal.toolkit.*;
duke@1 33
duke@1 34
duke@1 35 /**
duke@1 36 * Class for the Html Format Code Generation specific to JavaDoc.
duke@1 37 * This Class contains methods related to the Html Code Generation which
duke@1 38 * are used by the Sub-Classes in the package com.sun.tools.doclets.standard
duke@1 39 * and com.sun.tools.doclets.oneone.
duke@1 40 *
duke@1 41 * @since 1.2
duke@1 42 * @author Atul M Dambalkar
duke@1 43 * @author Robert Field
duke@1 44 */
duke@1 45 public abstract class HtmlDocWriter extends HtmlWriter {
duke@1 46
duke@1 47 /**
duke@1 48 * Constructor. Initializes the destination file name through the super
duke@1 49 * class HtmlWriter.
duke@1 50 *
duke@1 51 * @param filename String file name.
duke@1 52 */
duke@1 53 public HtmlDocWriter(Configuration configuration,
duke@1 54 String filename) throws IOException {
duke@1 55 super(configuration,
duke@1 56 null, configuration.destDirName + filename,
duke@1 57 configuration.docencoding);
jjg@197 58 // use File to normalize file separators
duke@1 59 configuration.message.notice("doclet.Generating_0",
jjg@197 60 new File(configuration.destDirName, filename));
duke@1 61 }
duke@1 62
duke@1 63 public HtmlDocWriter(Configuration configuration,
duke@1 64 String path, String filename) throws IOException {
duke@1 65 super(configuration,
duke@1 66 configuration.destDirName + path, filename,
duke@1 67 configuration.docencoding);
jjg@197 68 // use File to normalize file separators
duke@1 69 configuration.message.notice("doclet.Generating_0",
jjg@197 70 new File(configuration.destDirName,
jjg@197 71 ((path.length() > 0)? path + File.separator: "") + filename));
duke@1 72 }
duke@1 73
duke@1 74 /**
duke@1 75 * Accessor for configuration.
duke@1 76 */
duke@1 77 public abstract Configuration configuration();
duke@1 78
duke@1 79 /**
duke@1 80 * Print Html Hyper Link.
duke@1 81 *
duke@1 82 * @param link String name of the file.
duke@1 83 * @param where Position of the link in the file. Character '#' is not
duke@1 84 * needed.
duke@1 85 * @param label Tag for the link.
bpatel@182 86 * @param strong Boolean that sets label to strong.
duke@1 87 */
duke@1 88 public void printHyperLink(String link, String where,
bpatel@182 89 String label, boolean strong) {
bpatel@182 90 print(getHyperLink(link, where, label, strong, "", "", ""));
duke@1 91 }
duke@1 92
duke@1 93 /**
duke@1 94 * Print Html Hyper Link.
duke@1 95 *
duke@1 96 * @param link String name of the file.
duke@1 97 * @param where Position of the link in the file. Character '#' is not
duke@1 98 * needed.
duke@1 99 * @param label Tag for the link.
duke@1 100 */
duke@1 101 public void printHyperLink(String link, String where, String label) {
duke@1 102 printHyperLink(link, where, label, false);
duke@1 103 }
duke@1 104
duke@1 105 /**
duke@1 106 * Print Html Hyper Link.
duke@1 107 *
duke@1 108 * @param link String name of the file.
duke@1 109 * @param where Position of the link in the file. Character '#' is not
duke@1 110 * needed.
duke@1 111 * @param label Tag for the link.
bpatel@182 112 * @param strong Boolean that sets label to strong.
duke@1 113 * @param stylename String style of text defined in style sheet.
duke@1 114 */
duke@1 115 public void printHyperLink(String link, String where,
bpatel@182 116 String label, boolean strong,
duke@1 117 String stylename) {
bpatel@182 118 print(getHyperLink(link, where, label, strong, stylename, "", ""));
duke@1 119 }
duke@1 120
duke@1 121 /**
duke@1 122 * Return Html Hyper Link string.
duke@1 123 *
duke@1 124 * @param link String name of the file.
duke@1 125 * @param where Position of the link in the file. Character '#' is not
duke@1 126 * needed.
duke@1 127 * @param label Tag for the link.
bpatel@182 128 * @param strong Boolean that sets label to strong.
duke@1 129 * @return String Hyper Link.
duke@1 130 */
duke@1 131 public String getHyperLink(String link, String where,
bpatel@182 132 String label, boolean strong) {
bpatel@182 133 return getHyperLink(link, where, label, strong, "", "", "");
duke@1 134 }
duke@1 135
duke@1 136 /**
duke@1 137 * Get Html Hyper Link string.
duke@1 138 *
duke@1 139 * @param link String name of the file.
duke@1 140 * @param where Position of the link in the file. Character '#' is not
duke@1 141 * needed.
duke@1 142 * @param label Tag for the link.
bpatel@182 143 * @param strong Boolean that sets label to strong.
duke@1 144 * @param stylename String style of text defined in style sheet.
duke@1 145 * @return String Hyper Link.
duke@1 146 */
duke@1 147 public String getHyperLink(String link, String where,
bpatel@182 148 String label, boolean strong,
duke@1 149 String stylename) {
bpatel@182 150 return getHyperLink(link, where, label, strong, stylename, "", "");
duke@1 151 }
duke@1 152
duke@1 153 /**
duke@1 154 * Get Html Hyper Link string.
duke@1 155 *
duke@1 156 * @param link String name of the file.
duke@1 157 * @param where Position of the link in the file. Character '#' is not
duke@1 158 * needed.
duke@1 159 * @param label Tag for the link.
bpatel@182 160 * @param strong Boolean that sets label to strong.
duke@1 161 * @param stylename String style of text defined in style sheet.
duke@1 162 * @param title String that describes the link's content for accessibility.
duke@1 163 * @param target Target frame.
duke@1 164 * @return String Hyper Link.
duke@1 165 */
duke@1 166 public String getHyperLink(String link, String where,
bpatel@182 167 String label, boolean strong,
duke@1 168 String stylename, String title, String target) {
duke@1 169 StringBuffer retlink = new StringBuffer();
duke@1 170 retlink.append("<A HREF=\"");
duke@1 171 retlink.append(link);
duke@1 172 if (where != null && where.length() != 0) {
duke@1 173 retlink.append("#");
duke@1 174 retlink.append(where);
duke@1 175 }
duke@1 176 retlink.append("\"");
duke@1 177 if (title != null && title.length() != 0) {
duke@1 178 retlink.append(" title=\"" + title + "\"");
duke@1 179 }
duke@1 180 if (target != null && target.length() != 0) {
duke@1 181 retlink.append(" target=\"" + target + "\"");
duke@1 182 }
duke@1 183 retlink.append(">");
duke@1 184 if (stylename != null && stylename.length() != 0) {
duke@1 185 retlink.append("<FONT CLASS=\"");
duke@1 186 retlink.append(stylename);
duke@1 187 retlink.append("\">");
duke@1 188 }
bpatel@182 189 if (strong) {
bpatel@182 190 retlink.append("<STRONG>");
duke@1 191 }
duke@1 192 retlink.append(label);
bpatel@182 193 if (strong) {
bpatel@182 194 retlink.append("</STRONG>");
duke@1 195 }
duke@1 196 if (stylename != null && stylename.length() != 0) {
duke@1 197 retlink.append("</FONT>");
duke@1 198 }
duke@1 199 retlink.append("</A>");
duke@1 200 return retlink.toString();
duke@1 201 }
duke@1 202
duke@1 203 /**
duke@1 204 * Print link without positioning in the file.
duke@1 205 *
duke@1 206 * @param link String name of the file.
duke@1 207 * @param label Tag for the link.
duke@1 208 */
duke@1 209 public void printHyperLink(String link, String label) {
duke@1 210 print(getHyperLink(link, "", label, false));
duke@1 211 }
duke@1 212
duke@1 213 /**
duke@1 214 * Get link string without positioning in the file.
duke@1 215 *
duke@1 216 * @param link String name of the file.
duke@1 217 * @param label Tag for the link.
duke@1 218 * @return Strign Hyper link.
duke@1 219 */
duke@1 220 public String getHyperLink(String link, String label) {
duke@1 221 return getHyperLink(link, "", label, false);
duke@1 222 }
duke@1 223
duke@1 224 /**
duke@1 225 * Print the name of the package, this class is in.
duke@1 226 *
duke@1 227 * @param cd ClassDoc.
duke@1 228 */
duke@1 229 public void printPkgName(ClassDoc cd) {
duke@1 230 print(getPkgName(cd));
duke@1 231 }
duke@1 232
duke@1 233 /**
duke@1 234 * Get the name of the package, this class is in.
duke@1 235 *
duke@1 236 * @param cd ClassDoc.
duke@1 237 */
duke@1 238 public String getPkgName(ClassDoc cd) {
duke@1 239 String pkgName = cd.containingPackage().name();
duke@1 240 if (pkgName.length() > 0) {
duke@1 241 pkgName += ".";
duke@1 242 return pkgName;
duke@1 243 }
duke@1 244 return "";
duke@1 245 }
duke@1 246
duke@1 247 /**
duke@1 248 * Print the frameset version of the Html file header.
duke@1 249 * Called only when generating an HTML frameset file.
duke@1 250 *
duke@1 251 * @param title Title of this HTML document.
duke@1 252 */
duke@1 253 public void printFramesetHeader(String title) {
duke@1 254 printFramesetHeader(title, false);
duke@1 255 }
duke@1 256
duke@1 257 /**
duke@1 258 * Print the frameset version of the Html file header.
duke@1 259 * Called only when generating an HTML frameset file.
duke@1 260 *
duke@1 261 * @param title Title of this HTML document.
duke@1 262 * @param noTimeStamp If true, don't print time stamp in header.
duke@1 263 */
duke@1 264 public void printFramesetHeader(String title, boolean noTimeStamp) {
duke@1 265 println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 " +
duke@1 266 "Frameset//EN\" " +
duke@1 267 "\"http://www.w3.org/TR/html4/frameset.dtd\">");
duke@1 268 println("<!--NewPage-->");
duke@1 269 html();
duke@1 270 head();
duke@1 271 if (! noTimeStamp) {
duke@1 272 print("<!-- Generated by javadoc on ");
duke@1 273 print(today());
duke@1 274 println("-->");
duke@1 275 }
duke@1 276 if (configuration.charset.length() > 0) {
duke@1 277 println("<META http-equiv=\"Content-Type\" content=\"text/html; "
duke@1 278 + "charset=" + configuration.charset + "\">");
duke@1 279 }
duke@1 280 title();
duke@1 281 println(title);
duke@1 282 titleEnd();
duke@1 283 //Script to set the classFrame if necessary.
duke@1 284 script();
duke@1 285 println(" targetPage = \"\" + window.location.search;");
duke@1 286 println(" if (targetPage != \"\" && targetPage != \"undefined\")");
duke@1 287 println(" targetPage = targetPage.substring(1);");
duke@1 288 println(" if (targetPage.indexOf(\":\") != -1)");
duke@1 289 println(" targetPage = \"undefined\";");
duke@1 290
duke@1 291 println(" function loadFrames() {");
duke@1 292 println(" if (targetPage != \"\" && targetPage != \"undefined\")");
duke@1 293 println(" top.classFrame.location = top.targetPage;");
duke@1 294 println(" }");
duke@1 295 scriptEnd();
duke@1 296 noScript();
duke@1 297 noScriptEnd();
duke@1 298 headEnd();
duke@1 299 }
duke@1 300
duke@1 301 /**
duke@1 302 * Print the appropriate spaces to format the class tree in the class page.
duke@1 303 *
duke@1 304 * @param len Number of spaces.
duke@1 305 */
duke@1 306 public String spaces(int len) {
duke@1 307 String space = "";
duke@1 308
duke@1 309 for (int i = 0; i < len; i++) {
duke@1 310 space += " ";
duke@1 311 }
duke@1 312 return space;
duke@1 313 }
duke@1 314
duke@1 315 /**
duke@1 316 * Print the closing &lt;/body&gt; and &lt;/html&gt; tags.
duke@1 317 */
duke@1 318 public void printBodyHtmlEnd() {
duke@1 319 println();
duke@1 320 bodyEnd();
duke@1 321 htmlEnd();
duke@1 322 }
duke@1 323
duke@1 324 /**
duke@1 325 * Calls {@link #printBodyHtmlEnd()} method.
duke@1 326 */
duke@1 327 public void printFooter() {
duke@1 328 printBodyHtmlEnd();
duke@1 329 }
duke@1 330
duke@1 331 /**
duke@1 332 * Print closing &lt;/html&gt; tag.
duke@1 333 */
duke@1 334 public void printFrameFooter() {
duke@1 335 htmlEnd();
duke@1 336 }
duke@1 337
duke@1 338 /**
duke@1 339 * Print ten non-breaking spaces("&#38;nbsp;").
duke@1 340 */
duke@1 341 public void printNbsps() {
duke@1 342 print("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
duke@1 343 }
duke@1 344
duke@1 345 /**
duke@1 346 * Get the day and date information for today, depending upon user option.
duke@1 347 *
duke@1 348 * @return String Today.
duke@1 349 * @see java.util.Calendar
duke@1 350 * @see java.util.GregorianCalendar
duke@1 351 * @see java.util.TimeZone
duke@1 352 */
duke@1 353 public String today() {
duke@1 354 Calendar calendar = new GregorianCalendar(TimeZone.getDefault());
duke@1 355 return calendar.getTime().toString();
duke@1 356 }
duke@1 357 }

mercurial