Mercurial > hg > jdk9-shenandoah > langtools
changeset 1980:7fb27bc201cc
7052170: javadoc -charset option generates wrong meta tag
Reviewed-by: jjg
author | bpatel |
---|---|
date | Tue, 27 Aug 2013 11:41:39 -0700 |
parents | cc3fb73f5e08 |
children | 662a5188bded |
files | src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlAttr.java src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlDocWriter.java src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlTree.java test/com/sun/javadoc/testCharset/TestCharset.java test/com/sun/javadoc/testCharset/pkg/Foo.java |
diffstat | 6 files changed, 114 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java Mon Aug 26 22:18:38 2013 -0700 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java Tue Aug 27 11:41:39 2013 -0700 @@ -411,7 +411,7 @@ head.addContent(headComment); } if (configuration.charset.length() > 0) { - Content meta = HtmlTree.META("Content-Type", "text/html", + Content meta = HtmlTree.META("Content-Type", CONTENT_TYPE, configuration.charset); head.addContent(meta); }
--- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlAttr.java Mon Aug 26 22:18:38 2013 -0700 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlAttr.java Tue Aug 27 11:41:39 2013 -0700 @@ -40,7 +40,6 @@ BORDER, CELLPADDING, CELLSPACING, - CHARSET, CLASS, CLEAR, COLS,
--- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlDocWriter.java Mon Aug 26 22:18:38 2013 -0700 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlDocWriter.java Tue Aug 27 11:41:39 2013 -0700 @@ -53,6 +53,8 @@ */ public abstract class HtmlDocWriter extends HtmlWriter { + public static final String CONTENT_TYPE = "text/html"; + /** * Constructor. Initializes the destination file name through the super * class HtmlWriter. @@ -194,7 +196,7 @@ head.addContent(headComment); } if (configuration.charset.length() > 0) { - Content meta = HtmlTree.META("Content-Type", "text/html", + Content meta = HtmlTree.META("Content-Type", CONTENT_TYPE, configuration.charset); head.addContent(meta); }
--- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlTree.java Mon Aug 26 22:18:38 2013 -0700 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlTree.java Tue Aug 27 11:41:39 2013 -0700 @@ -456,9 +456,9 @@ */ public static HtmlTree META(String httpEquiv, String content, String charSet) { HtmlTree htmltree = new HtmlTree(HtmlTag.META); + String contentCharset = content + "; charset=" + charSet; htmltree.addAttr(HtmlAttr.HTTP_EQUIV, nullCheck(httpEquiv)); - htmltree.addAttr(HtmlAttr.CONTENT, nullCheck(content)); - htmltree.addAttr(HtmlAttr.CHARSET, nullCheck(charSet)); + htmltree.addAttr(HtmlAttr.CONTENT, contentCharset); return htmltree; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/com/sun/javadoc/testCharset/TestCharset.java Tue Aug 27 11:41:39 2013 -0700 @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 7052170 + * @summary Run a test on -charset to make sure the charset gets generated as a + * part of the meta tag. + * @author Bhavesh Patel + * @library ../lib/ + * @build JavadocTester TestCharset + * @run main TestCharset + */ + +public class TestCharset extends JavadocTester { + + //Test information. + private static final String BUG_ID = "7052170"; + + //Javadoc arguments. + private static final String[] ARGS = new String[] { + "-d", BUG_ID, "-charset", "UTF-8", "-sourcepath", SRC_DIR, "pkg" + }; + + private static final String[][] TEST = { + {BUG_ID + FS + "index.html", + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">"}, + {BUG_ID + FS + "pkg" + FS + "Foo.html", + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">"} + }; + + private static final String[][] NEGATED_TEST = { + {BUG_ID + FS + "index.html", + "<meta http-equiv=\"Content-Type\" content=\"text/html\" charset=\"UTF-8\">"}, + {BUG_ID + FS + "pkg" + FS + "Foo.html", + "<meta http-equiv=\"Content-Type\" content=\"text/html\" charset=\"UTF-8\">"} + }; + + /** + * The entry point of the test. + * @param args the array of command line arguments. + */ + public static void main(String[] args) { + TestCharset tester = new TestCharset(); + run(tester, ARGS, TEST, NEGATED_TEST); + tester.printSummary(); + } + + /** + * {@inheritDoc} + */ + public String getBugId() { + return BUG_ID; + } + + /** + * {@inheritDoc} + */ + public String getBugName() { + return getClass().getName(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/com/sun/javadoc/testCharset/pkg/Foo.java Tue Aug 27 11:41:39 2013 -0700 @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package pkg; + +public class Foo {}