changeset 2641:7e15b8d4631d

8047745: Javadoc should include encoding information in generated html files Reviewed-by: jjg, ksrini
author bpatel
date Thu, 18 Sep 2014 00:50:48 -0700
parents 9a6c1bf0d19a
children ad99965443d1
files src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlConstants.java src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlDocWriter.java test/com/sun/javadoc/testCharset/TestCharset.java
diffstat 4 files changed, 34 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java	Wed Sep 17 23:52:19 2014 -0700
+++ b/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java	Thu Sep 18 00:50:48 2014 -0700
@@ -397,20 +397,19 @@
         Content htmlComment = new Comment(configuration.getText("doclet.New_Page"));
         Content head = new HtmlTree(HtmlTag.HEAD);
         head.addContent(getGeneratedBy(!configuration.notimestamp));
-        if (configuration.charset.length() > 0) {
-            Content meta = HtmlTree.META("Content-Type", CONTENT_TYPE,
-                    configuration.charset);
-            head.addContent(meta);
-        }
         head.addContent(getTitle());
+        Content meta = HtmlTree.META("Content-Type", CONTENT_TYPE,
+                (configuration.charset.length() > 0) ?
+                        configuration.charset : HtmlConstants.HTML_DEFAULT_CHARSET);
+        head.addContent(meta);
         if (!configuration.notimestamp) {
             SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
-            Content meta = HtmlTree.META("date", dateFormat.format(new Date()));
+            meta = HtmlTree.META("date", dateFormat.format(new Date()));
             head.addContent(meta);
         }
         if (metakeywords != null) {
             for (String metakeyword : metakeywords) {
-                Content meta = HtmlTree.META("keywords", metakeyword);
+                meta = HtmlTree.META("keywords", metakeyword);
                 head.addContent(meta);
             }
         }
--- a/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlConstants.java	Wed Sep 17 23:52:19 2014 -0700
+++ b/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlConstants.java	Thu Sep 18 00:50:48 2014 -0700
@@ -220,4 +220,9 @@
      * Html tag for the member heading.
      */
     public static final HtmlTag MEMBER_HEADING = HtmlTag.H4;
+
+    /**
+     * Default charset for HTML.
+     */
+    public static final String HTML_DEFAULT_CHARSET = "utf-8";
 }
--- a/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlDocWriter.java	Wed Sep 17 23:52:19 2014 -0700
+++ b/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlDocWriter.java	Thu Sep 18 00:50:48 2014 -0700
@@ -311,13 +311,12 @@
         Content htmlComment = new Comment(configuration.getText("doclet.New_Page"));
         Content head = new HtmlTree(HtmlTag.HEAD);
         head.addContent(getGeneratedBy(!noTimeStamp));
-        if (configuration.charset.length() > 0) {
-            Content meta = HtmlTree.META("Content-Type", CONTENT_TYPE,
-                    configuration.charset);
-            head.addContent(meta);
-        }
         Content windowTitle = HtmlTree.TITLE(new StringContent(title));
         head.addContent(windowTitle);
+        Content meta = HtmlTree.META("Content-Type", CONTENT_TYPE,
+                (configuration.charset.length() > 0) ?
+                        configuration.charset : HtmlConstants.HTML_DEFAULT_CHARSET);
+        head.addContent(meta);
         head.addContent(getFramesetJavaScript());
         Content htmlTree = HtmlTree.HTML(configuration.getLocale().getLanguage(),
                 head, frameset);
--- a/test/com/sun/javadoc/testCharset/TestCharset.java	Wed Sep 17 23:52:19 2014 -0700
+++ b/test/com/sun/javadoc/testCharset/TestCharset.java	Thu Sep 18 00:50:48 2014 -0700
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug      7052170
+ * @bug      7052170 8047745
  * @summary  Run a test on -charset to make sure the charset gets generated as a
  *           part of the meta tag.
  * @author   Bhavesh Patel
@@ -42,19 +42,32 @@
     @Test
     void test() {
         javadoc("-d", "out",
-                "-charset", "UTF-8",
+                "-charset", "ISO-8859-1",
                 "-sourcepath", testSrc,
                 "pkg");
         checkExit(Exit.OK);
 
         checkOutput("index.html", true,
-            "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">");
+            "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">");
         checkOutput("pkg/Foo.html", true,
-            "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">");
+            "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">");
 
         checkOutput("index.html", false,
-            "<meta http-equiv=\"Content-Type\" content=\"text/html\" charset=\"UTF-8\">");
+            "<meta http-equiv=\"Content-Type\" content=\"text/html\" charset=\"ISO-8859-1\">");
         checkOutput("pkg/Foo.html", false,
-            "<meta http-equiv=\"Content-Type\" content=\"text/html\" charset=\"UTF-8\">");
+            "<meta http-equiv=\"Content-Type\" content=\"text/html\" charset=\"ISO-8859-1\">");
+    }
+
+    @Test
+    void test1() {
+        javadoc("-d", "out-1",
+                "-sourcepath", testSrc,
+                "pkg");
+        checkExit(Exit.OK);
+
+        checkOutput("index.html", true,
+            "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">");
+        checkOutput("pkg/Foo.html", true,
+            "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">");
     }
 }