Mon, 09 Mar 2009 23:53:41 -0700
Merge
duke@1 | 1 | /* |
xdono@229 | 2 | * Copyright 1997-2009 Sun Microsystems, Inc. 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 |
duke@1 | 7 | * published by the Free Software Foundation. Sun designates this |
duke@1 | 8 | * particular file as subject to the "Classpath" exception as provided |
duke@1 | 9 | * by Sun 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 | * |
duke@1 | 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@1 | 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@1 | 23 | * have any 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@197 | 32 | import com.sun.tools.doclets.internal.toolkit.*; |
duke@1 | 33 | |
duke@1 | 34 | |
duke@1 | 35 | /** |
duke@1 | 36 | * Class for the Html Format Code Generation specific to JavaDoc. |
duke@1 | 37 | * This Class contains methods related to the Html Code Generation which |
duke@1 | 38 | * are used by the Sub-Classes in the package com.sun.tools.doclets.standard |
duke@1 | 39 | * and com.sun.tools.doclets.oneone. |
duke@1 | 40 | * |
duke@1 | 41 | * @since 1.2 |
duke@1 | 42 | * @author Atul M Dambalkar |
duke@1 | 43 | * @author Robert Field |
duke@1 | 44 | */ |
duke@1 | 45 | public abstract class HtmlDocWriter extends HtmlWriter { |
duke@1 | 46 | |
duke@1 | 47 | /** |
duke@1 | 48 | * Constructor. Initializes the destination file name through the super |
duke@1 | 49 | * class HtmlWriter. |
duke@1 | 50 | * |
duke@1 | 51 | * @param filename String file name. |
duke@1 | 52 | */ |
duke@1 | 53 | public HtmlDocWriter(Configuration configuration, |
duke@1 | 54 | String filename) throws IOException { |
duke@1 | 55 | super(configuration, |
duke@1 | 56 | null, configuration.destDirName + filename, |
duke@1 | 57 | configuration.docencoding); |
jjg@197 | 58 | // use File to normalize file separators |
duke@1 | 59 | configuration.message.notice("doclet.Generating_0", |
jjg@197 | 60 | new File(configuration.destDirName, filename)); |
duke@1 | 61 | } |
duke@1 | 62 | |
duke@1 | 63 | public HtmlDocWriter(Configuration configuration, |
duke@1 | 64 | String path, String filename) throws IOException { |
duke@1 | 65 | super(configuration, |
duke@1 | 66 | configuration.destDirName + path, filename, |
duke@1 | 67 | configuration.docencoding); |
jjg@197 | 68 | // use File to normalize file separators |
duke@1 | 69 | configuration.message.notice("doclet.Generating_0", |
jjg@197 | 70 | new File(configuration.destDirName, |
jjg@197 | 71 | ((path.length() > 0)? path + File.separator: "") + filename)); |
duke@1 | 72 | } |
duke@1 | 73 | |
duke@1 | 74 | /** |
duke@1 | 75 | * Accessor for configuration. |
duke@1 | 76 | */ |
duke@1 | 77 | public abstract Configuration configuration(); |
duke@1 | 78 | |
duke@1 | 79 | /** |
duke@1 | 80 | * Print Html Hyper Link. |
duke@1 | 81 | * |
duke@1 | 82 | * @param link String name of the file. |
duke@1 | 83 | * @param where Position of the link in the file. Character '#' is not |
duke@1 | 84 | * needed. |
duke@1 | 85 | * @param label Tag for the link. |
bpatel@182 | 86 | * @param strong Boolean that sets label to strong. |
duke@1 | 87 | */ |
duke@1 | 88 | public void printHyperLink(String link, String where, |
bpatel@182 | 89 | String label, boolean strong) { |
bpatel@182 | 90 | print(getHyperLink(link, where, label, strong, "", "", "")); |
duke@1 | 91 | } |
duke@1 | 92 | |
duke@1 | 93 | /** |
duke@1 | 94 | * Print Html Hyper Link. |
duke@1 | 95 | * |
duke@1 | 96 | * @param link String name of the file. |
duke@1 | 97 | * @param where Position of the link in the file. Character '#' is not |
duke@1 | 98 | * needed. |
duke@1 | 99 | * @param label Tag for the link. |
duke@1 | 100 | */ |
duke@1 | 101 | public void printHyperLink(String link, String where, String label) { |
duke@1 | 102 | printHyperLink(link, where, label, false); |
duke@1 | 103 | } |
duke@1 | 104 | |
duke@1 | 105 | /** |
duke@1 | 106 | * Print Html Hyper Link. |
duke@1 | 107 | * |
duke@1 | 108 | * @param link String name of the file. |
duke@1 | 109 | * @param where Position of the link in the file. Character '#' is not |
duke@1 | 110 | * needed. |
duke@1 | 111 | * @param label Tag for the link. |
bpatel@182 | 112 | * @param strong Boolean that sets label to strong. |
duke@1 | 113 | * @param stylename String style of text defined in style sheet. |
duke@1 | 114 | */ |
duke@1 | 115 | public void printHyperLink(String link, String where, |
bpatel@182 | 116 | String label, boolean strong, |
duke@1 | 117 | String stylename) { |
bpatel@182 | 118 | print(getHyperLink(link, where, label, strong, stylename, "", "")); |
duke@1 | 119 | } |
duke@1 | 120 | |
duke@1 | 121 | /** |
duke@1 | 122 | * Return Html Hyper Link string. |
duke@1 | 123 | * |
duke@1 | 124 | * @param link String name of the file. |
duke@1 | 125 | * @param where Position of the link in the file. Character '#' is not |
duke@1 | 126 | * needed. |
duke@1 | 127 | * @param label Tag for the link. |
bpatel@182 | 128 | * @param strong Boolean that sets label to strong. |
duke@1 | 129 | * @return String Hyper Link. |
duke@1 | 130 | */ |
duke@1 | 131 | public String getHyperLink(String link, String where, |
bpatel@182 | 132 | String label, boolean strong) { |
bpatel@182 | 133 | return getHyperLink(link, where, label, strong, "", "", ""); |
duke@1 | 134 | } |
duke@1 | 135 | |
duke@1 | 136 | /** |
duke@1 | 137 | * Get Html Hyper Link string. |
duke@1 | 138 | * |
duke@1 | 139 | * @param link String name of the file. |
duke@1 | 140 | * @param where Position of the link in the file. Character '#' is not |
duke@1 | 141 | * needed. |
duke@1 | 142 | * @param label Tag for the link. |
bpatel@182 | 143 | * @param strong Boolean that sets label to strong. |
duke@1 | 144 | * @param stylename String style of text defined in style sheet. |
duke@1 | 145 | * @return String Hyper Link. |
duke@1 | 146 | */ |
duke@1 | 147 | public String getHyperLink(String link, String where, |
bpatel@182 | 148 | String label, boolean strong, |
duke@1 | 149 | String stylename) { |
bpatel@182 | 150 | return getHyperLink(link, where, label, strong, stylename, "", ""); |
duke@1 | 151 | } |
duke@1 | 152 | |
duke@1 | 153 | /** |
duke@1 | 154 | * Get Html Hyper Link string. |
duke@1 | 155 | * |
duke@1 | 156 | * @param link String name of the file. |
duke@1 | 157 | * @param where Position of the link in the file. Character '#' is not |
duke@1 | 158 | * needed. |
duke@1 | 159 | * @param label Tag for the link. |
bpatel@182 | 160 | * @param strong Boolean that sets label to strong. |
duke@1 | 161 | * @param stylename String style of text defined in style sheet. |
duke@1 | 162 | * @param title String that describes the link's content for accessibility. |
duke@1 | 163 | * @param target Target frame. |
duke@1 | 164 | * @return String Hyper Link. |
duke@1 | 165 | */ |
duke@1 | 166 | public String getHyperLink(String link, String where, |
bpatel@182 | 167 | String label, boolean strong, |
duke@1 | 168 | String stylename, String title, String target) { |
duke@1 | 169 | StringBuffer retlink = new StringBuffer(); |
duke@1 | 170 | retlink.append("<A HREF=\""); |
duke@1 | 171 | retlink.append(link); |
duke@1 | 172 | if (where != null && where.length() != 0) { |
duke@1 | 173 | retlink.append("#"); |
duke@1 | 174 | retlink.append(where); |
duke@1 | 175 | } |
duke@1 | 176 | retlink.append("\""); |
duke@1 | 177 | if (title != null && title.length() != 0) { |
duke@1 | 178 | retlink.append(" title=\"" + title + "\""); |
duke@1 | 179 | } |
duke@1 | 180 | if (target != null && target.length() != 0) { |
duke@1 | 181 | retlink.append(" target=\"" + target + "\""); |
duke@1 | 182 | } |
duke@1 | 183 | retlink.append(">"); |
duke@1 | 184 | if (stylename != null && stylename.length() != 0) { |
duke@1 | 185 | retlink.append("<FONT CLASS=\""); |
duke@1 | 186 | retlink.append(stylename); |
duke@1 | 187 | retlink.append("\">"); |
duke@1 | 188 | } |
bpatel@182 | 189 | if (strong) { |
bpatel@182 | 190 | retlink.append("<STRONG>"); |
duke@1 | 191 | } |
duke@1 | 192 | retlink.append(label); |
bpatel@182 | 193 | if (strong) { |
bpatel@182 | 194 | retlink.append("</STRONG>"); |
duke@1 | 195 | } |
duke@1 | 196 | if (stylename != null && stylename.length() != 0) { |
duke@1 | 197 | retlink.append("</FONT>"); |
duke@1 | 198 | } |
duke@1 | 199 | retlink.append("</A>"); |
duke@1 | 200 | return retlink.toString(); |
duke@1 | 201 | } |
duke@1 | 202 | |
duke@1 | 203 | /** |
duke@1 | 204 | * Print link without positioning in the file. |
duke@1 | 205 | * |
duke@1 | 206 | * @param link String name of the file. |
duke@1 | 207 | * @param label Tag for the link. |
duke@1 | 208 | */ |
duke@1 | 209 | public void printHyperLink(String link, String label) { |
duke@1 | 210 | print(getHyperLink(link, "", label, false)); |
duke@1 | 211 | } |
duke@1 | 212 | |
duke@1 | 213 | /** |
duke@1 | 214 | * Get link string without positioning in the file. |
duke@1 | 215 | * |
duke@1 | 216 | * @param link String name of the file. |
duke@1 | 217 | * @param label Tag for the link. |
duke@1 | 218 | * @return Strign Hyper link. |
duke@1 | 219 | */ |
duke@1 | 220 | public String getHyperLink(String link, String label) { |
duke@1 | 221 | return getHyperLink(link, "", label, false); |
duke@1 | 222 | } |
duke@1 | 223 | |
duke@1 | 224 | /** |
duke@1 | 225 | * Print the name of the package, this class is in. |
duke@1 | 226 | * |
duke@1 | 227 | * @param cd ClassDoc. |
duke@1 | 228 | */ |
duke@1 | 229 | public void printPkgName(ClassDoc cd) { |
duke@1 | 230 | print(getPkgName(cd)); |
duke@1 | 231 | } |
duke@1 | 232 | |
duke@1 | 233 | /** |
duke@1 | 234 | * Get the name of the package, this class is in. |
duke@1 | 235 | * |
duke@1 | 236 | * @param cd ClassDoc. |
duke@1 | 237 | */ |
duke@1 | 238 | public String getPkgName(ClassDoc cd) { |
duke@1 | 239 | String pkgName = cd.containingPackage().name(); |
duke@1 | 240 | if (pkgName.length() > 0) { |
duke@1 | 241 | pkgName += "."; |
duke@1 | 242 | return pkgName; |
duke@1 | 243 | } |
duke@1 | 244 | return ""; |
duke@1 | 245 | } |
duke@1 | 246 | |
duke@1 | 247 | /** |
bpatel@233 | 248 | * Keep track of member details list. Print the definition list start tag |
bpatel@233 | 249 | * if it is not printed yet. |
bpatel@233 | 250 | */ |
bpatel@233 | 251 | public void printMemberDetailsListStartTag () { |
bpatel@233 | 252 | if (!getMemberDetailsListPrinted()) { |
bpatel@233 | 253 | dl(); |
bpatel@233 | 254 | memberDetailsListPrinted = true; |
bpatel@233 | 255 | } |
bpatel@233 | 256 | } |
bpatel@233 | 257 | |
bpatel@233 | 258 | /** |
bpatel@233 | 259 | * Print the definition list end tag if the list start tag was printed. |
bpatel@233 | 260 | */ |
bpatel@233 | 261 | public void printMemberDetailsListEndTag () { |
bpatel@233 | 262 | if (getMemberDetailsListPrinted()) { |
bpatel@233 | 263 | dlEnd(); |
bpatel@233 | 264 | memberDetailsListPrinted = false; |
bpatel@233 | 265 | } |
bpatel@233 | 266 | } |
bpatel@233 | 267 | |
bpatel@233 | 268 | public boolean getMemberDetailsListPrinted() { |
bpatel@233 | 269 | return memberDetailsListPrinted; |
bpatel@233 | 270 | } |
bpatel@233 | 271 | |
bpatel@233 | 272 | /** |
duke@1 | 273 | * Print the frameset version of the Html file header. |
duke@1 | 274 | * Called only when generating an HTML frameset file. |
duke@1 | 275 | * |
duke@1 | 276 | * @param title Title of this HTML document. |
duke@1 | 277 | */ |
duke@1 | 278 | public void printFramesetHeader(String title) { |
duke@1 | 279 | printFramesetHeader(title, false); |
duke@1 | 280 | } |
duke@1 | 281 | |
duke@1 | 282 | /** |
duke@1 | 283 | * Print the frameset version of the Html file header. |
duke@1 | 284 | * Called only when generating an HTML frameset file. |
duke@1 | 285 | * |
duke@1 | 286 | * @param title Title of this HTML document. |
duke@1 | 287 | * @param noTimeStamp If true, don't print time stamp in header. |
duke@1 | 288 | */ |
duke@1 | 289 | public void printFramesetHeader(String title, boolean noTimeStamp) { |
duke@1 | 290 | println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 " + |
duke@1 | 291 | "Frameset//EN\" " + |
duke@1 | 292 | "\"http://www.w3.org/TR/html4/frameset.dtd\">"); |
duke@1 | 293 | println("<!--NewPage-->"); |
duke@1 | 294 | html(); |
duke@1 | 295 | head(); |
duke@1 | 296 | if (! noTimeStamp) { |
duke@1 | 297 | print("<!-- Generated by javadoc on "); |
duke@1 | 298 | print(today()); |
duke@1 | 299 | println("-->"); |
duke@1 | 300 | } |
duke@1 | 301 | if (configuration.charset.length() > 0) { |
duke@1 | 302 | println("<META http-equiv=\"Content-Type\" content=\"text/html; " |
duke@1 | 303 | + "charset=" + configuration.charset + "\">"); |
duke@1 | 304 | } |
duke@1 | 305 | title(); |
duke@1 | 306 | println(title); |
duke@1 | 307 | titleEnd(); |
duke@1 | 308 | //Script to set the classFrame if necessary. |
duke@1 | 309 | script(); |
duke@1 | 310 | println(" targetPage = \"\" + window.location.search;"); |
duke@1 | 311 | println(" if (targetPage != \"\" && targetPage != \"undefined\")"); |
duke@1 | 312 | println(" targetPage = targetPage.substring(1);"); |
duke@1 | 313 | println(" if (targetPage.indexOf(\":\") != -1)"); |
duke@1 | 314 | println(" targetPage = \"undefined\";"); |
duke@1 | 315 | |
duke@1 | 316 | println(" function loadFrames() {"); |
duke@1 | 317 | println(" if (targetPage != \"\" && targetPage != \"undefined\")"); |
duke@1 | 318 | println(" top.classFrame.location = top.targetPage;"); |
duke@1 | 319 | println(" }"); |
duke@1 | 320 | scriptEnd(); |
duke@1 | 321 | noScript(); |
duke@1 | 322 | noScriptEnd(); |
duke@1 | 323 | headEnd(); |
duke@1 | 324 | } |
duke@1 | 325 | |
duke@1 | 326 | /** |
duke@1 | 327 | * Print the appropriate spaces to format the class tree in the class page. |
duke@1 | 328 | * |
duke@1 | 329 | * @param len Number of spaces. |
duke@1 | 330 | */ |
duke@1 | 331 | public String spaces(int len) { |
duke@1 | 332 | String space = ""; |
duke@1 | 333 | |
duke@1 | 334 | for (int i = 0; i < len; i++) { |
duke@1 | 335 | space += " "; |
duke@1 | 336 | } |
duke@1 | 337 | return space; |
duke@1 | 338 | } |
duke@1 | 339 | |
duke@1 | 340 | /** |
duke@1 | 341 | * Print the closing </body> and </html> tags. |
duke@1 | 342 | */ |
duke@1 | 343 | public void printBodyHtmlEnd() { |
duke@1 | 344 | println(); |
duke@1 | 345 | bodyEnd(); |
duke@1 | 346 | htmlEnd(); |
duke@1 | 347 | } |
duke@1 | 348 | |
duke@1 | 349 | /** |
duke@1 | 350 | * Calls {@link #printBodyHtmlEnd()} method. |
duke@1 | 351 | */ |
duke@1 | 352 | public void printFooter() { |
duke@1 | 353 | printBodyHtmlEnd(); |
duke@1 | 354 | } |
duke@1 | 355 | |
duke@1 | 356 | /** |
duke@1 | 357 | * Print closing </html> tag. |
duke@1 | 358 | */ |
duke@1 | 359 | public void printFrameFooter() { |
duke@1 | 360 | htmlEnd(); |
duke@1 | 361 | } |
duke@1 | 362 | |
duke@1 | 363 | /** |
duke@1 | 364 | * Print ten non-breaking spaces("&nbsp;"). |
duke@1 | 365 | */ |
duke@1 | 366 | public void printNbsps() { |
duke@1 | 367 | print(" "); |
duke@1 | 368 | } |
duke@1 | 369 | |
duke@1 | 370 | /** |
duke@1 | 371 | * Get the day and date information for today, depending upon user option. |
duke@1 | 372 | * |
duke@1 | 373 | * @return String Today. |
duke@1 | 374 | * @see java.util.Calendar |
duke@1 | 375 | * @see java.util.GregorianCalendar |
duke@1 | 376 | * @see java.util.TimeZone |
duke@1 | 377 | */ |
duke@1 | 378 | public String today() { |
duke@1 | 379 | Calendar calendar = new GregorianCalendar(TimeZone.getDefault()); |
duke@1 | 380 | return calendar.getTime().toString(); |
duke@1 | 381 | } |
duke@1 | 382 | } |