author | jjg |
Fri, 18 Jan 2019 11:26:30 -0800 | |
changeset 53391 | a99bd2570660 |
parent 53310 | 8ce4083fc831 |
child 53562 | 0d9dee001667 |
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 |
DocType htmlDocType = DocType.forVersion(configuration.htmlVersion); |
80 |
Content htmlComment = contents.newPage; |
|
47849 | 81 |
Head head = new Head(path, configuration.htmlVersion, configuration.docletVersion) |
51468
d48a852983eb
8203792: Remove "compatibility" features from Head.java
pmuthuswamy
parents:
50434
diff
changeset
|
82 |
.setTimestamp(true) |
53391
a99bd2570660
8217034: JavadocTester should check for missing files by default
jjg
parents:
53310
diff
changeset
|
83 |
.setStylesheets(configuration.getMainStylesheet(), Collections.emptyList()) // avoid reference to default stylesheet |
47849 | 84 |
.addDefaultScript(false); |
40500
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 title = (configuration.windowtitle.length() > 0) |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
87 |
? configuration.windowtitle |
47847 | 88 |
: resources.getText("doclet.Generated_Docs_Untitled"); |
40500
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
89 |
|
47849 | 90 |
head.setTitle(title) |
50434 | 91 |
.setCharset(configuration.charset) |
92 |
.setCanonicalLink(target); |
|
40500
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
93 |
|
50434 | 94 |
String targetPath = target.getPath(); |
47847 | 95 |
Script script = new Script("window.location.replace(") |
50434 | 96 |
.appendStringLiteral(targetPath, '\'') |
47847 | 97 |
.append(")"); |
47849 | 98 |
HtmlTree metaRefresh = new HtmlTree(HtmlTag.META) |
99 |
.addAttr(HtmlAttr.HTTP_EQUIV, "Refresh") |
|
50434 | 100 |
.addAttr(HtmlAttr.CONTENT, "0;" + targetPath); |
47849 | 101 |
head.addContent( |
102 |
script.asContent(), |
|
103 |
configuration.isOutputHtml5() ? HtmlTree.NOSCRIPT(metaRefresh) : metaRefresh); |
|
40500
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
104 |
|
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
105 |
ContentBuilder bodyContent = new ContentBuilder(); |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
106 |
bodyContent.addContent(HtmlTree.NOSCRIPT( |
47847 | 107 |
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
|
108 |
|
50434 | 109 |
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
|
110 |
|
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
111 |
Content body = new HtmlTree(HtmlTag.BODY); |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
112 |
if (configuration.allowTag(HtmlTag.MAIN)) { |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
113 |
HtmlTree main = HtmlTree.MAIN(bodyContent); |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
114 |
body.addContent(main); |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
115 |
} else { |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
116 |
body.addContent(bodyContent); |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
117 |
} |
f293dbb81a53
8162353: javadoc should provide a way to disable use of frames
jjg
parents:
diff
changeset
|
118 |
|
47849 | 119 |
Content htmlTree = HtmlTree.HTML(configuration.getLocale().getLanguage(), head.toContent(), body); |
47848 | 120 |
HtmlDocument htmlDocument = new HtmlDocument(htmlDocType, htmlComment, htmlTree); |
121 |
htmlDocument.write(DocFile.createFileForOutput(configuration, path)); |
|
40500
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 |
} |