author | hannesw |
Wed, 27 Nov 2019 13:08:16 +0100 | |
changeset 59294 | 48b88b9c11eb |
parent 54610 | a9ab154b1384 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
53863
d001808c57e8
8218998: Add metadata to generated API documentation files
jjg
parents:
53562
diff
changeset
|
2 |
* Copyright (c) 1998, 2019, 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 |
|
59294
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54610
diff
changeset
|
35 |
import jdk.javadoc.internal.doclets.formats.html.markup.BodyContents; |
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54610
diff
changeset
|
36 |
import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder; |
54610 | 37 |
import jdk.javadoc.internal.doclets.formats.html.markup.Entity; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
33920
diff
changeset
|
38 |
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
33920
diff
changeset
|
39 |
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
33920
diff
changeset
|
40 |
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
33920
diff
changeset
|
41 |
import jdk.javadoc.internal.doclets.formats.html.markup.StringContent; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
33920
diff
changeset
|
42 |
import jdk.javadoc.internal.doclets.toolkit.Content; |
40587 | 43 |
import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
33920
diff
changeset
|
44 |
import jdk.javadoc.internal.doclets.toolkit.util.DocPath; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
33920
diff
changeset
|
45 |
import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
33920
diff
changeset
|
46 |
import jdk.javadoc.internal.doclets.toolkit.util.IndexBuilder; |
14258 | 47 |
|
10 | 48 |
|
49 |
/** |
|
50 |
* Generate Separate Index Files for all the member names with Indexing in |
|
51 |
* Unicode Order. This will create "index-files" directory in the current or |
|
52 |
* destination directory and will generate separate file for each unicode index. |
|
53 |
* |
|
14260
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
54 |
* <p><b>This is NOT part of any supported API. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
55 |
* 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
|
56 |
* 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
|
57 |
* deletion without notice.</b> |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
58 |
* |
10 | 59 |
* @see java.lang.Character |
60 |
* @author Atul M Dambalkar |
|
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 SplitIndexWriter extends AbstractIndexWriter { |
|
64 |
||
40587 | 65 |
private final List<Character> indexElements; |
33920 | 66 |
|
10 | 67 |
/** |
68 |
* Construct the SplitIndexWriter. Uses path to this file and relative path |
|
69 |
* from this file. |
|
70 |
* |
|
40587 | 71 |
* @param configuration the configuration for this doclet |
10 | 72 |
* @param path Path to the file which is getting generated. |
73 |
* @param indexbuilder Unicode based Index from {@link IndexBuilder} |
|
40587 | 74 |
* @param elements the collection of characters for which to generate index files |
10 | 75 |
*/ |
45417 | 76 |
public SplitIndexWriter(HtmlConfiguration configuration, |
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
77 |
DocPath path, |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
33920
diff
changeset
|
78 |
IndexBuilder indexbuilder, |
48756
ce608a09a666
8196027: Remove "Prev" and "Next" links from the javadoc navigation
bpatel
parents:
48654
diff
changeset
|
79 |
Collection<Character> elements) { |
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
80 |
super(configuration, path, indexbuilder); |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
33920
diff
changeset
|
81 |
this.indexElements = new ArrayList<>(elements); |
10 | 82 |
} |
83 |
||
84 |
/** |
|
85 |
* Generate separate index files, for each Unicode character, listing all |
|
86 |
* the members starting with the particular unicode character. |
|
87 |
* |
|
40587 | 88 |
* @param configuration the configuration for this doclet |
10 | 89 |
* @param indexbuilder IndexBuilder built by {@link IndexBuilder} |
40587 | 90 |
* @throws DocFileIOException if there is a problem generating the index files |
10 | 91 |
*/ |
45417 | 92 |
public static void generate(HtmlConfiguration configuration, |
40587 | 93 |
IndexBuilder indexbuilder) throws DocFileIOException { |
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
94 |
DocPath path = DocPaths.INDEX_FILES; |
40587 | 95 |
Set<Character> keys = new TreeSet<>(indexbuilder.getIndexMap().keySet()); |
96 |
keys.addAll(configuration.tagSearchIndexKeys); |
|
97 |
ListIterator<Character> li = new ArrayList<>(keys).listIterator(); |
|
45907 | 98 |
int prev; |
99 |
int next; |
|
40587 | 100 |
while (li.hasNext()) { |
45907 | 101 |
prev = (li.hasPrevious()) ? li.previousIndex() + 1 : -1; |
40587 | 102 |
Object ch = li.next(); |
45907 | 103 |
next = (li.hasNext()) ? li.nextIndex() + 1 : -1; |
40587 | 104 |
DocPath filename = DocPaths.indexN(li.nextIndex()); |
105 |
SplitIndexWriter indexgen = new SplitIndexWriter(configuration, |
|
106 |
path.resolve(filename), |
|
48756
ce608a09a666
8196027: Remove "Prev" and "Next" links from the javadoc navigation
bpatel
parents:
48654
diff
changeset
|
107 |
indexbuilder, keys); |
40587 | 108 |
indexgen.generateIndexFile((Character) ch); |
109 |
if (!li.hasNext()) { |
|
110 |
indexgen.createSearchIndexFiles(); |
|
10 | 111 |
} |
112 |
} |
|
113 |
} |
|
114 |
||
115 |
/** |
|
116 |
* Generate the contents of each index file, with Header, Footer, |
|
117 |
* Member Field, Method and Constructor Description. |
|
118 |
* |
|
119 |
* @param unicode Unicode character referring to the character for the |
|
120 |
* index. |
|
40587 | 121 |
* @throws DocFileIOException if there is a problem generating an index file |
10 | 122 |
*/ |
40587 | 123 |
protected void generateIndexFile(Character unicode) throws DocFileIOException { |
52644
43efb4ca6d6c
8214139: Remove wrapper methods from {Base,Html}Configuration
jjg
parents:
50167
diff
changeset
|
124 |
String title = resources.getText("doclet.Window_Split_Index", |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
125 |
unicode.toString()); |
54350
4f9772f4403d
8215599: Remove support for javadoc "frames" mode
pmuthuswamy
parents:
54060
diff
changeset
|
126 |
HtmlTree body = getBody(getWindowTitle(title)); |
59294
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54610
diff
changeset
|
127 |
Content headerContent = new ContentBuilder(); |
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54610
diff
changeset
|
128 |
addTop(headerContent); |
49551
0d4786e42471
8196200: Implement a navigation builder in javadoc
bpatel
parents:
48756
diff
changeset
|
129 |
navBar.setUserHeader(getUserHeaderFooter(true)); |
59294
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54610
diff
changeset
|
130 |
headerContent.add(navBar.getContent(true)); |
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54610
diff
changeset
|
131 |
Content main = new ContentBuilder(); |
54060
53a95878619f
8220202: Simplify/standardize method naming for HtmlTree
jjg
parents:
53991
diff
changeset
|
132 |
main.add(HtmlTree.DIV(HtmlStyle.header, |
53991 | 133 |
HtmlTree.HEADING(Headings.PAGE_TITLE_HEADING, |
134 |
contents.getContent("doclet.Index")))); |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
135 |
HtmlTree divTree = new HtmlTree(HtmlTag.DIV); |
47846 | 136 |
divTree.setStyle(HtmlStyle.contentContainer); |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
137 |
addLinksForIndexes(divTree); |
33920 | 138 |
if (configuration.tagSearchIndexMap.get(unicode) == null) { |
139 |
addContents(unicode, indexbuilder.getMemberList(unicode), divTree); |
|
140 |
} else if (indexbuilder.getMemberList(unicode) == null) { |
|
141 |
addSearchContents(unicode, configuration.tagSearchIndexMap.get(unicode), divTree); |
|
142 |
} else { |
|
143 |
addContents(unicode, indexbuilder.getMemberList(unicode), |
|
144 |
configuration.tagSearchIndexMap.get(unicode), divTree); |
|
145 |
} |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
146 |
addLinksForIndexes(divTree); |
54060
53a95878619f
8220202: Simplify/standardize method naming for HtmlTree
jjg
parents:
53991
diff
changeset
|
147 |
main.add(divTree); |
53562 | 148 |
HtmlTree footer = HtmlTree.FOOTER(); |
49551
0d4786e42471
8196200: Implement a navigation builder in javadoc
bpatel
parents:
48756
diff
changeset
|
149 |
navBar.setUserFooter(getUserHeaderFooter(false)); |
54060
53a95878619f
8220202: Simplify/standardize method naming for HtmlTree
jjg
parents:
53991
diff
changeset
|
150 |
footer.add(navBar.getContent(false)); |
53562 | 151 |
addBottom(footer); |
59294
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54610
diff
changeset
|
152 |
body.add(new BodyContents() |
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54610
diff
changeset
|
153 |
.setHeader(headerContent) |
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54610
diff
changeset
|
154 |
.addMainContent(main) |
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54610
diff
changeset
|
155 |
.setFooter(footer) |
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54610
diff
changeset
|
156 |
.toContent()); |
53863
d001808c57e8
8218998: Add metadata to generated API documentation files
jjg
parents:
53562
diff
changeset
|
157 |
String description = "index: " + unicode; |
53880
3f1e9372557f
8219497: Unused parameter in HtmlDocletWriter::printHtmlDocument
jjg
parents:
53863
diff
changeset
|
158 |
printHtmlDocument(null, description, 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; |
54060
53a95878619f
8220202: Simplify/standardize method naming for HtmlTree
jjg
parents:
53991
diff
changeset
|
169 |
contentTree.add(links.createLink(DocPaths.indexN(j), |
33920 | 170 |
new StringContent(indexElements.get(i).toString()))); |
54610 | 171 |
contentTree.add(Entity.NO_BREAK_SPACE); |
10 | 172 |
} |
54060
53a95878619f
8220202: Simplify/standardize method naming for HtmlTree
jjg
parents:
53991
diff
changeset
|
173 |
contentTree.add(new HtmlTree(HtmlTag.BR)); |
53a95878619f
8220202: Simplify/standardize method naming for HtmlTree
jjg
parents:
53991
diff
changeset
|
174 |
contentTree.add(links.createLink(pathToRoot.resolve(DocPaths.ALLCLASSES_INDEX), |
50167
cc705c956798
8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents:
49551
diff
changeset
|
175 |
contents.allClassesLabel)); |
cc705c956798
8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents:
49551
diff
changeset
|
176 |
if (!configuration.packages.isEmpty()) { |
54610 | 177 |
contentTree.add(Entity.NO_BREAK_SPACE); |
54060
53a95878619f
8220202: Simplify/standardize method naming for HtmlTree
jjg
parents:
53991
diff
changeset
|
178 |
contentTree.add(links.createLink(pathToRoot.resolve(DocPaths.ALLPACKAGES_INDEX), |
50167
cc705c956798
8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents:
49551
diff
changeset
|
179 |
contents.allPackagesLabel)); |
10 | 180 |
} |
181 |
} |
|
50167
cc705c956798
8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents:
49551
diff
changeset
|
182 |
} |