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

Tue, 16 Oct 2012 21:03:36 -0700

author
jjg
date
Tue, 16 Oct 2012 21:03:36 -0700
changeset 1365
2013982bee34
parent 1364
8db45b13526e
child 1372
78962d89f283
permissions
-rw-r--r--

8000673: remove dead code from HtmlWriter and subtypes
Reviewed-by: bpatel

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

mercurial