author | jjg |
Tue, 14 May 2013 10:14:55 -0700 | |
changeset 17570 | 78512b2899db |
parent 17569 | ef80738645e2 |
child 19663 | 9a3447cabe1a |
permissions | -rw-r--r-- |
10 | 1 |
/* |
17560 | 2 |
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
10 | 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 |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 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 |
* |
|
5520 | 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. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.doclets.formats.html.markup; |
|
27 |
||
1869
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1787
diff
changeset
|
28 |
import java.io.*; |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1787
diff
changeset
|
29 |
import java.util.*; |
10 | 30 |
|
31 |
import com.sun.javadoc.*; |
|
14262
058238ba531e
8000418: javadoc should used a standard "generated by javadoc" string
jjg
parents:
14260
diff
changeset
|
32 |
import com.sun.tools.doclets.formats.html.ConfigurationImpl; |
1869
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1787
diff
changeset
|
33 |
import com.sun.tools.doclets.internal.toolkit.*; |
14544 | 34 |
import com.sun.tools.doclets.internal.toolkit.util.DocFile; |
14358
9eda9239cba0
8000416: refactor javadoc to provide and use an abstraction for relative URIs
jjg
parents:
14357
diff
changeset
|
35 |
import com.sun.tools.doclets.internal.toolkit.util.DocLink; |
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14266
diff
changeset
|
36 |
import com.sun.tools.doclets.internal.toolkit.util.DocPath; |
10 | 37 |
|
38 |
||
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 |
* |
|
14260 | 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 |
* |
|
10 | 50 |
* @since 1.2 |
51 |
* @author Atul M Dambalkar |
|
52 |
* @author Robert Field |
|
53 |
*/ |
|
54 |
public abstract class HtmlDocWriter extends HtmlWriter { |
|
55 |
||
56 |
/** |
|
57 |
* Constructor. Initializes the destination file name through the super |
|
58 |
* class HtmlWriter. |
|
59 |
* |
|
60 |
* @param filename String file name. |
|
61 |
*/ |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14266
diff
changeset
|
62 |
public HtmlDocWriter(Configuration configuration, DocPath filename) |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14266
diff
changeset
|
63 |
throws IOException { |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14266
diff
changeset
|
64 |
super(configuration, filename); |
10 | 65 |
configuration.message.notice("doclet.Generating_0", |
14544 | 66 |
DocFile.createFileForOutput(configuration, filename).getPath()); |
10 | 67 |
} |
68 |
||
69 |
/** |
|
70 |
* Accessor for configuration. |
|
71 |
*/ |
|
72 |
public abstract Configuration configuration(); |
|
73 |
||
17563
e8ddeb9bd17c
8011668: Allow HTMLWriter.getResource to take Content args
jjg
parents:
17560
diff
changeset
|
74 |
public Content getHyperLink(DocPath link, String label) { |
e8ddeb9bd17c
8011668: Allow HTMLWriter.getResource to take Content args
jjg
parents:
17560
diff
changeset
|
75 |
return getHyperLink(link, new StringContent(label), false, "", "", ""); |
e8ddeb9bd17c
8011668: Allow HTMLWriter.getResource to take Content args
jjg
parents:
17560
diff
changeset
|
76 |
} |
e8ddeb9bd17c
8011668: Allow HTMLWriter.getResource to take Content args
jjg
parents:
17560
diff
changeset
|
77 |
|
10 | 78 |
/** |
79 |
* Get Html Hyper Link string. |
|
80 |
* |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14266
diff
changeset
|
81 |
* @param where Position of the link in the file. Character '#' is not |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14266
diff
changeset
|
82 |
* needed. |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14266
diff
changeset
|
83 |
* @param label Tag for the link. |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14266
diff
changeset
|
84 |
* @return a content tree for the hyper link |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14266
diff
changeset
|
85 |
*/ |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14266
diff
changeset
|
86 |
public Content getHyperLink(String where, |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14266
diff
changeset
|
87 |
Content label) { |
14358
9eda9239cba0
8000416: refactor javadoc to provide and use an abstraction for relative URIs
jjg
parents:
14357
diff
changeset
|
88 |
return getHyperLink(DocLink.fragment(where), label, "", ""); |
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14266
diff
changeset
|
89 |
} |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14266
diff
changeset
|
90 |
|
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14266
diff
changeset
|
91 |
/** |
17560 | 92 |
* Get Html hyperlink. |
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14266
diff
changeset
|
93 |
* |
17560 | 94 |
* @param link path of the file. |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
95 |
* @param label Tag for the link. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
96 |
* @return a content tree for the hyper link |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
97 |
*/ |
17560 | 98 |
public Content getHyperLink(DocPath link, Content label) { |
14358
9eda9239cba0
8000416: refactor javadoc to provide and use an abstraction for relative URIs
jjg
parents:
14357
diff
changeset
|
99 |
return getHyperLink(link, label, "", ""); |
9eda9239cba0
8000416: refactor javadoc to provide and use an abstraction for relative URIs
jjg
parents:
14357
diff
changeset
|
100 |
} |
9eda9239cba0
8000416: refactor javadoc to provide and use an abstraction for relative URIs
jjg
parents:
14357
diff
changeset
|
101 |
|
17560 | 102 |
public Content getHyperLink(DocLink link, Content label) { |
14358
9eda9239cba0
8000416: refactor javadoc to provide and use an abstraction for relative URIs
jjg
parents:
14357
diff
changeset
|
103 |
return getHyperLink(link, label, "", ""); |
10 | 104 |
} |
105 |
||
17563
e8ddeb9bd17c
8011668: Allow HTMLWriter.getResource to take Content args
jjg
parents:
17560
diff
changeset
|
106 |
public Content getHyperLink(DocPath link, |
e8ddeb9bd17c
8011668: Allow HTMLWriter.getResource to take Content args
jjg
parents:
17560
diff
changeset
|
107 |
Content label, boolean strong, |
e8ddeb9bd17c
8011668: Allow HTMLWriter.getResource to take Content args
jjg
parents:
17560
diff
changeset
|
108 |
String stylename, String title, String target) { |
e8ddeb9bd17c
8011668: Allow HTMLWriter.getResource to take Content args
jjg
parents:
17560
diff
changeset
|
109 |
return getHyperLink(new DocLink(link), label, strong, |
e8ddeb9bd17c
8011668: Allow HTMLWriter.getResource to take Content args
jjg
parents:
17560
diff
changeset
|
110 |
stylename, title, target); |
e8ddeb9bd17c
8011668: Allow HTMLWriter.getResource to take Content args
jjg
parents:
17560
diff
changeset
|
111 |
} |
e8ddeb9bd17c
8011668: Allow HTMLWriter.getResource to take Content args
jjg
parents:
17560
diff
changeset
|
112 |
|
17560 | 113 |
public Content getHyperLink(DocLink link, |
114 |
Content label, boolean strong, |
|
115 |
String stylename, String title, String target) { |
|
116 |
Content body = label; |
|
117 |
if (strong) { |
|
118 |
body = HtmlTree.SPAN(HtmlStyle.strong, body); |
|
119 |
} |
|
120 |
if (stylename != null && stylename.length() != 0) { |
|
121 |
HtmlTree t = new HtmlTree(HtmlTag.FONT, body); |
|
122 |
t.addAttr(HtmlAttr.CLASS, stylename); |
|
123 |
body = t; |
|
124 |
} |
|
125 |
HtmlTree l = HtmlTree.A(link.toString(), body); |
|
126 |
if (title != null && title.length() != 0) { |
|
127 |
l.addAttr(HtmlAttr.TITLE, title); |
|
128 |
} |
|
129 |
if (target != null && target.length() != 0) { |
|
130 |
l.addAttr(HtmlAttr.TARGET, target); |
|
131 |
} |
|
132 |
return l; |
|
133 |
} |
|
134 |
||
10 | 135 |
/** |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
136 |
* Get Html Hyper Link. |
10 | 137 |
* |
138 |
* @param link String name of the file. |
|
139 |
* @param label Tag for the link. |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
140 |
* @param title String that describes the link's content for accessibility. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
141 |
* @param target Target frame. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
142 |
* @return a content tree for the hyper link. |
10 | 143 |
*/ |
14358
9eda9239cba0
8000416: refactor javadoc to provide and use an abstraction for relative URIs
jjg
parents:
14357
diff
changeset
|
144 |
public Content getHyperLink(DocPath link, |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
145 |
Content label, String title, String target) { |
14358
9eda9239cba0
8000416: refactor javadoc to provide and use an abstraction for relative URIs
jjg
parents:
14357
diff
changeset
|
146 |
return getHyperLink(new DocLink(link), label, title, target); |
9eda9239cba0
8000416: refactor javadoc to provide and use an abstraction for relative URIs
jjg
parents:
14357
diff
changeset
|
147 |
} |
9eda9239cba0
8000416: refactor javadoc to provide and use an abstraction for relative URIs
jjg
parents:
14357
diff
changeset
|
148 |
|
9eda9239cba0
8000416: refactor javadoc to provide and use an abstraction for relative URIs
jjg
parents:
14357
diff
changeset
|
149 |
public Content getHyperLink(DocLink link, |
9eda9239cba0
8000416: refactor javadoc to provide and use an abstraction for relative URIs
jjg
parents:
14357
diff
changeset
|
150 |
Content label, String title, String target) { |
9eda9239cba0
8000416: refactor javadoc to provide and use an abstraction for relative URIs
jjg
parents:
14357
diff
changeset
|
151 |
HtmlTree anchor = HtmlTree.A(link.toString(), label); |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
152 |
if (title != null && title.length() != 0) { |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
153 |
anchor.addAttr(HtmlAttr.TITLE, title); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
154 |
} |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
155 |
if (target != null && target.length() != 0) { |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
156 |
anchor.addAttr(HtmlAttr.TARGET, target); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
157 |
} |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
158 |
return anchor; |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
159 |
} |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
160 |
|
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
161 |
/** |
10 | 162 |
* Get the name of the package, this class is in. |
163 |
* |
|
164 |
* @param cd ClassDoc. |
|
165 |
*/ |
|
166 |
public String getPkgName(ClassDoc cd) { |
|
167 |
String pkgName = cd.containingPackage().name(); |
|
168 |
if (pkgName.length() > 0) { |
|
169 |
pkgName += "."; |
|
170 |
return pkgName; |
|
171 |
} |
|
172 |
return ""; |
|
173 |
} |
|
174 |
||
2216
b124d5c924eb
6786690: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - DL tag and nesting issue
bpatel
parents:
1869
diff
changeset
|
175 |
public boolean getMemberDetailsListPrinted() { |
b124d5c924eb
6786690: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - DL tag and nesting issue
bpatel
parents:
1869
diff
changeset
|
176 |
return memberDetailsListPrinted; |
b124d5c924eb
6786690: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - DL tag and nesting issue
bpatel
parents:
1869
diff
changeset
|
177 |
} |
b124d5c924eb
6786690: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - DL tag and nesting issue
bpatel
parents:
1869
diff
changeset
|
178 |
|
b124d5c924eb
6786690: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - DL tag and nesting issue
bpatel
parents:
1869
diff
changeset
|
179 |
/** |
10 | 180 |
* Print the frameset version of the Html file header. |
181 |
* Called only when generating an HTML frameset file. |
|
182 |
* |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
183 |
* @param title Title of this HTML document |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
184 |
* @param noTimeStamp If true, don't print time stamp in header |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
185 |
* @param frameset the frameset to be added to the HTML document |
10 | 186 |
*/ |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
187 |
public void printFramesetDocument(String title, boolean noTimeStamp, |
14265
4e8e488eeae0
8000666: javadoc should write directly to Writer instead of composing strings
jjg
parents:
14263
diff
changeset
|
188 |
Content frameset) throws IOException { |
14542 | 189 |
Content htmlDocType = DocType.FRAMESET; |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
190 |
Content htmlComment = new Comment(configuration.getText("doclet.New_Page")); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
191 |
Content head = new HtmlTree(HtmlTag.HEAD); |
10 | 192 |
if (! noTimeStamp) { |
14262
058238ba531e
8000418: javadoc should used a standard "generated by javadoc" string
jjg
parents:
14260
diff
changeset
|
193 |
Content headComment = new Comment(getGeneratedByString()); |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
194 |
head.addContent(headComment); |
10 | 195 |
} |
196 |
if (configuration.charset.length() > 0) { |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
197 |
Content meta = HtmlTree.META("Content-Type", "text/html", |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
198 |
configuration.charset); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
199 |
head.addContent(meta); |
10 | 200 |
} |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
201 |
Content windowTitle = HtmlTree.TITLE(new StringContent(title)); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
202 |
head.addContent(windowTitle); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
203 |
head.addContent(getFramesetJavaScript()); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
204 |
Content htmlTree = HtmlTree.HTML(configuration.getLocale().getLanguage(), |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
205 |
head, frameset); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
206 |
Content htmlDocument = new HtmlDocument(htmlDocType, |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
207 |
htmlComment, htmlTree); |
14266
69453558960d
8000673: remove dead code from HtmlWriter and subtypes
jjg
parents:
14265
diff
changeset
|
208 |
write(htmlDocument); |
10 | 209 |
} |
210 |
||
14262
058238ba531e
8000418: javadoc should used a standard "generated by javadoc" string
jjg
parents:
14260
diff
changeset
|
211 |
protected String getGeneratedByString() { |
10 | 212 |
Calendar calendar = new GregorianCalendar(TimeZone.getDefault()); |
14262
058238ba531e
8000418: javadoc should used a standard "generated by javadoc" string
jjg
parents:
14260
diff
changeset
|
213 |
Date today = calendar.getTime(); |
058238ba531e
8000418: javadoc should used a standard "generated by javadoc" string
jjg
parents:
14260
diff
changeset
|
214 |
return "Generated by javadoc ("+ ConfigurationImpl.BUILD_DATE + ") on " + today; |
10 | 215 |
} |
216 |
} |