author | jjg |
Tue, 05 Mar 2019 10:35:29 -0800 | |
changeset 54002 | fb9541185457 |
parent 53863 | d001808c57e8 |
child 54060 | 53a95878619f |
permissions | -rw-r--r-- |
40500
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
1 |
/* |
53310
8ce4083fc831
8212233: javadoc fails on jdk12 with "The code being documented uses modules but the packages defined in $URL are in the unnamed module."
jjg
parents:
51468
diff
changeset
|
2 |
* Copyright (c) 2016, 2019, 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 |
|
53391
a99bd2570660
8217034: JavadocTester should check for missing files by default
jjg
parents:
53310
diff
changeset
|
28 |
import java.util.Collections; |
a99bd2570660
8217034: JavadocTester should check for missing files by default
jjg
parents:
53310
diff
changeset
|
29 |
|
47849 | 30 |
import jdk.javadoc.internal.doclets.formats.html.markup.Head; |
40500
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.ContentBuilder; |
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.DocType; |
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.HtmlAttr; |
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.HtmlDocument; |
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.HtmlTag; |
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.HtmlTree; |
47847 | 37 |
import jdk.javadoc.internal.doclets.formats.html.markup.Script; |
40500
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
38 |
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
|
39 |
import jdk.javadoc.internal.doclets.toolkit.Content; |
47848 | 40 |
import jdk.javadoc.internal.doclets.toolkit.util.DocFile; |
40587 | 41 |
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
|
42 |
import jdk.javadoc.internal.doclets.toolkit.util.DocPath; |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
43 |
import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
44 |
|
53310
8ce4083fc831
8212233: javadoc fails on jdk12 with "The code being documented uses modules but the packages defined in $URL are in the unnamed module."
jjg
parents:
51468
diff
changeset
|
45 |
import java.util.Collections; |
8ce4083fc831
8212233: javadoc fails on jdk12 with "The code being documented uses modules but the packages defined in $URL are in the unnamed module."
jjg
parents:
51468
diff
changeset
|
46 |
|
40500
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
47 |
/** |
50434 | 48 |
* Writes a file that tries to redirect to an alternate page. |
49 |
* The redirect uses JavaScript, if enabled, falling back on |
|
40500
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
50 |
* {@code <meta http-eqiv=refresh content="0,<uri>">}. |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
51 |
* 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
|
52 |
* 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
|
53 |
*/ |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
54 |
public class IndexRedirectWriter extends HtmlDocletWriter { |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
55 |
|
45417 | 56 |
public static void generate(HtmlConfiguration configuration) |
40587 | 57 |
throws DocFileIOException { |
50434 | 58 |
generate(configuration, DocPaths.INDEX, configuration.topFile); |
40500
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
59 |
} |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
60 |
|
50434 | 61 |
public static void generate(HtmlConfiguration configuration, DocPath fileName, DocPath target) |
62 |
throws DocFileIOException { |
|
63 |
IndexRedirectWriter indexRedirect = new IndexRedirectWriter(configuration, fileName, target); |
|
64 |
indexRedirect.generateIndexFile(); |
|
65 |
} |
|
66 |
||
67 |
private DocPath target; |
|
68 |
||
69 |
private IndexRedirectWriter(HtmlConfiguration configuration, DocPath filename, DocPath target) { |
|
40500
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
70 |
super(configuration, filename); |
50434 | 71 |
this.target = target; |
40500
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
72 |
} |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
73 |
|
40587 | 74 |
/** |
75 |
* Generate an index file that redirects to an alternate file. |
|
76 |
* @throws DocFileIOException if there is a problem generating the file |
|
77 |
*/ |
|
50434 | 78 |
private void generateIndexFile() throws DocFileIOException { |
47848 | 79 |
Content htmlComment = contents.newPage; |
53562 | 80 |
Head head = new Head(path, configuration.docletVersion) |
51468
d48a852983eb
8203792: Remove "compatibility" features from Head.java
pmuthuswamy
parents:
50434
diff
changeset
|
81 |
.setTimestamp(true) |
53863
d001808c57e8
8218998: Add metadata to generated API documentation files
jjg
parents:
53562
diff
changeset
|
82 |
.setDescription("index redirect") |
d001808c57e8
8218998: Add metadata to generated API documentation files
jjg
parents:
53562
diff
changeset
|
83 |
.setGenerator(getGenerator(getClass())) |
53391
a99bd2570660
8217034: JavadocTester should check for missing files by default
jjg
parents:
53310
diff
changeset
|
84 |
.setStylesheets(configuration.getMainStylesheet(), Collections.emptyList()) // avoid reference to default stylesheet |
47849 | 85 |
.addDefaultScript(false); |
40500
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
86 |
|
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
87 |
String title = (configuration.windowtitle.length() > 0) |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
88 |
? configuration.windowtitle |
47847 | 89 |
: resources.getText("doclet.Generated_Docs_Untitled"); |
40500
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
90 |
|
47849 | 91 |
head.setTitle(title) |
50434 | 92 |
.setCharset(configuration.charset) |
93 |
.setCanonicalLink(target); |
|
40500
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
94 |
|
50434 | 95 |
String targetPath = target.getPath(); |
47847 | 96 |
Script script = new Script("window.location.replace(") |
50434 | 97 |
.appendStringLiteral(targetPath, '\'') |
47847 | 98 |
.append(")"); |
47849 | 99 |
HtmlTree metaRefresh = new HtmlTree(HtmlTag.META) |
100 |
.addAttr(HtmlAttr.HTTP_EQUIV, "Refresh") |
|
50434 | 101 |
.addAttr(HtmlAttr.CONTENT, "0;" + targetPath); |
53562 | 102 |
head.addContent(script.asContent(), HtmlTree.NOSCRIPT(metaRefresh)); |
40500
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
103 |
|
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
104 |
ContentBuilder bodyContent = new ContentBuilder(); |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
105 |
bodyContent.addContent(HtmlTree.NOSCRIPT( |
47847 | 106 |
HtmlTree.P(contents.getContent("doclet.No_Script_Message")))); |
40500
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
107 |
|
50434 | 108 |
bodyContent.addContent(HtmlTree.P(HtmlTree.A(targetPath, new StringContent(targetPath)))); |
40500
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
109 |
|
54002 | 110 |
Content body = new HtmlTree(HtmlTag.BODY) |
111 |
.addAttr(HtmlAttr.CLASS, "index-redirect"); |
|
53562 | 112 |
HtmlTree main = HtmlTree.MAIN(bodyContent); |
113 |
body.addContent(main); |
|
40500
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
114 |
|
47849 | 115 |
Content htmlTree = HtmlTree.HTML(configuration.getLocale().getLanguage(), head.toContent(), body); |
53562 | 116 |
HtmlDocument htmlDocument = new HtmlDocument(htmlComment, htmlTree); |
47848 | 117 |
htmlDocument.write(DocFile.createFileForOutput(configuration, path)); |
40500
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
118 |
} |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
119 |
} |