Wed, 04 Sep 2013 14:44:05 -0700
8024288: javadoc generated-by comment should always be present
Reviewed-by: bpatel
1 /*
2 * Copyright (c) 1997, 2013, 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.markup;
28 import java.io.*;
29 import java.util.*;
31 import com.sun.javadoc.*;
32 import com.sun.tools.doclets.formats.html.ConfigurationImpl;
33 import com.sun.tools.doclets.internal.toolkit.*;
34 import com.sun.tools.doclets.internal.toolkit.util.DocFile;
35 import com.sun.tools.doclets.internal.toolkit.util.DocLink;
36 import com.sun.tools.doclets.internal.toolkit.util.DocPath;
39 /**
40 * Class for the Html Format Code Generation specific to JavaDoc.
41 * This Class contains methods related to the Html Code Generation which
42 * are used by the Sub-Classes in the package com.sun.tools.doclets.standard
43 * and com.sun.tools.doclets.oneone.
44 *
45 * <p><b>This is NOT part of any supported API.
46 * If you write code that depends on this, you do so at your own risk.
47 * This code and its internal interfaces are subject to change or
48 * deletion without notice.</b>
49 *
50 * @since 1.2
51 * @author Atul M Dambalkar
52 * @author Robert Field
53 */
54 public abstract class HtmlDocWriter extends HtmlWriter {
56 public static final String CONTENT_TYPE = "text/html";
58 /**
59 * Constructor. Initializes the destination file name through the super
60 * class HtmlWriter.
61 *
62 * @param filename String file name.
63 */
64 public HtmlDocWriter(Configuration configuration, DocPath filename)
65 throws IOException {
66 super(configuration, filename);
67 configuration.message.notice("doclet.Generating_0",
68 DocFile.createFileForOutput(configuration, filename).getPath());
69 }
71 /**
72 * Accessor for configuration.
73 */
74 public abstract Configuration configuration();
76 public Content getHyperLink(DocPath link, String label) {
77 return getHyperLink(link, new StringContent(label), false, "", "", "");
78 }
80 /**
81 * Get Html Hyper Link string.
82 *
83 * @param where Position of the link in the file. Character '#' is not
84 * needed.
85 * @param label Tag for the link.
86 * @return a content tree for the hyper link
87 */
88 public Content getHyperLink(String where,
89 Content label) {
90 return getHyperLink(DocLink.fragment(where), label, "", "");
91 }
93 /**
94 * Get Html hyperlink.
95 *
96 * @param link path of the file.
97 * @param label Tag for the link.
98 * @return a content tree for the hyper link
99 */
100 public Content getHyperLink(DocPath link, Content label) {
101 return getHyperLink(link, label, "", "");
102 }
104 public Content getHyperLink(DocLink link, Content label) {
105 return getHyperLink(link, label, "", "");
106 }
108 public Content getHyperLink(DocPath link,
109 Content label, boolean strong,
110 String stylename, String title, String target) {
111 return getHyperLink(new DocLink(link), label, strong,
112 stylename, title, target);
113 }
115 public Content getHyperLink(DocLink link,
116 Content label, boolean strong,
117 String stylename, String title, String target) {
118 Content body = label;
119 if (strong) {
120 body = HtmlTree.SPAN(HtmlStyle.strong, body);
121 }
122 if (stylename != null && stylename.length() != 0) {
123 HtmlTree t = new HtmlTree(HtmlTag.FONT, body);
124 t.addAttr(HtmlAttr.CLASS, stylename);
125 body = t;
126 }
127 HtmlTree l = HtmlTree.A(link.toString(), body);
128 if (title != null && title.length() != 0) {
129 l.addAttr(HtmlAttr.TITLE, title);
130 }
131 if (target != null && target.length() != 0) {
132 l.addAttr(HtmlAttr.TARGET, target);
133 }
134 return l;
135 }
137 /**
138 * Get Html Hyper Link.
139 *
140 * @param link String name of the file.
141 * @param label Tag for the link.
142 * @param title String that describes the link's content for accessibility.
143 * @param target Target frame.
144 * @return a content tree for the hyper link.
145 */
146 public Content getHyperLink(DocPath link,
147 Content label, String title, String target) {
148 return getHyperLink(new DocLink(link), label, title, target);
149 }
151 public Content getHyperLink(DocLink link,
152 Content label, String title, String target) {
153 HtmlTree anchor = HtmlTree.A(link.toString(), label);
154 if (title != null && title.length() != 0) {
155 anchor.addAttr(HtmlAttr.TITLE, title);
156 }
157 if (target != null && target.length() != 0) {
158 anchor.addAttr(HtmlAttr.TARGET, target);
159 }
160 return anchor;
161 }
163 /**
164 * Get the name of the package, this class is in.
165 *
166 * @param cd ClassDoc.
167 */
168 public String getPkgName(ClassDoc cd) {
169 String pkgName = cd.containingPackage().name();
170 if (pkgName.length() > 0) {
171 pkgName += ".";
172 return pkgName;
173 }
174 return "";
175 }
177 public boolean getMemberDetailsListPrinted() {
178 return memberDetailsListPrinted;
179 }
181 /**
182 * Print the frameset version of the Html file header.
183 * Called only when generating an HTML frameset file.
184 *
185 * @param title Title of this HTML document
186 * @param noTimeStamp If true, don't print time stamp in header
187 * @param frameset the frameset to be added to the HTML document
188 */
189 public void printFramesetDocument(String title, boolean noTimeStamp,
190 Content frameset) throws IOException {
191 Content htmlDocType = DocType.FRAMESET;
192 Content htmlComment = new Comment(configuration.getText("doclet.New_Page"));
193 Content head = new HtmlTree(HtmlTag.HEAD);
194 head.addContent(getGeneratedBy(!noTimeStamp));
195 if (configuration.charset.length() > 0) {
196 Content meta = HtmlTree.META("Content-Type", CONTENT_TYPE,
197 configuration.charset);
198 head.addContent(meta);
199 }
200 Content windowTitle = HtmlTree.TITLE(new StringContent(title));
201 head.addContent(windowTitle);
202 head.addContent(getFramesetJavaScript());
203 Content htmlTree = HtmlTree.HTML(configuration.getLocale().getLanguage(),
204 head, frameset);
205 Content htmlDocument = new HtmlDocument(htmlDocType,
206 htmlComment, htmlTree);
207 write(htmlDocument);
208 }
210 protected Comment getGeneratedBy(boolean timestamp) {
211 String text = "Generated by javadoc"; // marker string, deliberately not localized
212 if (timestamp) {
213 Calendar calendar = new GregorianCalendar(TimeZone.getDefault());
214 Date today = calendar.getTime();
215 text += " ("+ ConfigurationImpl.BUILD_DATE + ") on " + today;
216 }
217 return new Comment(text);
218 }
219 }