Tue, 03 Dec 2013 14:21:45 -0800
8025416: doclet not substituting {@docRoot} in some cases
Reviewed-by: jjg
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) { |
bpatel@2101 | 110 | link = getHyperLink(getDocLink( |
bpatel@2101 | 111 | SectionName.UNNAMED_PACKAGE_ANCHOR), |
jjg@1373 | 112 | defaultPackageLabel, "", ""); |
bpatel@766 | 113 | } else { |
bpatel@766 | 114 | Content packageNameContent = getPackageLabel(parsedPackageName); |
bpatel@766 | 115 | packageNameContent.addContent(".*"); |
jjg@1373 | 116 | link = getHyperLink(DocLink.fragment(parsedPackageName), |
jjg@1373 | 117 | packageNameContent, "", ""); |
bpatel@766 | 118 | printedPackageHeaders.add(parsedPackageName); |
bpatel@766 | 119 | } |
bpatel@766 | 120 | contentListTree.addContent(HtmlTree.LI(link)); |
duke@1 | 121 | } |
duke@1 | 122 | |
duke@1 | 123 | /** |
duke@1 | 124 | * {@inheritDoc} |
duke@1 | 125 | */ |
bpatel@766 | 126 | public Content getContentsList(Content contentListTree) { |
bpatel@766 | 127 | Content titleContent = getResource( |
bpatel@766 | 128 | "doclet.Constants_Summary"); |
bpatel@766 | 129 | Content pHeading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true, |
bpatel@766 | 130 | HtmlStyle.title, titleContent); |
bpatel@766 | 131 | Content div = HtmlTree.DIV(HtmlStyle.header, pHeading); |
bpatel@766 | 132 | Content headingContent = getResource( |
bpatel@766 | 133 | "doclet.Contents"); |
bpatel@766 | 134 | div.addContent(HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, true, |
bpatel@766 | 135 | headingContent)); |
bpatel@766 | 136 | div.addContent(contentListTree); |
bpatel@766 | 137 | return div; |
duke@1 | 138 | } |
duke@1 | 139 | |
duke@1 | 140 | /** |
duke@1 | 141 | * {@inheritDoc} |
duke@1 | 142 | */ |
bpatel@766 | 143 | public Content getConstantSummaries() { |
bpatel@766 | 144 | HtmlTree summariesDiv = new HtmlTree(HtmlTag.DIV); |
bpatel@766 | 145 | summariesDiv.addStyle(HtmlStyle.constantValuesContainer); |
bpatel@766 | 146 | return summariesDiv; |
duke@1 | 147 | } |
duke@1 | 148 | |
duke@1 | 149 | /** |
duke@1 | 150 | * {@inheritDoc} |
duke@1 | 151 | */ |
bpatel@766 | 152 | public void addPackageName(PackageDoc pkg, String parsedPackageName, |
bpatel@766 | 153 | Content summariesTree) { |
bpatel@766 | 154 | Content pkgNameContent; |
bpatel@766 | 155 | if (parsedPackageName.length() == 0) { |
bpatel@766 | 156 | summariesTree.addContent(getMarkerAnchor( |
bpatel@2101 | 157 | SectionName.UNNAMED_PACKAGE_ANCHOR)); |
bpatel@766 | 158 | pkgNameContent = defaultPackageLabel; |
bpatel@766 | 159 | } else { |
bpatel@766 | 160 | summariesTree.addContent(getMarkerAnchor( |
bpatel@766 | 161 | parsedPackageName)); |
bpatel@766 | 162 | pkgNameContent = getPackageLabel(parsedPackageName); |
bpatel@766 | 163 | } |
bpatel@766 | 164 | Content headingContent = new StringContent(".*"); |
bpatel@766 | 165 | Content heading = HtmlTree.HEADING(HtmlConstants.PACKAGE_HEADING, true, |
bpatel@766 | 166 | pkgNameContent); |
bpatel@766 | 167 | heading.addContent(headingContent); |
bpatel@766 | 168 | summariesTree.addContent(heading); |
bpatel@766 | 169 | } |
bpatel@766 | 170 | |
bpatel@766 | 171 | /** |
bpatel@766 | 172 | * {@inheritDoc} |
bpatel@766 | 173 | */ |
bpatel@766 | 174 | public Content getClassConstantHeader() { |
bpatel@766 | 175 | HtmlTree ul = new HtmlTree(HtmlTag.UL); |
bpatel@766 | 176 | ul.addStyle(HtmlStyle.blockList); |
bpatel@766 | 177 | return ul; |
bpatel@766 | 178 | } |
bpatel@766 | 179 | |
bpatel@766 | 180 | /** |
bpatel@766 | 181 | * Get the table caption and header for the constant summary table |
bpatel@766 | 182 | * |
bpatel@766 | 183 | * @param cd classdoc to be documented |
bpatel@766 | 184 | * @return constant members header content |
bpatel@766 | 185 | */ |
bpatel@766 | 186 | public Content getConstantMembersHeader(ClassDoc cd) { |
duke@1 | 187 | //generate links backward only to public classes. |
jjg@1747 | 188 | Content classlink = (cd.isPublic() || cd.isProtected()) ? |
jjg@1410 | 189 | getLink(new LinkInfoImpl(configuration, |
jjg@1747 | 190 | LinkInfoImpl.Kind.CONSTANT_SUMMARY, cd)) : |
jjg@1747 | 191 | new StringContent(cd.qualifiedName()); |
duke@1 | 192 | String name = cd.containingPackage().name(); |
duke@1 | 193 | if (name.length() > 0) { |
jjg@1747 | 194 | Content cb = new ContentBuilder(); |
jjg@1747 | 195 | cb.addContent(name); |
jjg@1747 | 196 | cb.addContent("."); |
jjg@1747 | 197 | cb.addContent(classlink); |
jjg@1747 | 198 | return getClassName(cb); |
duke@1 | 199 | } else { |
bpatel@766 | 200 | return getClassName(classlink); |
duke@1 | 201 | } |
duke@1 | 202 | } |
duke@1 | 203 | |
duke@1 | 204 | /** |
bpatel@766 | 205 | * Get the class name in the table caption and the table header. |
bpatel@766 | 206 | * |
bpatel@766 | 207 | * @param classStr the class name to print. |
bpatel@766 | 208 | * @return the table caption and header |
bpatel@766 | 209 | */ |
jjg@1747 | 210 | protected Content getClassName(Content classStr) { |
bpatel@2084 | 211 | Content table = HtmlTree.TABLE(HtmlStyle.constantsSummary, 0, 3, 0, constantsTableSummary, |
bpatel@766 | 212 | getTableCaption(classStr)); |
bpatel@766 | 213 | table.addContent(getSummaryTableHeader(constantsTableHeader, "col")); |
bpatel@766 | 214 | return table; |
bpatel@766 | 215 | } |
bpatel@766 | 216 | |
bpatel@766 | 217 | /** |
duke@1 | 218 | * {@inheritDoc} |
duke@1 | 219 | */ |
bpatel@766 | 220 | public void addConstantMembers(ClassDoc cd, List<FieldDoc> fields, |
bpatel@766 | 221 | Content classConstantTree) { |
bpatel@766 | 222 | currentClassDoc = cd; |
bpatel@766 | 223 | Content tbody = new HtmlTree(HtmlTag.TBODY); |
bpatel@766 | 224 | for (int i = 0; i < fields.size(); ++i) { |
bpatel@766 | 225 | HtmlTree tr = new HtmlTree(HtmlTag.TR); |
bpatel@766 | 226 | if (i%2 == 0) |
bpatel@766 | 227 | tr.addStyle(HtmlStyle.altColor); |
bpatel@766 | 228 | else |
bpatel@766 | 229 | tr.addStyle(HtmlStyle.rowColor); |
bpatel@766 | 230 | addConstantMember(fields.get(i), tr); |
bpatel@766 | 231 | tbody.addContent(tr); |
bpatel@766 | 232 | } |
bpatel@766 | 233 | Content table = getConstantMembersHeader(cd); |
bpatel@766 | 234 | table.addContent(tbody); |
bpatel@766 | 235 | Content li = HtmlTree.LI(HtmlStyle.blockList, table); |
bpatel@766 | 236 | classConstantTree.addContent(li); |
duke@1 | 237 | } |
duke@1 | 238 | |
duke@1 | 239 | /** |
bpatel@766 | 240 | * Add the row for the constant summary table. |
bpatel@766 | 241 | * |
bpatel@766 | 242 | * @param member the field to be documented. |
bpatel@766 | 243 | * @param trTree an htmltree object for the table row |
duke@1 | 244 | */ |
bpatel@766 | 245 | private void addConstantMember(FieldDoc member, HtmlTree trTree) { |
bpatel@766 | 246 | trTree.addContent(getTypeColumn(member)); |
bpatel@766 | 247 | trTree.addContent(getNameColumn(member)); |
bpatel@766 | 248 | trTree.addContent(getValue(member)); |
duke@1 | 249 | } |
duke@1 | 250 | |
bpatel@766 | 251 | /** |
bpatel@766 | 252 | * Get the type column for the constant summary table row. |
bpatel@766 | 253 | * |
bpatel@766 | 254 | * @param member the field to be documented. |
bpatel@766 | 255 | * @return the type column of the constant table row |
bpatel@766 | 256 | */ |
bpatel@766 | 257 | private Content getTypeColumn(FieldDoc member) { |
bpatel@766 | 258 | Content anchor = getMarkerAnchor(currentClassDoc.qualifiedName() + |
bpatel@766 | 259 | "." + member.name()); |
bpatel@766 | 260 | Content tdType = HtmlTree.TD(HtmlStyle.colFirst, anchor); |
bpatel@766 | 261 | Content code = new HtmlTree(HtmlTag.CODE); |
bpatel@766 | 262 | StringTokenizer mods = new StringTokenizer(member.modifiers()); |
bpatel@766 | 263 | while(mods.hasMoreTokens()) { |
bpatel@766 | 264 | Content modifier = new StringContent(mods.nextToken()); |
bpatel@766 | 265 | code.addContent(modifier); |
bpatel@766 | 266 | code.addContent(getSpace()); |
duke@1 | 267 | } |
jjg@1736 | 268 | Content type = getLink(new LinkInfoImpl(configuration, |
jjg@1736 | 269 | LinkInfoImpl.Kind.CONSTANT_SUMMARY, member.type())); |
bpatel@766 | 270 | code.addContent(type); |
bpatel@766 | 271 | tdType.addContent(code); |
bpatel@766 | 272 | return tdType; |
bpatel@766 | 273 | } |
bpatel@766 | 274 | |
bpatel@766 | 275 | /** |
bpatel@766 | 276 | * Get the name column for the constant summary table row. |
bpatel@766 | 277 | * |
bpatel@766 | 278 | * @param member the field to be documented. |
bpatel@766 | 279 | * @return the name column of the constant table row |
bpatel@766 | 280 | */ |
bpatel@766 | 281 | private Content getNameColumn(FieldDoc member) { |
jjg@1736 | 282 | Content nameContent = getDocLink( |
jjg@1736 | 283 | LinkInfoImpl.Kind.CONSTANT_SUMMARY, member, member.name(), false); |
bpatel@766 | 284 | Content code = HtmlTree.CODE(nameContent); |
bpatel@766 | 285 | return HtmlTree.TD(code); |
bpatel@766 | 286 | } |
bpatel@766 | 287 | |
bpatel@766 | 288 | /** |
bpatel@766 | 289 | * Get the value column for the constant summary table row. |
bpatel@766 | 290 | * |
bpatel@766 | 291 | * @param member the field to be documented. |
bpatel@766 | 292 | * @return the value column of the constant table row |
bpatel@766 | 293 | */ |
bpatel@766 | 294 | private Content getValue(FieldDoc member) { |
bpatel@766 | 295 | Content valueContent = new StringContent(member.constantValueExpression()); |
bpatel@766 | 296 | Content code = HtmlTree.CODE(valueContent); |
bpatel@766 | 297 | return HtmlTree.TD(HtmlStyle.colLast, code); |
duke@1 | 298 | } |
duke@1 | 299 | |
duke@1 | 300 | /** |
duke@1 | 301 | * {@inheritDoc} |
duke@1 | 302 | */ |
bpatel@766 | 303 | public void addFooter(Content contentTree) { |
bpatel@766 | 304 | addNavLinks(false, contentTree); |
bpatel@766 | 305 | addBottom(contentTree); |
duke@1 | 306 | } |
duke@1 | 307 | |
duke@1 | 308 | /** |
duke@1 | 309 | * {@inheritDoc} |
duke@1 | 310 | */ |
jjg@1364 | 311 | public void printDocument(Content contentTree) throws IOException { |
bpatel@766 | 312 | printHtmlDocument(null, true, contentTree); |
duke@1 | 313 | } |
duke@1 | 314 | } |