author | chegar |
Sun, 17 Aug 2014 15:52:32 +0100 | |
changeset 25874 | 83c19f00452c |
parent 25454 | langtools/src/share/classes/com/sun/tools/doclets/formats/html/PackageTreeWriter.java@376a52c9540c |
child 29957 | 7740f9657f56 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
24221
2376793dd33b
8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents:
21478
diff
changeset
|
2 |
* Copyright (c) 1998, 2014, 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 |
||
2216
b124d5c924eb
6786690: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - DL tag and nesting issue
bpatel
parents:
1787
diff
changeset
|
28 |
import java.io.*; |
b124d5c924eb
6786690: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - DL tag and nesting issue
bpatel
parents:
1787
diff
changeset
|
29 |
|
10 | 30 |
import com.sun.javadoc.*; |
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 |
* Class to generate Tree page for a package. The name of the file generated is |
|
37 |
* "package-tree.html" and it is generated in the respective package directory. |
|
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 |
* @author Atul M Dambalkar |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
45 |
* @author Bhavesh Patel (Modified) |
10 | 46 |
*/ |
47 |
public class PackageTreeWriter extends AbstractTreeWriter { |
|
48 |
||
49 |
/** |
|
50 |
* Package for which tree is to be generated. |
|
51 |
*/ |
|
52 |
protected PackageDoc packagedoc; |
|
53 |
||
54 |
/** |
|
55 |
* The previous package name in the alpha-order list. |
|
56 |
*/ |
|
57 |
protected PackageDoc prev; |
|
58 |
||
59 |
/** |
|
60 |
* The next package name in the alpha-order list. |
|
61 |
*/ |
|
62 |
protected PackageDoc next; |
|
63 |
||
64 |
/** |
|
65 |
* Constructor. |
|
66 |
* @throws IOException |
|
67 |
* @throws DocletAbortException |
|
68 |
*/ |
|
69 |
public PackageTreeWriter(ConfigurationImpl configuration, |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
70 |
DocPath path, |
10 | 71 |
PackageDoc packagedoc, |
72 |
PackageDoc prev, PackageDoc next) |
|
73 |
throws IOException { |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
74 |
super(configuration, path, |
10 | 75 |
new ClassTree( |
76 |
configuration.classDocCatalog.allClasses(packagedoc), |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
77 |
configuration)); |
10 | 78 |
this.packagedoc = packagedoc; |
79 |
this.prev = prev; |
|
80 |
this.next = next; |
|
81 |
} |
|
82 |
||
83 |
/** |
|
84 |
* Construct a PackageTreeWriter object and then use it to generate the |
|
85 |
* package tree page. |
|
86 |
* |
|
87 |
* @param pkg Package for which tree file is to be generated. |
|
88 |
* @param prev Previous package in the alpha-ordered list. |
|
89 |
* @param next Next package in the alpha-ordered list. |
|
90 |
* @param noDeprecated If true, do not generate any information for |
|
91 |
* deprecated classe or interfaces. |
|
92 |
* @throws DocletAbortException |
|
93 |
*/ |
|
94 |
public static void generate(ConfigurationImpl configuration, |
|
95 |
PackageDoc pkg, PackageDoc prev, |
|
96 |
PackageDoc next, boolean noDeprecated) { |
|
97 |
PackageTreeWriter packgen; |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
98 |
DocPath path = DocPath.forPackage(pkg).resolve(DocPaths.PACKAGE_TREE); |
10 | 99 |
try { |
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
100 |
packgen = new PackageTreeWriter(configuration, path, pkg, |
10 | 101 |
prev, next); |
102 |
packgen.generatePackageTreeFile(); |
|
103 |
packgen.close(); |
|
104 |
} catch (IOException exc) { |
|
105 |
configuration.standardmessage.error( |
|
106 |
"doclet.exception_encountered", |
|
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
107 |
exc.toString(), path.getPath()); |
19667
fdfce85627a9
8001669: javadoc internal DocletAbortException should set cause when appropriate
jjg
parents:
17563
diff
changeset
|
108 |
throw new DocletAbortException(exc); |
10 | 109 |
} |
110 |
} |
|
111 |
||
112 |
/** |
|
113 |
* Generate a separate tree file for each package. |
|
114 |
*/ |
|
115 |
protected void generatePackageTreeFile() throws IOException { |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
116 |
Content body = getPackageTreeHeader(); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
117 |
Content headContent = getResource("doclet.Hierarchy_For_Package", |
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
24221
diff
changeset
|
118 |
utils.getPackageName(packagedoc)); |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
119 |
Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, false, |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
120 |
HtmlStyle.title, headContent); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
121 |
Content div = HtmlTree.DIV(HtmlStyle.header, heading); |
24221
2376793dd33b
8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents:
21478
diff
changeset
|
122 |
if (configuration.packages.size() > 1) { |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
123 |
addLinkToMainTree(div); |
10 | 124 |
} |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
125 |
body.addContent(div); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
126 |
HtmlTree divTree = new HtmlTree(HtmlTag.DIV); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
127 |
divTree.addStyle(HtmlStyle.contentContainer); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
128 |
addTree(classtree.baseclasses(), "doclet.Class_Hierarchy", divTree); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
129 |
addTree(classtree.baseinterfaces(), "doclet.Interface_Hierarchy", divTree); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
130 |
addTree(classtree.baseAnnotationTypes(), "doclet.Annotation_Type_Hierarchy", divTree); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
131 |
addTree(classtree.baseEnums(), "doclet.Enum_Hierarchy", divTree); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
132 |
body.addContent(divTree); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
133 |
addNavLinks(false, body); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
134 |
addBottom(body); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
135 |
printHtmlDocument(null, true, body); |
10 | 136 |
} |
137 |
||
138 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
139 |
* Get the package tree header. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
140 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
141 |
* @return a content tree for the header |
10 | 142 |
*/ |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
143 |
protected Content getPackageTreeHeader() { |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
144 |
String title = packagedoc.name() + " " + |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
145 |
configuration.getText("doclet.Window_Class_Hierarchy"); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
146 |
Content bodyTree = getBody(true, getWindowTitle(title)); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
147 |
addTop(bodyTree); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
148 |
addNavLinks(true, bodyTree); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
149 |
return bodyTree; |
10 | 150 |
} |
151 |
||
152 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
153 |
* Add a link to the tree for all the packages. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
154 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
155 |
* @param div the content tree to which the link will be added |
10 | 156 |
*/ |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
157 |
protected void addLinkToMainTree(Content div) { |
21478
fa4c7cda1b41
8026567: Use meaningful style names for strong and italic styles.
bpatel
parents:
19667
diff
changeset
|
158 |
Content span = HtmlTree.SPAN(HtmlStyle.packageHierarchyLabel, |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
159 |
getResource("doclet.Package_Hierarchies")); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
160 |
div.addContent(span); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
161 |
HtmlTree ul = new HtmlTree (HtmlTag.UL); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
162 |
ul.addStyle(HtmlStyle.horizontal); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
163 |
ul.addContent(getNavLinkMainTree(configuration.getText("doclet.All_Packages"))); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
164 |
div.addContent(ul); |
10 | 165 |
} |
166 |
||
167 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
168 |
* Get link for the previous package tree file. |
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 |
* @return a content tree for the link |
10 | 171 |
*/ |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
172 |
protected Content getNavLinkPrevious() { |
10 | 173 |
if (prev == null) { |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
174 |
return getNavLinkPrevious(null); |
10 | 175 |
} else { |
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
176 |
DocPath path = DocPath.relativePath(packagedoc, prev); |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
177 |
return getNavLinkPrevious(path.resolve(DocPaths.PACKAGE_TREE)); |
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 for the next package tree file. |
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 |
*/ |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
186 |
protected Content getNavLinkNext() { |
10 | 187 |
if (next == null) { |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
188 |
return getNavLinkNext(null); |
10 | 189 |
} else { |
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
190 |
DocPath path = DocPath.relativePath(packagedoc, next); |
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
191 |
return getNavLinkNext(path.resolve(DocPaths.PACKAGE_TREE)); |
10 | 192 |
} |
193 |
} |
|
194 |
||
195 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
196 |
* Get link to the package summary page for the package of this tree. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
197 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
198 |
* @return a content tree for the package link |
10 | 199 |
*/ |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
200 |
protected Content getNavLinkPackage() { |
14358
9eda9239cba0
8000416: refactor javadoc to provide and use an abstraction for relative URIs
jjg
parents:
14357
diff
changeset
|
201 |
Content linkContent = getHyperLink(DocPaths.PACKAGE_SUMMARY, |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
202 |
packageLabel); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
203 |
Content li = HtmlTree.LI(linkContent); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
204 |
return li; |
10 | 205 |
} |
206 |
} |