author | jjg |
Fri, 27 May 2016 13:06:58 -0700 | |
changeset 38617 | d93a7f64e231 |
parent 33920 | bd731341c405 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
29957
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
2 |
* Copyright (c) 1998, 2015, 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; |
|
27 |
||
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
28 |
import java.io.*; |
33920 | 29 |
import java.util.*; |
14258 | 30 |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
31 |
import com.sun.tools.doclets.formats.html.markup.*; |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
32 |
import com.sun.tools.doclets.internal.toolkit.*; |
14258 | 33 |
import com.sun.tools.doclets.internal.toolkit.util.*; |
10 | 34 |
|
35 |
/** |
|
36 |
* Generate Separate Index Files for all the member names with Indexing in |
|
37 |
* Unicode Order. This will create "index-files" directory in the current or |
|
38 |
* destination directory and will generate separate file for each unicode index. |
|
39 |
* |
|
14260
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
40 |
* <p><b>This is NOT part of any supported API. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
41 |
* If you write code that depends on this, you do so at your own risk. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
42 |
* This code and its internal interfaces are subject to change or |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
43 |
* deletion without notice.</b> |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
44 |
* |
10 | 45 |
* @see java.lang.Character |
46 |
* @author Atul M Dambalkar |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
47 |
* @author Bhavesh Patel (Modified) |
10 | 48 |
*/ |
38617 | 49 |
@Deprecated |
10 | 50 |
public class SplitIndexWriter extends AbstractIndexWriter { |
51 |
||
52 |
/** |
|
53 |
* Previous unicode character index in the built index. |
|
54 |
*/ |
|
55 |
protected int prev; |
|
56 |
||
57 |
/** |
|
58 |
* Next unicode character in the built index. |
|
59 |
*/ |
|
60 |
protected int next; |
|
61 |
||
33920 | 62 |
private List<Object> indexElements; |
63 |
||
10 | 64 |
/** |
65 |
* Construct the SplitIndexWriter. Uses path to this file and relative path |
|
66 |
* from this file. |
|
67 |
* |
|
68 |
* @param path Path to the file which is getting generated. |
|
69 |
* @param indexbuilder Unicode based Index from {@link IndexBuilder} |
|
70 |
*/ |
|
71 |
public SplitIndexWriter(ConfigurationImpl configuration, |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
72 |
DocPath path, |
33920 | 73 |
IndexBuilder indexbuilder, List<Object> elements, |
10 | 74 |
int prev, int next) throws IOException { |
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
75 |
super(configuration, path, indexbuilder); |
33920 | 76 |
this.indexElements = elements; |
10 | 77 |
this.prev = prev; |
78 |
this.next = next; |
|
79 |
} |
|
80 |
||
81 |
/** |
|
82 |
* Generate separate index files, for each Unicode character, listing all |
|
83 |
* the members starting with the particular unicode character. |
|
84 |
* |
|
85 |
* @param indexbuilder IndexBuilder built by {@link IndexBuilder} |
|
86 |
* @throws DocletAbortException |
|
87 |
*/ |
|
88 |
public static void generate(ConfigurationImpl configuration, |
|
89 |
IndexBuilder indexbuilder) { |
|
90 |
SplitIndexWriter indexgen; |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
91 |
DocPath filename = DocPath.empty; |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
92 |
DocPath path = DocPaths.INDEX_FILES; |
10 | 93 |
try { |
33920 | 94 |
Set<Object> keys = new TreeSet<>(Arrays.asList(indexbuilder.elements())); |
95 |
keys.addAll(configuration.tagSearchIndexKeys); |
|
96 |
List<Object> elements = new ArrayList<>(keys); |
|
97 |
ListIterator<Object> li = elements.listIterator(); |
|
98 |
while (li.hasNext()) { |
|
99 |
Object ch = li.next(); |
|
100 |
filename = DocPaths.indexN(li.nextIndex()); |
|
10 | 101 |
indexgen = new SplitIndexWriter(configuration, |
33920 | 102 |
path.resolve(filename), |
103 |
indexbuilder, elements, li.previousIndex(), li.nextIndex()); |
|
104 |
indexgen.generateIndexFile((Character) ch); |
|
105 |
if (!li.hasNext()) { |
|
106 |
indexgen.createSearchIndexFiles(); |
|
107 |
} |
|
10 | 108 |
indexgen.close(); |
109 |
} |
|
110 |
} catch (IOException exc) { |
|
111 |
configuration.standardmessage.error( |
|
112 |
"doclet.exception_encountered", |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
113 |
exc.toString(), filename.getPath()); |
19667
fdfce85627a9
8001669: javadoc internal DocletAbortException should set cause when appropriate
jjg
parents:
14366
diff
changeset
|
114 |
throw new DocletAbortException(exc); |
10 | 115 |
} |
116 |
} |
|
117 |
||
118 |
/** |
|
119 |
* Generate the contents of each index file, with Header, Footer, |
|
120 |
* Member Field, Method and Constructor Description. |
|
121 |
* |
|
122 |
* @param unicode Unicode character referring to the character for the |
|
123 |
* index. |
|
124 |
*/ |
|
125 |
protected void generateIndexFile(Character unicode) throws IOException { |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
126 |
String title = configuration.getText("doclet.Window_Split_Index", |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
127 |
unicode.toString()); |
29957
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
128 |
HtmlTree body = getBody(true, getWindowTitle(title)); |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
129 |
HtmlTree htmlTree = (configuration.allowTag(HtmlTag.HEADER)) |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
130 |
? HtmlTree.HEADER() |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
131 |
: body; |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
132 |
addTop(htmlTree); |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
133 |
addNavLinks(true, htmlTree); |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
134 |
if (configuration.allowTag(HtmlTag.HEADER)) { |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
135 |
body.addContent(htmlTree); |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
136 |
} |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
137 |
HtmlTree divTree = new HtmlTree(HtmlTag.DIV); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
138 |
divTree.addStyle(HtmlStyle.contentContainer); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
139 |
addLinksForIndexes(divTree); |
33920 | 140 |
if (configuration.tagSearchIndexMap.get(unicode) == null) { |
141 |
addContents(unicode, indexbuilder.getMemberList(unicode), divTree); |
|
142 |
} else if (indexbuilder.getMemberList(unicode) == null) { |
|
143 |
addSearchContents(unicode, configuration.tagSearchIndexMap.get(unicode), divTree); |
|
144 |
} else { |
|
145 |
addContents(unicode, indexbuilder.getMemberList(unicode), |
|
146 |
configuration.tagSearchIndexMap.get(unicode), divTree); |
|
147 |
} |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
148 |
addLinksForIndexes(divTree); |
29957
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
149 |
body.addContent((configuration.allowTag(HtmlTag.MAIN)) ? HtmlTree.MAIN(divTree) : divTree); |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
150 |
if (configuration.allowTag(HtmlTag.FOOTER)) { |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
151 |
htmlTree = HtmlTree.FOOTER(); |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
152 |
} |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
153 |
addNavLinks(false, htmlTree); |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
154 |
addBottom(htmlTree); |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
155 |
if (configuration.allowTag(HtmlTag.FOOTER)) { |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
156 |
body.addContent(htmlTree); |
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
157 |
} |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
158 |
printHtmlDocument(null, true, body); |
10 | 159 |
} |
160 |
||
161 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
162 |
* Add links for all the Index Files per unicode character. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
163 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
164 |
* @param contentTree the content tree to which the links for indexes will be added |
10 | 165 |
*/ |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
166 |
protected void addLinksForIndexes(Content contentTree) { |
33920 | 167 |
for (int i = 0; i < indexElements.size(); i++) { |
10 | 168 |
int j = i + 1; |
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
169 |
contentTree.addContent(getHyperLink(DocPaths.indexN(j), |
33920 | 170 |
new StringContent(indexElements.get(i).toString()))); |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
171 |
contentTree.addContent(getSpace()); |
10 | 172 |
} |
173 |
} |
|
174 |
||
175 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
176 |
* Get link to the previous unicode character. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
177 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
178 |
* @return a content tree for the link |
10 | 179 |
*/ |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
180 |
public Content getNavLinkPrevious() { |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
181 |
Content prevletterLabel = getResource("doclet.Prev_Letter"); |
10 | 182 |
if (prev == -1) { |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
183 |
return HtmlTree.LI(prevletterLabel); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
184 |
} |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
185 |
else { |
14358
9eda9239cba0
8000416: refactor javadoc to provide and use an abstraction for relative URIs
jjg
parents:
14357
diff
changeset
|
186 |
Content prevLink = getHyperLink(DocPaths.indexN(prev), |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
187 |
prevletterLabel); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
188 |
return HtmlTree.LI(prevLink); |
10 | 189 |
} |
190 |
} |
|
191 |
||
192 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
193 |
* Get link to the next unicode character. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
194 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
195 |
* @return a content tree for the link |
10 | 196 |
*/ |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
197 |
public Content getNavLinkNext() { |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
198 |
Content nextletterLabel = getResource("doclet.Next_Letter"); |
10 | 199 |
if (next == -1) { |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
200 |
return HtmlTree.LI(nextletterLabel); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
201 |
} |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
202 |
else { |
14358
9eda9239cba0
8000416: refactor javadoc to provide and use an abstraction for relative URIs
jjg
parents:
14357
diff
changeset
|
203 |
Content nextLink = getHyperLink(DocPaths.indexN(next), |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
204 |
nextletterLabel); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
205 |
return HtmlTree.LI(nextLink); |
10 | 206 |
} |
207 |
} |
|
208 |
} |