1 /*
   2  * Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 6786682 4649116 8182765
  27  * @summary This test verifies the use of lang attribute by <HTML>.
  28  * @library ../../lib
  29  * @modules jdk.javadoc/jdk.javadoc.internal.tool
  30  * @build javadoc.tester.*
  31  * @run main TestHtmlTag
  32  */
  33 
  34 import java.util.Locale;
  35 
  36 import javadoc.tester.JavadocTester;
  37 
  38 public class TestHtmlTag extends JavadocTester {
  39     private static final String defaultLanguage = Locale.getDefault().getLanguage();
  40     public static void main(String... args) throws Exception {
  41         TestHtmlTag tester = new TestHtmlTag();
  42         tester.runTests();
  43     }
  44     @Test
  45     public void test_default() {
  46         javadoc("-locale", defaultLanguage,
  47                 "-d", "out-default",
  48                 "-sourcepath", testSrc,
  49                 "pkg1");
  50 
  51         checkExit(Exit.OK);
  52 
  53         checkOutput("pkg1/C1.html", true,
  54             "<html lang=\"" + defaultLanguage + "\">");
  55 
  56         checkOutput("pkg1/package-summary.html", true,
  57             "<html lang=\"" + defaultLanguage + "\">");
  58 
  59         checkOutput("pkg1/C1.html", false,
  60                 "<html>");
  61     }
  62 
  63     @Test
  64     public void test_ja() {
  65         // TODO: why does this test need/use pkg2; why can't it use pkg1
  66         // like the other two tests, so that we can share the check methods?
  67         javadoc("-locale", "ja",
  68                 "-d", "out-ja",
  69                 "-sourcepath", testSrc,
  70                 "pkg2");
  71         checkExit(Exit.OK);
  72 
  73         checkOutput("pkg2/C2.html", true,
  74                 "<html lang=\"ja\">");
  75 
  76         checkOutput("pkg2/package-summary.html", true,
  77                 "<html lang=\"ja\">");
  78 
  79         checkOutput("pkg2/C2.html", false,
  80                 "<html>");
  81     }
  82 
  83     @Test
  84     public void test_en_US() {
  85         javadoc("-locale", "en_US",
  86                 "-d", "out-en_US",
  87                 "-sourcepath", testSrc,
  88                 "pkg1");
  89         checkExit(Exit.OK);
  90 
  91         checkOutput("pkg1/C1.html", true,
  92                 "<html lang=\"en\">");
  93 
  94         checkOutput("pkg1/package-summary.html", true,
  95                 "<html lang=\"en\">");
  96 
  97         checkOutput("pkg1/C1.html", false,
  98                 "<html>");
  99     }
 100 
 101     @Test
 102     public void test_other() {
 103         javadoc("-locale", "en_US",
 104                 "-d", "out-other",
 105                 "-sourcepath", testSrc,
 106                 "pkg3");
 107         checkExit(Exit.OK);
 108 
 109         checkOutput("pkg3/package-summary.html", true,
 110                 "<div class=\"contentContainer\">\n"
 111                 + "<section class=\"packageDescription\"><a id=\"package.description\">\n"
 112                 + "<!--   -->\n"
 113                 + "</a>\n"
 114                 + "<div class=\"block\"><p>This is the first line. Note the newlines before the &lt;p&gt; is relevant.</div>\n"
 115                 + "</section>");
 116 
 117         checkOutput("pkg3/A.DatatypeFactory.html", true,
 118                 "<div class=\"block\"><p>\n"
 119                 + " Factory that creates new <code>javax.xml.datatype</code>\n"
 120                 + " <code>Object</code>s that map XML to/from Java <code>Object</code>s.</p>\n"
 121                 + "\n"
 122                 + " <p id=\"DatatypeFactory.newInstance\">\n"
 123                 + " A new instance of the <code>DatatypeFactory</code> is created through the\n"
 124                 + " <a href=\"#newInstance()\"><code>newInstance()</code></a> method that uses the following implementation\n"
 125                 + " resolution mechanisms to determine an implementation:</p>\n"
 126                 + " <ol>\n"
 127                 + " <li>\n"
 128                 + " If the system property specified by <a href=\"#DATATYPEFACTORY_PROPERTY\"><code>DATATYPEFACTORY_PROPERTY</code></a>,\n"
 129                 + " \"<code>javax.xml.datatype.DatatypeFactory</code>\", exists, a class with\n"
 130                 + " the name of the property value is instantiated. Any Exception thrown\n"
 131                 + " during the instantiation process is wrapped as a\n"
 132                 + " <code>IllegalStateException</code>.\n"
 133                 + " </li>\n"
 134                 + " <li>\n"
 135                 + " If the file ${JAVA_HOME}/lib/jaxp.properties exists, it is loaded in a\n"
 136                 + " <code>Properties</code> <code>Object</code>. The\n"
 137                 + " <code>Properties</code> <code>Object </code> is then queried for the\n"
 138                 + " property as documented in the prior step and processed as documented in\n"
 139                 + " the prior step.\n"
 140                 + " </li>\n"
 141                 + " <li>\n"
 142                 + " Uses the service-provider loading facilities, defined by the\n"
 143                 + " <code>ServiceLoader</code> class, to attempt to locate and load an\n"
 144                 + " implementation of the service using the default loading mechanism:\n"
 145                 + " the service-provider loading facility will use the current thread's context class loader\n"
 146                 + " to attempt to load the service. If the context class loader is null, the system class loader will be used.\n"
 147                 + " <br>\n"
 148                 + " In case of <code>service configuration error</code> a\n"
 149                 + " <code>DatatypeConfigurationException</code> will be thrown.\n"
 150                 + " </li>\n"
 151                 + " <li>\n"
 152                 + " The final mechanism is to attempt to instantiate the <code>Class</code>\n"
 153                 + " specified by <a href=\"#DATATYPEFACTORY_IMPLEMENTATION_CLASS\"><code>DATATYPEFACTORY_IMPLEMENTATION_CLASS</code></a>. Any Exception\n"
 154                 + " thrown during the instantiation process is wrapped as a\n"
 155                 + " <code>IllegalStateException</code>.\n"
 156                 + " </li>\n"
 157                 + " </ol></div>");
 158 
 159         checkOutput("pkg3/A.ActivationDesc.html", true,
 160                 "<pre>public class <span class=\"typeNameLabel\">A.ActivationDesc</span>\n"
 161                 + "extends java.lang.Object\n"
 162                 + "implements java.io.Serializable</pre>\n"
 163                 + "<div class=\"block\">An activation descriptor contains the information necessary to activate\n"
 164                 + " an object: <ul>\n"
 165                 + " <li> the object's group identifier,\n"
 166                 + " <li> the object's fully-qualified class name,\n"
 167                 + " <li> the object's code location (the location of the class), a codebase\n"
 168                 + " URL path,\n"
 169                 + " <li> the object's restart \"mode\", and,\n"
 170                 + " <li> a \"marshalled\" object that can contain object specific\n"
 171                 + " initialization data. </ul>\n"
 172                 + "\n"
 173                 + " <p>\n"
 174                 + " A descriptor registered with the activation system can be used to\n"
 175                 + " recreate/activate the object specified by the descriptor. The\n"
 176                 + " <code>MarshalledObject</code> in the object's descriptor is passed as the\n"
 177                 + " second argument to the remote object's constructor for object to use\n"
 178                 + " during reinitialization/activation.</div>");
 179 
 180         checkOutput("pkg3/A.ActivationGroupID.html", true,
 181                 "<pre>public class <span class=\"typeNameLabel\">A.ActivationGroupID</span>\n"
 182                 + "extends java.lang.Object\n"
 183                 + "implements java.io.Serializable</pre>\n"
 184                 + "<div class=\"block\">The identifier for a registered activation group serves several purposes:\n"
 185                 + " <ul>\n"
 186                 + " <li>identifies the group uniquely within the activation system, and\n"
 187                 + " <li>contains a reference to the group's activation system so that the\n"
 188                 + " group can contact its activation system when necessary.</ul><p>\n"
 189                 + "\n"
 190                 + " The <code>ActivationGroupID</code> is returned from the call to\n"
 191                 + " <code>ActivationSystem.registerGroup</code> and is used to identify the\n"
 192                 + " group within the activation system. This group id is passed as one of the\n"
 193                 + " arguments to the activation group's special constructor when an\n"
 194                 + " activation group is created/recreated.</div>\n"
 195                 + "<dl>");
 196     }
 197 }