author | jjg |
Wed, 10 Oct 2012 16:48:21 -0700 | |
changeset 14260 | 727a84636f12 |
parent 14258 | 8d2148961366 |
child 14357 | faf9cde2817b |
permissions | -rw-r--r-- |
10 | 1 |
/* |
14258 | 2 |
* Copyright (c) 1998, 2012, 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.*; |
14258 | 29 |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
30 |
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
|
31 |
import com.sun.tools.doclets.internal.toolkit.*; |
14258 | 32 |
import com.sun.tools.doclets.internal.toolkit.util.*; |
10 | 33 |
|
34 |
/** |
|
35 |
* Generate Separate Index Files for all the member names with Indexing in |
|
36 |
* Unicode Order. This will create "index-files" directory in the current or |
|
37 |
* destination directory and will generate separate file for each unicode index. |
|
38 |
* |
|
14260
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
39 |
* <p><b>This is NOT part of any supported API. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
40 |
* 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
|
41 |
* 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
|
42 |
* deletion without notice.</b> |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
43 |
* |
10 | 44 |
* @see java.lang.Character |
45 |
* @author Atul M Dambalkar |
|
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 |
*/ |
48 |
public class SplitIndexWriter extends AbstractIndexWriter { |
|
49 |
||
50 |
/** |
|
51 |
* Previous unicode character index in the built index. |
|
52 |
*/ |
|
53 |
protected int prev; |
|
54 |
||
55 |
/** |
|
56 |
* Next unicode character in the built index. |
|
57 |
*/ |
|
58 |
protected int next; |
|
59 |
||
60 |
/** |
|
61 |
* Construct the SplitIndexWriter. Uses path to this file and relative path |
|
62 |
* from this file. |
|
63 |
* |
|
64 |
* @param path Path to the file which is getting generated. |
|
65 |
* @param filename Name of the file which is getting genrated. |
|
66 |
* @param relpath Relative path from this file to the current directory. |
|
67 |
* @param indexbuilder Unicode based Index from {@link IndexBuilder} |
|
68 |
*/ |
|
69 |
public SplitIndexWriter(ConfigurationImpl configuration, |
|
70 |
String path, String filename, |
|
71 |
String relpath, IndexBuilder indexbuilder, |
|
72 |
int prev, int next) throws IOException { |
|
73 |
super(configuration, path, filename, relpath, indexbuilder); |
|
74 |
this.prev = prev; |
|
75 |
this.next = next; |
|
76 |
} |
|
77 |
||
78 |
/** |
|
79 |
* Generate separate index files, for each Unicode character, listing all |
|
80 |
* the members starting with the particular unicode character. |
|
81 |
* |
|
82 |
* @param indexbuilder IndexBuilder built by {@link IndexBuilder} |
|
83 |
* @throws DocletAbortException |
|
84 |
*/ |
|
85 |
public static void generate(ConfigurationImpl configuration, |
|
86 |
IndexBuilder indexbuilder) { |
|
87 |
SplitIndexWriter indexgen; |
|
88 |
String filename = ""; |
|
89 |
String path = DirectoryManager.getPath("index-files"); |
|
90 |
String relpath = DirectoryManager.getRelativePath("index-files"); |
|
91 |
try { |
|
92 |
for (int i = 0; i < indexbuilder.elements().length; i++) { |
|
93 |
int j = i + 1; |
|
94 |
int prev = (j == 1)? -1: i; |
|
95 |
int next = (j == indexbuilder.elements().length)? -1: j + 1; |
|
96 |
filename = "index-" + j +".html"; |
|
97 |
indexgen = new SplitIndexWriter(configuration, |
|
98 |
path, filename, relpath, |
|
99 |
indexbuilder, prev, next); |
|
100 |
indexgen.generateIndexFile((Character)indexbuilder. |
|
101 |
elements()[i]); |
|
102 |
indexgen.close(); |
|
103 |
} |
|
104 |
} catch (IOException exc) { |
|
105 |
configuration.standardmessage.error( |
|
106 |
"doclet.exception_encountered", |
|
107 |
exc.toString(), filename); |
|
108 |
throw new DocletAbortException(); |
|
109 |
} |
|
110 |
} |
|
111 |
||
112 |
/** |
|
113 |
* Generate the contents of each index file, with Header, Footer, |
|
114 |
* Member Field, Method and Constructor Description. |
|
115 |
* |
|
116 |
* @param unicode Unicode character referring to the character for the |
|
117 |
* index. |
|
118 |
*/ |
|
119 |
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
|
120 |
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
|
121 |
unicode.toString()); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
122 |
Content body = getBody(true, getWindowTitle(title)); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
123 |
addTop(body); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
124 |
addNavLinks(true, body); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
125 |
HtmlTree divTree = new HtmlTree(HtmlTag.DIV); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
126 |
divTree.addStyle(HtmlStyle.contentContainer); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
127 |
addLinksForIndexes(divTree); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
128 |
addContents(unicode, indexbuilder.getMemberList(unicode), divTree); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
129 |
addLinksForIndexes(divTree); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
130 |
body.addContent(divTree); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
131 |
addNavLinks(false, body); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
132 |
addBottom(body); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
133 |
printHtmlDocument(null, true, body); |
10 | 134 |
} |
135 |
||
136 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
137 |
* 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
|
138 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
139 |
* @param contentTree the content tree to which the links for indexes will be added |
10 | 140 |
*/ |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
141 |
protected void addLinksForIndexes(Content contentTree) { |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
142 |
Object[] unicodeChars = indexbuilder.elements(); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
143 |
for (int i = 0; i < unicodeChars.length; i++) { |
10 | 144 |
int j = i + 1; |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
145 |
contentTree.addContent(getHyperLink("index-" + j + ".html", |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
146 |
new StringContent(unicodeChars[i].toString()))); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
147 |
contentTree.addContent(getSpace()); |
10 | 148 |
} |
149 |
} |
|
150 |
||
151 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
152 |
* 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
|
153 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
154 |
* @return a content tree for the link |
10 | 155 |
*/ |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
156 |
public Content getNavLinkPrevious() { |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
157 |
Content prevletterLabel = getResource("doclet.Prev_Letter"); |
10 | 158 |
if (prev == -1) { |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
159 |
return HtmlTree.LI(prevletterLabel); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
160 |
} |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
161 |
else { |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
162 |
Content prevLink = getHyperLink("index-" + prev + ".html", "", |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
163 |
prevletterLabel); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
164 |
return HtmlTree.LI(prevLink); |
10 | 165 |
} |
166 |
} |
|
167 |
||
168 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
169 |
* 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
|
170 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
171 |
* @return a content tree for the link |
10 | 172 |
*/ |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
173 |
public Content getNavLinkNext() { |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
174 |
Content nextletterLabel = getResource("doclet.Next_Letter"); |
10 | 175 |
if (next == -1) { |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
176 |
return HtmlTree.LI(nextletterLabel); |
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 |
else { |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
179 |
Content nextLink = getHyperLink("index-" + next + ".html","", |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
180 |
nextletterLabel); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
181 |
return HtmlTree.LI(nextLink); |
10 | 182 |
} |
183 |
} |
|
184 |
} |