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

Wed, 31 Oct 2012 13:48:15 -0700

author
jjg
date
Wed, 31 Oct 2012 13:48:15 -0700
changeset 1383
b980e8e6aabf
parent 1381
23fe1a96bc0f
child 1417
522a1ee72340
permissions
-rw-r--r--

8001664: refactor javadoc to use abstraction to handle files
Reviewed-by: darcy

duke@1 1 /*
jjg@1358 2 * Copyright (c) 1997, 2012, 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
bpatel@233 28 import java.io.*;
bpatel@233 29
duke@1 30 import com.sun.tools.doclets.internal.toolkit.*;
duke@1 31 import com.sun.tools.doclets.internal.toolkit.util.*;
duke@1 32
duke@1 33 /**
duke@1 34 * Class for the Html format code generation.
jjg@1365 35 * Initializes PrintWriter with FileWriter, to enable print
duke@1 36 * related methods to generate the code to the named File through FileWriter.
duke@1 37 *
jjg@1359 38 * <p><b>This is NOT part of any supported API.
jjg@1359 39 * If you write code that depends on this, you do so at your own risk.
jjg@1359 40 * This code and its internal interfaces are subject to change or
jjg@1359 41 * deletion without notice.</b>
jjg@1359 42 *
duke@1 43 * @since 1.2
duke@1 44 * @author Atul M Dambalkar
bpatel@243 45 * @author Bhavesh Patel (Modified)
duke@1 46 */
jjg@1365 47 public class HtmlWriter {
duke@1 48
duke@1 49 /**
duke@1 50 * The window title of this file
duke@1 51 */
duke@1 52 protected String winTitle;
duke@1 53
duke@1 54 /**
duke@1 55 * The configuration
duke@1 56 */
duke@1 57 protected Configuration configuration;
duke@1 58
duke@1 59 /**
bpatel@233 60 * The flag to indicate whether a member details list is printed or not.
bpatel@233 61 */
bpatel@233 62 protected boolean memberDetailsListPrinted;
bpatel@233 63
bpatel@233 64 /**
bpatel@243 65 * Header for tables displaying packages and description..
bpatel@243 66 */
bpatel@243 67 protected final String[] packageTableHeader;
bpatel@243 68
bpatel@243 69 /**
bpatel@243 70 * Summary for use tables displaying class and package use.
bpatel@243 71 */
bpatel@243 72 protected final String useTableSummary;
bpatel@243 73
bpatel@243 74 /**
bpatel@243 75 * Column header for class docs displaying Modifier and Type header.
bpatel@243 76 */
bpatel@243 77 protected final String modifierTypeHeader;
bpatel@243 78
bpatel@766 79 public final Content overviewLabel;
bpatel@766 80
bpatel@766 81 public final Content defaultPackageLabel;
bpatel@766 82
bpatel@766 83 public final Content packageLabel;
bpatel@766 84
bpatel@766 85 public final Content useLabel;
bpatel@766 86
bpatel@766 87 public final Content prevLabel;
bpatel@766 88
bpatel@766 89 public final Content nextLabel;
bpatel@766 90
bpatel@766 91 public final Content prevclassLabel;
bpatel@766 92
bpatel@766 93 public final Content nextclassLabel;
bpatel@766 94
bpatel@766 95 public final Content summaryLabel;
bpatel@766 96
bpatel@766 97 public final Content detailLabel;
bpatel@766 98
bpatel@766 99 public final Content framesLabel;
bpatel@766 100
bpatel@766 101 public final Content noframesLabel;
bpatel@766 102
bpatel@766 103 public final Content treeLabel;
bpatel@766 104
bpatel@766 105 public final Content classLabel;
bpatel@766 106
bpatel@766 107 public final Content deprecatedLabel;
bpatel@766 108
bpatel@766 109 public final Content deprecatedPhrase;
bpatel@766 110
bpatel@766 111 public final Content allclassesLabel;
bpatel@766 112
bpatel@766 113 public final Content indexLabel;
bpatel@766 114
bpatel@766 115 public final Content helpLabel;
bpatel@766 116
bpatel@766 117 public final Content seeLabel;
bpatel@766 118
bpatel@766 119 public final Content descriptionLabel;
bpatel@766 120
bpatel@766 121 public final Content prevpackageLabel;
bpatel@766 122
bpatel@766 123 public final Content nextpackageLabel;
bpatel@766 124
bpatel@766 125 public final Content packagesLabel;
bpatel@766 126
bpatel@766 127 public final Content methodDetailsLabel;
bpatel@766 128
bpatel@766 129 public final Content annotationTypeDetailsLabel;
bpatel@766 130
bpatel@766 131 public final Content fieldDetailsLabel;
bpatel@766 132
bpatel@766 133 public final Content constructorDetailsLabel;
bpatel@766 134
bpatel@766 135 public final Content enumConstantsDetailsLabel;
bpatel@766 136
bpatel@766 137 public final Content specifiedByLabel;
bpatel@766 138
bpatel@766 139 public final Content overridesLabel;
bpatel@766 140
bpatel@766 141 public final Content descfrmClassLabel;
bpatel@766 142
bpatel@766 143 public final Content descfrmInterfaceLabel;
bpatel@766 144
jjg@1365 145 private final Writer writer;
jjg@1365 146
bpatel@243 147 /**
duke@1 148 * Constructor.
duke@1 149 *
duke@1 150 * @param path The directory path to be created for this file
duke@1 151 * or null if none to be created.
duke@1 152 * @exception IOException Exception raised by the FileWriter is passed on
duke@1 153 * to next level.
jjg@1358 154 * @exception UnsupportedEncodingException Exception raised by the
duke@1 155 * OutputStreamWriter is passed on to next level.
duke@1 156 */
jjg@1381 157 public HtmlWriter(Configuration configuration, DocPath path)
jjg@1372 158 throws IOException, UnsupportedEncodingException {
jjg@1383 159 writer = DocFile.createFileForOutput(configuration, path).openWriter();
duke@1 160 this.configuration = configuration;
bpatel@233 161 this.memberDetailsListPrinted = false;
bpatel@243 162 packageTableHeader = new String[] {
bpatel@243 163 configuration.getText("doclet.Package"),
bpatel@243 164 configuration.getText("doclet.Description")
bpatel@243 165 };
bpatel@243 166 useTableSummary = configuration.getText("doclet.Use_Table_Summary",
bpatel@243 167 configuration.getText("doclet.packages"));
bpatel@243 168 modifierTypeHeader = configuration.getText("doclet.0_and_1",
bpatel@243 169 configuration.getText("doclet.Modifier"),
bpatel@243 170 configuration.getText("doclet.Type"));
bpatel@766 171 overviewLabel = getResource("doclet.Overview");
bpatel@766 172 defaultPackageLabel = new RawHtml(
bpatel@766 173 DocletConstants.DEFAULT_PACKAGE_NAME);
bpatel@766 174 packageLabel = getResource("doclet.Package");
bpatel@766 175 useLabel = getResource("doclet.navClassUse");
bpatel@766 176 prevLabel = getResource("doclet.Prev");
bpatel@766 177 nextLabel = getResource("doclet.Next");
bpatel@766 178 prevclassLabel = getResource("doclet.Prev_Class");
bpatel@766 179 nextclassLabel = getResource("doclet.Next_Class");
bpatel@766 180 summaryLabel = getResource("doclet.Summary");
bpatel@766 181 detailLabel = getResource("doclet.Detail");
bpatel@942 182 framesLabel = getResource("doclet.Frames");
bpatel@942 183 noframesLabel = getResource("doclet.No_Frames");
bpatel@766 184 treeLabel = getResource("doclet.Tree");
bpatel@766 185 classLabel = getResource("doclet.Class");
bpatel@766 186 deprecatedLabel = getResource("doclet.navDeprecated");
bpatel@766 187 deprecatedPhrase = getResource("doclet.Deprecated");
bpatel@766 188 allclassesLabel = getResource("doclet.All_Classes");
bpatel@766 189 indexLabel = getResource("doclet.Index");
bpatel@766 190 helpLabel = getResource("doclet.Help");
bpatel@766 191 seeLabel = getResource("doclet.See");
bpatel@766 192 descriptionLabel = getResource("doclet.Description");
bpatel@766 193 prevpackageLabel = getResource("doclet.Prev_Package");
bpatel@766 194 nextpackageLabel = getResource("doclet.Next_Package");
bpatel@766 195 packagesLabel = getResource("doclet.Packages");
bpatel@766 196 methodDetailsLabel = getResource("doclet.Method_Detail");
bpatel@766 197 annotationTypeDetailsLabel = getResource("doclet.Annotation_Type_Member_Detail");
bpatel@766 198 fieldDetailsLabel = getResource("doclet.Field_Detail");
bpatel@766 199 constructorDetailsLabel = getResource("doclet.Constructor_Detail");
bpatel@766 200 enumConstantsDetailsLabel = getResource("doclet.Enum_Constant_Detail");
bpatel@766 201 specifiedByLabel = getResource("doclet.Specified_By");
bpatel@766 202 overridesLabel = getResource("doclet.Overrides");
bpatel@766 203 descfrmClassLabel = getResource("doclet.Description_From_Class");
bpatel@766 204 descfrmInterfaceLabel = getResource("doclet.Description_From_Interface");
bpatel@766 205 }
bpatel@766 206
jjg@1365 207 public void write(Content c) throws IOException {
jjg@1365 208 c.write(writer, true);
jjg@1365 209 }
jjg@1365 210
jjg@1365 211 public void close() throws IOException {
jjg@1365 212 writer.close();
jjg@1365 213 }
jjg@1365 214
bpatel@766 215 /**
bpatel@766 216 * Get the configuration string as a content.
bpatel@766 217 *
bpatel@766 218 * @param key the key to look for in the configuration file
bpatel@766 219 * @return a content tree for the text
bpatel@766 220 */
bpatel@766 221 public Content getResource(String key) {
bpatel@766 222 return new StringContent(configuration.getText(key));
bpatel@766 223 }
bpatel@766 224
bpatel@766 225 /**
bpatel@766 226 * Get the configuration string as a content.
bpatel@766 227 *
bpatel@766 228 * @param key the key to look for in the configuration file
bpatel@766 229 * @param a1 string argument added to configuration text
bpatel@766 230 * @return a content tree for the text
bpatel@766 231 */
bpatel@766 232 public Content getResource(String key, String a1) {
bpatel@766 233 return new RawHtml(configuration.getText(key, a1));
bpatel@766 234 }
bpatel@766 235
bpatel@766 236 /**
bpatel@766 237 * Get the configuration string as a content.
bpatel@766 238 *
bpatel@766 239 * @param key the key to look for in the configuration file
bpatel@766 240 * @param a1 string argument added to configuration text
bpatel@766 241 * @param a2 string argument added to configuration text
bpatel@766 242 * @return a content tree for the text
bpatel@766 243 */
bpatel@766 244 public Content getResource(String key, String a1, String a2) {
bpatel@766 245 return new RawHtml(configuration.getText(key, a1, a2));
duke@1 246 }
duke@1 247
duke@1 248 /**
bpatel@766 249 * Returns an HtmlTree for the SCRIPT tag.
bpatel@766 250 *
bpatel@766 251 * @return an HtmlTree for the SCRIPT tag
bpatel@766 252 */
bpatel@766 253 protected HtmlTree getWinTitleScript(){
bpatel@766 254 HtmlTree script = new HtmlTree(HtmlTag.SCRIPT);
bpatel@766 255 if(winTitle != null && winTitle.length() > 0) {
bpatel@766 256 script.addAttr(HtmlAttr.TYPE, "text/javascript");
bpatel@793 257 String scriptCode = "<!--" + DocletConstants.NL +
bpatel@793 258 " if (location.href.indexOf('is-external=true') == -1) {" + DocletConstants.NL +
bpatel@793 259 " parent.document.title=\"" + winTitle + "\";" + DocletConstants.NL +
bpatel@793 260 " }" + DocletConstants.NL +
bpatel@793 261 "//-->" + DocletConstants.NL;
bpatel@766 262 RawHtml scriptContent = new RawHtml(scriptCode);
bpatel@766 263 script.addContent(scriptContent);
bpatel@766 264 }
bpatel@766 265 return script;
bpatel@766 266 }
bpatel@766 267
bpatel@766 268 /**
bpatel@766 269 * Returns a content tree for the SCRIPT tag for the main page(index.html).
bpatel@766 270 *
bpatel@766 271 * @return a content for the SCRIPT tag
bpatel@766 272 */
bpatel@766 273 protected Content getFramesetJavaScript(){
bpatel@766 274 HtmlTree script = new HtmlTree(HtmlTag.SCRIPT);
bpatel@766 275 script.addAttr(HtmlAttr.TYPE, "text/javascript");
bpatel@793 276 String scriptCode = DocletConstants.NL + " targetPage = \"\" + window.location.search;" + DocletConstants.NL +
bpatel@793 277 " if (targetPage != \"\" && targetPage != \"undefined\")" + DocletConstants.NL +
bpatel@793 278 " targetPage = targetPage.substring(1);" + DocletConstants.NL +
bpatel@793 279 " if (targetPage.indexOf(\":\") != -1)" + DocletConstants.NL +
bpatel@793 280 " targetPage = \"undefined\";" + DocletConstants.NL +
bpatel@793 281 " function loadFrames() {" + DocletConstants.NL +
bpatel@793 282 " if (targetPage != \"\" && targetPage != \"undefined\")" + DocletConstants.NL +
bpatel@793 283 " top.classFrame.location = top.targetPage;" + DocletConstants.NL +
bpatel@793 284 " }" + DocletConstants.NL;
bpatel@766 285 RawHtml scriptContent = new RawHtml(scriptCode);
bpatel@766 286 script.addContent(scriptContent);
bpatel@766 287 return script;
bpatel@766 288 }
bpatel@766 289
bpatel@766 290 /**
bpatel@766 291 * Returns an HtmlTree for the BODY tag.
bpatel@766 292 *
bpatel@766 293 * @param includeScript set true if printing windowtitle script
bpatel@766 294 * @param title title for the window
bpatel@766 295 * @return an HtmlTree for the BODY tag
bpatel@766 296 */
bpatel@766 297 public HtmlTree getBody(boolean includeScript, String title) {
bpatel@766 298 HtmlTree body = new HtmlTree(HtmlTag.BODY);
bpatel@766 299 // Set window title string which is later printed
bpatel@766 300 this.winTitle = title;
bpatel@766 301 // Don't print windowtitle script for overview-frame, allclasses-frame
bpatel@766 302 // and package-frame
bpatel@766 303 if (includeScript) {
bpatel@766 304 body.addContent(getWinTitleScript());
bpatel@766 305 Content noScript = HtmlTree.NOSCRIPT(
bpatel@766 306 HtmlTree.DIV(getResource("doclet.No_Script_Message")));
bpatel@766 307 body.addContent(noScript);
bpatel@766 308 }
bpatel@766 309 return body;
bpatel@766 310 }
bpatel@766 311
bpatel@766 312 /**
bpatel@766 313 * Returns an HtmlTree for the TITLE tag.
bpatel@766 314 *
bpatel@766 315 * @return an HtmlTree for the TITLE tag
bpatel@766 316 */
bpatel@766 317 public HtmlTree getTitle() {
bpatel@766 318 HtmlTree title = HtmlTree.TITLE(new StringContent(winTitle));
bpatel@766 319 return title;
bpatel@766 320 }
duke@1 321
duke@1 322 /**
bpatel@766 323 * Return, text passed, with Italics &lt;i&gt; and &lt;/i&gt; tags, surrounding it.
bpatel@766 324 * So if the text passed is "Hi", then string returned will be "&lt;i&gt;Hi&lt;/i&gt;".
duke@1 325 *
duke@1 326 * @param text String to be printed in between &lt;I&gt; and &lt;/I&gt; tags.
duke@1 327 */
duke@1 328 public String italicsText(String text) {
bpatel@766 329 return "<i>" + text + "</i>";
duke@1 330 }
duke@1 331
duke@1 332 public String codeText(String text) {
bpatel@766 333 return "<code>" + text + "</code>";
duke@1 334 }
duke@1 335
duke@1 336 /**
bpatel@766 337 * Return "&#38;nbsp;", non-breaking space.
bpatel@766 338 */
bpatel@766 339 public Content getSpace() {
bpatel@766 340 return RawHtml.nbsp;
bpatel@766 341 }
bpatel@766 342
bpatel@243 343 /*
bpatel@243 344 * Returns a header for Modifier and Type column of a table.
bpatel@243 345 */
bpatel@243 346 public String getModifierTypeHeader() {
bpatel@243 347 return modifierTypeHeader;
bpatel@243 348 }
duke@1 349 }

mercurial