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