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

Sat, 01 Dec 2007 00:00:00 +0000

author
duke
date
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1
9a66ca7c79fa
child 182
47a62d8d98b4
permissions
-rw-r--r--

Initial load

     1 /*
     2  * Copyright 2003-2005 Sun Microsystems, Inc.  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.  Sun designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    22  * CA 95054 USA or visit www.sun.com if you need additional information or
    23  * have any questions.
    24  */
    26 package com.sun.tools.doclets.formats.html;
    28 import com.sun.tools.doclets.internal.toolkit.*;
    29 import com.sun.tools.doclets.internal.toolkit.builders.SerializedFormBuilder;
    30 import com.sun.tools.doclets.internal.toolkit.taglets.*;
    31 import com.sun.tools.doclets.internal.toolkit.util.*;
    32 import com.sun.javadoc.*;
    34 /**
    35  * The taglet writer that writes HTML.
    36  *
    37  * @since 1.5
    38  * @author Jamie Ho
    39  */
    41 public class TagletWriterImpl extends TagletWriter {
    43     private HtmlDocletWriter htmlWriter;
    45     public TagletWriterImpl(HtmlDocletWriter htmlWriter, boolean isFirstSentence) {
    46         this.htmlWriter = htmlWriter;
    47         this.isFirstSentence = isFirstSentence;
    48     }
    50     /**
    51      * {@inheritDoc}
    52      */
    53     public TagletOutput getOutputInstance() {
    54         return new TagletOutputImpl("");
    55     }
    57     /**
    58      * {@inheritDoc}
    59      */
    60     public TagletOutput getDocRootOutput() {
    61         return new TagletOutputImpl(htmlWriter.relativepathNoSlash);
    62     }
    64     /**
    65      * {@inheritDoc}
    66      */
    67     public TagletOutput deprecatedTagOutput(Doc doc) {
    68         StringBuffer output = new StringBuffer();
    69         Tag[] deprs = doc.tags("deprecated");
    70         if (doc instanceof ClassDoc) {
    71             if (Util.isDeprecated((ProgramElementDoc) doc)) {
    72                 output.append("<B>" +
    73                     ConfigurationImpl.getInstance().
    74                         getText("doclet.Deprecated") + "</B>&nbsp;");
    75                 if (deprs.length > 0) {
    76                     Tag[] commentTags = deprs[0].inlineTags();
    77                     if (commentTags.length > 0) {
    79                         output.append(commentTagsToOutput(null, doc,
    80                             deprs[0].inlineTags(), false).toString()
    81                         );
    82                     }
    83                 }
    84                 output.append("<p>");
    85             }
    86         } else {
    87             MemberDoc member = (MemberDoc) doc;
    88             if (Util.isDeprecated((ProgramElementDoc) doc)) {
    89                 output.append("<DD><B>" +
    90                     ConfigurationImpl.getInstance().
    91                             getText("doclet.Deprecated") + "</B>&nbsp;");
    92                 if (deprs.length > 0) {
    93                     output.append("<I>");
    94                     output.append(commentTagsToOutput(null, doc,
    95                         deprs[0].inlineTags(), false).toString());
    96                     output.append("</I>");
    97                 }
    98                 if (member instanceof ExecutableMemberDoc) {
    99                     output.append(DocletConstants.NL + "<P>" +
   100                         DocletConstants.NL);
   101                 }
   102             } else {
   103                 if (Util.isDeprecated(member.containingClass())) {
   104                     output.append("<DD><B>" +
   105                     ConfigurationImpl.getInstance().
   106                             getText("doclet.Deprecated") + "</B>&nbsp;");
   107                 }
   108             }
   109         }
   110         return new TagletOutputImpl(output.toString());
   111     }
   113     /**
   114      * {@inheritDoc}
   115      */
   116     public MessageRetriever getMsgRetriever() {
   117         return htmlWriter.configuration.message;
   118     }
   120     /**
   121      * {@inheritDoc}
   122      */
   123     public TagletOutput getParamHeader(String header) {
   124         StringBuffer result = new StringBuffer();
   125         result.append("<DT>");
   126         result.append("<B>" +  header + "</B>");
   127         return new TagletOutputImpl(result.toString());
   128     }
   130     /**
   131      * {@inheritDoc}
   132      */
   133     public TagletOutput paramTagOutput(ParamTag paramTag, String paramName) {
   134         TagletOutput result = new TagletOutputImpl("<DD><CODE>" + paramName + "</CODE>"
   135          + " - " + htmlWriter.commentTagsToString(paramTag, null, paramTag.inlineTags(), false));
   136         return result;
   137     }
   139     /**
   140      * {@inheritDoc}
   141      */
   142     public TagletOutput returnTagOutput(Tag returnTag) {
   143         TagletOutput result = new TagletOutputImpl(DocletConstants.NL + "<DT>" +
   144             "<B>" + htmlWriter.configuration.getText("doclet.Returns") +
   145             "</B>" + "<DD>" +
   146             htmlWriter.commentTagsToString(returnTag, null, returnTag.inlineTags(),
   147             false));
   148         return result;
   149     }
   151     /**
   152      * {@inheritDoc}
   153      */
   154     public TagletOutput seeTagOutput(Doc holder, SeeTag[] seeTags) {
   155         String result = "";
   156         if (seeTags.length > 0) {
   157             result = addSeeHeader(result);
   158             for (int i = 0; i < seeTags.length; ++i) {
   159                 if (i > 0) {
   160                     result += ", " + DocletConstants.NL;
   161                 }
   162                 result += htmlWriter.seeTagToString(seeTags[i]);
   163             }
   164         }
   165         if (holder.isField() && ((FieldDoc)holder).constantValue() != null &&
   166                 htmlWriter instanceof ClassWriterImpl) {
   167             //Automatically add link to constant values page for constant fields.
   168             result = addSeeHeader(result);
   169             result += htmlWriter.getHyperLink(htmlWriter.relativePath +
   170                 ConfigurationImpl.CONSTANTS_FILE_NAME
   171                 + "#" + ((ClassWriterImpl) htmlWriter).getClassDoc().qualifiedName()
   172                 + "." + ((FieldDoc) holder).name(),
   173                 htmlWriter.configuration.getText("doclet.Constants_Summary"));
   174         }
   175         if (holder.isClass() && ((ClassDoc)holder).isSerializable()) {
   176             //Automatically add link to serialized form page for serializable classes.
   177             if (!(SerializedFormBuilder.serialInclude(holder) &&
   178                       SerializedFormBuilder.serialInclude(((ClassDoc)holder).containingPackage()))) {
   179                 return result.equals("") ? null : new TagletOutputImpl(result);
   180             }
   181             result = addSeeHeader(result);
   182             result += htmlWriter.getHyperLink(htmlWriter.relativePath + "serialized-form.html",
   183                 ((ClassDoc)holder).qualifiedName(), htmlWriter.configuration.getText("doclet.Serialized_Form"), false);
   184         }
   185         return result.equals("") ? null : new TagletOutputImpl(result);
   186     }
   188     private String addSeeHeader(String result) {
   189         if (result != null && result.length() > 0) {
   190             return result + ", " + DocletConstants.NL;
   191         } else {
   192             return "<DT><B>" + htmlWriter.configuration().getText("doclet.See_Also") + "</B><DD>";
   193         }
   194      }
   196     /**
   197      * {@inheritDoc}
   198      */
   199     public TagletOutput simpleTagOutput(Tag[] simpleTags, String header) {
   200         String result = "<DT><B>" + header + "</B></DT>" + DocletConstants.NL +
   201             "  <DD>";
   202         for (int i = 0; i < simpleTags.length; i++) {
   203             if (i > 0) {
   204                 result += ", ";
   205             }
   206             result += htmlWriter.commentTagsToString(simpleTags[i], null, simpleTags[i].inlineTags(), false);
   207         }
   208          return new TagletOutputImpl(result + "</DD>" + DocletConstants.NL);
   209     }
   211     /**
   212      * {@inheritDoc}
   213      */
   214     public TagletOutput simpleTagOutput(Tag simpleTag, String header) {
   215         return new TagletOutputImpl("<DT><B>" + header + "</B></DT>" + "  <DD>"
   216             + htmlWriter.commentTagsToString(simpleTag, null, simpleTag.inlineTags(), false)
   217             + "</DD>" + DocletConstants.NL);
   218     }
   220     /**
   221      * {@inheritDoc}
   222      */
   223     public TagletOutput getThrowsHeader() {
   224         return new TagletOutputImpl(DocletConstants.NL + "<DT>" + "<B>" +
   225             htmlWriter.configuration().getText("doclet.Throws") + "</B>");
   226     }
   228     /**
   229      * {@inheritDoc}
   230      */
   231     public TagletOutput throwsTagOutput(ThrowsTag throwsTag) {
   232         String result = DocletConstants.NL + "<DD>";
   233         result += throwsTag.exceptionType() == null ?
   234             htmlWriter.codeText(throwsTag.exceptionName()) :
   235             htmlWriter.codeText(
   236                 htmlWriter.getLink(new LinkInfoImpl(LinkInfoImpl.CONTEXT_MEMBER,
   237                 throwsTag.exceptionType())));
   238         TagletOutput text = new TagletOutputImpl(
   239             htmlWriter.commentTagsToString(throwsTag, null,
   240             throwsTag.inlineTags(), false));
   241         if (text != null && text.toString().length() > 0) {
   242             result += " - " + text;
   243         }
   244         return new TagletOutputImpl(result);
   245     }
   247     /**
   248      * {@inheritDoc}
   249      */
   250     public TagletOutput throwsTagOutput(Type throwsType) {
   251         return new TagletOutputImpl(DocletConstants.NL + "<DD>" +
   252             htmlWriter.codeText(htmlWriter.getLink(
   253                 new LinkInfoImpl(LinkInfoImpl.CONTEXT_MEMBER, throwsType))));
   254     }
   256     /**
   257      * {@inheritDoc}
   258      */
   259     public TagletOutput valueTagOutput(FieldDoc field, String constantVal,
   260             boolean includeLink) {
   261         return new TagletOutputImpl(includeLink ?
   262             htmlWriter.getDocLink(LinkInfoImpl.CONTEXT_VALUE_TAG, field,
   263                 constantVal, false) : constantVal);
   264     }
   266     /**
   267      * {@inheritDoc}
   268      */
   269     public TagletOutput commentTagsToOutput(Tag holderTag, Tag[] tags) {
   270         return commentTagsToOutput(holderTag, null, tags, false);
   271     }
   273     /**
   274      * {@inheritDoc}
   275      */
   276     public TagletOutput commentTagsToOutput(Doc holderDoc, Tag[] tags) {
   277         return commentTagsToOutput(null, holderDoc, tags, false);
   278     }
   280     /**
   281      * {@inheritDoc}
   282      */
   283     public TagletOutput commentTagsToOutput(Tag holderTag,
   284         Doc holderDoc, Tag[] tags, boolean isFirstSentence) {
   285         return new TagletOutputImpl(htmlWriter.commentTagsToString(
   286             holderTag, holderDoc, tags, isFirstSentence));
   287     }
   289     /**
   290      * {@inheritDoc}
   291      */
   292     public Configuration configuration() {
   293         return htmlWriter.configuration();
   294     }
   296     /**
   297      * Return an instance of a TagletWriter that knows how to write HTML.
   298      *
   299      * @return an instance of a TagletWriter that knows how to write HTML.
   300      */
   301     public TagletOutput getTagletOutputInstance() {
   302         return new TagletOutputImpl("");
   303     }
   304 }

mercurial