Tue, 14 May 2013 10:14:53 -0700
8011668: Allow HTMLWriter.getResource to take Content args
Reviewed-by: darcy
duke@1 | 1 | /* |
jjg@1735 | 2 | * Copyright (c) 2001, 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; |
duke@1 | 27 | |
bpatel@766 | 28 | import java.io.*; |
bpatel@766 | 29 | import java.util.*; |
jjg@1357 | 30 | |
bpatel@766 | 31 | import com.sun.javadoc.*; |
jjg@1357 | 32 | import com.sun.tools.doclets.formats.html.markup.*; |
duke@1 | 33 | import com.sun.tools.doclets.internal.toolkit.*; |
duke@1 | 34 | import com.sun.tools.doclets.internal.toolkit.util.*; |
duke@1 | 35 | |
duke@1 | 36 | /** |
duke@1 | 37 | * Write the Constants Summary Page in HTML format. |
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 | * @author Jamie Ho |
bpatel@243 | 45 | * @author Bhavesh Patel (Modified) |
duke@1 | 46 | * @since 1.4 |
duke@1 | 47 | */ |
duke@1 | 48 | public class ConstantsSummaryWriterImpl extends HtmlDocletWriter |
duke@1 | 49 | implements ConstantsSummaryWriter { |
duke@1 | 50 | |
duke@1 | 51 | /** |
duke@1 | 52 | * The configuration used in this run of the standard doclet. |
duke@1 | 53 | */ |
duke@1 | 54 | ConfigurationImpl configuration; |
duke@1 | 55 | |
duke@1 | 56 | /** |
duke@1 | 57 | * The current class being documented. |
duke@1 | 58 | */ |
duke@1 | 59 | private ClassDoc currentClassDoc; |
duke@1 | 60 | |
bpatel@243 | 61 | private final String constantsTableSummary; |
bpatel@243 | 62 | |
bpatel@243 | 63 | private final String[] constantsTableHeader; |
bpatel@243 | 64 | |
duke@1 | 65 | /** |
duke@1 | 66 | * Construct a ConstantsSummaryWriter. |
duke@1 | 67 | * @param configuration the configuration used in this run |
duke@1 | 68 | * of the standard doclet. |
duke@1 | 69 | */ |
duke@1 | 70 | public ConstantsSummaryWriterImpl(ConfigurationImpl configuration) |
duke@1 | 71 | throws IOException { |
jjg@1372 | 72 | super(configuration, DocPaths.CONSTANT_VALUES); |
duke@1 | 73 | this.configuration = configuration; |
bpatel@243 | 74 | constantsTableSummary = configuration.getText("doclet.Constants_Table_Summary", |
bpatel@243 | 75 | configuration.getText("doclet.Constants_Summary")); |
bpatel@243 | 76 | constantsTableHeader = new String[] { |
bpatel@243 | 77 | getModifierTypeHeader(), |
bpatel@243 | 78 | configuration.getText("doclet.ConstantField"), |
bpatel@243 | 79 | configuration.getText("doclet.Value") |
bpatel@243 | 80 | }; |
duke@1 | 81 | } |
duke@1 | 82 | |
duke@1 | 83 | /** |
duke@1 | 84 | * {@inheritDoc} |
duke@1 | 85 | */ |
bpatel@766 | 86 | public Content getHeader() { |
bpatel@766 | 87 | String label = configuration.getText("doclet.Constants_Summary"); |
bpatel@766 | 88 | Content bodyTree = getBody(true, getWindowTitle(label)); |
bpatel@766 | 89 | addTop(bodyTree); |
bpatel@766 | 90 | addNavLinks(true, bodyTree); |
bpatel@766 | 91 | return bodyTree; |
duke@1 | 92 | } |
duke@1 | 93 | |
duke@1 | 94 | /** |
duke@1 | 95 | * {@inheritDoc} |
duke@1 | 96 | */ |
bpatel@766 | 97 | public Content getContentsHeader() { |
bpatel@766 | 98 | return new HtmlTree(HtmlTag.UL); |
duke@1 | 99 | } |
duke@1 | 100 | |
duke@1 | 101 | /** |
duke@1 | 102 | * {@inheritDoc} |
duke@1 | 103 | */ |
bpatel@766 | 104 | public void addLinkToPackageContent(PackageDoc pkg, String parsedPackageName, |
bpatel@766 | 105 | Set<String> printedPackageHeaders, Content contentListTree) { |
bpatel@766 | 106 | String packageName = pkg.name(); |
bpatel@766 | 107 | //add link to summary |
bpatel@766 | 108 | Content link; |
bpatel@766 | 109 | if (packageName.length() == 0) { |
jjg@1373 | 110 | link = getHyperLink(DocLink.fragment(DocletConstants.UNNAMED_PACKAGE_ANCHOR), |
jjg@1373 | 111 | defaultPackageLabel, "", ""); |
bpatel@766 | 112 | } else { |
bpatel@766 | 113 | Content packageNameContent = getPackageLabel(parsedPackageName); |
bpatel@766 | 114 | packageNameContent.addContent(".*"); |
jjg@1373 | 115 | link = getHyperLink(DocLink.fragment(parsedPackageName), |
jjg@1373 | 116 | packageNameContent, "", ""); |
bpatel@766 | 117 | printedPackageHeaders.add(parsedPackageName); |
bpatel@766 | 118 | } |
bpatel@766 | 119 | contentListTree.addContent(HtmlTree.LI(link)); |
duke@1 | 120 | } |
duke@1 | 121 | |
duke@1 | 122 | /** |
duke@1 | 123 | * {@inheritDoc} |
duke@1 | 124 | */ |
bpatel@766 | 125 | public Content getContentsList(Content contentListTree) { |
bpatel@766 | 126 | Content titleContent = getResource( |
bpatel@766 | 127 | "doclet.Constants_Summary"); |
bpatel@766 | 128 | Content pHeading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true, |
bpatel@766 | 129 | HtmlStyle.title, titleContent); |
bpatel@766 | 130 | Content div = HtmlTree.DIV(HtmlStyle.header, pHeading); |
bpatel@766 | 131 | Content headingContent = getResource( |
bpatel@766 | 132 | "doclet.Contents"); |
bpatel@766 | 133 | div.addContent(HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, true, |
bpatel@766 | 134 | headingContent)); |
bpatel@766 | 135 | div.addContent(contentListTree); |
bpatel@766 | 136 | return div; |
duke@1 | 137 | } |
duke@1 | 138 | |
duke@1 | 139 | /** |
duke@1 | 140 | * {@inheritDoc} |
duke@1 | 141 | */ |
bpatel@766 | 142 | public Content getConstantSummaries() { |
bpatel@766 | 143 | HtmlTree summariesDiv = new HtmlTree(HtmlTag.DIV); |
bpatel@766 | 144 | summariesDiv.addStyle(HtmlStyle.constantValuesContainer); |
bpatel@766 | 145 | return summariesDiv; |
duke@1 | 146 | } |
duke@1 | 147 | |
duke@1 | 148 | /** |
duke@1 | 149 | * {@inheritDoc} |
duke@1 | 150 | */ |
bpatel@766 | 151 | public void addPackageName(PackageDoc pkg, String parsedPackageName, |
bpatel@766 | 152 | Content summariesTree) { |
bpatel@766 | 153 | Content pkgNameContent; |
bpatel@766 | 154 | if (parsedPackageName.length() == 0) { |
bpatel@766 | 155 | summariesTree.addContent(getMarkerAnchor( |
bpatel@766 | 156 | DocletConstants.UNNAMED_PACKAGE_ANCHOR)); |
bpatel@766 | 157 | pkgNameContent = defaultPackageLabel; |
bpatel@766 | 158 | } else { |
bpatel@766 | 159 | summariesTree.addContent(getMarkerAnchor( |
bpatel@766 | 160 | parsedPackageName)); |
bpatel@766 | 161 | pkgNameContent = getPackageLabel(parsedPackageName); |
bpatel@766 | 162 | } |
bpatel@766 | 163 | Content headingContent = new StringContent(".*"); |
bpatel@766 | 164 | Content heading = HtmlTree.HEADING(HtmlConstants.PACKAGE_HEADING, true, |
bpatel@766 | 165 | pkgNameContent); |
bpatel@766 | 166 | heading.addContent(headingContent); |
bpatel@766 | 167 | summariesTree.addContent(heading); |
bpatel@766 | 168 | } |
bpatel@766 | 169 | |
bpatel@766 | 170 | /** |
bpatel@766 | 171 | * {@inheritDoc} |
bpatel@766 | 172 | */ |
bpatel@766 | 173 | public Content getClassConstantHeader() { |
bpatel@766 | 174 | HtmlTree ul = new HtmlTree(HtmlTag.UL); |
bpatel@766 | 175 | ul.addStyle(HtmlStyle.blockList); |
bpatel@766 | 176 | return ul; |
bpatel@766 | 177 | } |
bpatel@766 | 178 | |
bpatel@766 | 179 | /** |
bpatel@766 | 180 | * Get the table caption and header for the constant summary table |
bpatel@766 | 181 | * |
bpatel@766 | 182 | * @param cd classdoc to be documented |
bpatel@766 | 183 | * @return constant members header content |
bpatel@766 | 184 | */ |
bpatel@766 | 185 | public Content getConstantMembersHeader(ClassDoc cd) { |
duke@1 | 186 | //generate links backward only to public classes. |
jjg@1410 | 187 | String classlink = (cd.isPublic() || cd.isProtected()) ? |
jjg@1410 | 188 | getLink(new LinkInfoImpl(configuration, |
jjg@1738 | 189 | LinkInfoImpl.Kind.CONSTANT_SUMMARY, cd)).toString() : |
duke@1 | 190 | cd.qualifiedName(); |
duke@1 | 191 | String name = cd.containingPackage().name(); |
duke@1 | 192 | if (name.length() > 0) { |
bpatel@766 | 193 | return getClassName(name + "." + classlink); |
duke@1 | 194 | } else { |
bpatel@766 | 195 | return getClassName(classlink); |
duke@1 | 196 | } |
duke@1 | 197 | } |
duke@1 | 198 | |
duke@1 | 199 | /** |
bpatel@766 | 200 | * Get the class name in the table caption and the table header. |
bpatel@766 | 201 | * |
bpatel@766 | 202 | * @param classStr the class name to print. |
bpatel@766 | 203 | * @return the table caption and header |
bpatel@766 | 204 | */ |
bpatel@766 | 205 | protected Content getClassName(String classStr) { |
bpatel@766 | 206 | Content table = HtmlTree.TABLE(0, 3, 0, constantsTableSummary, |
bpatel@766 | 207 | getTableCaption(classStr)); |
bpatel@766 | 208 | table.addContent(getSummaryTableHeader(constantsTableHeader, "col")); |
bpatel@766 | 209 | return table; |
bpatel@766 | 210 | } |
bpatel@766 | 211 | |
bpatel@766 | 212 | /** |
duke@1 | 213 | * {@inheritDoc} |
duke@1 | 214 | */ |
bpatel@766 | 215 | public void addConstantMembers(ClassDoc cd, List<FieldDoc> fields, |
bpatel@766 | 216 | Content classConstantTree) { |
bpatel@766 | 217 | currentClassDoc = cd; |
bpatel@766 | 218 | Content tbody = new HtmlTree(HtmlTag.TBODY); |
bpatel@766 | 219 | for (int i = 0; i < fields.size(); ++i) { |
bpatel@766 | 220 | HtmlTree tr = new HtmlTree(HtmlTag.TR); |
bpatel@766 | 221 | if (i%2 == 0) |
bpatel@766 | 222 | tr.addStyle(HtmlStyle.altColor); |
bpatel@766 | 223 | else |
bpatel@766 | 224 | tr.addStyle(HtmlStyle.rowColor); |
bpatel@766 | 225 | addConstantMember(fields.get(i), tr); |
bpatel@766 | 226 | tbody.addContent(tr); |
bpatel@766 | 227 | } |
bpatel@766 | 228 | Content table = getConstantMembersHeader(cd); |
bpatel@766 | 229 | table.addContent(tbody); |
bpatel@766 | 230 | Content li = HtmlTree.LI(HtmlStyle.blockList, table); |
bpatel@766 | 231 | classConstantTree.addContent(li); |
duke@1 | 232 | } |
duke@1 | 233 | |
duke@1 | 234 | /** |
bpatel@766 | 235 | * Add the row for the constant summary table. |
bpatel@766 | 236 | * |
bpatel@766 | 237 | * @param member the field to be documented. |
bpatel@766 | 238 | * @param trTree an htmltree object for the table row |
duke@1 | 239 | */ |
bpatel@766 | 240 | private void addConstantMember(FieldDoc member, HtmlTree trTree) { |
bpatel@766 | 241 | trTree.addContent(getTypeColumn(member)); |
bpatel@766 | 242 | trTree.addContent(getNameColumn(member)); |
bpatel@766 | 243 | trTree.addContent(getValue(member)); |
duke@1 | 244 | } |
duke@1 | 245 | |
bpatel@766 | 246 | /** |
bpatel@766 | 247 | * Get the type column for the constant summary table row. |
bpatel@766 | 248 | * |
bpatel@766 | 249 | * @param member the field to be documented. |
bpatel@766 | 250 | * @return the type column of the constant table row |
bpatel@766 | 251 | */ |
bpatel@766 | 252 | private Content getTypeColumn(FieldDoc member) { |
bpatel@766 | 253 | Content anchor = getMarkerAnchor(currentClassDoc.qualifiedName() + |
bpatel@766 | 254 | "." + member.name()); |
bpatel@766 | 255 | Content tdType = HtmlTree.TD(HtmlStyle.colFirst, anchor); |
bpatel@766 | 256 | Content code = new HtmlTree(HtmlTag.CODE); |
bpatel@766 | 257 | StringTokenizer mods = new StringTokenizer(member.modifiers()); |
bpatel@766 | 258 | while(mods.hasMoreTokens()) { |
bpatel@766 | 259 | Content modifier = new StringContent(mods.nextToken()); |
bpatel@766 | 260 | code.addContent(modifier); |
bpatel@766 | 261 | code.addContent(getSpace()); |
duke@1 | 262 | } |
jjg@1736 | 263 | Content type = getLink(new LinkInfoImpl(configuration, |
jjg@1736 | 264 | LinkInfoImpl.Kind.CONSTANT_SUMMARY, member.type())); |
bpatel@766 | 265 | code.addContent(type); |
bpatel@766 | 266 | tdType.addContent(code); |
bpatel@766 | 267 | return tdType; |
bpatel@766 | 268 | } |
bpatel@766 | 269 | |
bpatel@766 | 270 | /** |
bpatel@766 | 271 | * Get the name column for the constant summary table row. |
bpatel@766 | 272 | * |
bpatel@766 | 273 | * @param member the field to be documented. |
bpatel@766 | 274 | * @return the name column of the constant table row |
bpatel@766 | 275 | */ |
bpatel@766 | 276 | private Content getNameColumn(FieldDoc member) { |
jjg@1736 | 277 | Content nameContent = getDocLink( |
jjg@1736 | 278 | LinkInfoImpl.Kind.CONSTANT_SUMMARY, member, member.name(), false); |
bpatel@766 | 279 | Content code = HtmlTree.CODE(nameContent); |
bpatel@766 | 280 | return HtmlTree.TD(code); |
bpatel@766 | 281 | } |
bpatel@766 | 282 | |
bpatel@766 | 283 | /** |
bpatel@766 | 284 | * Get the value column for the constant summary table row. |
bpatel@766 | 285 | * |
bpatel@766 | 286 | * @param member the field to be documented. |
bpatel@766 | 287 | * @return the value column of the constant table row |
bpatel@766 | 288 | */ |
bpatel@766 | 289 | private Content getValue(FieldDoc member) { |
bpatel@766 | 290 | Content valueContent = new StringContent(member.constantValueExpression()); |
bpatel@766 | 291 | Content code = HtmlTree.CODE(valueContent); |
bpatel@766 | 292 | return HtmlTree.TD(HtmlStyle.colLast, code); |
duke@1 | 293 | } |
duke@1 | 294 | |
duke@1 | 295 | /** |
duke@1 | 296 | * {@inheritDoc} |
duke@1 | 297 | */ |
bpatel@766 | 298 | public void addFooter(Content contentTree) { |
bpatel@766 | 299 | addNavLinks(false, contentTree); |
bpatel@766 | 300 | addBottom(contentTree); |
duke@1 | 301 | } |
duke@1 | 302 | |
duke@1 | 303 | /** |
duke@1 | 304 | * {@inheritDoc} |
duke@1 | 305 | */ |
jjg@1364 | 306 | public void printDocument(Content contentTree) throws IOException { |
bpatel@766 | 307 | printHtmlDocument(null, true, contentTree); |
duke@1 | 308 | } |
duke@1 | 309 | } |