duke@1: /* bpatel@997: * Copyright (c) 2003, 2011, 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@233: import com.sun.javadoc.*; duke@1: import com.sun.tools.doclets.internal.toolkit.*; duke@1: import com.sun.tools.doclets.internal.toolkit.builders.SerializedFormBuilder; duke@1: import com.sun.tools.doclets.internal.toolkit.taglets.*; duke@1: import com.sun.tools.doclets.internal.toolkit.util.*; duke@1: duke@1: /** duke@1: * The taglet writer that writes HTML. duke@1: * duke@1: * @since 1.5 duke@1: * @author Jamie Ho bpatel@233: * @author Bhavesh Patel (Modified) duke@1: */ duke@1: duke@1: public class TagletWriterImpl extends TagletWriter { duke@1: duke@1: private HtmlDocletWriter htmlWriter; duke@1: duke@1: public TagletWriterImpl(HtmlDocletWriter htmlWriter, boolean isFirstSentence) { duke@1: this.htmlWriter = htmlWriter; duke@1: this.isFirstSentence = isFirstSentence; duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ duke@1: public TagletOutput getOutputInstance() { duke@1: return new TagletOutputImpl(""); duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ duke@1: public TagletOutput getDocRootOutput() { bpatel@997: if (htmlWriter.configuration.docrootparent.length() > 0) bpatel@997: return new TagletOutputImpl(htmlWriter.configuration.docrootparent); bpatel@997: else bpatel@997: return new TagletOutputImpl(htmlWriter.relativepathNoSlash); duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ duke@1: public TagletOutput deprecatedTagOutput(Doc doc) { duke@1: StringBuffer output = new StringBuffer(); duke@1: Tag[] deprs = doc.tags("deprecated"); duke@1: if (doc instanceof ClassDoc) { duke@1: if (Util.isDeprecated((ProgramElementDoc) doc)) { bpatel@766: output.append("" + duke@1: ConfigurationImpl.getInstance(). bpatel@766: getText("doclet.Deprecated") + " "); duke@1: if (deprs.length > 0) { duke@1: Tag[] commentTags = deprs[0].inlineTags(); duke@1: if (commentTags.length > 0) { duke@1: duke@1: output.append(commentTagsToOutput(null, doc, duke@1: deprs[0].inlineTags(), false).toString() duke@1: ); duke@1: } duke@1: } duke@1: } duke@1: } else { duke@1: MemberDoc member = (MemberDoc) doc; duke@1: if (Util.isDeprecated((ProgramElementDoc) doc)) { bpatel@766: output.append("" + duke@1: ConfigurationImpl.getInstance(). bpatel@766: getText("doclet.Deprecated") + " "); duke@1: if (deprs.length > 0) { bpatel@766: output.append(""); duke@1: output.append(commentTagsToOutput(null, doc, duke@1: deprs[0].inlineTags(), false).toString()); bpatel@766: output.append(""); duke@1: } duke@1: } else { duke@1: if (Util.isDeprecated(member.containingClass())) { bpatel@766: output.append("" + duke@1: ConfigurationImpl.getInstance(). bpatel@766: getText("doclet.Deprecated") + " "); duke@1: } duke@1: } duke@1: } duke@1: return new TagletOutputImpl(output.toString()); duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ duke@1: public MessageRetriever getMsgRetriever() { duke@1: return htmlWriter.configuration.message; duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ duke@1: public TagletOutput getParamHeader(String header) { duke@1: StringBuffer result = new StringBuffer(); bpatel@766: result.append("
"); bpatel@766: result.append("" + header + "
"); duke@1: return new TagletOutputImpl(result.toString()); duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ duke@1: public TagletOutput paramTagOutput(ParamTag paramTag, String paramName) { bpatel@766: TagletOutput result = new TagletOutputImpl("
" + paramName + "" bpatel@766: + " - " + htmlWriter.commentTagsToString(paramTag, null, paramTag.inlineTags(), false) + "
"); duke@1: return result; duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ duke@1: public TagletOutput returnTagOutput(Tag returnTag) { bpatel@766: TagletOutput result = new TagletOutputImpl(DocletConstants.NL + "
" + bpatel@766: "" + htmlWriter.configuration.getText("doclet.Returns") + bpatel@766: "" + "
" + "
" + duke@1: htmlWriter.commentTagsToString(returnTag, null, returnTag.inlineTags(), bpatel@766: false) + "
"); duke@1: return result; duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ duke@1: public TagletOutput seeTagOutput(Doc holder, SeeTag[] seeTags) { duke@1: String result = ""; duke@1: if (seeTags.length > 0) { duke@1: result = addSeeHeader(result); duke@1: for (int i = 0; i < seeTags.length; ++i) { duke@1: if (i > 0) { duke@1: result += ", " + DocletConstants.NL; duke@1: } duke@1: result += htmlWriter.seeTagToString(seeTags[i]); duke@1: } duke@1: } duke@1: if (holder.isField() && ((FieldDoc)holder).constantValue() != null && duke@1: htmlWriter instanceof ClassWriterImpl) { duke@1: //Automatically add link to constant values page for constant fields. duke@1: result = addSeeHeader(result); bpatel@766: result += htmlWriter.getHyperLinkString(htmlWriter.relativePath + duke@1: ConfigurationImpl.CONSTANTS_FILE_NAME duke@1: + "#" + ((ClassWriterImpl) htmlWriter).getClassDoc().qualifiedName() duke@1: + "." + ((FieldDoc) holder).name(), duke@1: htmlWriter.configuration.getText("doclet.Constants_Summary")); duke@1: } duke@1: if (holder.isClass() && ((ClassDoc)holder).isSerializable()) { duke@1: //Automatically add link to serialized form page for serializable classes. bpatel@233: if ((SerializedFormBuilder.serialInclude(holder) && duke@1: SerializedFormBuilder.serialInclude(((ClassDoc)holder).containingPackage()))) { bpatel@233: result = addSeeHeader(result); bpatel@766: result += htmlWriter.getHyperLinkString(htmlWriter.relativePath + "serialized-form.html", bpatel@233: ((ClassDoc)holder).qualifiedName(), htmlWriter.configuration.getText("doclet.Serialized_Form"), false); duke@1: } duke@1: } bpatel@766: return result.equals("") ? null : new TagletOutputImpl(result + ""); duke@1: } duke@1: duke@1: private String addSeeHeader(String result) { duke@1: if (result != null && result.length() > 0) { duke@1: return result + ", " + DocletConstants.NL; duke@1: } else { bpatel@766: return "
" + bpatel@766: htmlWriter.configuration().getText("doclet.See_Also") + "
"; duke@1: } duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ duke@1: public TagletOutput simpleTagOutput(Tag[] simpleTags, String header) { bpatel@766: String result = "
" + header + "
" + DocletConstants.NL + bpatel@766: "
"; duke@1: for (int i = 0; i < simpleTags.length; i++) { duke@1: if (i > 0) { duke@1: result += ", "; duke@1: } duke@1: result += htmlWriter.commentTagsToString(simpleTags[i], null, simpleTags[i].inlineTags(), false); duke@1: } bpatel@766: result += "
" + DocletConstants.NL; bpatel@233: return new TagletOutputImpl(result); duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ duke@1: public TagletOutput simpleTagOutput(Tag simpleTag, String header) { bpatel@766: return new TagletOutputImpl("
" + header + "
" + "
" duke@1: + htmlWriter.commentTagsToString(simpleTag, null, simpleTag.inlineTags(), false) bpatel@766: + "
" + DocletConstants.NL); duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ duke@1: public TagletOutput getThrowsHeader() { bpatel@766: return new TagletOutputImpl(DocletConstants.NL + "
" + "" + bpatel@766: htmlWriter.configuration().getText("doclet.Throws") + "
"); duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ duke@1: public TagletOutput throwsTagOutput(ThrowsTag throwsTag) { bpatel@766: String result = DocletConstants.NL + "
"; duke@1: result += throwsTag.exceptionType() == null ? duke@1: htmlWriter.codeText(throwsTag.exceptionName()) : duke@1: htmlWriter.codeText( duke@1: htmlWriter.getLink(new LinkInfoImpl(LinkInfoImpl.CONTEXT_MEMBER, duke@1: throwsTag.exceptionType()))); duke@1: TagletOutput text = new TagletOutputImpl( duke@1: htmlWriter.commentTagsToString(throwsTag, null, duke@1: throwsTag.inlineTags(), false)); duke@1: if (text != null && text.toString().length() > 0) { duke@1: result += " - " + text; duke@1: } bpatel@766: result += "
"; duke@1: return new TagletOutputImpl(result); duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ duke@1: public TagletOutput throwsTagOutput(Type throwsType) { bpatel@766: return new TagletOutputImpl(DocletConstants.NL + "
" + duke@1: htmlWriter.codeText(htmlWriter.getLink( bpatel@766: new LinkInfoImpl(LinkInfoImpl.CONTEXT_MEMBER, throwsType))) + "
"); duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ duke@1: public TagletOutput valueTagOutput(FieldDoc field, String constantVal, duke@1: boolean includeLink) { duke@1: return new TagletOutputImpl(includeLink ? duke@1: htmlWriter.getDocLink(LinkInfoImpl.CONTEXT_VALUE_TAG, field, duke@1: constantVal, false) : constantVal); duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ duke@1: public TagletOutput commentTagsToOutput(Tag holderTag, Tag[] tags) { duke@1: return commentTagsToOutput(holderTag, null, tags, false); duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ duke@1: public TagletOutput commentTagsToOutput(Doc holderDoc, Tag[] tags) { duke@1: return commentTagsToOutput(null, holderDoc, tags, false); duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ duke@1: public TagletOutput commentTagsToOutput(Tag holderTag, duke@1: Doc holderDoc, Tag[] tags, boolean isFirstSentence) { duke@1: return new TagletOutputImpl(htmlWriter.commentTagsToString( duke@1: holderTag, holderDoc, tags, isFirstSentence)); duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ duke@1: public Configuration configuration() { duke@1: return htmlWriter.configuration(); duke@1: } duke@1: duke@1: /** duke@1: * Return an instance of a TagletWriter that knows how to write HTML. duke@1: * duke@1: * @return an instance of a TagletWriter that knows how to write HTML. duke@1: */ duke@1: public TagletOutput getTagletOutputInstance() { duke@1: return new TagletOutputImpl(""); duke@1: } duke@1: }