Tue, 27 Aug 2013 11:41:39 -0700
7052170: javadoc -charset option generates wrong meta tag
Reviewed-by: jjg
1.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java Mon Aug 26 22:18:38 2013 -0700 1.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java Tue Aug 27 11:41:39 2013 -0700 1.3 @@ -411,7 +411,7 @@ 1.4 head.addContent(headComment); 1.5 } 1.6 if (configuration.charset.length() > 0) { 1.7 - Content meta = HtmlTree.META("Content-Type", "text/html", 1.8 + Content meta = HtmlTree.META("Content-Type", CONTENT_TYPE, 1.9 configuration.charset); 1.10 head.addContent(meta); 1.11 }
2.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlAttr.java Mon Aug 26 22:18:38 2013 -0700 2.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlAttr.java Tue Aug 27 11:41:39 2013 -0700 2.3 @@ -40,7 +40,6 @@ 2.4 BORDER, 2.5 CELLPADDING, 2.6 CELLSPACING, 2.7 - CHARSET, 2.8 CLASS, 2.9 CLEAR, 2.10 COLS,
3.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlDocWriter.java Mon Aug 26 22:18:38 2013 -0700 3.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlDocWriter.java Tue Aug 27 11:41:39 2013 -0700 3.3 @@ -53,6 +53,8 @@ 3.4 */ 3.5 public abstract class HtmlDocWriter extends HtmlWriter { 3.6 3.7 + public static final String CONTENT_TYPE = "text/html"; 3.8 + 3.9 /** 3.10 * Constructor. Initializes the destination file name through the super 3.11 * class HtmlWriter. 3.12 @@ -194,7 +196,7 @@ 3.13 head.addContent(headComment); 3.14 } 3.15 if (configuration.charset.length() > 0) { 3.16 - Content meta = HtmlTree.META("Content-Type", "text/html", 3.17 + Content meta = HtmlTree.META("Content-Type", CONTENT_TYPE, 3.18 configuration.charset); 3.19 head.addContent(meta); 3.20 }
4.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlTree.java Mon Aug 26 22:18:38 2013 -0700 4.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlTree.java Tue Aug 27 11:41:39 2013 -0700 4.3 @@ -456,9 +456,9 @@ 4.4 */ 4.5 public static HtmlTree META(String httpEquiv, String content, String charSet) { 4.6 HtmlTree htmltree = new HtmlTree(HtmlTag.META); 4.7 + String contentCharset = content + "; charset=" + charSet; 4.8 htmltree.addAttr(HtmlAttr.HTTP_EQUIV, nullCheck(httpEquiv)); 4.9 - htmltree.addAttr(HtmlAttr.CONTENT, nullCheck(content)); 4.10 - htmltree.addAttr(HtmlAttr.CHARSET, nullCheck(charSet)); 4.11 + htmltree.addAttr(HtmlAttr.CONTENT, contentCharset); 4.12 return htmltree; 4.13 } 4.14
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/test/com/sun/javadoc/testCharset/TestCharset.java Tue Aug 27 11:41:39 2013 -0700 5.3 @@ -0,0 +1,82 @@ 5.4 +/* 5.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5.7 + * 5.8 + * This code is free software; you can redistribute it and/or modify it 5.9 + * under the terms of the GNU General Public License version 2 only, as 5.10 + * published by the Free Software Foundation. 5.11 + * 5.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 5.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 5.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 5.15 + * version 2 for more details (a copy is included in the LICENSE file that 5.16 + * accompanied this code). 5.17 + * 5.18 + * You should have received a copy of the GNU General Public License version 5.19 + * 2 along with this work; if not, write to the Free Software Foundation, 5.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 5.21 + * 5.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 5.23 + * or visit www.oracle.com if you need additional information or have any 5.24 + * questions. 5.25 + */ 5.26 + 5.27 +/* 5.28 + * @test 5.29 + * @bug 7052170 5.30 + * @summary Run a test on -charset to make sure the charset gets generated as a 5.31 + * part of the meta tag. 5.32 + * @author Bhavesh Patel 5.33 + * @library ../lib/ 5.34 + * @build JavadocTester TestCharset 5.35 + * @run main TestCharset 5.36 + */ 5.37 + 5.38 +public class TestCharset extends JavadocTester { 5.39 + 5.40 + //Test information. 5.41 + private static final String BUG_ID = "7052170"; 5.42 + 5.43 + //Javadoc arguments. 5.44 + private static final String[] ARGS = new String[] { 5.45 + "-d", BUG_ID, "-charset", "UTF-8", "-sourcepath", SRC_DIR, "pkg" 5.46 + }; 5.47 + 5.48 + private static final String[][] TEST = { 5.49 + {BUG_ID + FS + "index.html", 5.50 + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">"}, 5.51 + {BUG_ID + FS + "pkg" + FS + "Foo.html", 5.52 + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">"} 5.53 + }; 5.54 + 5.55 + private static final String[][] NEGATED_TEST = { 5.56 + {BUG_ID + FS + "index.html", 5.57 + "<meta http-equiv=\"Content-Type\" content=\"text/html\" charset=\"UTF-8\">"}, 5.58 + {BUG_ID + FS + "pkg" + FS + "Foo.html", 5.59 + "<meta http-equiv=\"Content-Type\" content=\"text/html\" charset=\"UTF-8\">"} 5.60 + }; 5.61 + 5.62 + /** 5.63 + * The entry point of the test. 5.64 + * @param args the array of command line arguments. 5.65 + */ 5.66 + public static void main(String[] args) { 5.67 + TestCharset tester = new TestCharset(); 5.68 + run(tester, ARGS, TEST, NEGATED_TEST); 5.69 + tester.printSummary(); 5.70 + } 5.71 + 5.72 + /** 5.73 + * {@inheritDoc} 5.74 + */ 5.75 + public String getBugId() { 5.76 + return BUG_ID; 5.77 + } 5.78 + 5.79 + /** 5.80 + * {@inheritDoc} 5.81 + */ 5.82 + public String getBugName() { 5.83 + return getClass().getName(); 5.84 + } 5.85 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/test/com/sun/javadoc/testCharset/pkg/Foo.java Tue Aug 27 11:41:39 2013 -0700 6.3 @@ -0,0 +1,26 @@ 6.4 +/* 6.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6.7 + * 6.8 + * This code is free software; you can redistribute it and/or modify it 6.9 + * under the terms of the GNU General Public License version 2 only, as 6.10 + * published by the Free Software Foundation. 6.11 + * 6.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 6.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 6.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 6.15 + * version 2 for more details (a copy is included in the LICENSE file that 6.16 + * accompanied this code). 6.17 + * 6.18 + * You should have received a copy of the GNU General Public License version 6.19 + * 2 along with this work; if not, write to the Free Software Foundation, 6.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 6.21 + * 6.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 6.23 + * or visit www.oracle.com if you need additional information or have any 6.24 + * questions. 6.25 + */ 6.26 + 6.27 +package pkg; 6.28 + 6.29 +public class Foo {}