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

Mon, 16 Oct 2017 16:07:48 +0800

author
aoqi
date
Mon, 16 Oct 2017 16:07:48 +0800
changeset 2893
ca5783d9a597
parent 2800
f6923d26b0fb
parent 2525
2eb010b6cb22
child 3295
859dc787b52b
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 package com.sun.tools.doclets.formats.html.markup;
aoqi@0 27
aoqi@0 28 import java.io.*;
aoqi@0 29 import java.util.*;
aoqi@0 30 import java.util.regex.Matcher;
aoqi@0 31 import java.util.regex.Pattern;
aoqi@0 32
aoqi@0 33 import com.sun.tools.doclets.internal.toolkit.*;
aoqi@0 34 import com.sun.tools.doclets.internal.toolkit.util.*;
aoqi@0 35
aoqi@0 36 /**
aoqi@0 37 * Class for the Html format code generation.
aoqi@0 38 * Initializes PrintWriter with FileWriter, to enable print
aoqi@0 39 * related methods to generate the code to the named File through FileWriter.
aoqi@0 40 *
aoqi@0 41 * <p><b>This is NOT part of any supported API.
aoqi@0 42 * If you write code that depends on this, you do so at your own risk.
aoqi@0 43 * This code and its internal interfaces are subject to change or
aoqi@0 44 * deletion without notice.</b>
aoqi@0 45 *
aoqi@0 46 * @since 1.2
aoqi@0 47 * @author Atul M Dambalkar
aoqi@0 48 * @author Bhavesh Patel (Modified)
aoqi@0 49 */
aoqi@0 50 public class HtmlWriter {
aoqi@0 51
aoqi@0 52 /**
aoqi@0 53 * The window title of this file
aoqi@0 54 */
aoqi@0 55 protected String winTitle;
aoqi@0 56
aoqi@0 57 /**
aoqi@0 58 * The configuration
aoqi@0 59 */
aoqi@0 60 protected Configuration configuration;
aoqi@0 61
aoqi@0 62 /**
aoqi@0 63 * The flag to indicate whether a member details list is printed or not.
aoqi@0 64 */
aoqi@0 65 protected boolean memberDetailsListPrinted;
aoqi@0 66
aoqi@0 67 /**
aoqi@0 68 * Header for table displaying profiles and description..
aoqi@0 69 */
aoqi@0 70 protected final String[] profileTableHeader;
aoqi@0 71
aoqi@0 72 /**
aoqi@0 73 * Header for tables displaying packages and description..
aoqi@0 74 */
aoqi@0 75 protected final String[] packageTableHeader;
aoqi@0 76
aoqi@0 77 /**
aoqi@0 78 * Summary for use tables displaying class and package use.
aoqi@0 79 */
aoqi@0 80 protected final String useTableSummary;
aoqi@0 81
aoqi@0 82 /**
aoqi@0 83 * Column header for class docs displaying Modifier and Type header.
aoqi@0 84 */
aoqi@0 85 protected final String modifierTypeHeader;
aoqi@0 86
aoqi@0 87 public final Content overviewLabel;
aoqi@0 88
aoqi@0 89 public final Content defaultPackageLabel;
aoqi@0 90
aoqi@0 91 public final Content packageLabel;
aoqi@0 92
aoqi@0 93 public final Content profileLabel;
aoqi@0 94
aoqi@0 95 public final Content useLabel;
aoqi@0 96
aoqi@0 97 public final Content prevLabel;
aoqi@0 98
aoqi@0 99 public final Content nextLabel;
aoqi@0 100
aoqi@0 101 public final Content prevclassLabel;
aoqi@0 102
aoqi@0 103 public final Content nextclassLabel;
aoqi@0 104
aoqi@0 105 public final Content summaryLabel;
aoqi@0 106
aoqi@0 107 public final Content detailLabel;
aoqi@0 108
aoqi@0 109 public final Content framesLabel;
aoqi@0 110
aoqi@0 111 public final Content noframesLabel;
aoqi@0 112
aoqi@0 113 public final Content treeLabel;
aoqi@0 114
aoqi@0 115 public final Content classLabel;
aoqi@0 116
aoqi@0 117 public final Content deprecatedLabel;
aoqi@0 118
aoqi@0 119 public final Content deprecatedPhrase;
aoqi@0 120
aoqi@0 121 public final Content allclassesLabel;
aoqi@0 122
aoqi@0 123 public final Content allpackagesLabel;
aoqi@0 124
aoqi@0 125 public final Content allprofilesLabel;
aoqi@0 126
aoqi@0 127 public final Content indexLabel;
aoqi@0 128
aoqi@0 129 public final Content helpLabel;
aoqi@0 130
aoqi@0 131 public final Content seeLabel;
aoqi@0 132
aoqi@0 133 public final Content descriptionLabel;
aoqi@0 134
aoqi@0 135 public final Content prevpackageLabel;
aoqi@0 136
aoqi@0 137 public final Content nextpackageLabel;
aoqi@0 138
aoqi@0 139 public final Content prevprofileLabel;
aoqi@0 140
aoqi@0 141 public final Content nextprofileLabel;
aoqi@0 142
aoqi@0 143 public final Content packagesLabel;
aoqi@0 144
aoqi@0 145 public final Content profilesLabel;
aoqi@0 146
aoqi@0 147 public final Content methodDetailsLabel;
aoqi@0 148
aoqi@0 149 public final Content annotationTypeDetailsLabel;
aoqi@0 150
aoqi@0 151 public final Content fieldDetailsLabel;
aoqi@0 152
aoqi@0 153 public final Content propertyDetailsLabel;
aoqi@0 154
aoqi@0 155 public final Content constructorDetailsLabel;
aoqi@0 156
aoqi@0 157 public final Content enumConstantsDetailsLabel;
aoqi@0 158
aoqi@0 159 public final Content specifiedByLabel;
aoqi@0 160
aoqi@0 161 public final Content overridesLabel;
aoqi@0 162
aoqi@0 163 public final Content descfrmClassLabel;
aoqi@0 164
aoqi@0 165 public final Content descfrmInterfaceLabel;
aoqi@0 166
aoqi@0 167 private final Writer writer;
aoqi@0 168
aoqi@0 169 private Content script;
aoqi@0 170
aoqi@0 171 /**
aoqi@0 172 * Constructor.
aoqi@0 173 *
aoqi@0 174 * @param path The directory path to be created for this file
aoqi@0 175 * or null if none to be created.
aoqi@0 176 * @exception IOException Exception raised by the FileWriter is passed on
aoqi@0 177 * to next level.
aoqi@0 178 * @exception UnsupportedEncodingException Exception raised by the
aoqi@0 179 * OutputStreamWriter is passed on to next level.
aoqi@0 180 */
aoqi@0 181 public HtmlWriter(Configuration configuration, DocPath path)
aoqi@0 182 throws IOException, UnsupportedEncodingException {
aoqi@0 183 writer = DocFile.createFileForOutput(configuration, path).openWriter();
aoqi@0 184 this.configuration = configuration;
aoqi@0 185 this.memberDetailsListPrinted = false;
aoqi@0 186 profileTableHeader = new String[] {
aoqi@0 187 configuration.getText("doclet.Profile"),
aoqi@0 188 configuration.getText("doclet.Description")
aoqi@0 189 };
aoqi@0 190 packageTableHeader = new String[] {
aoqi@0 191 configuration.getText("doclet.Package"),
aoqi@0 192 configuration.getText("doclet.Description")
aoqi@0 193 };
aoqi@0 194 useTableSummary = configuration.getText("doclet.Use_Table_Summary",
aoqi@0 195 configuration.getText("doclet.packages"));
aoqi@0 196 modifierTypeHeader = configuration.getText("doclet.0_and_1",
aoqi@0 197 configuration.getText("doclet.Modifier"),
aoqi@0 198 configuration.getText("doclet.Type"));
aoqi@0 199 overviewLabel = getResource("doclet.Overview");
aoqi@0 200 defaultPackageLabel = new StringContent(DocletConstants.DEFAULT_PACKAGE_NAME);
aoqi@0 201 packageLabel = getResource("doclet.Package");
aoqi@0 202 profileLabel = getResource("doclet.Profile");
aoqi@0 203 useLabel = getResource("doclet.navClassUse");
aoqi@0 204 prevLabel = getResource("doclet.Prev");
aoqi@0 205 nextLabel = getResource("doclet.Next");
aoqi@0 206 prevclassLabel = getNonBreakResource("doclet.Prev_Class");
aoqi@0 207 nextclassLabel = getNonBreakResource("doclet.Next_Class");
aoqi@0 208 summaryLabel = getResource("doclet.Summary");
aoqi@0 209 detailLabel = getResource("doclet.Detail");
aoqi@0 210 framesLabel = getResource("doclet.Frames");
aoqi@0 211 noframesLabel = getNonBreakResource("doclet.No_Frames");
aoqi@0 212 treeLabel = getResource("doclet.Tree");
aoqi@0 213 classLabel = getResource("doclet.Class");
aoqi@0 214 deprecatedLabel = getResource("doclet.navDeprecated");
aoqi@0 215 deprecatedPhrase = getResource("doclet.Deprecated");
aoqi@0 216 allclassesLabel = getNonBreakResource("doclet.All_Classes");
aoqi@0 217 allpackagesLabel = getNonBreakResource("doclet.All_Packages");
aoqi@0 218 allprofilesLabel = getNonBreakResource("doclet.All_Profiles");
aoqi@0 219 indexLabel = getResource("doclet.Index");
aoqi@0 220 helpLabel = getResource("doclet.Help");
aoqi@0 221 seeLabel = getResource("doclet.See");
aoqi@0 222 descriptionLabel = getResource("doclet.Description");
aoqi@0 223 prevpackageLabel = getNonBreakResource("doclet.Prev_Package");
aoqi@0 224 nextpackageLabel = getNonBreakResource("doclet.Next_Package");
aoqi@0 225 prevprofileLabel = getNonBreakResource("doclet.Prev_Profile");
aoqi@0 226 nextprofileLabel = getNonBreakResource("doclet.Next_Profile");
aoqi@0 227 packagesLabel = getResource("doclet.Packages");
aoqi@0 228 profilesLabel = getResource("doclet.Profiles");
aoqi@0 229 methodDetailsLabel = getResource("doclet.Method_Detail");
aoqi@0 230 annotationTypeDetailsLabel = getResource("doclet.Annotation_Type_Member_Detail");
aoqi@0 231 fieldDetailsLabel = getResource("doclet.Field_Detail");
aoqi@0 232 propertyDetailsLabel = getResource("doclet.Property_Detail");
aoqi@0 233 constructorDetailsLabel = getResource("doclet.Constructor_Detail");
aoqi@0 234 enumConstantsDetailsLabel = getResource("doclet.Enum_Constant_Detail");
aoqi@0 235 specifiedByLabel = getResource("doclet.Specified_By");
aoqi@0 236 overridesLabel = getResource("doclet.Overrides");
aoqi@0 237 descfrmClassLabel = getResource("doclet.Description_From_Class");
aoqi@0 238 descfrmInterfaceLabel = getResource("doclet.Description_From_Interface");
aoqi@0 239 }
aoqi@0 240
aoqi@0 241 public void write(Content c) throws IOException {
aoqi@0 242 c.write(writer, true);
aoqi@0 243 }
aoqi@0 244
aoqi@0 245 public void close() throws IOException {
aoqi@0 246 writer.close();
aoqi@0 247 }
aoqi@0 248
aoqi@0 249 /**
aoqi@0 250 * Get the configuration string as a content.
aoqi@0 251 *
aoqi@0 252 * @param key the key to look for in the configuration file
aoqi@0 253 * @return a content tree for the text
aoqi@0 254 */
aoqi@0 255 public Content getResource(String key) {
aoqi@0 256 return configuration.getResource(key);
aoqi@0 257 }
aoqi@0 258
aoqi@0 259 /**
aoqi@0 260 * Get the configuration string as a content, replacing spaces
aoqi@0 261 * with non-breaking spaces.
aoqi@0 262 *
aoqi@0 263 * @param key the key to look for in the configuration file
aoqi@0 264 * @return a content tree for the text
aoqi@0 265 */
aoqi@0 266 public Content getNonBreakResource(String key) {
aoqi@0 267 String text = configuration.getText(key);
aoqi@0 268 Content c = configuration.newContent();
aoqi@0 269 int start = 0;
aoqi@0 270 int p;
aoqi@0 271 while ((p = text.indexOf(" ", start)) != -1) {
aoqi@0 272 c.addContent(text.substring(start, p));
aoqi@0 273 c.addContent(RawHtml.nbsp);
aoqi@0 274 start = p + 1;
aoqi@0 275 }
aoqi@0 276 c.addContent(text.substring(start));
aoqi@0 277 return c;
aoqi@0 278 }
aoqi@0 279
aoqi@0 280 /**
aoqi@0 281 * Get the configuration string as a content.
aoqi@0 282 *
aoqi@0 283 * @param key the key to look for in the configuration file
aoqi@0 284 * @param o string or content argument added to configuration text
aoqi@0 285 * @return a content tree for the text
aoqi@0 286 */
aoqi@0 287 public Content getResource(String key, Object o) {
aoqi@0 288 return configuration.getResource(key, o);
aoqi@0 289 }
aoqi@0 290
aoqi@0 291 /**
aoqi@0 292 * Get the configuration string as a content.
aoqi@0 293 *
aoqi@0 294 * @param key the key to look for in the configuration file
aoqi@0 295 * @param o1 string or content argument added to configuration text
aoqi@0 296 * @param o2 string or content argument added to configuration text
aoqi@0 297 * @return a content tree for the text
aoqi@0 298 */
aoqi@0 299 public Content getResource(String key, Object o0, Object o1) {
aoqi@0 300 return configuration.getResource(key, o0, o1);
aoqi@0 301 }
aoqi@0 302
aoqi@0 303 /**
aoqi@0 304 * Returns an HtmlTree for the SCRIPT tag.
aoqi@0 305 *
aoqi@0 306 * @return an HtmlTree for the SCRIPT tag
aoqi@0 307 */
aoqi@0 308 protected HtmlTree getWinTitleScript(){
aoqi@0 309 HtmlTree script = new HtmlTree(HtmlTag.SCRIPT);
aoqi@0 310 if(winTitle != null && winTitle.length() > 0) {
aoqi@0 311 script.addAttr(HtmlAttr.TYPE, "text/javascript");
aoqi@0 312 String scriptCode = "<!--" + DocletConstants.NL +
aoqi@0 313 " try {" + DocletConstants.NL +
aoqi@0 314 " if (location.href.indexOf('is-external=true') == -1) {" + DocletConstants.NL +
aoqi@0 315 " parent.document.title=\"" + escapeJavaScriptChars(winTitle) + "\";" + DocletConstants.NL +
aoqi@0 316 " }" + DocletConstants.NL +
aoqi@0 317 " }" + DocletConstants.NL +
aoqi@0 318 " catch(err) {" + DocletConstants.NL +
aoqi@0 319 " }" + DocletConstants.NL +
aoqi@0 320 "//-->" + DocletConstants.NL;
aoqi@0 321 RawHtml scriptContent = new RawHtml(scriptCode);
aoqi@0 322 script.addContent(scriptContent);
aoqi@0 323 }
aoqi@0 324 return script;
aoqi@0 325 }
aoqi@0 326
aoqi@0 327 /**
aoqi@0 328 * Returns a String with escaped special JavaScript characters.
aoqi@0 329 *
aoqi@0 330 * @param s String that needs to be escaped
aoqi@0 331 * @return a valid escaped JavaScript string
aoqi@0 332 */
aoqi@0 333 private static String escapeJavaScriptChars(String s) {
aoqi@0 334 StringBuilder sb = new StringBuilder();
aoqi@0 335 for (int i = 0; i < s.length(); i++) {
aoqi@0 336 char ch = s.charAt(i);
aoqi@0 337 switch (ch) {
aoqi@0 338 case '\b':
aoqi@0 339 sb.append("\\b");
aoqi@0 340 break;
aoqi@0 341 case '\t':
aoqi@0 342 sb.append("\\t");
aoqi@0 343 break;
aoqi@0 344 case '\n':
aoqi@0 345 sb.append("\\n");
aoqi@0 346 break;
aoqi@0 347 case '\f':
aoqi@0 348 sb.append("\\f");
aoqi@0 349 break;
aoqi@0 350 case '\r':
aoqi@0 351 sb.append("\\r");
aoqi@0 352 break;
aoqi@0 353 case '"':
aoqi@0 354 sb.append("\\\"");
aoqi@0 355 break;
aoqi@0 356 case '\'':
aoqi@0 357 sb.append("\\\'");
aoqi@0 358 break;
aoqi@0 359 case '\\':
aoqi@0 360 sb.append("\\\\");
aoqi@0 361 break;
aoqi@0 362 default:
aoqi@0 363 if (ch < 32 || ch >= 127) {
aoqi@0 364 sb.append(String.format("\\u%04X", (int)ch));
aoqi@0 365 } else {
aoqi@0 366 sb.append(ch);
aoqi@0 367 }
aoqi@0 368 break;
aoqi@0 369 }
aoqi@0 370 }
aoqi@0 371 return sb.toString();
aoqi@0 372 }
aoqi@0 373
aoqi@0 374 /**
aoqi@0 375 * Returns a content tree for the SCRIPT tag for the main page(index.html).
aoqi@0 376 *
aoqi@0 377 * @return a content for the SCRIPT tag
aoqi@0 378 */
aoqi@0 379 protected Content getFramesetJavaScript() {
aoqi@0 380 HtmlTree script = new HtmlTree(HtmlTag.SCRIPT);
aoqi@0 381 script.addAttr(HtmlAttr.TYPE, "text/javascript");
aoqi@0 382 String scriptCode = DocletConstants.NL +
aoqi@0 383 " targetPage = \"\" + window.location.search;" + DocletConstants.NL +
aoqi@0 384 " if (targetPage != \"\" && targetPage != \"undefined\")" + DocletConstants.NL +
aoqi@0 385 " targetPage = targetPage.substring(1);" + DocletConstants.NL +
aoqi@0 386 " if (targetPage.indexOf(\":\") != -1 || (targetPage != \"\" && !validURL(targetPage)))" + DocletConstants.NL +
aoqi@0 387 " targetPage = \"undefined\";" + DocletConstants.NL +
aoqi@0 388 " function validURL(url) {" + DocletConstants.NL +
aoqi@0 389 " try {" + DocletConstants.NL +
aoqi@0 390 " url = decodeURIComponent(url);" + DocletConstants.NL +
aoqi@0 391 " }" + DocletConstants.NL +
aoqi@0 392 " catch (error) {" + DocletConstants.NL +
aoqi@0 393 " return false;" + DocletConstants.NL +
aoqi@0 394 " }" + DocletConstants.NL +
aoqi@0 395 " var pos = url.indexOf(\".html\");" + DocletConstants.NL +
aoqi@0 396 " if (pos == -1 || pos != url.length - 5)" + DocletConstants.NL +
aoqi@0 397 " return false;" + DocletConstants.NL +
aoqi@0 398 " var allowNumber = false;" + DocletConstants.NL +
aoqi@0 399 " var allowSep = false;" + DocletConstants.NL +
aoqi@0 400 " var seenDot = false;" + DocletConstants.NL +
aoqi@0 401 " for (var i = 0; i < url.length - 5; i++) {" + DocletConstants.NL +
aoqi@0 402 " var ch = url.charAt(i);" + DocletConstants.NL +
aoqi@0 403 " if ('a' <= ch && ch <= 'z' ||" + DocletConstants.NL +
aoqi@0 404 " 'A' <= ch && ch <= 'Z' ||" + DocletConstants.NL +
aoqi@0 405 " ch == '$' ||" + DocletConstants.NL +
aoqi@0 406 " ch == '_' ||" + DocletConstants.NL +
aoqi@0 407 " ch.charCodeAt(0) > 127) {" + DocletConstants.NL +
aoqi@0 408 " allowNumber = true;" + DocletConstants.NL +
aoqi@0 409 " allowSep = true;" + DocletConstants.NL +
aoqi@0 410 " } else if ('0' <= ch && ch <= '9'" + DocletConstants.NL +
aoqi@0 411 " || ch == '-') {" + DocletConstants.NL +
aoqi@0 412 " if (!allowNumber)" + DocletConstants.NL +
aoqi@0 413 " return false;" + DocletConstants.NL +
aoqi@0 414 " } else if (ch == '/' || ch == '.') {" + DocletConstants.NL +
aoqi@0 415 " if (!allowSep)" + DocletConstants.NL +
aoqi@0 416 " return false;" + DocletConstants.NL +
aoqi@0 417 " allowNumber = false;" + DocletConstants.NL +
aoqi@0 418 " allowSep = false;" + DocletConstants.NL +
aoqi@0 419 " if (ch == '.')" + DocletConstants.NL +
aoqi@0 420 " seenDot = true;" + DocletConstants.NL +
aoqi@0 421 " if (ch == '/' && seenDot)" + DocletConstants.NL +
aoqi@0 422 " return false;" + DocletConstants.NL +
aoqi@0 423 " } else {" + DocletConstants.NL +
aoqi@0 424 " return false;"+ DocletConstants.NL +
aoqi@0 425 " }" + DocletConstants.NL +
aoqi@0 426 " }" + DocletConstants.NL +
aoqi@0 427 " return true;" + DocletConstants.NL +
aoqi@0 428 " }" + DocletConstants.NL +
aoqi@0 429 " function loadFrames() {" + DocletConstants.NL +
aoqi@0 430 " if (targetPage != \"\" && targetPage != \"undefined\")" + DocletConstants.NL +
aoqi@0 431 " top.classFrame.location = top.targetPage;" + DocletConstants.NL +
aoqi@0 432 " }" + DocletConstants.NL;
aoqi@0 433 RawHtml scriptContent = new RawHtml(scriptCode);
aoqi@0 434 script.addContent(scriptContent);
aoqi@0 435 return script;
aoqi@0 436 }
aoqi@0 437
aoqi@0 438 /**
aoqi@0 439 * Returns an HtmlTree for the BODY tag.
aoqi@0 440 *
aoqi@0 441 * @param includeScript set true if printing windowtitle script
aoqi@0 442 * @param title title for the window
aoqi@0 443 * @return an HtmlTree for the BODY tag
aoqi@0 444 */
aoqi@0 445 public HtmlTree getBody(boolean includeScript, String title) {
aoqi@0 446 HtmlTree body = new HtmlTree(HtmlTag.BODY);
aoqi@0 447 // Set window title string which is later printed
aoqi@0 448 this.winTitle = title;
aoqi@0 449 // Don't print windowtitle script for overview-frame, allclasses-frame
aoqi@0 450 // and package-frame
aoqi@0 451 if (includeScript) {
aoqi@0 452 this.script = getWinTitleScript();
aoqi@0 453 body.addContent(script);
aoqi@0 454 Content noScript = HtmlTree.NOSCRIPT(
aoqi@0 455 HtmlTree.DIV(getResource("doclet.No_Script_Message")));
aoqi@0 456 body.addContent(noScript);
aoqi@0 457 }
aoqi@0 458 return body;
aoqi@0 459 }
aoqi@0 460
aoqi@0 461 /**
aoqi@0 462 * Generated javascript variables for the document.
aoqi@0 463 *
aoqi@0 464 * @param typeMap map comprising of method and type relationship
aoqi@0 465 * @param methodTypes set comprising of all methods types for this class
aoqi@0 466 */
aoqi@0 467 public void generateMethodTypesScript(Map<String,Integer> typeMap,
aoqi@0 468 Set<MethodTypes> methodTypes) {
aoqi@0 469 String sep = "";
aoqi@0 470 StringBuilder vars = new StringBuilder("var methods = {");
aoqi@0 471 for (Map.Entry<String,Integer> entry : typeMap.entrySet()) {
aoqi@0 472 vars.append(sep);
aoqi@0 473 sep = ",";
bpatel@2800 474 vars.append("\"")
bpatel@2800 475 .append(entry.getKey())
bpatel@2800 476 .append("\":")
bpatel@2800 477 .append(entry.getValue());
aoqi@0 478 }
aoqi@0 479 vars.append("};").append(DocletConstants.NL);
aoqi@0 480 sep = "";
aoqi@0 481 vars.append("var tabs = {");
aoqi@0 482 for (MethodTypes entry : methodTypes) {
aoqi@0 483 vars.append(sep);
aoqi@0 484 sep = ",";
bpatel@2800 485 vars.append(entry.value())
bpatel@2800 486 .append(":")
bpatel@2800 487 .append("[")
bpatel@2800 488 .append("\"")
bpatel@2800 489 .append(entry.tabId())
bpatel@2800 490 .append("\"")
bpatel@2800 491 .append(sep)
bpatel@2800 492 .append("\"")
bpatel@2800 493 .append(configuration.getText(entry.resourceKey()))
bpatel@2800 494 .append("\"]");
aoqi@0 495 }
bpatel@2800 496 vars.append("};")
bpatel@2800 497 .append(DocletConstants.NL);
aoqi@0 498 addStyles(HtmlStyle.altColor, vars);
aoqi@0 499 addStyles(HtmlStyle.rowColor, vars);
aoqi@0 500 addStyles(HtmlStyle.tableTab, vars);
aoqi@0 501 addStyles(HtmlStyle.activeTableTab, vars);
aoqi@0 502 script.addContent(new RawHtml(vars.toString()));
aoqi@0 503 }
aoqi@0 504
aoqi@0 505 /**
aoqi@0 506 * Adds javascript style variables to the document.
aoqi@0 507 *
aoqi@0 508 * @param style style to be added as a javascript variable
aoqi@0 509 * @param vars variable string to which the style variable will be added
aoqi@0 510 */
aoqi@0 511 public void addStyles(HtmlStyle style, StringBuilder vars) {
aoqi@0 512 vars.append("var ").append(style).append(" = \"").append(style)
aoqi@0 513 .append("\";").append(DocletConstants.NL);
aoqi@0 514 }
aoqi@0 515
aoqi@0 516 /**
aoqi@0 517 * Returns an HtmlTree for the TITLE tag.
aoqi@0 518 *
aoqi@0 519 * @return an HtmlTree for the TITLE tag
aoqi@0 520 */
aoqi@0 521 public HtmlTree getTitle() {
aoqi@0 522 HtmlTree title = HtmlTree.TITLE(new StringContent(winTitle));
aoqi@0 523 return title;
aoqi@0 524 }
aoqi@0 525
aoqi@0 526 public String codeText(String text) {
aoqi@0 527 return "<code>" + text + "</code>";
aoqi@0 528 }
aoqi@0 529
aoqi@0 530 /**
aoqi@0 531 * Return "&#38;nbsp;", non-breaking space.
aoqi@0 532 */
aoqi@0 533 public Content getSpace() {
aoqi@0 534 return RawHtml.nbsp;
aoqi@0 535 }
aoqi@0 536
aoqi@0 537 /*
aoqi@0 538 * Returns a header for Modifier and Type column of a table.
aoqi@0 539 */
aoqi@0 540 public String getModifierTypeHeader() {
aoqi@0 541 return modifierTypeHeader;
aoqi@0 542 }
aoqi@0 543 }

mercurial