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

Fri, 05 Oct 2012 14:16:32 -0700

author
bpatel
date
Fri, 05 Oct 2012 14:16:32 -0700
changeset 1350
ef88ae455c88
parent 997
dbc4ced9d171
child 1359
25e14ad23cef
permissions
-rw-r--r--

7068595: html files in class-use dir do not get loaded correctly when Frames link is clicked
Reviewed-by: jjg

     1 /*
     2  * Copyright (c) 2003, 2011, 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 com.sun.javadoc.*;
    29 import com.sun.tools.doclets.internal.toolkit.*;
    30 import com.sun.tools.doclets.internal.toolkit.builders.SerializedFormBuilder;
    31 import com.sun.tools.doclets.internal.toolkit.taglets.*;
    32 import com.sun.tools.doclets.internal.toolkit.util.*;
    34 /**
    35  * The taglet writer that writes HTML.
    36  *
    37  * @since 1.5
    38  * @author Jamie Ho
    39  * @author Bhavesh Patel (Modified)
    40  */
    42 public class TagletWriterImpl extends TagletWriter {
    44     private HtmlDocletWriter htmlWriter;
    46     public TagletWriterImpl(HtmlDocletWriter htmlWriter, boolean isFirstSentence) {
    47         this.htmlWriter = htmlWriter;
    48         this.isFirstSentence = isFirstSentence;
    49     }
    51     /**
    52      * {@inheritDoc}
    53      */
    54     public TagletOutput getOutputInstance() {
    55         return new TagletOutputImpl("");
    56     }
    58     /**
    59      * {@inheritDoc}
    60      */
    61     public TagletOutput getDocRootOutput() {
    62         if (htmlWriter.configuration.docrootparent.length() > 0)
    63             return new TagletOutputImpl(htmlWriter.configuration.docrootparent);
    64         else
    65             return new TagletOutputImpl(htmlWriter.relativepathNoSlash);
    66     }
    68     /**
    69      * {@inheritDoc}
    70      */
    71     public TagletOutput deprecatedTagOutput(Doc doc) {
    72         StringBuffer output = new StringBuffer();
    73         Tag[] deprs = doc.tags("deprecated");
    74         if (doc instanceof ClassDoc) {
    75             if (Util.isDeprecated((ProgramElementDoc) doc)) {
    76                 output.append("<span class=\"strong\">" +
    77                     ConfigurationImpl.getInstance().
    78                         getText("doclet.Deprecated") + "</span>&nbsp;");
    79                 if (deprs.length > 0) {
    80                     Tag[] commentTags = deprs[0].inlineTags();
    81                     if (commentTags.length > 0) {
    83                         output.append(commentTagsToOutput(null, doc,
    84                             deprs[0].inlineTags(), false).toString()
    85                         );
    86                     }
    87                 }
    88             }
    89         } else {
    90             MemberDoc member = (MemberDoc) doc;
    91             if (Util.isDeprecated((ProgramElementDoc) doc)) {
    92                 output.append("<span class=\"strong\">" +
    93                     ConfigurationImpl.getInstance().
    94                             getText("doclet.Deprecated") + "</span>&nbsp;");
    95                 if (deprs.length > 0) {
    96                     output.append("<i>");
    97                     output.append(commentTagsToOutput(null, doc,
    98                         deprs[0].inlineTags(), false).toString());
    99                     output.append("</i>");
   100                 }
   101             } else {
   102                 if (Util.isDeprecated(member.containingClass())) {
   103                     output.append("<span class=\"strong\">" +
   104                     ConfigurationImpl.getInstance().
   105                             getText("doclet.Deprecated") + "</span>&nbsp;");
   106                 }
   107             }
   108         }
   109         return new TagletOutputImpl(output.toString());
   110     }
   112     /**
   113      * {@inheritDoc}
   114      */
   115     public MessageRetriever getMsgRetriever() {
   116         return htmlWriter.configuration.message;
   117     }
   119     /**
   120      * {@inheritDoc}
   121      */
   122     public TagletOutput getParamHeader(String header) {
   123         StringBuffer result = new StringBuffer();
   124         result.append("<dt>");
   125         result.append("<span class=\"strong\">" +  header + "</span></dt>");
   126         return new TagletOutputImpl(result.toString());
   127     }
   129     /**
   130      * {@inheritDoc}
   131      */
   132     public TagletOutput paramTagOutput(ParamTag paramTag, String paramName) {
   133         TagletOutput result = new TagletOutputImpl("<dd><code>" + paramName + "</code>"
   134          + " - " + htmlWriter.commentTagsToString(paramTag, null, paramTag.inlineTags(), false) + "</dd>");
   135         return result;
   136     }
   138     /**
   139      * {@inheritDoc}
   140      */
   141     public TagletOutput returnTagOutput(Tag returnTag) {
   142         TagletOutput result = new TagletOutputImpl(DocletConstants.NL + "<dt>" +
   143             "<span class=\"strong\">" + htmlWriter.configuration.getText("doclet.Returns") +
   144             "</span>" + "</dt>" + "<dd>" +
   145             htmlWriter.commentTagsToString(returnTag, null, returnTag.inlineTags(),
   146             false) + "</dd>");
   147         return result;
   148     }
   150     /**
   151      * {@inheritDoc}
   152      */
   153     public TagletOutput seeTagOutput(Doc holder, SeeTag[] seeTags) {
   154         String result = "";
   155         if (seeTags.length > 0) {
   156             result = addSeeHeader(result);
   157             for (int i = 0; i < seeTags.length; ++i) {
   158                 if (i > 0) {
   159                     result += ", " + DocletConstants.NL;
   160                 }
   161                 result += htmlWriter.seeTagToString(seeTags[i]);
   162             }
   163         }
   164         if (holder.isField() && ((FieldDoc)holder).constantValue() != null &&
   165                 htmlWriter instanceof ClassWriterImpl) {
   166             //Automatically add link to constant values page for constant fields.
   167             result = addSeeHeader(result);
   168             result += htmlWriter.getHyperLinkString(htmlWriter.relativePath +
   169                 ConfigurationImpl.CONSTANTS_FILE_NAME
   170                 + "#" + ((ClassWriterImpl) htmlWriter).getClassDoc().qualifiedName()
   171                 + "." + ((FieldDoc) holder).name(),
   172                 htmlWriter.configuration.getText("doclet.Constants_Summary"));
   173         }
   174         if (holder.isClass() && ((ClassDoc)holder).isSerializable()) {
   175             //Automatically add link to serialized form page for serializable classes.
   176             if ((SerializedFormBuilder.serialInclude(holder) &&
   177                       SerializedFormBuilder.serialInclude(((ClassDoc)holder).containingPackage()))) {
   178                 result = addSeeHeader(result);
   179                 result += htmlWriter.getHyperLinkString(htmlWriter.relativePath + "serialized-form.html",
   180                         ((ClassDoc)holder).qualifiedName(), htmlWriter.configuration.getText("doclet.Serialized_Form"), false);
   181             }
   182         }
   183         return result.equals("") ? null : new TagletOutputImpl(result + "</dd>");
   184     }
   186     private String addSeeHeader(String result) {
   187         if (result != null && result.length() > 0) {
   188             return result + ", " + DocletConstants.NL;
   189         } else {
   190             return "<dt><span class=\"strong\">" +
   191                     htmlWriter.configuration().getText("doclet.See_Also") + "</span></dt><dd>";
   192         }
   193      }
   195     /**
   196      * {@inheritDoc}
   197      */
   198     public TagletOutput simpleTagOutput(Tag[] simpleTags, String header) {
   199         String result = "<dt><span class=\"strong\">" + header + "</span></dt>" + DocletConstants.NL +
   200             "  <dd>";
   201         for (int i = 0; i < simpleTags.length; i++) {
   202             if (i > 0) {
   203                 result += ", ";
   204             }
   205             result += htmlWriter.commentTagsToString(simpleTags[i], null, simpleTags[i].inlineTags(), false);
   206         }
   207         result += "</dd>" + DocletConstants.NL;
   208         return new TagletOutputImpl(result);
   209     }
   211     /**
   212      * {@inheritDoc}
   213      */
   214     public TagletOutput simpleTagOutput(Tag simpleTag, String header) {
   215         return new TagletOutputImpl("<dt><span class=\"strong\">" + header + "</span></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>" + "<span class=\"strong\">" +
   225             htmlWriter.configuration().getText("doclet.Throws") + "</span></dt>");
   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         result += "</dd>";
   245         return new TagletOutputImpl(result);
   246     }
   248     /**
   249      * {@inheritDoc}
   250      */
   251     public TagletOutput throwsTagOutput(Type throwsType) {
   252         return new TagletOutputImpl(DocletConstants.NL + "<dd>" +
   253             htmlWriter.codeText(htmlWriter.getLink(
   254                 new LinkInfoImpl(LinkInfoImpl.CONTEXT_MEMBER, throwsType))) + "</dd>");
   255     }
   257     /**
   258      * {@inheritDoc}
   259      */
   260     public TagletOutput valueTagOutput(FieldDoc field, String constantVal,
   261             boolean includeLink) {
   262         return new TagletOutputImpl(includeLink ?
   263             htmlWriter.getDocLink(LinkInfoImpl.CONTEXT_VALUE_TAG, field,
   264                 constantVal, false) : constantVal);
   265     }
   267     /**
   268      * {@inheritDoc}
   269      */
   270     public TagletOutput commentTagsToOutput(Tag holderTag, Tag[] tags) {
   271         return commentTagsToOutput(holderTag, null, tags, false);
   272     }
   274     /**
   275      * {@inheritDoc}
   276      */
   277     public TagletOutput commentTagsToOutput(Doc holderDoc, Tag[] tags) {
   278         return commentTagsToOutput(null, holderDoc, tags, false);
   279     }
   281     /**
   282      * {@inheritDoc}
   283      */
   284     public TagletOutput commentTagsToOutput(Tag holderTag,
   285         Doc holderDoc, Tag[] tags, boolean isFirstSentence) {
   286         return new TagletOutputImpl(htmlWriter.commentTagsToString(
   287             holderTag, holderDoc, tags, isFirstSentence));
   288     }
   290     /**
   291      * {@inheritDoc}
   292      */
   293     public Configuration configuration() {
   294         return htmlWriter.configuration();
   295     }
   297     /**
   298      * Return an instance of a TagletWriter that knows how to write HTML.
   299      *
   300      * @return an instance of a TagletWriter that knows how to write HTML.
   301      */
   302     public TagletOutput getTagletOutputInstance() {
   303         return new TagletOutputImpl("");
   304     }
   305 }

mercurial