duke@1: /* ohair@798: * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as ohair@554: * published by the Free Software Foundation. Oracle designates this duke@1: * particular file as subject to the "Classpath" exception as provided ohair@554: * by Oracle in the LICENSE file that accompanied this code. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. duke@1: */ duke@1: duke@1: package com.sun.tools.doclets.formats.html; duke@1: bpatel@766: import java.io.*; bpatel@766: import java.util.*; bpatel@766: import com.sun.javadoc.*; duke@1: import com.sun.tools.doclets.internal.toolkit.*; duke@1: import com.sun.tools.doclets.internal.toolkit.util.*; bpatel@766: import com.sun.tools.doclets.formats.html.markup.*; duke@1: duke@1: /** duke@1: * Write the Constants Summary Page in HTML format. duke@1: * duke@1: * @author Jamie Ho bpatel@243: * @author Bhavesh Patel (Modified) duke@1: * @since 1.4 duke@1: */ duke@1: public class ConstantsSummaryWriterImpl extends HtmlDocletWriter duke@1: implements ConstantsSummaryWriter { duke@1: duke@1: /** duke@1: * The configuration used in this run of the standard doclet. duke@1: */ duke@1: ConfigurationImpl configuration; duke@1: duke@1: /** duke@1: * The current class being documented. duke@1: */ duke@1: private ClassDoc currentClassDoc; duke@1: bpatel@243: private final String constantsTableSummary; bpatel@243: bpatel@243: private final String[] constantsTableHeader; bpatel@243: duke@1: /** duke@1: * Construct a ConstantsSummaryWriter. duke@1: * @param configuration the configuration used in this run duke@1: * of the standard doclet. duke@1: */ duke@1: public ConstantsSummaryWriterImpl(ConfigurationImpl configuration) duke@1: throws IOException { duke@1: super(configuration, ConfigurationImpl.CONSTANTS_FILE_NAME); duke@1: this.configuration = configuration; bpatel@243: constantsTableSummary = configuration.getText("doclet.Constants_Table_Summary", bpatel@243: configuration.getText("doclet.Constants_Summary")); bpatel@243: constantsTableHeader = new String[] { bpatel@243: getModifierTypeHeader(), bpatel@243: configuration.getText("doclet.ConstantField"), bpatel@243: configuration.getText("doclet.Value") bpatel@243: }; duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ bpatel@766: public Content getHeader() { bpatel@766: String label = configuration.getText("doclet.Constants_Summary"); bpatel@766: Content bodyTree = getBody(true, getWindowTitle(label)); bpatel@766: addTop(bodyTree); bpatel@766: addNavLinks(true, bodyTree); bpatel@766: return bodyTree; duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ bpatel@766: public Content getContentsHeader() { bpatel@766: return new HtmlTree(HtmlTag.UL); duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ bpatel@766: public void addLinkToPackageContent(PackageDoc pkg, String parsedPackageName, bpatel@766: Set printedPackageHeaders, Content contentListTree) { bpatel@766: String packageName = pkg.name(); bpatel@766: //add link to summary bpatel@766: Content link; bpatel@766: if (packageName.length() == 0) { bpatel@766: link = getHyperLink("#" + DocletConstants.UNNAMED_PACKAGE_ANCHOR, bpatel@766: "", defaultPackageLabel, "", ""); bpatel@766: } else { bpatel@766: Content packageNameContent = getPackageLabel(parsedPackageName); bpatel@766: packageNameContent.addContent(".*"); bpatel@766: link = getHyperLink("#" + parsedPackageName, bpatel@766: "", packageNameContent, "", ""); bpatel@766: printedPackageHeaders.add(parsedPackageName); bpatel@766: } bpatel@766: contentListTree.addContent(HtmlTree.LI(link)); duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ bpatel@766: public Content getContentsList(Content contentListTree) { bpatel@766: Content titleContent = getResource( bpatel@766: "doclet.Constants_Summary"); bpatel@766: Content pHeading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true, bpatel@766: HtmlStyle.title, titleContent); bpatel@766: Content div = HtmlTree.DIV(HtmlStyle.header, pHeading); bpatel@766: Content headingContent = getResource( bpatel@766: "doclet.Contents"); bpatel@766: div.addContent(HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, true, bpatel@766: headingContent)); bpatel@766: div.addContent(contentListTree); bpatel@766: return div; duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ bpatel@766: public Content getConstantSummaries() { bpatel@766: HtmlTree summariesDiv = new HtmlTree(HtmlTag.DIV); bpatel@766: summariesDiv.addStyle(HtmlStyle.constantValuesContainer); bpatel@766: return summariesDiv; duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ bpatel@766: public void addPackageName(PackageDoc pkg, String parsedPackageName, bpatel@766: Content summariesTree) { bpatel@766: Content pkgNameContent; bpatel@766: if (parsedPackageName.length() == 0) { bpatel@766: summariesTree.addContent(getMarkerAnchor( bpatel@766: DocletConstants.UNNAMED_PACKAGE_ANCHOR)); bpatel@766: pkgNameContent = defaultPackageLabel; bpatel@766: } else { bpatel@766: summariesTree.addContent(getMarkerAnchor( bpatel@766: parsedPackageName)); bpatel@766: pkgNameContent = getPackageLabel(parsedPackageName); bpatel@766: } bpatel@766: Content headingContent = new StringContent(".*"); bpatel@766: Content heading = HtmlTree.HEADING(HtmlConstants.PACKAGE_HEADING, true, bpatel@766: pkgNameContent); bpatel@766: heading.addContent(headingContent); bpatel@766: summariesTree.addContent(heading); bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * {@inheritDoc} bpatel@766: */ bpatel@766: public Content getClassConstantHeader() { bpatel@766: HtmlTree ul = new HtmlTree(HtmlTag.UL); bpatel@766: ul.addStyle(HtmlStyle.blockList); bpatel@766: return ul; bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * Get the table caption and header for the constant summary table bpatel@766: * bpatel@766: * @param cd classdoc to be documented bpatel@766: * @return constant members header content bpatel@766: */ bpatel@766: public Content getConstantMembersHeader(ClassDoc cd) { duke@1: //generate links backward only to public classes. duke@1: String classlink = (cd.isPublic() || cd.isProtected())? duke@1: getLink(new LinkInfoImpl(LinkInfoImpl.CONTEXT_CONSTANT_SUMMARY, cd, duke@1: false)) : duke@1: cd.qualifiedName(); duke@1: String name = cd.containingPackage().name(); duke@1: if (name.length() > 0) { bpatel@766: return getClassName(name + "." + classlink); duke@1: } else { bpatel@766: return getClassName(classlink); duke@1: } duke@1: } duke@1: duke@1: /** bpatel@766: * Get the class name in the table caption and the table header. bpatel@766: * bpatel@766: * @param classStr the class name to print. bpatel@766: * @return the table caption and header bpatel@766: */ bpatel@766: protected Content getClassName(String classStr) { bpatel@766: Content table = HtmlTree.TABLE(0, 3, 0, constantsTableSummary, bpatel@766: getTableCaption(classStr)); bpatel@766: table.addContent(getSummaryTableHeader(constantsTableHeader, "col")); bpatel@766: return table; bpatel@766: } bpatel@766: bpatel@766: /** duke@1: * {@inheritDoc} duke@1: */ bpatel@766: public void addConstantMembers(ClassDoc cd, List fields, bpatel@766: Content classConstantTree) { bpatel@766: currentClassDoc = cd; bpatel@766: Content tbody = new HtmlTree(HtmlTag.TBODY); bpatel@766: for (int i = 0; i < fields.size(); ++i) { bpatel@766: HtmlTree tr = new HtmlTree(HtmlTag.TR); bpatel@766: if (i%2 == 0) bpatel@766: tr.addStyle(HtmlStyle.altColor); bpatel@766: else bpatel@766: tr.addStyle(HtmlStyle.rowColor); bpatel@766: addConstantMember(fields.get(i), tr); bpatel@766: tbody.addContent(tr); bpatel@766: } bpatel@766: Content table = getConstantMembersHeader(cd); bpatel@766: table.addContent(tbody); bpatel@766: Content li = HtmlTree.LI(HtmlStyle.blockList, table); bpatel@766: classConstantTree.addContent(li); duke@1: } duke@1: duke@1: /** bpatel@766: * Add the row for the constant summary table. bpatel@766: * bpatel@766: * @param member the field to be documented. bpatel@766: * @param trTree an htmltree object for the table row duke@1: */ bpatel@766: private void addConstantMember(FieldDoc member, HtmlTree trTree) { bpatel@766: trTree.addContent(getTypeColumn(member)); bpatel@766: trTree.addContent(getNameColumn(member)); bpatel@766: trTree.addContent(getValue(member)); duke@1: } duke@1: bpatel@766: /** bpatel@766: * Get the type column for the constant summary table row. bpatel@766: * bpatel@766: * @param member the field to be documented. bpatel@766: * @return the type column of the constant table row bpatel@766: */ bpatel@766: private Content getTypeColumn(FieldDoc member) { bpatel@766: Content anchor = getMarkerAnchor(currentClassDoc.qualifiedName() + bpatel@766: "." + member.name()); bpatel@766: Content tdType = HtmlTree.TD(HtmlStyle.colFirst, anchor); bpatel@766: Content code = new HtmlTree(HtmlTag.CODE); bpatel@766: StringTokenizer mods = new StringTokenizer(member.modifiers()); bpatel@766: while(mods.hasMoreTokens()) { bpatel@766: Content modifier = new StringContent(mods.nextToken()); bpatel@766: code.addContent(modifier); bpatel@766: code.addContent(getSpace()); duke@1: } bpatel@766: Content type = new RawHtml(getLink(new LinkInfoImpl( bpatel@766: LinkInfoImpl.CONTEXT_CONSTANT_SUMMARY, member.type()))); bpatel@766: code.addContent(type); bpatel@766: tdType.addContent(code); bpatel@766: return tdType; bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * Get the name column for the constant summary table row. bpatel@766: * bpatel@766: * @param member the field to be documented. bpatel@766: * @return the name column of the constant table row bpatel@766: */ bpatel@766: private Content getNameColumn(FieldDoc member) { bpatel@766: Content nameContent = new RawHtml(getDocLink( bpatel@766: LinkInfoImpl.CONTEXT_CONSTANT_SUMMARY, member, member.name(), false)); bpatel@766: Content code = HtmlTree.CODE(nameContent); bpatel@766: return HtmlTree.TD(code); bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * Get the value column for the constant summary table row. bpatel@766: * bpatel@766: * @param member the field to be documented. bpatel@766: * @return the value column of the constant table row bpatel@766: */ bpatel@766: private Content getValue(FieldDoc member) { bpatel@766: Content valueContent = new StringContent(member.constantValueExpression()); bpatel@766: Content code = HtmlTree.CODE(valueContent); bpatel@766: return HtmlTree.TD(HtmlStyle.colLast, code); duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ bpatel@766: public void addFooter(Content contentTree) { bpatel@766: addNavLinks(false, contentTree); bpatel@766: addBottom(contentTree); duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ bpatel@766: public void printDocument(Content contentTree) { bpatel@766: printHtmlDocument(null, true, contentTree); duke@1: } duke@1: }