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

Tue, 14 May 2013 10:14:53 -0700

author
jjg
date
Tue, 14 May 2013 10:14:53 -0700
changeset 1740
ce4f0769b4b2
parent 1737
7a9ef837e57f
child 1746
bd51ca92c013
permissions
-rw-r--r--

8011668: Allow HTMLWriter.getResource to take Content args
Reviewed-by: darcy

duke@1 1 /*
jjg@1737 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. 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
ohair@554 7 * published by the Free Software Foundation. Oracle designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
ohair@554 9 * by Oracle 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 *
ohair@554 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 22 * or visit www.oracle.com if you need additional information or have any
ohair@554 23 * 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@1361 32 import com.sun.tools.doclets.formats.html.ConfigurationImpl;
jjg@197 33 import com.sun.tools.doclets.internal.toolkit.*;
jjg@1412 34 import com.sun.tools.doclets.internal.toolkit.util.DocFile;
jjg@1373 35 import com.sun.tools.doclets.internal.toolkit.util.DocLink;
jjg@1372 36 import com.sun.tools.doclets.internal.toolkit.util.DocPath;
duke@1 37
duke@1 38
duke@1 39 /**
duke@1 40 * Class for the Html Format Code Generation specific to JavaDoc.
duke@1 41 * This Class contains methods related to the Html Code Generation which
duke@1 42 * are used by the Sub-Classes in the package com.sun.tools.doclets.standard
duke@1 43 * and com.sun.tools.doclets.oneone.
duke@1 44 *
jjg@1359 45 * <p><b>This is NOT part of any supported API.
jjg@1359 46 * If you write code that depends on this, you do so at your own risk.
jjg@1359 47 * This code and its internal interfaces are subject to change or
jjg@1359 48 * deletion without notice.</b>
jjg@1359 49 *
duke@1 50 * @since 1.2
duke@1 51 * @author Atul M Dambalkar
duke@1 52 * @author Robert Field
duke@1 53 */
duke@1 54 public abstract class HtmlDocWriter extends HtmlWriter {
duke@1 55
duke@1 56 /**
duke@1 57 * Constructor. Initializes the destination file name through the super
duke@1 58 * class HtmlWriter.
duke@1 59 *
duke@1 60 * @param filename String file name.
duke@1 61 */
jjg@1372 62 public HtmlDocWriter(Configuration configuration, DocPath filename)
jjg@1372 63 throws IOException {
jjg@1372 64 super(configuration, filename);
duke@1 65 configuration.message.notice("doclet.Generating_0",
jjg@1412 66 DocFile.createFileForOutput(configuration, filename).getPath());
duke@1 67 }
duke@1 68
duke@1 69 /**
duke@1 70 * Accessor for configuration.
duke@1 71 */
duke@1 72 public abstract Configuration configuration();
duke@1 73
duke@1 74 /**
jjg@1737 75 * Return Html hyperlink string.
duke@1 76 *
duke@1 77 * @param link String name of the file.
duke@1 78 * @param label Tag for the link.
duke@1 79 * @return String Hyper Link.
duke@1 80 */
jjg@1737 81 public String getHyperLinkString(DocPath link, String label) {
jjg@1737 82 return getHyperLinkString(link, label, false, "", "", "");
jjg@1373 83 }
jjg@1373 84
jjg@1740 85 public Content getHyperLink(DocPath link, String label) {
jjg@1740 86 return getHyperLink(link, new StringContent(label), false, "", "", "");
jjg@1740 87 }
jjg@1740 88
jjg@1737 89 public String getHyperLinkString(DocLink link, String label) {
jjg@1737 90 return getHyperLinkString(link, label, false, "", "", "");
duke@1 91 }
duke@1 92
duke@1 93 /**
duke@1 94 * Get Html Hyper Link string.
duke@1 95 *
duke@1 96 * @param link String name of the file.
duke@1 97 * @param label Tag for the link.
bpatel@182 98 * @param strong Boolean that sets label to strong.
duke@1 99 * @param stylename String style of text defined in style sheet.
duke@1 100 * @return String Hyper Link.
duke@1 101 */
jjg@1373 102 public String getHyperLinkString(DocPath link,
bpatel@182 103 String label, boolean strong,
duke@1 104 String stylename) {
jjg@1373 105 return getHyperLinkString(link, label, strong, stylename, "", "");
jjg@1373 106 }
jjg@1373 107
jjg@1373 108 public String getHyperLinkString(DocLink link,
jjg@1373 109 String label, boolean strong,
jjg@1373 110 String stylename) {
jjg@1373 111 return getHyperLinkString(link, label, strong, stylename, "", "");
bpatel@766 112 }
bpatel@766 113
bpatel@766 114 /**
bpatel@766 115 * Get Html Hyper Link string.
bpatel@766 116 *
jjg@1372 117 * @param where Position of the link in the file. Character '#' is not
jjg@1372 118 * needed.
jjg@1372 119 * @param label Tag for the link.
jjg@1372 120 * @return a content tree for the hyper link
jjg@1372 121 */
jjg@1372 122 public Content getHyperLink(String where,
jjg@1372 123 Content label) {
jjg@1373 124 return getHyperLink(DocLink.fragment(where), label, "", "");
jjg@1372 125 }
jjg@1372 126
jjg@1372 127 /**
jjg@1737 128 * Get Html hyperlink.
jjg@1372 129 *
jjg@1737 130 * @param link path of the file.
bpatel@766 131 * @param label Tag for the link.
bpatel@766 132 * @return a content tree for the hyper link
bpatel@766 133 */
jjg@1737 134 public Content getHyperLink(DocPath link, Content label) {
jjg@1373 135 return getHyperLink(link, label, "", "");
jjg@1373 136 }
jjg@1373 137
jjg@1737 138 public Content getHyperLink(DocLink link, Content label) {
jjg@1373 139 return getHyperLink(link, label, "", "");
duke@1 140 }
duke@1 141
duke@1 142 /**
duke@1 143 * Get Html Hyper Link string.
duke@1 144 *
duke@1 145 * @param link String name of the file.
duke@1 146 * @param label Tag for the link.
bpatel@182 147 * @param strong Boolean that sets label to strong.
duke@1 148 * @param stylename String style of text defined in style sheet.
jjg@1373 149 * @param title String that describes the links content for accessibility.
duke@1 150 * @param target Target frame.
duke@1 151 * @return String Hyper Link.
duke@1 152 */
jjg@1373 153 public String getHyperLinkString(DocPath link,
jjg@1372 154 String label, boolean strong,
jjg@1372 155 String stylename, String title, String target) {
jjg@1373 156 return getHyperLinkString(new DocLink(link), label, strong,
jjg@1372 157 stylename, title, target);
jjg@1372 158 }
jjg@1372 159
jjg@1373 160 public String getHyperLinkString(DocLink link,
bpatel@182 161 String label, boolean strong,
duke@1 162 String stylename, String title, String target) {
jjg@1362 163 StringBuilder retlink = new StringBuilder();
jjg@1373 164 retlink.append("<a href=\"").append(link).append('"');
duke@1 165 if (title != null && title.length() != 0) {
jjg@1373 166 retlink.append(" title=\"").append(title).append('"');
duke@1 167 }
duke@1 168 if (target != null && target.length() != 0) {
jjg@1373 169 retlink.append(" target=\"").append(target).append('"');
duke@1 170 }
duke@1 171 retlink.append(">");
duke@1 172 if (stylename != null && stylename.length() != 0) {
duke@1 173 retlink.append("<FONT CLASS=\"");
duke@1 174 retlink.append(stylename);
duke@1 175 retlink.append("\">");
duke@1 176 }
bpatel@182 177 if (strong) {
bpatel@766 178 retlink.append("<span class=\"strong\">");
duke@1 179 }
duke@1 180 retlink.append(label);
bpatel@182 181 if (strong) {
bpatel@766 182 retlink.append("</span>");
duke@1 183 }
duke@1 184 if (stylename != null && stylename.length() != 0) {
duke@1 185 retlink.append("</FONT>");
duke@1 186 }
bpatel@766 187 retlink.append("</a>");
duke@1 188 return retlink.toString();
duke@1 189 }
duke@1 190
jjg@1740 191 public Content getHyperLink(DocPath link,
jjg@1740 192 Content label, boolean strong,
jjg@1740 193 String stylename, String title, String target) {
jjg@1740 194 return getHyperLink(new DocLink(link), label, strong,
jjg@1740 195 stylename, title, target);
jjg@1740 196 }
jjg@1740 197
jjg@1737 198 public Content getHyperLink(DocLink link,
jjg@1737 199 Content label, boolean strong,
jjg@1737 200 String stylename, String title, String target) {
jjg@1737 201 Content body = label;
jjg@1737 202 if (strong) {
jjg@1737 203 body = HtmlTree.SPAN(HtmlStyle.strong, body);
jjg@1737 204 }
jjg@1737 205 if (stylename != null && stylename.length() != 0) {
jjg@1737 206 HtmlTree t = new HtmlTree(HtmlTag.FONT, body);
jjg@1737 207 t.addAttr(HtmlAttr.CLASS, stylename);
jjg@1737 208 body = t;
jjg@1737 209 }
jjg@1737 210 HtmlTree l = HtmlTree.A(link.toString(), body);
jjg@1737 211 if (title != null && title.length() != 0) {
jjg@1737 212 l.addAttr(HtmlAttr.TITLE, title);
jjg@1737 213 }
jjg@1737 214 if (target != null && target.length() != 0) {
jjg@1737 215 l.addAttr(HtmlAttr.TARGET, target);
jjg@1737 216 }
jjg@1737 217 return l;
jjg@1737 218 }
jjg@1737 219
duke@1 220 /**
bpatel@766 221 * Get Html Hyper Link.
duke@1 222 *
duke@1 223 * @param link String name of the file.
duke@1 224 * @param label Tag for the link.
bpatel@766 225 * @param title String that describes the link's content for accessibility.
bpatel@766 226 * @param target Target frame.
bpatel@766 227 * @return a content tree for the hyper link.
duke@1 228 */
jjg@1373 229 public Content getHyperLink(DocPath link,
jjg@1372 230 Content label, String title, String target) {
jjg@1373 231 return getHyperLink(new DocLink(link), label, title, target);
jjg@1372 232 }
jjg@1373 233
jjg@1373 234 public Content getHyperLink(DocLink link,
bpatel@766 235 Content label, String title, String target) {
jjg@1373 236 HtmlTree anchor = HtmlTree.A(link.toString(), label);
bpatel@766 237 if (title != null && title.length() != 0) {
bpatel@766 238 anchor.addAttr(HtmlAttr.TITLE, title);
bpatel@766 239 }
bpatel@766 240 if (target != null && target.length() != 0) {
bpatel@766 241 anchor.addAttr(HtmlAttr.TARGET, target);
bpatel@766 242 }
bpatel@766 243 return anchor;
bpatel@766 244 }
bpatel@766 245
bpatel@766 246 /**
duke@1 247 * Get the name of the package, this class is in.
duke@1 248 *
duke@1 249 * @param cd ClassDoc.
duke@1 250 */
duke@1 251 public String getPkgName(ClassDoc cd) {
duke@1 252 String pkgName = cd.containingPackage().name();
duke@1 253 if (pkgName.length() > 0) {
duke@1 254 pkgName += ".";
duke@1 255 return pkgName;
duke@1 256 }
duke@1 257 return "";
duke@1 258 }
duke@1 259
bpatel@233 260 public boolean getMemberDetailsListPrinted() {
bpatel@233 261 return memberDetailsListPrinted;
bpatel@233 262 }
bpatel@233 263
bpatel@233 264 /**
duke@1 265 * Print the frameset version of the Html file header.
duke@1 266 * Called only when generating an HTML frameset file.
duke@1 267 *
bpatel@766 268 * @param title Title of this HTML document
bpatel@766 269 * @param noTimeStamp If true, don't print time stamp in header
bpatel@766 270 * @param frameset the frameset to be added to the HTML document
duke@1 271 */
bpatel@766 272 public void printFramesetDocument(String title, boolean noTimeStamp,
jjg@1364 273 Content frameset) throws IOException {
jjg@1410 274 Content htmlDocType = DocType.FRAMESET;
bpatel@766 275 Content htmlComment = new Comment(configuration.getText("doclet.New_Page"));
bpatel@766 276 Content head = new HtmlTree(HtmlTag.HEAD);
duke@1 277 if (! noTimeStamp) {
jjg@1361 278 Content headComment = new Comment(getGeneratedByString());
bpatel@766 279 head.addContent(headComment);
duke@1 280 }
duke@1 281 if (configuration.charset.length() > 0) {
bpatel@766 282 Content meta = HtmlTree.META("Content-Type", "text/html",
bpatel@766 283 configuration.charset);
bpatel@766 284 head.addContent(meta);
duke@1 285 }
bpatel@766 286 Content windowTitle = HtmlTree.TITLE(new StringContent(title));
bpatel@766 287 head.addContent(windowTitle);
bpatel@766 288 head.addContent(getFramesetJavaScript());
bpatel@766 289 Content htmlTree = HtmlTree.HTML(configuration.getLocale().getLanguage(),
bpatel@766 290 head, frameset);
bpatel@766 291 Content htmlDocument = new HtmlDocument(htmlDocType,
bpatel@766 292 htmlComment, htmlTree);
jjg@1365 293 write(htmlDocument);
duke@1 294 }
duke@1 295
jjg@1361 296 protected String getGeneratedByString() {
duke@1 297 Calendar calendar = new GregorianCalendar(TimeZone.getDefault());
jjg@1361 298 Date today = calendar.getTime();
jjg@1361 299 return "Generated by javadoc ("+ ConfigurationImpl.BUILD_DATE + ") on " + today;
duke@1 300 }
duke@1 301 }

mercurial