author | jjg |
Mon, 22 Aug 2016 16:32:40 -0700 | |
changeset 40587 | 1c355ea550ed |
parent 40508 | 74ef30d16fb9 |
child 42277 | 2668b0bc7ad7 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
2 |
* Copyright (c) 2001, 2016, 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 |
||
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
26 |
package jdk.javadoc.internal.doclets.formats.html; |
10 | 27 |
|
28 |
import java.io.*; |
|
14368
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
29 |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
30 |
import javax.lang.model.element.Element; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
31 |
import javax.lang.model.element.PackageElement; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
32 |
import javax.lang.model.element.TypeElement; |
1869
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1863
diff
changeset
|
33 |
import javax.tools.FileObject; |
14368
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
34 |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
35 |
import jdk.javadoc.doclet.DocletEnvironment; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
36 |
import jdk.javadoc.internal.doclets.formats.html.markup.DocType; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
37 |
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlDocument; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
38 |
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
39 |
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
40 |
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
41 |
import jdk.javadoc.internal.doclets.formats.html.markup.StringContent; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
42 |
import jdk.javadoc.internal.doclets.toolkit.Content; |
40303 | 43 |
import jdk.javadoc.internal.doclets.toolkit.Messages; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
44 |
import jdk.javadoc.internal.doclets.toolkit.util.DocFile; |
40587 | 45 |
import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
46 |
import jdk.javadoc.internal.doclets.toolkit.util.DocPath; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
47 |
import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
48 |
import jdk.javadoc.internal.doclets.toolkit.util.DocletConstants; |
40587 | 49 |
import jdk.javadoc.internal.doclets.toolkit.util.SimpleDocletException; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
50 |
import jdk.javadoc.internal.doclets.toolkit.util.Utils; |
10 | 51 |
|
52 |
/** |
|
53 |
* Converts Java Source Code to HTML. |
|
54 |
* |
|
14260 | 55 |
* <p><b>This is NOT part of any supported API. |
56 |
* If you write code that depends on this, you do so at your own risk. |
|
57 |
* This code and its internal interfaces are subject to change or |
|
58 |
* deletion without notice.</b> |
|
10 | 59 |
* |
60 |
* @author Jamie Ho |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
61 |
* @author Bhavesh Patel (Modified) |
10 | 62 |
*/ |
63 |
public class SourceToHTMLConverter { |
|
64 |
||
65 |
/** |
|
66 |
* The number of trailing blank lines at the end of the page. |
|
67 |
* This is inserted so that anchors at the bottom of small pages |
|
68 |
* can be reached. |
|
69 |
*/ |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
70 |
private static final int NUM_BLANK_LINES = 60; |
10 | 71 |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
72 |
/** |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
73 |
* New line to be added to the documentation. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
74 |
*/ |
17560 | 75 |
private static final String NEW_LINE = DocletConstants.NL; |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
76 |
|
14542 | 77 |
private final ConfigurationImpl configuration; |
40303 | 78 |
private final Messages messages; |
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22159
diff
changeset
|
79 |
private final Utils utils; |
14542 | 80 |
|
39364
bd6d4a7936b4
8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents:
35426
diff
changeset
|
81 |
private final DocletEnvironment docEnv; |
14542 | 82 |
|
40587 | 83 |
private final DocPath outputdir; |
14542 | 84 |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
85 |
/** |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
86 |
* Relative path from the documentation root to the file that is being |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
87 |
* generated. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
88 |
*/ |
14542 | 89 |
private DocPath relativePath = DocPath.empty; |
10 | 90 |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
91 |
private SourceToHTMLConverter(ConfigurationImpl configuration, DocletEnvironment rd, |
14542 | 92 |
DocPath outputdir) { |
93 |
this.configuration = configuration; |
|
40303 | 94 |
this.messages = configuration.getMessages(); |
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22159
diff
changeset
|
95 |
this.utils = configuration.utils; |
39364
bd6d4a7936b4
8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents:
35426
diff
changeset
|
96 |
this.docEnv = rd; |
14542 | 97 |
this.outputdir = outputdir; |
98 |
} |
|
10 | 99 |
|
100 |
/** |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
101 |
* Translate the TypeElements in the given DocletEnvironment to HTML representation. |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
102 |
* |
10 | 103 |
* @param configuration the configuration. |
39364
bd6d4a7936b4
8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents:
35426
diff
changeset
|
104 |
* @param docEnv the DocletEnvironment to convert. |
10 | 105 |
* @param outputdir the name of the directory to output to. |
40587 | 106 |
* @throws DocFileIOException if there is a problem generating an output file |
107 |
* @throws SimpleDocletException if there is a problem reading a source file |
|
10 | 108 |
*/ |
39364
bd6d4a7936b4
8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents:
35426
diff
changeset
|
109 |
public static void convertRoot(ConfigurationImpl configuration, DocletEnvironment docEnv, |
40587 | 110 |
DocPath outputdir) throws DocFileIOException, SimpleDocletException { |
39364
bd6d4a7936b4
8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents:
35426
diff
changeset
|
111 |
new SourceToHTMLConverter(configuration, docEnv, outputdir).generate(); |
14542 | 112 |
} |
113 |
||
40587 | 114 |
void generate() throws DocFileIOException, SimpleDocletException { |
39364
bd6d4a7936b4
8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents:
35426
diff
changeset
|
115 |
if (docEnv == null || outputdir == null) { |
10 | 116 |
return; |
117 |
} |
|
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40303
diff
changeset
|
118 |
for (PackageElement pkg : configuration.getSpecifiedPackages()) { |
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
8631
diff
changeset
|
119 |
// If -nodeprecated option is set and the package is marked as deprecated, |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
8631
diff
changeset
|
120 |
// do not convert the package files to HTML. |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
121 |
if (!(configuration.nodeprecated && utils.isDeprecated(pkg))) |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
122 |
convertPackage(pkg, outputdir); |
10 | 123 |
} |
40508
74ef30d16fb9
8159305: Enhance the javadoc tool to support module related options
ksrini
parents:
40303
diff
changeset
|
124 |
for (TypeElement te : configuration.getSpecifiedClasses()) { |
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
8631
diff
changeset
|
125 |
// If -nodeprecated option is set and the class is marked as deprecated |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
8631
diff
changeset
|
126 |
// or the containing package is deprecated, do not convert the |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
8631
diff
changeset
|
127 |
// package files to HTML. |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
8631
diff
changeset
|
128 |
if (!(configuration.nodeprecated && |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
129 |
(utils.isDeprecated(te) || utils.isDeprecated(utils.containingPackage(te))))) |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
130 |
convertClass(te, outputdir); |
10 | 131 |
} |
132 |
} |
|
133 |
||
134 |
/** |
|
40587 | 135 |
* Convert the Classes in the given Package to an HTML file. |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
136 |
* |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
137 |
* @param pkg the Package to convert. |
10 | 138 |
* @param outputdir the name of the directory to output to. |
40587 | 139 |
* @throws DocFileIOException if there is a problem generating an output file |
140 |
* @throws SimpleDocletException if there is a problem reading a source file |
|
10 | 141 |
*/ |
40587 | 142 |
public void convertPackage(PackageElement pkg, DocPath outputdir) |
143 |
throws DocFileIOException, SimpleDocletException { |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
144 |
if (pkg == null) { |
10 | 145 |
return; |
146 |
} |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
147 |
for (Element te : utils.getAllClasses(pkg)) { |
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
8631
diff
changeset
|
148 |
// If -nodeprecated option is set and the class is marked as deprecated, |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
8631
diff
changeset
|
149 |
// do not convert the package files to HTML. We do not check for |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
8631
diff
changeset
|
150 |
// containing package deprecation since it is already check in |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
8631
diff
changeset
|
151 |
// the calling method above. |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
152 |
if (!(configuration.nodeprecated && utils.isDeprecated(te))) |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
153 |
convertClass((TypeElement)te, outputdir); |
10 | 154 |
} |
155 |
} |
|
156 |
||
157 |
/** |
|
158 |
* Convert the given Class to an HTML. |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
159 |
* |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
160 |
* @param te the class to convert. |
40587 | 161 |
* @param outputdir the name of the directory to output to |
162 |
* @throws DocFileIOException if there is a problem generating the output file |
|
163 |
* @throws SimpleDocletException if there is a problem reading the source file |
|
10 | 164 |
*/ |
40587 | 165 |
public void convertClass(TypeElement te, DocPath outputdir) |
166 |
throws DocFileIOException, SimpleDocletException { |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
167 |
if (te == null) { |
10 | 168 |
return; |
169 |
} |
|
40587 | 170 |
FileObject fo = utils.getFileObject(te); |
171 |
if (fo == null) |
|
172 |
return; |
|
173 |
||
10 | 174 |
try { |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
175 |
Reader r = fo.openReader(true); |
10 | 176 |
int lineno = 1; |
177 |
String line; |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
178 |
relativePath = DocPaths.SOURCE_OUTPUT |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
179 |
.resolve(DocPath.forPackage(utils, te)) |
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
180 |
.invert(); |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
181 |
Content body = getHeader(); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
182 |
Content pre = new HtmlTree(HtmlTag.PRE); |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
17571
diff
changeset
|
183 |
try (LineNumberReader reader = new LineNumberReader(r)) { |
10 | 184 |
while ((line = reader.readLine()) != null) { |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
185 |
addLineNo(pre, lineno); |
14542 | 186 |
addLine(pre, line, lineno); |
10 | 187 |
lineno++; |
188 |
} |
|
189 |
} |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
190 |
addBlankLines(pre); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
191 |
Content div = HtmlTree.DIV(HtmlStyle.sourceContainer, pre); |
29957
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
192 |
body.addContent((configuration.allowTag(HtmlTag.MAIN)) ? HtmlTree.MAIN(div) : div); |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
193 |
writeToFile(body, outputdir.resolve(DocPath.forClass(utils, te))); |
14368
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
194 |
} catch (IOException e) { |
40587 | 195 |
String message = configuration.resources.getText("doclet.exception.read.file", fo.getName()); |
196 |
throw new SimpleDocletException(message, e); |
|
10 | 197 |
} |
198 |
} |
|
199 |
||
200 |
/** |
|
201 |
* Write the output to the file. |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
202 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
203 |
* @param body the documentation content to be written to the file. |
14368
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
204 |
* @param path the path for the file. |
10 | 205 |
*/ |
40587 | 206 |
private void writeToFile(Content body, DocPath path) throws DocFileIOException { |
29957
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
207 |
Content htmlDocType = configuration.isOutputHtml5() |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
208 |
? DocType.HTML5 |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
209 |
: DocType.TRANSITIONAL; |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
210 |
Content head = new HtmlTree(HtmlTag.HEAD); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
211 |
head.addContent(HtmlTree.TITLE(new StringContent( |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
212 |
configuration.getText("doclet.Window_Source_title")))); |
14542 | 213 |
head.addContent(getStyleSheetProperties()); |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
214 |
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
|
215 |
head, body); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
216 |
Content htmlDocument = new HtmlDocument(htmlDocType, htmlTree); |
40303 | 217 |
messages.notice("doclet.Generating_0", path.getPath()); |
14368
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
218 |
DocFile df = DocFile.createFileForOutput(configuration, path); |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
17571
diff
changeset
|
219 |
try (Writer w = df.openWriter()) { |
14368
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
220 |
htmlDocument.write(w, true); |
40587 | 221 |
} catch (IOException e) { |
222 |
throw new DocFileIOException(df, DocFileIOException.Mode.WRITE, e); |
|
14368
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
223 |
} |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
224 |
|
10 | 225 |
} |
226 |
||
227 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
228 |
* Returns a link to the stylesheet file. |
10 | 229 |
* |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
230 |
* @return an HtmlTree for the lINK tag which provides the stylesheet location |
10 | 231 |
*/ |
14542 | 232 |
public HtmlTree getStyleSheetProperties() { |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
233 |
String filename = configuration.stylesheetfile; |
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
234 |
DocPath stylesheet; |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
235 |
if (filename.length() > 0) { |
14368
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
236 |
DocFile file = DocFile.createFileForInput(configuration, filename); |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
237 |
stylesheet = DocPath.create(file.getName()); |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
238 |
} else { |
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
239 |
stylesheet = DocPaths.STYLESHEET; |
10 | 240 |
} |
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
241 |
DocPath p = relativePath.resolve(stylesheet); |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
242 |
HtmlTree link = HtmlTree.LINK("stylesheet", "text/css", p.getPath(), "Style"); |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
243 |
return link; |
10 | 244 |
} |
245 |
||
246 |
/** |
|
247 |
* Get the header. |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
248 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
249 |
* @return the header content for the HTML file |
10 | 250 |
*/ |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
251 |
private static Content getHeader() { |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
252 |
return new HtmlTree(HtmlTag.BODY); |
10 | 253 |
} |
254 |
||
255 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
256 |
* Add the line numbers for the source code. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
257 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
258 |
* @param pre the content tree to which the line number will be added |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
259 |
* @param lineno The line number |
10 | 260 |
*/ |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
261 |
private static void addLineNo(Content pre, int lineno) { |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
262 |
HtmlTree span = new HtmlTree(HtmlTag.SPAN); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
263 |
span.addStyle(HtmlStyle.sourceLineNo); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
264 |
if (lineno < 10) { |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
265 |
span.addContent("00" + Integer.toString(lineno)); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
266 |
} else if (lineno < 100) { |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
267 |
span.addContent("0" + Integer.toString(lineno)); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
268 |
} else { |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
269 |
span.addContent(Integer.toString(lineno)); |
10 | 270 |
} |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
271 |
pre.addContent(span); |
10 | 272 |
} |
273 |
||
274 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
275 |
* Add a line from source to the HTML file that is generated. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
276 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
277 |
* @param pre the content tree to which the line will be added. |
10 | 278 |
* @param line the string to format. |
279 |
* @param currentLineNo the current number. |
|
280 |
*/ |
|
14542 | 281 |
private void addLine(Content pre, String line, int currentLineNo) { |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
282 |
if (line != null) { |
31297
86fe1414f12c
8081854: Javadoc should generate named anchors for HTML4 output
bpatel
parents:
29957
diff
changeset
|
283 |
Content anchor = HtmlTree.A(configuration.htmlVersion, |
86fe1414f12c
8081854: Javadoc should generate named anchors for HTML4 output
bpatel
parents:
29957
diff
changeset
|
284 |
"line." + Integer.toString(currentLineNo), |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
285 |
new StringContent(utils.replaceTabs(line))); |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
286 |
pre.addContent(anchor); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
287 |
pre.addContent(NEW_LINE); |
10 | 288 |
} |
289 |
} |
|
290 |
||
291 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
292 |
* Add trailing blank lines at the end of the page. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
293 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
294 |
* @param pre the content tree to which the blank lines will be added. |
10 | 295 |
*/ |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
296 |
private static void addBlankLines(Content pre) { |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
297 |
for (int i = 0; i < NUM_BLANK_LINES; i++) { |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
298 |
pre.addContent(NEW_LINE); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
299 |
} |
10 | 300 |
} |
301 |
||
302 |
/** |
|
40587 | 303 |
* Given an element, return an anchor name for it. |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
304 |
* |
40587 | 305 |
* @param utils the utility class, used to get the line number of the element |
306 |
* @param e the element to check. |
|
10 | 307 |
* @return the name of the anchor. |
308 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
309 |
public static String getAnchorName(Utils utils, Element e) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
31297
diff
changeset
|
310 |
return "line." + utils.getLineNumber(e); |
10 | 311 |
} |
312 |
} |