duke@1: /* jjg@1735: * Copyright (c) 2003, 2013, 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: * jjg@1359: *

This is NOT part of any supported API. jjg@1359: * If you write code that depends on this, you do so at your own risk. jjg@1359: * This code and its internal interfaces are subject to change or jjg@1359: * deletion without notice. jjg@1359: * 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: jjg@1410: private final HtmlDocletWriter htmlWriter; jjg@1410: private final ConfigurationImpl configuration; duke@1: duke@1: public TagletWriterImpl(HtmlDocletWriter htmlWriter, boolean isFirstSentence) { jjg@1410: super(isFirstSentence); duke@1: this.htmlWriter = htmlWriter; jjg@1410: configuration = htmlWriter.configuration; 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() { jjg@1410: if (configuration.docrootparent.length() > 0) jjg@1410: return new TagletOutputImpl(configuration.docrootparent); jjg@1372: else if (htmlWriter.pathToRoot.isEmpty()) jjg@1372: return new TagletOutputImpl("."); bpatel@997: else jjg@1372: return new TagletOutputImpl(htmlWriter.pathToRoot.getPath()); duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ duke@1: public TagletOutput deprecatedTagOutput(Doc doc) { jjg@1362: StringBuilder output = new StringBuilder(); duke@1: Tag[] deprs = doc.tags("deprecated"); duke@1: if (doc instanceof ClassDoc) { duke@1: if (Util.isDeprecated((ProgramElementDoc) doc)) { bpatel@766: output.append("" + jjg@1410: configuration. 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("" + jjg@1410: configuration. 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("" + jjg@1410: configuration. 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() { jjg@1410: return configuration.message; duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ duke@1: public TagletOutput getParamHeader(String header) { jjg@1362: StringBuilder result = new StringBuilder(); bpatel@766: result.append("

"); jjg@1362: result.append("").append(header).append("
"); 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 + "
" + jjg@1410: "" + 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); jjg@1373: DocPath constantsPath = jjg@1373: htmlWriter.pathToRoot.resolve(DocPaths.CONSTANT_VALUES); jjg@1373: String whichConstant = jjg@1373: ((ClassWriterImpl) htmlWriter).getClassDoc().qualifiedName() + "." + ((FieldDoc) holder).name(); jjg@1373: DocLink link = constantsPath.fragment(whichConstant); jjg@1373: result += htmlWriter.getHyperLinkString(link, jjg@1737: 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); jjg@1373: DocPath serialPath = htmlWriter.pathToRoot.resolve(DocPaths.SERIALIZED_FORM); jjg@1373: DocLink link = serialPath.fragment(((ClassDoc)holder).qualifiedName()); jjg@1373: result += htmlWriter.getHyperLinkString(link, jjg@1737: configuration.getText("doclet.Serialized_Form")); 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 "
" + jjg@1410: 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 + "
" + "" + jjg@1410: 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( jjg@1735: htmlWriter.getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.MEMBER, jjg@1736: throwsTag.exceptionType())).toString()); 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( jjg@1736: new LinkInfoImpl(configuration, LinkInfoImpl.Kind.MEMBER, throwsType)).toString()) + "
"); 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 ? jjg@1735: htmlWriter.getDocLink(LinkInfoImpl.Kind.VALUE_TAG, field, jjg@1736: constantVal, false).toString() : 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() { jjg@1410: return 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: }