author | ksrini |
Mon, 05 Jun 2017 13:45:34 -0700 | |
changeset 45417 | f7479ee8de69 |
parent 40587 | 1c355ea550ed |
child 46080 | 65ccd412049b |
permissions | -rw-r--r-- |
40500
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
1 |
/* |
45417 | 2 |
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. |
40500
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
4 |
* |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
10 |
* |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
15 |
* accompanied this code). |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
16 |
* |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
20 |
* |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
23 |
* questions. |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
24 |
*/ |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
25 |
|
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
26 |
package jdk.javadoc.internal.doclets.formats.html; |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
27 |
|
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
28 |
import jdk.javadoc.internal.doclets.formats.html.markup.Comment; |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
29 |
import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder; |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
30 |
import jdk.javadoc.internal.doclets.formats.html.markup.DocType; |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
31 |
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlAttr; |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
32 |
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlConstants; |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
33 |
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlDocument; |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
34 |
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag; |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
35 |
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
36 |
import jdk.javadoc.internal.doclets.formats.html.markup.StringContent; |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
37 |
import jdk.javadoc.internal.doclets.toolkit.Content; |
40587 | 38 |
import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; |
40500
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
39 |
import jdk.javadoc.internal.doclets.toolkit.util.DocPath; |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
40 |
import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
41 |
|
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
42 |
/** |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
43 |
* Writes an index.html file that tries to redirect to an alternate page. |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
44 |
* The redirect uses JavaSCript, if enabled, falling back on |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
45 |
* {@code <meta http-eqiv=refresh content="0,<uri>">}. |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
46 |
* If neither are supported/enabled in a browser, the page displays the |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
47 |
* standard "JavaScipt not enabled" message, and a link to the alternate page. |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
48 |
*/ |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
49 |
public class IndexRedirectWriter extends HtmlDocletWriter { |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
50 |
|
45417 | 51 |
public static void generate(HtmlConfiguration configuration) |
40587 | 52 |
throws DocFileIOException { |
40500
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
53 |
IndexRedirectWriter indexRedirect; |
40587 | 54 |
DocPath filename = DocPaths.INDEX; |
40500
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
55 |
indexRedirect = new IndexRedirectWriter(configuration, filename); |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
56 |
indexRedirect.generateIndexFile(); |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
57 |
} |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
58 |
|
45417 | 59 |
IndexRedirectWriter(HtmlConfiguration configuration, DocPath filename) { |
40500
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
60 |
super(configuration, filename); |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
61 |
} |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
62 |
|
40587 | 63 |
/** |
64 |
* Generate an index file that redirects to an alternate file. |
|
65 |
* @throws DocFileIOException if there is a problem generating the file |
|
66 |
*/ |
|
67 |
void generateIndexFile() throws DocFileIOException { |
|
40500
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
68 |
Content htmlDocType = configuration.isOutputHtml5() |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
69 |
? DocType.HTML5 |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
70 |
: DocType.TRANSITIONAL; |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
71 |
Content htmlComment = new Comment(configuration.getText("doclet.New_Page")); |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
72 |
Content head = new HtmlTree(HtmlTag.HEAD); |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
73 |
head.addContent(getGeneratedBy(!configuration.notimestamp)); |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
74 |
|
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
75 |
String title = (configuration.windowtitle.length() > 0) |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
76 |
? configuration.windowtitle |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
77 |
: configuration.getText("doclet.Generated_Docs_Untitled"); |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
78 |
|
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
79 |
Content windowTitle = HtmlTree.TITLE(new StringContent(title)); |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
80 |
head.addContent(windowTitle); |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
81 |
Content metaContentType = HtmlTree.META("Content", CONTENT_TYPE, |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
82 |
(configuration.charset.length() > 0) ? |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
83 |
configuration.charset : HtmlConstants.HTML_DEFAULT_CHARSET); |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
84 |
head.addContent(metaContentType); |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
85 |
|
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
86 |
String topFilePath = configuration.topFile.getPath(); |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
87 |
String javaScriptRefresh = "window.location.replace('" + topFilePath + "')"; |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
88 |
HtmlTree scriptTree = HtmlTree.SCRIPT(); |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
89 |
scriptTree.addContent(javaScriptRefresh); |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
90 |
head.addContent(scriptTree); |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
91 |
HtmlTree metaRefresh = new HtmlTree(HtmlTag.META); |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
92 |
metaRefresh.addAttr(HtmlAttr.HTTP_EQUIV, "Refresh"); |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
93 |
metaRefresh.addAttr(HtmlAttr.CONTENT, "0;" + topFilePath); |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
94 |
if (configuration.isOutputHtml5()) { |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
95 |
head.addContent(HtmlTree.NOSCRIPT(metaRefresh)); |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
96 |
} else { |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
97 |
head.addContent(metaRefresh); |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
98 |
} |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
99 |
|
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
100 |
head.addContent(getStyleSheetProperties(configuration)); |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
101 |
|
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
102 |
ContentBuilder bodyContent = new ContentBuilder(); |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
103 |
bodyContent.addContent(HtmlTree.NOSCRIPT( |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
104 |
HtmlTree.P(configuration.getContent("doclet.No_Script_Message")))); |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
105 |
|
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
106 |
bodyContent.addContent(HtmlTree.P(HtmlTree.A(topFilePath, new StringContent(topFilePath)))); |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
107 |
|
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
108 |
Content body = new HtmlTree(HtmlTag.BODY); |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
109 |
if (configuration.allowTag(HtmlTag.MAIN)) { |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
110 |
HtmlTree main = HtmlTree.MAIN(bodyContent); |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
111 |
body.addContent(main); |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
112 |
} else { |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
113 |
body.addContent(bodyContent); |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
114 |
} |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
115 |
|
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
116 |
Content htmlTree = HtmlTree.HTML(configuration.getLocale().getLanguage(), |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
117 |
head, body); |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
118 |
Content htmlDocument = new HtmlDocument(htmlDocType, |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
119 |
htmlComment, htmlTree); |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
120 |
write(htmlDocument); |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
121 |
|
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
122 |
} |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
123 |
} |