author | jjg |
Tue, 14 May 2013 10:14:55 -0700 | |
changeset 17570 | 78512b2899db |
parent 17560 | 9f6771abbd1a |
child 17571 | 50895ba58e0d |
permissions | -rw-r--r-- |
10 | 1 |
/* |
17560 | 2 |
* Copyright (c) 2001, 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 |
||
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
26 |
package com.sun.tools.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 |
|
1869
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1863
diff
changeset
|
30 |
import javax.tools.FileObject; |
14368
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
31 |
|
1869
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1863
diff
changeset
|
32 |
import com.sun.javadoc.*; |
14368
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
33 |
import com.sun.tools.doclets.formats.html.markup.*; |
1869
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1863
diff
changeset
|
34 |
import com.sun.tools.doclets.internal.toolkit.*; |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
35 |
import com.sun.tools.doclets.internal.toolkit.util.*; |
10 | 36 |
|
37 |
/** |
|
38 |
* Converts Java Source Code to HTML. |
|
39 |
* |
|
14260 | 40 |
* <p><b>This is NOT part of any supported API. |
41 |
* If you write code that depends on this, you do so at your own risk. |
|
42 |
* This code and its internal interfaces are subject to change or |
|
43 |
* deletion without notice.</b> |
|
10 | 44 |
* |
45 |
* @author Jamie Ho |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
46 |
* @author Bhavesh Patel (Modified) |
10 | 47 |
* @since 1.4 |
48 |
*/ |
|
49 |
public class SourceToHTMLConverter { |
|
50 |
||
51 |
/** |
|
52 |
* The number of trailing blank lines at the end of the page. |
|
53 |
* This is inserted so that anchors at the bottom of small pages |
|
54 |
* can be reached. |
|
55 |
*/ |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
56 |
private static final int NUM_BLANK_LINES = 60; |
10 | 57 |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
58 |
/** |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
59 |
* 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
|
60 |
*/ |
17560 | 61 |
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
|
62 |
|
14542 | 63 |
private final ConfigurationImpl configuration; |
64 |
||
65 |
private final RootDoc rootDoc; |
|
66 |
||
67 |
private DocPath outputdir; |
|
68 |
||
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
69 |
/** |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
70 |
* 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
|
71 |
* generated. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
72 |
*/ |
14542 | 73 |
private DocPath relativePath = DocPath.empty; |
10 | 74 |
|
14542 | 75 |
private SourceToHTMLConverter(ConfigurationImpl configuration, RootDoc rd, |
76 |
DocPath outputdir) { |
|
77 |
this.configuration = configuration; |
|
78 |
this.rootDoc = rd; |
|
79 |
this.outputdir = outputdir; |
|
80 |
} |
|
10 | 81 |
|
82 |
/** |
|
83 |
* Convert the Classes in the given RootDoc to an HTML. |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
84 |
* |
10 | 85 |
* @param configuration the configuration. |
86 |
* @param rd the RootDoc to convert. |
|
87 |
* @param outputdir the name of the directory to output to. |
|
88 |
*/ |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
89 |
public static void convertRoot(ConfigurationImpl configuration, RootDoc rd, |
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
90 |
DocPath outputdir) { |
14542 | 91 |
new SourceToHTMLConverter(configuration, rd, outputdir).generate(); |
92 |
} |
|
93 |
||
94 |
void generate() { |
|
95 |
if (rootDoc == null || outputdir == null) { |
|
10 | 96 |
return; |
97 |
} |
|
14542 | 98 |
PackageDoc[] pds = rootDoc.specifiedPackages(); |
10 | 99 |
for (int i = 0; i < pds.length; i++) { |
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
8631
diff
changeset
|
100 |
// 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
|
101 |
// do not convert the package files to HTML. |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
8631
diff
changeset
|
102 |
if (!(configuration.nodeprecated && Util.isDeprecated(pds[i]))) |
14542 | 103 |
convertPackage(pds[i], outputdir); |
10 | 104 |
} |
14542 | 105 |
ClassDoc[] cds = rootDoc.specifiedClasses(); |
10 | 106 |
for (int i = 0; i < cds.length; i++) { |
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
8631
diff
changeset
|
107 |
// 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
|
108 |
// 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
|
109 |
// package files to HTML. |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
8631
diff
changeset
|
110 |
if (!(configuration.nodeprecated && |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
8631
diff
changeset
|
111 |
(Util.isDeprecated(cds[i]) || Util.isDeprecated(cds[i].containingPackage())))) |
14542 | 112 |
convertClass(cds[i], outputdir); |
10 | 113 |
} |
114 |
} |
|
115 |
||
116 |
/** |
|
117 |
* Convert the Classes in the given Package to an HTML. |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
118 |
* |
10 | 119 |
* @param pd the Package to convert. |
120 |
* @param outputdir the name of the directory to output to. |
|
121 |
*/ |
|
14542 | 122 |
public void convertPackage(PackageDoc pd, DocPath outputdir) { |
14368
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
123 |
if (pd == null) { |
10 | 124 |
return; |
125 |
} |
|
126 |
ClassDoc[] cds = pd.allClasses(); |
|
127 |
for (int i = 0; i < cds.length; i++) { |
|
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
8631
diff
changeset
|
128 |
// 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
|
129 |
// 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
|
130 |
// 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
|
131 |
// the calling method above. |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
8631
diff
changeset
|
132 |
if (!(configuration.nodeprecated && Util.isDeprecated(cds[i]))) |
14542 | 133 |
convertClass(cds[i], outputdir); |
10 | 134 |
} |
135 |
} |
|
136 |
||
137 |
/** |
|
138 |
* 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
|
139 |
* |
10 | 140 |
* @param cd the class to convert. |
141 |
* @param outputdir the name of the directory to output to. |
|
142 |
*/ |
|
14542 | 143 |
public void convertClass(ClassDoc cd, DocPath outputdir) { |
14368
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
144 |
if (cd == null) { |
10 | 145 |
return; |
146 |
} |
|
147 |
try { |
|
1869
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1863
diff
changeset
|
148 |
SourcePosition sp = cd.position(); |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1863
diff
changeset
|
149 |
if (sp == null) |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1863
diff
changeset
|
150 |
return; |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1863
diff
changeset
|
151 |
Reader r; |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1863
diff
changeset
|
152 |
// temp hack until we can update SourcePosition API. |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1863
diff
changeset
|
153 |
if (sp instanceof com.sun.tools.javadoc.SourcePositionImpl) { |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1863
diff
changeset
|
154 |
FileObject fo = ((com.sun.tools.javadoc.SourcePositionImpl) sp).fileObject(); |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1863
diff
changeset
|
155 |
if (fo == null) |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1863
diff
changeset
|
156 |
return; |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1863
diff
changeset
|
157 |
r = fo.openReader(true); |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1863
diff
changeset
|
158 |
} else { |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1863
diff
changeset
|
159 |
File file = sp.file(); |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1863
diff
changeset
|
160 |
if (file == null) |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1863
diff
changeset
|
161 |
return; |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1863
diff
changeset
|
162 |
r = new FileReader(file); |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1863
diff
changeset
|
163 |
} |
0e193a8f3520
6794582: javadoc should read files using a FileManager
jjg
parents:
1863
diff
changeset
|
164 |
LineNumberReader reader = new LineNumberReader(r); |
10 | 165 |
int lineno = 1; |
166 |
String line; |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
167 |
relativePath = DocPaths.SOURCE_OUTPUT |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
168 |
.resolve(DocPath.forPackage(cd)) |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
169 |
.invert(); |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
170 |
Content body = getHeader(); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
171 |
Content pre = new HtmlTree(HtmlTag.PRE); |
10 | 172 |
try { |
173 |
while ((line = reader.readLine()) != null) { |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
174 |
addLineNo(pre, lineno); |
14542 | 175 |
addLine(pre, line, lineno); |
10 | 176 |
lineno++; |
177 |
} |
|
178 |
} finally { |
|
179 |
reader.close(); |
|
180 |
} |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
181 |
addBlankLines(pre); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
182 |
Content div = HtmlTree.DIV(HtmlStyle.sourceContainer, pre); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
183 |
body.addContent(div); |
14542 | 184 |
writeToFile(body, outputdir.resolve(DocPath.forClass(cd))); |
14368
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
185 |
} catch (IOException e) { |
10 | 186 |
e.printStackTrace(); |
187 |
} |
|
188 |
} |
|
189 |
||
190 |
/** |
|
191 |
* 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
|
192 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
193 |
* @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
|
194 |
* @param path the path for the file. |
10 | 195 |
*/ |
14542 | 196 |
private void writeToFile(Content body, DocPath path) throws IOException { |
197 |
Content htmlDocType = DocType.TRANSITIONAL; |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
198 |
Content head = new HtmlTree(HtmlTag.HEAD); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
199 |
head.addContent(HtmlTree.TITLE(new StringContent( |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
200 |
configuration.getText("doclet.Window_Source_title")))); |
14542 | 201 |
head.addContent(getStyleSheetProperties()); |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
202 |
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
|
203 |
head, body); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
204 |
Content htmlDocument = new HtmlDocument(htmlDocType, htmlTree); |
14368
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
205 |
configuration.message.notice("doclet.Generating_0", path.getPath()); |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
206 |
DocFile df = DocFile.createFileForOutput(configuration, path); |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
207 |
Writer w = df.openWriter(); |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
208 |
try { |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
209 |
htmlDocument.write(w, true); |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
210 |
} finally { |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
211 |
w.close(); |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
212 |
} |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
213 |
|
10 | 214 |
} |
215 |
||
216 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
217 |
* Returns a link to the stylesheet file. |
10 | 218 |
* |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
219 |
* @return an HtmlTree for the lINK tag which provides the stylesheet location |
10 | 220 |
*/ |
14542 | 221 |
public HtmlTree getStyleSheetProperties() { |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
222 |
String filename = configuration.stylesheetfile; |
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
223 |
DocPath stylesheet; |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
224 |
if (filename.length() > 0) { |
14368
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
225 |
DocFile file = DocFile.createFileForInput(configuration, filename); |
6f4c62de6985
8001664: refactor javadoc to use abstraction to handle files
jjg
parents:
14357
diff
changeset
|
226 |
stylesheet = DocPath.create(file.getName()); |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
227 |
} else { |
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
228 |
stylesheet = DocPaths.STYLESHEET; |
10 | 229 |
} |
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
230 |
DocPath p = relativePath.resolve(stylesheet); |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
231 |
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
|
232 |
return link; |
10 | 233 |
} |
234 |
||
235 |
/** |
|
236 |
* Get the header. |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
237 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
238 |
* @return the header content for the HTML file |
10 | 239 |
*/ |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
240 |
private static Content getHeader() { |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
241 |
return new HtmlTree(HtmlTag.BODY); |
10 | 242 |
} |
243 |
||
244 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
245 |
* 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
|
246 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
247 |
* @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
|
248 |
* @param lineno The line number |
10 | 249 |
*/ |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
250 |
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
|
251 |
HtmlTree span = new HtmlTree(HtmlTag.SPAN); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
252 |
span.addStyle(HtmlStyle.sourceLineNo); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
253 |
if (lineno < 10) { |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
254 |
span.addContent("00" + Integer.toString(lineno)); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
255 |
} else if (lineno < 100) { |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
256 |
span.addContent("0" + Integer.toString(lineno)); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
257 |
} else { |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
258 |
span.addContent(Integer.toString(lineno)); |
10 | 259 |
} |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
260 |
pre.addContent(span); |
10 | 261 |
} |
262 |
||
263 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
264 |
* 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
|
265 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
266 |
* @param pre the content tree to which the line will be added. |
10 | 267 |
* @param line the string to format. |
268 |
* @param currentLineNo the current number. |
|
269 |
*/ |
|
14542 | 270 |
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
|
271 |
if (line != null) { |
14542 | 272 |
StringBuilder lineBuffer = new StringBuilder(line); |
273 |
Util.replaceTabs(configuration, lineBuffer); |
|
17560 | 274 |
pre.addContent(lineBuffer.toString()); |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
275 |
Content anchor = HtmlTree.A_NAME("line." + Integer.toString(currentLineNo)); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
276 |
pre.addContent(anchor); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
277 |
pre.addContent(NEW_LINE); |
10 | 278 |
} |
279 |
} |
|
280 |
||
281 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
282 |
* 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
|
283 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
284 |
* @param pre the content tree to which the blank lines will be added. |
10 | 285 |
*/ |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
286 |
private static void addBlankLines(Content pre) { |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
287 |
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
|
288 |
pre.addContent(NEW_LINE); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
289 |
} |
10 | 290 |
} |
291 |
||
292 |
/** |
|
293 |
* Given a <code>Doc</code>, 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
|
294 |
* |
10 | 295 |
* @param d the <code>Doc</code> to check. |
296 |
* @return the name of the anchor. |
|
297 |
*/ |
|
298 |
public static String getAnchorName(Doc d) { |
|
299 |
return "line." + d.position().line(); |
|
300 |
} |
|
301 |
} |