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

Sat, 13 Apr 2013 18:48:29 -0700

author
bpatel
date
Sat, 13 Apr 2013 18:48:29 -0700
changeset 1691
f10cffab99b4
parent 1606
ccbe7ffdd867
child 1736
74cd21f2c2fe
child 1829
c7c6bfe7fc1f
permissions
-rw-r--r--

8009686: Generated javadoc documentation should be able to display type annotation on an array
Reviewed-by: jjg

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

mercurial