Tue, 23 Oct 2012 13:20:37 -0700
8000741: refactor javadoc to use abstraction to handle relative paths
Reviewed-by: darcy
1 /*
2 * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
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 *
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.
24 */
26 package com.sun.tools.doclets.formats.html;
28 import java.io.*;
30 import com.sun.tools.doclets.formats.html.markup.*;
31 import com.sun.tools.doclets.internal.toolkit.*;
32 import com.sun.tools.doclets.internal.toolkit.util.*;
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 *
39 * <p><b>This is NOT part of any supported API.
40 * If you write code that depends on this, you do so at your own risk.
41 * This code and its internal interfaces are subject to change or
42 * deletion without notice.</b>
43 *
44 * @see java.lang.Character
45 * @author Atul M Dambalkar
46 * @author Bhavesh Patel (Modified)
47 */
48 public class SplitIndexWriter extends AbstractIndexWriter {
50 /**
51 * Previous unicode character index in the built index.
52 */
53 protected int prev;
55 /**
56 * Next unicode character in the built index.
57 */
58 protected int next;
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 DocPath path,
71 IndexBuilder indexbuilder,
72 int prev, int next) throws IOException {
73 super(configuration, path, indexbuilder);
74 this.prev = prev;
75 this.next = next;
76 }
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 DocPath filename = DocPath.empty;
89 DocPath path = DocPaths.INDEX_FILES;
90 try {
91 for (int i = 0; i < indexbuilder.elements().length; i++) {
92 int j = i + 1;
93 int prev = (j == 1)? -1: i;
94 int next = (j == indexbuilder.elements().length)? -1: j + 1;
95 filename = DocPaths.indexN(j);
96 indexgen = new SplitIndexWriter(configuration,
97 path.resolve(filename),
98 indexbuilder, prev, next);
99 indexgen.generateIndexFile((Character)indexbuilder.
100 elements()[i]);
101 indexgen.close();
102 }
103 } catch (IOException exc) {
104 configuration.standardmessage.error(
105 "doclet.exception_encountered",
106 exc.toString(), filename.getPath());
107 throw new DocletAbortException();
108 }
109 }
111 /**
112 * Generate the contents of each index file, with Header, Footer,
113 * Member Field, Method and Constructor Description.
114 *
115 * @param unicode Unicode character referring to the character for the
116 * index.
117 */
118 protected void generateIndexFile(Character unicode) throws IOException {
119 String title = configuration.getText("doclet.Window_Split_Index",
120 unicode.toString());
121 Content body = getBody(true, getWindowTitle(title));
122 addTop(body);
123 addNavLinks(true, body);
124 HtmlTree divTree = new HtmlTree(HtmlTag.DIV);
125 divTree.addStyle(HtmlStyle.contentContainer);
126 addLinksForIndexes(divTree);
127 addContents(unicode, indexbuilder.getMemberList(unicode), divTree);
128 addLinksForIndexes(divTree);
129 body.addContent(divTree);
130 addNavLinks(false, body);
131 addBottom(body);
132 printHtmlDocument(null, true, body);
133 }
135 /**
136 * Add links for all the Index Files per unicode character.
137 *
138 * @param contentTree the content tree to which the links for indexes will be added
139 */
140 protected void addLinksForIndexes(Content contentTree) {
141 Object[] unicodeChars = indexbuilder.elements();
142 for (int i = 0; i < unicodeChars.length; i++) {
143 int j = i + 1;
144 contentTree.addContent(getHyperLink(DocPaths.indexN(j),
145 new StringContent(unicodeChars[i].toString())));
146 contentTree.addContent(getSpace());
147 }
148 }
150 /**
151 * Get link to the previous unicode character.
152 *
153 * @return a content tree for the link
154 */
155 public Content getNavLinkPrevious() {
156 Content prevletterLabel = getResource("doclet.Prev_Letter");
157 if (prev == -1) {
158 return HtmlTree.LI(prevletterLabel);
159 }
160 else {
161 Content prevLink = getHyperLink(DocPaths.indexN(prev), "",
162 prevletterLabel);
163 return HtmlTree.LI(prevLink);
164 }
165 }
167 /**
168 * Get link to the next unicode character.
169 *
170 * @return a content tree for the link
171 */
172 public Content getNavLinkNext() {
173 Content nextletterLabel = getResource("doclet.Next_Letter");
174 if (next == -1) {
175 return HtmlTree.LI(nextletterLabel);
176 }
177 else {
178 Content nextLink = getHyperLink(DocPaths.indexN(next), "",
179 nextletterLabel);
180 return HtmlTree.LI(nextLink);
181 }
182 }
183 }