< prev index next >

jdk/test/javax/xml/jaxp/Encodings/CheckEncodingPropertiesFile.java

Print this page




   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 8008738
  27  * @summary checks that the mapping implemented by
  28  *      com.sun.org.apache.xml.internal.serializer.Encodings
  29  *      correctly identifies valid Charset names and
  30  *      correctly maps them to their preferred mime names.
  31  *      Also checks that the Encodings.properties resource file
  32  *      is consistent.
  33  * @compile -XDignore.symbol.file CheckEncodingPropertiesFile.java
  34  * @run main CheckEncodingPropertiesFile
  35  * @author Daniel Fuchs
  36  */
  37 
  38 import com.sun.org.apache.xml.internal.serializer.EncodingInfo;
  39 import com.sun.org.apache.xml.internal.serializer.Encodings;
  40 import java.io.InputStreamReader;
  41 import java.lang.reflect.Method;
  42 import java.nio.charset.Charset;
  43 import java.util.ArrayList;
  44 import java.util.Arrays;
  45 import java.util.Collection;
  46 import java.util.Collections;
  47 import java.util.HashMap;
  48 import java.util.HashSet;
  49 import java.util.LinkedHashSet;
  50 import java.util.List;
  51 import java.util.Map;
  52 import java.util.Map.Entry;
  53 import java.util.Properties;
  54 import java.util.Set;
  55 import java.util.StringTokenizer;
  56 
  57 public class CheckEncodingPropertiesFile {
  58 
  59     private static final String ENCODINGS_FILE = "com/sun/org/apache/xml/internal/serializer/Encodings.properties";
  60 
  61     public static void main(String[] args) throws Exception {
  62         Properties props = new Properties();
  63         try (InputStreamReader is = new InputStreamReader(ClassLoader.getSystemResourceAsStream(ENCODINGS_FILE))) {
  64             props.load(is);
  65         }
  66 









  67         //printAllCharsets();
  68 
  69         test(props);
  70     }
  71 
  72 
  73     private static final class CheckCharsetMapping {
  74 
  75         /**
  76          * A map that maps Java or XML name to canonical charset names.
  77          * key:    upper cased value of Java or XML name.
  78          * value:  case-sensitive canonical name of charset.
  79          */
  80         private final Map<String, String> charsetMap = new HashMap<>();
  81 
  82         private final Map<String, String> preferredMime = new HashMap<>();
  83 
  84         /**
  85          * Unresolved alias names.
  86          * For a given set of names pointing to the same unresolved charset,




   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 8008738 8065138
  27  * @summary checks that the mapping implemented by
  28  *      com.sun.org.apache.xml.internal.serializer.Encodings
  29  *      correctly identifies valid Charset names and
  30  *      correctly maps them to their preferred mime names.
  31  *      Also checks that the Encodings.properties resource file
  32  *      is consistent.
  33  * @compile -XDignore.symbol.file CheckEncodingPropertiesFile.java
  34  * @run main CheckEncodingPropertiesFile
  35  * @author Daniel Fuchs
  36  */
  37 
  38 import com.sun.org.apache.xml.internal.serializer.EncodingInfo;
  39 import com.sun.org.apache.xml.internal.serializer.Encodings;
  40 import java.io.InputStreamReader;
  41 import java.lang.reflect.Method;
  42 import java.nio.charset.Charset;
  43 import java.util.ArrayList;
  44 import java.util.Arrays;
  45 import java.util.Collection;
  46 import java.util.Collections;
  47 import java.util.HashMap;
  48 import java.util.HashSet;
  49 import java.util.LinkedHashSet;
  50 import java.util.List;
  51 import java.util.Map;
  52 import java.util.Map.Entry;
  53 import java.util.Properties;
  54 import java.util.Set;
  55 import java.util.StringTokenizer;
  56 
  57 public class CheckEncodingPropertiesFile {
  58 
  59     private static final String ENCODINGS_FILE = "com/sun/org/apache/xml/internal/serializer/Encodings.properties";
  60 
  61     public static void main(String[] args) throws Exception {
  62         Properties props = new Properties();
  63         try (InputStreamReader is = new InputStreamReader(ClassLoader.getSystemResourceAsStream(ENCODINGS_FILE))) {
  64             props.load(is);
  65         }
  66 
  67        if (!props.containsKey("UTF8")) {
  68            // If the test fails here - it may indicate that you stumbled on an
  69            // issue similar to that fixed by JDK-8065138.
  70            // Check that the content of the Encodings.properties included in
  71            // the tested build image matches the content of the file in the source
  72            // jaxp tree of the jdk forest.
  73            throw new RuntimeException("UTF8 key missing in " + ClassLoader.getSystemResource(ENCODINGS_FILE));
  74        }
  75 
  76         //printAllCharsets();
  77 
  78         test(props);
  79     }
  80 
  81 
  82     private static final class CheckCharsetMapping {
  83 
  84         /**
  85          * A map that maps Java or XML name to canonical charset names.
  86          * key:    upper cased value of Java or XML name.
  87          * value:  case-sensitive canonical name of charset.
  88          */
  89         private final Map<String, String> charsetMap = new HashMap<>();
  90 
  91         private final Map<String, String> preferredMime = new HashMap<>();
  92 
  93         /**
  94          * Unresolved alias names.
  95          * For a given set of names pointing to the same unresolved charset,


< prev index next >