Tue, 23 Oct 2012 13:20:37 -0700
8000741: refactor javadoc to use abstraction to handle relative paths
Reviewed-by: darcy
duke@1 | 1 | /* |
jjg@1359 | 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 | |
jjg@197 | 28 | import java.io.*; |
jjg@197 | 29 | import java.util.*; |
duke@1 | 30 | |
duke@1 | 31 | import com.sun.javadoc.*; |
jjg@1361 | 32 | import com.sun.tools.doclets.formats.html.ConfigurationImpl; |
jjg@197 | 33 | import com.sun.tools.doclets.internal.toolkit.*; |
jjg@1372 | 34 | import com.sun.tools.doclets.internal.toolkit.util.DocPath; |
jjg@1372 | 35 | import com.sun.tools.doclets.internal.toolkit.util.DocPaths; |
duke@1 | 36 | |
duke@1 | 37 | |
duke@1 | 38 | /** |
duke@1 | 39 | * Class for the Html Format Code Generation specific to JavaDoc. |
duke@1 | 40 | * This Class contains methods related to the Html Code Generation which |
duke@1 | 41 | * are used by the Sub-Classes in the package com.sun.tools.doclets.standard |
duke@1 | 42 | * and com.sun.tools.doclets.oneone. |
duke@1 | 43 | * |
jjg@1359 | 44 | * <p><b>This is NOT part of any supported API. |
jjg@1359 | 45 | * If you write code that depends on this, you do so at your own risk. |
jjg@1359 | 46 | * This code and its internal interfaces are subject to change or |
jjg@1359 | 47 | * deletion without notice.</b> |
jjg@1359 | 48 | * |
duke@1 | 49 | * @since 1.2 |
duke@1 | 50 | * @author Atul M Dambalkar |
duke@1 | 51 | * @author Robert Field |
duke@1 | 52 | */ |
duke@1 | 53 | public abstract class HtmlDocWriter extends HtmlWriter { |
duke@1 | 54 | |
duke@1 | 55 | /** |
duke@1 | 56 | * Constructor. Initializes the destination file name through the super |
duke@1 | 57 | * class HtmlWriter. |
duke@1 | 58 | * |
duke@1 | 59 | * @param filename String file name. |
duke@1 | 60 | */ |
jjg@1372 | 61 | public HtmlDocWriter(Configuration configuration, DocPath filename) |
jjg@1372 | 62 | throws IOException { |
jjg@1372 | 63 | super(configuration, filename); |
duke@1 | 64 | configuration.message.notice("doclet.Generating_0", |
jjg@1372 | 65 | filename.resolveAgainst(configuration.destDirName)); |
duke@1 | 66 | } |
duke@1 | 67 | |
duke@1 | 68 | /** |
duke@1 | 69 | * Accessor for configuration. |
duke@1 | 70 | */ |
duke@1 | 71 | public abstract Configuration configuration(); |
duke@1 | 72 | |
duke@1 | 73 | /** |
duke@1 | 74 | * Return Html Hyper Link string. |
duke@1 | 75 | * |
duke@1 | 76 | * @param link String name of the file. |
duke@1 | 77 | * @param where Position of the link in the file. Character '#' is not |
duke@1 | 78 | * needed. |
duke@1 | 79 | * @param label Tag for the link. |
bpatel@182 | 80 | * @param strong Boolean that sets label to strong. |
duke@1 | 81 | * @return String Hyper Link. |
duke@1 | 82 | */ |
jjg@1372 | 83 | public String getHyperLinkString(DocPath link, String where, |
bpatel@182 | 84 | String label, boolean strong) { |
bpatel@766 | 85 | return getHyperLinkString(link, where, label, strong, "", "", ""); |
duke@1 | 86 | } |
duke@1 | 87 | |
duke@1 | 88 | /** |
duke@1 | 89 | * Get Html Hyper Link string. |
duke@1 | 90 | * |
duke@1 | 91 | * @param link String name of the file. |
duke@1 | 92 | * @param where Position of the link in the file. Character '#' is not |
duke@1 | 93 | * needed. |
duke@1 | 94 | * @param label Tag for the link. |
bpatel@182 | 95 | * @param strong Boolean that sets label to strong. |
duke@1 | 96 | * @param stylename String style of text defined in style sheet. |
duke@1 | 97 | * @return String Hyper Link. |
duke@1 | 98 | */ |
jjg@1372 | 99 | public String getHyperLinkString(DocPath link, String where, |
bpatel@182 | 100 | String label, boolean strong, |
duke@1 | 101 | String stylename) { |
bpatel@766 | 102 | return getHyperLinkString(link, where, label, strong, stylename, "", ""); |
bpatel@766 | 103 | } |
bpatel@766 | 104 | |
bpatel@766 | 105 | /** |
bpatel@766 | 106 | * Get Html Hyper Link string. |
bpatel@766 | 107 | * |
jjg@1372 | 108 | * @param where Position of the link in the file. Character '#' is not |
jjg@1372 | 109 | * needed. |
jjg@1372 | 110 | * @param label Tag for the link. |
jjg@1372 | 111 | * @return a content tree for the hyper link |
jjg@1372 | 112 | */ |
jjg@1372 | 113 | public Content getHyperLink(String where, |
jjg@1372 | 114 | Content label) { |
jjg@1372 | 115 | return getHyperLink(DocPath.empty, where, label, "", ""); |
jjg@1372 | 116 | } |
jjg@1372 | 117 | |
jjg@1372 | 118 | /** |
jjg@1372 | 119 | * Get Html Hyper Link string. |
jjg@1372 | 120 | * |
bpatel@766 | 121 | * @param link String name of the file. |
bpatel@766 | 122 | * @param where Position of the link in the file. Character '#' is not |
bpatel@766 | 123 | * needed. |
bpatel@766 | 124 | * @param label Tag for the link. |
bpatel@766 | 125 | * @return a content tree for the hyper link |
bpatel@766 | 126 | */ |
jjg@1372 | 127 | public Content getHyperLink(DocPath link, String where, |
bpatel@766 | 128 | Content label) { |
bpatel@766 | 129 | return getHyperLink(link, where, label, "", ""); |
duke@1 | 130 | } |
duke@1 | 131 | |
duke@1 | 132 | /** |
duke@1 | 133 | * Get Html Hyper Link string. |
duke@1 | 134 | * |
duke@1 | 135 | * @param link String name of the file. |
duke@1 | 136 | * @param where Position of the link in the file. Character '#' is not |
duke@1 | 137 | * needed. |
duke@1 | 138 | * @param label Tag for the link. |
bpatel@182 | 139 | * @param strong Boolean that sets label to strong. |
duke@1 | 140 | * @param stylename String style of text defined in style sheet. |
duke@1 | 141 | * @param title String that describes the link's content for accessibility. |
duke@1 | 142 | * @param target Target frame. |
duke@1 | 143 | * @return String Hyper Link. |
duke@1 | 144 | */ |
jjg@1372 | 145 | public String getHyperLinkString(DocPath link, String where, |
jjg@1372 | 146 | String label, boolean strong, |
jjg@1372 | 147 | String stylename, String title, String target) { |
jjg@1372 | 148 | return getHyperLinkString(link.getPath(), where, label, strong, |
jjg@1372 | 149 | stylename, title, target); |
jjg@1372 | 150 | } |
jjg@1372 | 151 | |
bpatel@766 | 152 | public String getHyperLinkString(String link, String where, |
bpatel@182 | 153 | String label, boolean strong, |
duke@1 | 154 | String stylename, String title, String target) { |
jjg@1362 | 155 | StringBuilder retlink = new StringBuilder(); |
bpatel@766 | 156 | retlink.append("<a href=\""); |
duke@1 | 157 | retlink.append(link); |
duke@1 | 158 | if (where != null && where.length() != 0) { |
duke@1 | 159 | retlink.append("#"); |
duke@1 | 160 | retlink.append(where); |
duke@1 | 161 | } |
duke@1 | 162 | retlink.append("\""); |
duke@1 | 163 | if (title != null && title.length() != 0) { |
jjg@1362 | 164 | retlink.append(" title=\"").append(title).append("\""); |
duke@1 | 165 | } |
duke@1 | 166 | if (target != null && target.length() != 0) { |
jjg@1362 | 167 | retlink.append(" target=\"").append(target).append("\""); |
duke@1 | 168 | } |
duke@1 | 169 | retlink.append(">"); |
duke@1 | 170 | if (stylename != null && stylename.length() != 0) { |
duke@1 | 171 | retlink.append("<FONT CLASS=\""); |
duke@1 | 172 | retlink.append(stylename); |
duke@1 | 173 | retlink.append("\">"); |
duke@1 | 174 | } |
bpatel@182 | 175 | if (strong) { |
bpatel@766 | 176 | retlink.append("<span class=\"strong\">"); |
duke@1 | 177 | } |
duke@1 | 178 | retlink.append(label); |
bpatel@182 | 179 | if (strong) { |
bpatel@766 | 180 | retlink.append("</span>"); |
duke@1 | 181 | } |
duke@1 | 182 | if (stylename != null && stylename.length() != 0) { |
duke@1 | 183 | retlink.append("</FONT>"); |
duke@1 | 184 | } |
bpatel@766 | 185 | retlink.append("</a>"); |
duke@1 | 186 | return retlink.toString(); |
duke@1 | 187 | } |
duke@1 | 188 | |
duke@1 | 189 | /** |
bpatel@766 | 190 | * Get Html Hyper Link. |
duke@1 | 191 | * |
duke@1 | 192 | * @param link String name of the file. |
bpatel@766 | 193 | * @param where Position of the link in the file. Character '#' is not |
bpatel@766 | 194 | * needed. |
duke@1 | 195 | * @param label Tag for the link. |
bpatel@766 | 196 | * @param title String that describes the link's content for accessibility. |
bpatel@766 | 197 | * @param target Target frame. |
bpatel@766 | 198 | * @return a content tree for the hyper link. |
duke@1 | 199 | */ |
jjg@1372 | 200 | public Content getHyperLink(DocPath link, String where, |
jjg@1372 | 201 | Content label, String title, String target) { |
jjg@1372 | 202 | return getHyperLink(link.getPath(), where, label, title, target); |
jjg@1372 | 203 | } |
bpatel@766 | 204 | public Content getHyperLink(String link, String where, |
bpatel@766 | 205 | Content label, String title, String target) { |
jjg@1372 | 206 | if (link.startsWith("/")) Thread.dumpStack(); |
bpatel@766 | 207 | if (where != null && where.length() != 0) { |
bpatel@766 | 208 | link += "#" + where; |
bpatel@766 | 209 | } |
bpatel@766 | 210 | HtmlTree anchor = HtmlTree.A(link, label); |
bpatel@766 | 211 | if (title != null && title.length() != 0) { |
bpatel@766 | 212 | anchor.addAttr(HtmlAttr.TITLE, title); |
bpatel@766 | 213 | } |
bpatel@766 | 214 | if (target != null && target.length() != 0) { |
bpatel@766 | 215 | anchor.addAttr(HtmlAttr.TARGET, target); |
bpatel@766 | 216 | } |
bpatel@766 | 217 | return anchor; |
bpatel@766 | 218 | } |
bpatel@766 | 219 | |
bpatel@766 | 220 | /** |
bpatel@766 | 221 | * Get a hyperlink to a file. |
bpatel@766 | 222 | * |
bpatel@766 | 223 | * @param link String name of the file |
bpatel@766 | 224 | * @param label Label for the link |
bpatel@766 | 225 | * @return a content for the hyperlink to the file |
bpatel@766 | 226 | */ |
jjg@1372 | 227 | public Content getHyperLink(DocPath link, Content label) { |
bpatel@766 | 228 | return getHyperLink(link, "", label); |
duke@1 | 229 | } |
duke@1 | 230 | |
duke@1 | 231 | /** |
duke@1 | 232 | * Get link string without positioning in the file. |
duke@1 | 233 | * |
duke@1 | 234 | * @param link String name of the file. |
duke@1 | 235 | * @param label Tag for the link. |
duke@1 | 236 | * @return Strign Hyper link. |
duke@1 | 237 | */ |
jjg@1372 | 238 | public String getHyperLinkString(DocPath link, String label) { |
bpatel@766 | 239 | return getHyperLinkString(link, "", label, false); |
duke@1 | 240 | } |
duke@1 | 241 | |
duke@1 | 242 | /** |
duke@1 | 243 | * Get the name of the package, this class is in. |
duke@1 | 244 | * |
duke@1 | 245 | * @param cd ClassDoc. |
duke@1 | 246 | */ |
duke@1 | 247 | public String getPkgName(ClassDoc cd) { |
duke@1 | 248 | String pkgName = cd.containingPackage().name(); |
duke@1 | 249 | if (pkgName.length() > 0) { |
duke@1 | 250 | pkgName += "."; |
duke@1 | 251 | return pkgName; |
duke@1 | 252 | } |
duke@1 | 253 | return ""; |
duke@1 | 254 | } |
duke@1 | 255 | |
bpatel@233 | 256 | public boolean getMemberDetailsListPrinted() { |
bpatel@233 | 257 | return memberDetailsListPrinted; |
bpatel@233 | 258 | } |
bpatel@233 | 259 | |
bpatel@233 | 260 | /** |
duke@1 | 261 | * Print the frameset version of the Html file header. |
duke@1 | 262 | * Called only when generating an HTML frameset file. |
duke@1 | 263 | * |
bpatel@766 | 264 | * @param title Title of this HTML document |
bpatel@766 | 265 | * @param noTimeStamp If true, don't print time stamp in header |
bpatel@766 | 266 | * @param frameset the frameset to be added to the HTML document |
duke@1 | 267 | */ |
bpatel@766 | 268 | public void printFramesetDocument(String title, boolean noTimeStamp, |
jjg@1364 | 269 | Content frameset) throws IOException { |
bpatel@766 | 270 | Content htmlDocType = DocType.Frameset(); |
bpatel@766 | 271 | Content htmlComment = new Comment(configuration.getText("doclet.New_Page")); |
bpatel@766 | 272 | Content head = new HtmlTree(HtmlTag.HEAD); |
duke@1 | 273 | if (! noTimeStamp) { |
jjg@1361 | 274 | Content headComment = new Comment(getGeneratedByString()); |
bpatel@766 | 275 | head.addContent(headComment); |
duke@1 | 276 | } |
duke@1 | 277 | if (configuration.charset.length() > 0) { |
bpatel@766 | 278 | Content meta = HtmlTree.META("Content-Type", "text/html", |
bpatel@766 | 279 | configuration.charset); |
bpatel@766 | 280 | head.addContent(meta); |
duke@1 | 281 | } |
bpatel@766 | 282 | Content windowTitle = HtmlTree.TITLE(new StringContent(title)); |
bpatel@766 | 283 | head.addContent(windowTitle); |
bpatel@766 | 284 | head.addContent(getFramesetJavaScript()); |
bpatel@766 | 285 | Content htmlTree = HtmlTree.HTML(configuration.getLocale().getLanguage(), |
bpatel@766 | 286 | head, frameset); |
bpatel@766 | 287 | Content htmlDocument = new HtmlDocument(htmlDocType, |
bpatel@766 | 288 | htmlComment, htmlTree); |
jjg@1365 | 289 | write(htmlDocument); |
duke@1 | 290 | } |
duke@1 | 291 | |
duke@1 | 292 | /** |
duke@1 | 293 | * Print the appropriate spaces to format the class tree in the class page. |
duke@1 | 294 | * |
duke@1 | 295 | * @param len Number of spaces. |
duke@1 | 296 | */ |
duke@1 | 297 | public String spaces(int len) { |
duke@1 | 298 | String space = ""; |
duke@1 | 299 | |
duke@1 | 300 | for (int i = 0; i < len; i++) { |
duke@1 | 301 | space += " "; |
duke@1 | 302 | } |
duke@1 | 303 | return space; |
duke@1 | 304 | } |
duke@1 | 305 | |
jjg@1361 | 306 | protected String getGeneratedByString() { |
duke@1 | 307 | Calendar calendar = new GregorianCalendar(TimeZone.getDefault()); |
jjg@1361 | 308 | Date today = calendar.getTime(); |
jjg@1361 | 309 | return "Generated by javadoc ("+ ConfigurationImpl.BUILD_DATE + ") on " + today; |
duke@1 | 310 | } |
duke@1 | 311 | } |