src/share/classes/com/sun/tools/doclets/formats/html/ConstantsSummaryWriterImpl.java

Tue, 28 Dec 2010 15:54:52 -0800

author
ohair
date
Tue, 28 Dec 2010 15:54:52 -0800
changeset 798
4868a36f6fd8
parent 766
90af8d87741f
child 1357
c75be5bc5283
permissions
-rw-r--r--

6962318: Update copyright year
Reviewed-by: xdono

     1 /*
     2  * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package com.sun.tools.doclets.formats.html;
    28 import java.io.*;
    29 import java.util.*;
    30 import com.sun.javadoc.*;
    31 import com.sun.tools.doclets.internal.toolkit.*;
    32 import com.sun.tools.doclets.internal.toolkit.util.*;
    33 import com.sun.tools.doclets.formats.html.markup.*;
    35 /**
    36  * Write the Constants Summary Page in HTML format.
    37  *
    38  * @author Jamie Ho
    39  * @author Bhavesh Patel (Modified)
    40  * @since 1.4
    41  */
    42 public class ConstantsSummaryWriterImpl extends HtmlDocletWriter
    43         implements ConstantsSummaryWriter {
    45     /**
    46      * The configuration used in this run of the standard doclet.
    47      */
    48     ConfigurationImpl configuration;
    50     /**
    51      * The current class being documented.
    52      */
    53     private ClassDoc currentClassDoc;
    55     private final String constantsTableSummary;
    57     private final String[] constantsTableHeader;
    59     /**
    60      * Construct a ConstantsSummaryWriter.
    61      * @param configuration the configuration used in this run
    62      *        of the standard doclet.
    63      */
    64     public ConstantsSummaryWriterImpl(ConfigurationImpl configuration)
    65             throws IOException {
    66         super(configuration, ConfigurationImpl.CONSTANTS_FILE_NAME);
    67         this.configuration = configuration;
    68         constantsTableSummary = configuration.getText("doclet.Constants_Table_Summary",
    69                 configuration.getText("doclet.Constants_Summary"));
    70         constantsTableHeader = new String[] {
    71             getModifierTypeHeader(),
    72             configuration.getText("doclet.ConstantField"),
    73             configuration.getText("doclet.Value")
    74         };
    75     }
    77     /**
    78      * {@inheritDoc}
    79      */
    80     public Content getHeader() {
    81         String label = configuration.getText("doclet.Constants_Summary");
    82         Content bodyTree = getBody(true, getWindowTitle(label));
    83         addTop(bodyTree);
    84         addNavLinks(true, bodyTree);
    85         return bodyTree;
    86     }
    88     /**
    89      * {@inheritDoc}
    90      */
    91     public Content getContentsHeader() {
    92         return new HtmlTree(HtmlTag.UL);
    93     }
    95     /**
    96      * {@inheritDoc}
    97      */
    98     public void addLinkToPackageContent(PackageDoc pkg, String parsedPackageName,
    99             Set<String> printedPackageHeaders, Content contentListTree) {
   100         String packageName = pkg.name();
   101         //add link to summary
   102         Content link;
   103         if (packageName.length() == 0) {
   104             link = getHyperLink("#" + DocletConstants.UNNAMED_PACKAGE_ANCHOR,
   105                     "", defaultPackageLabel, "", "");
   106         } else {
   107             Content packageNameContent = getPackageLabel(parsedPackageName);
   108             packageNameContent.addContent(".*");
   109             link = getHyperLink("#" + parsedPackageName,
   110                     "", packageNameContent, "", "");
   111             printedPackageHeaders.add(parsedPackageName);
   112         }
   113         contentListTree.addContent(HtmlTree.LI(link));
   114     }
   116     /**
   117      * {@inheritDoc}
   118      */
   119     public Content getContentsList(Content contentListTree) {
   120         Content titleContent = getResource(
   121                 "doclet.Constants_Summary");
   122         Content pHeading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true,
   123                 HtmlStyle.title, titleContent);
   124         Content div = HtmlTree.DIV(HtmlStyle.header, pHeading);
   125         Content headingContent = getResource(
   126                 "doclet.Contents");
   127         div.addContent(HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, true,
   128                 headingContent));
   129         div.addContent(contentListTree);
   130         return div;
   131     }
   133     /**
   134      * {@inheritDoc}
   135      */
   136     public Content getConstantSummaries() {
   137         HtmlTree summariesDiv = new HtmlTree(HtmlTag.DIV);
   138         summariesDiv.addStyle(HtmlStyle.constantValuesContainer);
   139         return summariesDiv;
   140     }
   142     /**
   143      * {@inheritDoc}
   144      */
   145     public void addPackageName(PackageDoc pkg, String parsedPackageName,
   146             Content summariesTree) {
   147         Content pkgNameContent;
   148         if (parsedPackageName.length() == 0) {
   149             summariesTree.addContent(getMarkerAnchor(
   150                     DocletConstants.UNNAMED_PACKAGE_ANCHOR));
   151             pkgNameContent = defaultPackageLabel;
   152         } else {
   153             summariesTree.addContent(getMarkerAnchor(
   154                     parsedPackageName));
   155             pkgNameContent = getPackageLabel(parsedPackageName);
   156         }
   157         Content headingContent = new StringContent(".*");
   158         Content heading = HtmlTree.HEADING(HtmlConstants.PACKAGE_HEADING, true,
   159                 pkgNameContent);
   160         heading.addContent(headingContent);
   161         summariesTree.addContent(heading);
   162     }
   164     /**
   165      * {@inheritDoc}
   166      */
   167     public Content getClassConstantHeader() {
   168         HtmlTree ul = new HtmlTree(HtmlTag.UL);
   169         ul.addStyle(HtmlStyle.blockList);
   170         return ul;
   171     }
   173     /**
   174      * Get the table caption and header for the constant summary table
   175      *
   176      * @param cd classdoc to be documented
   177      * @return constant members header content
   178      */
   179     public Content getConstantMembersHeader(ClassDoc cd) {
   180         //generate links backward only to public classes.
   181         String classlink = (cd.isPublic() || cd.isProtected())?
   182             getLink(new LinkInfoImpl(LinkInfoImpl.CONTEXT_CONSTANT_SUMMARY, cd,
   183                 false)) :
   184             cd.qualifiedName();
   185         String name = cd.containingPackage().name();
   186         if (name.length() > 0) {
   187             return getClassName(name + "." + classlink);
   188         } else {
   189             return getClassName(classlink);
   190         }
   191     }
   193     /**
   194      * Get the class name in the table caption and the table header.
   195      *
   196      * @param classStr the class name to print.
   197      * @return the table caption and header
   198      */
   199     protected Content getClassName(String classStr) {
   200         Content table = HtmlTree.TABLE(0, 3, 0, constantsTableSummary,
   201                 getTableCaption(classStr));
   202         table.addContent(getSummaryTableHeader(constantsTableHeader, "col"));
   203         return table;
   204     }
   206     /**
   207      * {@inheritDoc}
   208      */
   209     public void addConstantMembers(ClassDoc cd, List<FieldDoc> fields,
   210             Content classConstantTree) {
   211         currentClassDoc = cd;
   212         Content tbody = new HtmlTree(HtmlTag.TBODY);
   213         for (int i = 0; i < fields.size(); ++i) {
   214             HtmlTree tr = new HtmlTree(HtmlTag.TR);
   215             if (i%2 == 0)
   216                 tr.addStyle(HtmlStyle.altColor);
   217             else
   218                 tr.addStyle(HtmlStyle.rowColor);
   219             addConstantMember(fields.get(i), tr);
   220             tbody.addContent(tr);
   221         }
   222         Content table = getConstantMembersHeader(cd);
   223         table.addContent(tbody);
   224         Content li = HtmlTree.LI(HtmlStyle.blockList, table);
   225         classConstantTree.addContent(li);
   226     }
   228     /**
   229      * Add the row for the constant summary table.
   230      *
   231      * @param member the field to be documented.
   232      * @param trTree an htmltree object for the table row
   233      */
   234     private void addConstantMember(FieldDoc member, HtmlTree trTree) {
   235         trTree.addContent(getTypeColumn(member));
   236         trTree.addContent(getNameColumn(member));
   237         trTree.addContent(getValue(member));
   238     }
   240     /**
   241      * Get the type column for the constant summary table row.
   242      *
   243      * @param member the field to be documented.
   244      * @return the type column of the constant table row
   245      */
   246     private Content getTypeColumn(FieldDoc member) {
   247         Content anchor = getMarkerAnchor(currentClassDoc.qualifiedName() +
   248                 "." + member.name());
   249         Content tdType = HtmlTree.TD(HtmlStyle.colFirst, anchor);
   250         Content code = new HtmlTree(HtmlTag.CODE);
   251         StringTokenizer mods = new StringTokenizer(member.modifiers());
   252         while(mods.hasMoreTokens()) {
   253             Content modifier = new StringContent(mods.nextToken());
   254             code.addContent(modifier);
   255             code.addContent(getSpace());
   256         }
   257         Content type = new RawHtml(getLink(new LinkInfoImpl(
   258                 LinkInfoImpl.CONTEXT_CONSTANT_SUMMARY, member.type())));
   259         code.addContent(type);
   260         tdType.addContent(code);
   261         return tdType;
   262     }
   264     /**
   265      * Get the name column for the constant summary table row.
   266      *
   267      * @param member the field to be documented.
   268      * @return the name column of the constant table row
   269      */
   270     private Content getNameColumn(FieldDoc member) {
   271         Content nameContent = new RawHtml(getDocLink(
   272                 LinkInfoImpl.CONTEXT_CONSTANT_SUMMARY, member, member.name(), false));
   273         Content code = HtmlTree.CODE(nameContent);
   274         return HtmlTree.TD(code);
   275     }
   277     /**
   278      * Get the value column for the constant summary table row.
   279      *
   280      * @param member the field to be documented.
   281      * @return the value column of the constant table row
   282      */
   283     private Content getValue(FieldDoc member) {
   284         Content valueContent = new StringContent(member.constantValueExpression());
   285         Content code = HtmlTree.CODE(valueContent);
   286         return HtmlTree.TD(HtmlStyle.colLast, code);
   287     }
   289     /**
   290      * {@inheritDoc}
   291      */
   292     public void addFooter(Content contentTree) {
   293         addNavLinks(false, contentTree);
   294         addBottom(contentTree);
   295     }
   297     /**
   298      * {@inheritDoc}
   299      */
   300     public void printDocument(Content contentTree) {
   301         printHtmlDocument(null, true, contentTree);
   302     }
   303 }

mercurial