1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/TagletWriterImpl.java Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,304 @@ 1.4 +/* 1.5 + * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Sun designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Sun in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.26 + * have any questions. 1.27 + */ 1.28 + 1.29 +package com.sun.tools.doclets.formats.html; 1.30 + 1.31 +import com.sun.tools.doclets.internal.toolkit.*; 1.32 +import com.sun.tools.doclets.internal.toolkit.builders.SerializedFormBuilder; 1.33 +import com.sun.tools.doclets.internal.toolkit.taglets.*; 1.34 +import com.sun.tools.doclets.internal.toolkit.util.*; 1.35 +import com.sun.javadoc.*; 1.36 + 1.37 +/** 1.38 + * The taglet writer that writes HTML. 1.39 + * 1.40 + * @since 1.5 1.41 + * @author Jamie Ho 1.42 + */ 1.43 + 1.44 +public class TagletWriterImpl extends TagletWriter { 1.45 + 1.46 + private HtmlDocletWriter htmlWriter; 1.47 + 1.48 + public TagletWriterImpl(HtmlDocletWriter htmlWriter, boolean isFirstSentence) { 1.49 + this.htmlWriter = htmlWriter; 1.50 + this.isFirstSentence = isFirstSentence; 1.51 + } 1.52 + 1.53 + /** 1.54 + * {@inheritDoc} 1.55 + */ 1.56 + public TagletOutput getOutputInstance() { 1.57 + return new TagletOutputImpl(""); 1.58 + } 1.59 + 1.60 + /** 1.61 + * {@inheritDoc} 1.62 + */ 1.63 + public TagletOutput getDocRootOutput() { 1.64 + return new TagletOutputImpl(htmlWriter.relativepathNoSlash); 1.65 + } 1.66 + 1.67 + /** 1.68 + * {@inheritDoc} 1.69 + */ 1.70 + public TagletOutput deprecatedTagOutput(Doc doc) { 1.71 + StringBuffer output = new StringBuffer(); 1.72 + Tag[] deprs = doc.tags("deprecated"); 1.73 + if (doc instanceof ClassDoc) { 1.74 + if (Util.isDeprecated((ProgramElementDoc) doc)) { 1.75 + output.append("<B>" + 1.76 + ConfigurationImpl.getInstance(). 1.77 + getText("doclet.Deprecated") + "</B> "); 1.78 + if (deprs.length > 0) { 1.79 + Tag[] commentTags = deprs[0].inlineTags(); 1.80 + if (commentTags.length > 0) { 1.81 + 1.82 + output.append(commentTagsToOutput(null, doc, 1.83 + deprs[0].inlineTags(), false).toString() 1.84 + ); 1.85 + } 1.86 + } 1.87 + output.append("<p>"); 1.88 + } 1.89 + } else { 1.90 + MemberDoc member = (MemberDoc) doc; 1.91 + if (Util.isDeprecated((ProgramElementDoc) doc)) { 1.92 + output.append("<DD><B>" + 1.93 + ConfigurationImpl.getInstance(). 1.94 + getText("doclet.Deprecated") + "</B> "); 1.95 + if (deprs.length > 0) { 1.96 + output.append("<I>"); 1.97 + output.append(commentTagsToOutput(null, doc, 1.98 + deprs[0].inlineTags(), false).toString()); 1.99 + output.append("</I>"); 1.100 + } 1.101 + if (member instanceof ExecutableMemberDoc) { 1.102 + output.append(DocletConstants.NL + "<P>" + 1.103 + DocletConstants.NL); 1.104 + } 1.105 + } else { 1.106 + if (Util.isDeprecated(member.containingClass())) { 1.107 + output.append("<DD><B>" + 1.108 + ConfigurationImpl.getInstance(). 1.109 + getText("doclet.Deprecated") + "</B> "); 1.110 + } 1.111 + } 1.112 + } 1.113 + return new TagletOutputImpl(output.toString()); 1.114 + } 1.115 + 1.116 + /** 1.117 + * {@inheritDoc} 1.118 + */ 1.119 + public MessageRetriever getMsgRetriever() { 1.120 + return htmlWriter.configuration.message; 1.121 + } 1.122 + 1.123 + /** 1.124 + * {@inheritDoc} 1.125 + */ 1.126 + public TagletOutput getParamHeader(String header) { 1.127 + StringBuffer result = new StringBuffer(); 1.128 + result.append("<DT>"); 1.129 + result.append("<B>" + header + "</B>"); 1.130 + return new TagletOutputImpl(result.toString()); 1.131 + } 1.132 + 1.133 + /** 1.134 + * {@inheritDoc} 1.135 + */ 1.136 + public TagletOutput paramTagOutput(ParamTag paramTag, String paramName) { 1.137 + TagletOutput result = new TagletOutputImpl("<DD><CODE>" + paramName + "</CODE>" 1.138 + + " - " + htmlWriter.commentTagsToString(paramTag, null, paramTag.inlineTags(), false)); 1.139 + return result; 1.140 + } 1.141 + 1.142 + /** 1.143 + * {@inheritDoc} 1.144 + */ 1.145 + public TagletOutput returnTagOutput(Tag returnTag) { 1.146 + TagletOutput result = new TagletOutputImpl(DocletConstants.NL + "<DT>" + 1.147 + "<B>" + htmlWriter.configuration.getText("doclet.Returns") + 1.148 + "</B>" + "<DD>" + 1.149 + htmlWriter.commentTagsToString(returnTag, null, returnTag.inlineTags(), 1.150 + false)); 1.151 + return result; 1.152 + } 1.153 + 1.154 + /** 1.155 + * {@inheritDoc} 1.156 + */ 1.157 + public TagletOutput seeTagOutput(Doc holder, SeeTag[] seeTags) { 1.158 + String result = ""; 1.159 + if (seeTags.length > 0) { 1.160 + result = addSeeHeader(result); 1.161 + for (int i = 0; i < seeTags.length; ++i) { 1.162 + if (i > 0) { 1.163 + result += ", " + DocletConstants.NL; 1.164 + } 1.165 + result += htmlWriter.seeTagToString(seeTags[i]); 1.166 + } 1.167 + } 1.168 + if (holder.isField() && ((FieldDoc)holder).constantValue() != null && 1.169 + htmlWriter instanceof ClassWriterImpl) { 1.170 + //Automatically add link to constant values page for constant fields. 1.171 + result = addSeeHeader(result); 1.172 + result += htmlWriter.getHyperLink(htmlWriter.relativePath + 1.173 + ConfigurationImpl.CONSTANTS_FILE_NAME 1.174 + + "#" + ((ClassWriterImpl) htmlWriter).getClassDoc().qualifiedName() 1.175 + + "." + ((FieldDoc) holder).name(), 1.176 + htmlWriter.configuration.getText("doclet.Constants_Summary")); 1.177 + } 1.178 + if (holder.isClass() && ((ClassDoc)holder).isSerializable()) { 1.179 + //Automatically add link to serialized form page for serializable classes. 1.180 + if (!(SerializedFormBuilder.serialInclude(holder) && 1.181 + SerializedFormBuilder.serialInclude(((ClassDoc)holder).containingPackage()))) { 1.182 + return result.equals("") ? null : new TagletOutputImpl(result); 1.183 + } 1.184 + result = addSeeHeader(result); 1.185 + result += htmlWriter.getHyperLink(htmlWriter.relativePath + "serialized-form.html", 1.186 + ((ClassDoc)holder).qualifiedName(), htmlWriter.configuration.getText("doclet.Serialized_Form"), false); 1.187 + } 1.188 + return result.equals("") ? null : new TagletOutputImpl(result); 1.189 + } 1.190 + 1.191 + private String addSeeHeader(String result) { 1.192 + if (result != null && result.length() > 0) { 1.193 + return result + ", " + DocletConstants.NL; 1.194 + } else { 1.195 + return "<DT><B>" + htmlWriter.configuration().getText("doclet.See_Also") + "</B><DD>"; 1.196 + } 1.197 + } 1.198 + 1.199 + /** 1.200 + * {@inheritDoc} 1.201 + */ 1.202 + public TagletOutput simpleTagOutput(Tag[] simpleTags, String header) { 1.203 + String result = "<DT><B>" + header + "</B></DT>" + DocletConstants.NL + 1.204 + " <DD>"; 1.205 + for (int i = 0; i < simpleTags.length; i++) { 1.206 + if (i > 0) { 1.207 + result += ", "; 1.208 + } 1.209 + result += htmlWriter.commentTagsToString(simpleTags[i], null, simpleTags[i].inlineTags(), false); 1.210 + } 1.211 + return new TagletOutputImpl(result + "</DD>" + DocletConstants.NL); 1.212 + } 1.213 + 1.214 + /** 1.215 + * {@inheritDoc} 1.216 + */ 1.217 + public TagletOutput simpleTagOutput(Tag simpleTag, String header) { 1.218 + return new TagletOutputImpl("<DT><B>" + header + "</B></DT>" + " <DD>" 1.219 + + htmlWriter.commentTagsToString(simpleTag, null, simpleTag.inlineTags(), false) 1.220 + + "</DD>" + DocletConstants.NL); 1.221 + } 1.222 + 1.223 + /** 1.224 + * {@inheritDoc} 1.225 + */ 1.226 + public TagletOutput getThrowsHeader() { 1.227 + return new TagletOutputImpl(DocletConstants.NL + "<DT>" + "<B>" + 1.228 + htmlWriter.configuration().getText("doclet.Throws") + "</B>"); 1.229 + } 1.230 + 1.231 + /** 1.232 + * {@inheritDoc} 1.233 + */ 1.234 + public TagletOutput throwsTagOutput(ThrowsTag throwsTag) { 1.235 + String result = DocletConstants.NL + "<DD>"; 1.236 + result += throwsTag.exceptionType() == null ? 1.237 + htmlWriter.codeText(throwsTag.exceptionName()) : 1.238 + htmlWriter.codeText( 1.239 + htmlWriter.getLink(new LinkInfoImpl(LinkInfoImpl.CONTEXT_MEMBER, 1.240 + throwsTag.exceptionType()))); 1.241 + TagletOutput text = new TagletOutputImpl( 1.242 + htmlWriter.commentTagsToString(throwsTag, null, 1.243 + throwsTag.inlineTags(), false)); 1.244 + if (text != null && text.toString().length() > 0) { 1.245 + result += " - " + text; 1.246 + } 1.247 + return new TagletOutputImpl(result); 1.248 + } 1.249 + 1.250 + /** 1.251 + * {@inheritDoc} 1.252 + */ 1.253 + public TagletOutput throwsTagOutput(Type throwsType) { 1.254 + return new TagletOutputImpl(DocletConstants.NL + "<DD>" + 1.255 + htmlWriter.codeText(htmlWriter.getLink( 1.256 + new LinkInfoImpl(LinkInfoImpl.CONTEXT_MEMBER, throwsType)))); 1.257 + } 1.258 + 1.259 + /** 1.260 + * {@inheritDoc} 1.261 + */ 1.262 + public TagletOutput valueTagOutput(FieldDoc field, String constantVal, 1.263 + boolean includeLink) { 1.264 + return new TagletOutputImpl(includeLink ? 1.265 + htmlWriter.getDocLink(LinkInfoImpl.CONTEXT_VALUE_TAG, field, 1.266 + constantVal, false) : constantVal); 1.267 + } 1.268 + 1.269 + /** 1.270 + * {@inheritDoc} 1.271 + */ 1.272 + public TagletOutput commentTagsToOutput(Tag holderTag, Tag[] tags) { 1.273 + return commentTagsToOutput(holderTag, null, tags, false); 1.274 + } 1.275 + 1.276 + /** 1.277 + * {@inheritDoc} 1.278 + */ 1.279 + public TagletOutput commentTagsToOutput(Doc holderDoc, Tag[] tags) { 1.280 + return commentTagsToOutput(null, holderDoc, tags, false); 1.281 + } 1.282 + 1.283 + /** 1.284 + * {@inheritDoc} 1.285 + */ 1.286 + public TagletOutput commentTagsToOutput(Tag holderTag, 1.287 + Doc holderDoc, Tag[] tags, boolean isFirstSentence) { 1.288 + return new TagletOutputImpl(htmlWriter.commentTagsToString( 1.289 + holderTag, holderDoc, tags, isFirstSentence)); 1.290 + } 1.291 + 1.292 + /** 1.293 + * {@inheritDoc} 1.294 + */ 1.295 + public Configuration configuration() { 1.296 + return htmlWriter.configuration(); 1.297 + } 1.298 + 1.299 + /** 1.300 + * Return an instance of a TagletWriter that knows how to write HTML. 1.301 + * 1.302 + * @return an instance of a TagletWriter that knows how to write HTML. 1.303 + */ 1.304 + public TagletOutput getTagletOutputInstance() { 1.305 + return new TagletOutputImpl(""); 1.306 + } 1.307 +}