jdk/test/javax/xml/jaxp/Encodings/CheckEncodingPropertiesFile.java
author alanb
Fri, 07 Apr 2017 08:05:54 +0000
changeset 44545 83b611b88ac8
parent 42338 a60f280f803c
permissions -rw-r--r--
8177530: Module system implementation refresh (4/2017) Reviewed-by: mchung, alanb Contributed-by: alan.bateman@oracle.com, mandy.chung@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17437
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
     1
/*
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
     4
 *
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
     8
 *
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    13
 * accompanied this code).
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    14
 *
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    18
 *
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    21
 * questions.
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    22
 */
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    23
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    24
/**
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    25
 * @test
27774
659f0511ec75 8065748: Add a test to verify that non ascii characters in Encodings.properties do not cause issues
dfuchs
parents: 17437
diff changeset
    26
 * @bug 8008738 8065138
17437
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    27
 * @summary checks that the mapping implemented by
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    28
 *      com.sun.org.apache.xml.internal.serializer.Encodings
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    29
 *      correctly identifies valid Charset names and
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    30
 *      correctly maps them to their preferred mime names.
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    31
 *      Also checks that the Encodings.properties resource file
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    32
 *      is consistent.
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 36511
diff changeset
    33
 * @modules java.xml/com.sun.org.apache.xml.internal.serializer:+open
17437
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    34
 * @compile -XDignore.symbol.file CheckEncodingPropertiesFile.java
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    35
 * @run main CheckEncodingPropertiesFile
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    36
 * @author Daniel Fuchs
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    37
 */
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    38
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    39
import com.sun.org.apache.xml.internal.serializer.EncodingInfo;
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    40
import com.sun.org.apache.xml.internal.serializer.Encodings;
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    41
import java.io.InputStreamReader;
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    42
import java.lang.reflect.Method;
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    43
import java.nio.charset.Charset;
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    44
import java.util.ArrayList;
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    45
import java.util.Arrays;
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    46
import java.util.Collection;
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    47
import java.util.Collections;
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    48
import java.util.HashMap;
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    49
import java.util.HashSet;
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    50
import java.util.LinkedHashSet;
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    51
import java.util.List;
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    52
import java.util.Map;
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    53
import java.util.Map.Entry;
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    54
import java.util.Properties;
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    55
import java.util.Set;
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    56
import java.util.StringTokenizer;
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    57
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    58
public class CheckEncodingPropertiesFile {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    59
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    60
    private static final String ENCODINGS_FILE = "com/sun/org/apache/xml/internal/serializer/Encodings.properties";
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    61
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    62
    public static void main(String[] args) throws Exception {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    63
        Properties props = new Properties();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30820
diff changeset
    64
        Module xmlModule = EncodingInfo.class.getModule();
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30820
diff changeset
    65
        try (InputStreamReader is = new InputStreamReader(xmlModule.getResourceAsStream(ENCODINGS_FILE))) {
17437
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    66
            props.load(is);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    67
        }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    68
27774
659f0511ec75 8065748: Add a test to verify that non ascii characters in Encodings.properties do not cause issues
dfuchs
parents: 17437
diff changeset
    69
       if (!props.containsKey("UTF8")) {
659f0511ec75 8065748: Add a test to verify that non ascii characters in Encodings.properties do not cause issues
dfuchs
parents: 17437
diff changeset
    70
           // If the test fails here - it may indicate that you stumbled on an
659f0511ec75 8065748: Add a test to verify that non ascii characters in Encodings.properties do not cause issues
dfuchs
parents: 17437
diff changeset
    71
           // issue similar to that fixed by JDK-8065138.
659f0511ec75 8065748: Add a test to verify that non ascii characters in Encodings.properties do not cause issues
dfuchs
parents: 17437
diff changeset
    72
           // Check that the content of the Encodings.properties included in
659f0511ec75 8065748: Add a test to verify that non ascii characters in Encodings.properties do not cause issues
dfuchs
parents: 17437
diff changeset
    73
           // the tested build image matches the content of the file in the source
659f0511ec75 8065748: Add a test to verify that non ascii characters in Encodings.properties do not cause issues
dfuchs
parents: 17437
diff changeset
    74
           // jaxp tree of the jdk forest.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 30820
diff changeset
    75
           throw new RuntimeException("UTF8 key missing in " + ENCODINGS_FILE);
27774
659f0511ec75 8065748: Add a test to verify that non ascii characters in Encodings.properties do not cause issues
dfuchs
parents: 17437
diff changeset
    76
       }
659f0511ec75 8065748: Add a test to verify that non ascii characters in Encodings.properties do not cause issues
dfuchs
parents: 17437
diff changeset
    77
17437
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    78
        //printAllCharsets();
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    79
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    80
        test(props);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    81
    }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    82
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    83
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    84
    private static final class CheckCharsetMapping {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    85
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    86
        /**
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    87
         * A map that maps Java or XML name to canonical charset names.
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    88
         * key:    upper cased value of Java or XML name.
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    89
         * value:  case-sensitive canonical name of charset.
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    90
         */
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    91
        private final Map<String, String> charsetMap = new HashMap<>();
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    92
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    93
        private final Map<String, String> preferredMime = new HashMap<>();
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    94
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    95
        /**
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    96
         * Unresolved alias names.
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    97
         * For a given set of names pointing to the same unresolved charset,
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    98
         * this map will contain, for each alias in the set, a mapping
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
    99
         * with the alias.toUpperValue() as key and the set of known aliases
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   100
         * as value.
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   101
         */
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   102
        private final Map<String, Collection<String>> unresolved = new HashMap<>();
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   103
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   104
        public final static class ConflictingCharsetError extends Error {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   105
            ConflictingCharsetError(String a, String cs1, String cs2) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   106
                super("Conflicting charset mapping for '"+a+"': '"+cs1+"' and '"+cs2+"'");
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   107
            }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   108
        }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   109
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   110
        public final static class MissingValidCharsetNameError extends Error {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   111
            MissingValidCharsetNameError(String name, Collection<String> aliases) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   112
                super(name+": Line "+aliases+" has no recognized charset alias");
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   113
            }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   114
        }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   115
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   116
        public final static class ConflictingPreferredMimeNameError extends Error {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   117
            ConflictingPreferredMimeNameError(String a, String cs1, String cs2) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   118
                super("Conflicting preferred mime name for '"+a+"': '"+cs1+"' and '"+cs2+"'");
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   119
            }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   120
        }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   121
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   122
        /**
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   123
         * For each alias in aliases, attempt to find the canonical
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   124
         * charset name.
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   125
         * All names in aliases are supposed to point to the same charset.
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   126
         * Names in aliases can be java names or XML names, indifferently.
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   127
         * @param aliases list of names (aliases) for a given charset.
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   128
         * @return The canonical name of the charset, if found, null otherwise.
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   129
         */
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   130
        private String findCharsetNameFor(String[] aliases) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   131
            String cs = null;
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   132
            String res = null;
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   133
            for (String a : aliases) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   134
                final String k = a.toUpperCase();
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   135
                String cachedCs = charsetMap.get(k);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   136
                if (cs == null) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   137
                    cs = cachedCs;
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   138
                }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   139
                if (cachedCs != null && cs != null
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   140
                        && !Charset.forName(cachedCs).name().equals(Charset.forName(cs).name())) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   141
                    throw new ConflictingCharsetError(a,cs,cachedCs);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   142
                }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   143
                try {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   144
                    final String rcs = Charset.forName(a).name();
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   145
                    if (cs != null && !Charset.forName(cs).name().equals(rcs)) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   146
                        throw new ConflictingCharsetError(a,cs,rcs);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   147
                    }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   148
                    if (res == null) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   149
                        if (a.equals(aliases[0])) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   150
                            res = a;
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   151
                        } else {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   152
                            res = cs;
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   153
                        }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   154
                    }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   155
                    cs = rcs;
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   156
                    charsetMap.put(k, res == null ? cs : res);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   157
                } catch (Exception x) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   158
                    continue;
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   159
                }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   160
            }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   161
            return res == null ? cs : res;
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   162
        }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   163
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   164
        /**
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   165
         * Register a canonical charset name for a given set of aliases.
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   166
         *
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   167
         * @param charsetName the canonical charset name.
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   168
         * @param aliases a list of aliases for the given charset.
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   169
         */
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   170
        private void registerCharsetNameFor(String charsetName, String[] aliases) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   171
            if (charsetName == null) throw new NullPointerException();
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   172
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   173
            for (String a : aliases) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   174
                String k = a.toUpperCase();
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   175
                String csv = charsetMap.get(k);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   176
                if (csv == null) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   177
                    charsetMap.put(k, charsetName);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   178
                    csv = charsetName;
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   179
                } else if (!csv.equals(charsetName)) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   180
                    throw new ConflictingCharsetError(a,charsetName,csv);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   181
                }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   182
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   183
                final Collection<String> c = unresolved.get(k);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   184
                if (c != null) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   185
                    for (String aa : c) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   186
                        k = aa.toUpperCase();
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   187
                        String csvv = charsetMap.get(k);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   188
                        if (csvv == null) charsetMap.put(k, csv);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   189
                        unresolved.remove(k);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   190
                    }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   191
                    throw new MissingValidCharsetNameError(charsetName,c);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   192
                }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   193
            }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   194
        }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   195
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   196
        /**
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   197
         * Register a set of aliases as being unresolved.
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   198
         * @param names    the list of names - this should be what is returned by
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   199
         *                 nameSet.toArray(new String[nameSet.size()])
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   200
         * @param nameSet  the set of unresolved aliases.
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   201
         */
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   202
        private void registerUnresolvedNamesFor(String[] names, Collection<String> nameSet) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   203
            // This is not necessarily an error: it could happen that some
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   204
            //    charsets are simply not supported on some OS/Arch
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   205
            System.err.println("Warning: unresolved charset names: '"+ nameSet
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   206
                    + "' This is not necessarily an error "
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   207
                    + "- this charset may not be supported on this platform.");
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   208
            for (String a : names) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   209
                final String k = a.toUpperCase();
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   210
                final Collection<String> c = unresolved.get(k);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   211
                if (c != null) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   212
                    //System.out.println("Found: "+a+" -> "+c);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   213
                    //System.out.println("\t merging "+ c + " with " + nameSet);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   214
                    nameSet.addAll(c);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   215
                    for (String aa : c) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   216
                        unresolved.put(aa.toUpperCase(), nameSet);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   217
                    }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   218
                }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   219
                unresolved.put(k, nameSet);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   220
            }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   221
        }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   222
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   223
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   224
        /**
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   225
         * Add a new charset name mapping
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   226
         * @param javaName the (supposedly) java name of the charset.
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   227
         * @param xmlNames a list of corresponding XML names for that charset.
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   228
         */
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   229
        void addMapping(String javaName, Collection<String> xmlNames) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   230
            final LinkedHashSet<String> aliasNames = new LinkedHashSet<>();
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   231
            aliasNames.add(javaName);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   232
            aliasNames.addAll(xmlNames);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   233
            final String[] aliases = aliasNames.toArray(new String[aliasNames.size()]);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   234
            final String cs = findCharsetNameFor(aliases);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   235
            if (cs != null) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   236
                registerCharsetNameFor(cs, aliases);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   237
                if (xmlNames.size() > 0) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   238
                    String preferred = xmlNames.iterator().next();
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   239
                    String cachedPreferred = preferredMime.get(cs.toUpperCase());
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   240
                    if (cachedPreferred != null && !cachedPreferred.equals(preferred)) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   241
                        throw new ConflictingPreferredMimeNameError(cs, cachedPreferred, preferred);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   242
                    }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   243
                    preferredMime.put(cs.toUpperCase(), preferred);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   244
                }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   245
            } else {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   246
                registerUnresolvedNamesFor(aliases, aliasNames);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   247
            }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   248
        }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   249
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   250
        /**
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   251
         * Returns the canonical name of the charset for the given Java or XML
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   252
         * alias name.
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   253
         * @param alias the alias name
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   254
         * @return the canonical charset name - or null if unknown.
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   255
         */
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   256
        public String getCharsetNameFor(String alias) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   257
            return charsetMap.get(alias.toUpperCase());
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   258
        }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   259
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   260
    }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   261
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   262
    public static void test(Properties props) throws Exception {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   263
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   264
        // First, build a mapping from the properties read from the resource
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   265
        // file.
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   266
        // We're going to check the consistency of the resource file
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   267
        // while building this mapping, and throw errors if the file
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   268
        // does not meet our assumptions.
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   269
        //
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   270
        Map<String, Collection<String>> lines = new HashMap<>();
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   271
        final CheckCharsetMapping mapping = new CheckCharsetMapping();
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   272
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   273
        for (String key : props.stringPropertyNames()) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   274
            Collection<String> values = getValues(props.getProperty(key));
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   275
            lines.put(key, values);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   276
            mapping.addMapping(key, values);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   277
        }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   278
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   279
        // Then build maps of EncodingInfos, and print along debugging
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   280
        // information that should help understand the content of the
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   281
        // resource file and the mapping it defines.
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   282
        //
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   283
        Map<String, EncodingInfo> javaInfos = new HashMap<>(); // Map indexed by java names
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   284
        Map<String, EncodingInfo> xmlMap = new HashMap<>();    // Map indexed by XML names
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   285
        Map<String, String> preferred =
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   286
                new HashMap<>(mapping.preferredMime);          // Java Name -> Preferred Mime Name
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   287
        List<EncodingInfo> all = new ArrayList<>();            // unused...
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   288
        for (Entry<String, Collection<String>> e : lines.entrySet()) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   289
            final String charsetName = mapping.getCharsetNameFor(e.getKey());
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   290
            if (charsetName == null) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   291
                System.out.println("!! No charset for: "+e.getKey()+ " "+ e.getValue());
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   292
                continue;
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   293
            }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   294
            Charset c = Charset.forName(charsetName);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   295
            EncodingInfo info;
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   296
            final String k = e.getKey().toUpperCase();
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   297
            final String kc = charsetName.toUpperCase();
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   298
            StringBuilder sb = new StringBuilder();
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   299
            for (String xml : e.getValue()) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   300
                final String kx = xml.toUpperCase();
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   301
                info = xmlMap.get(kx);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   302
                if (info == null) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   303
                    info = new EncodingInfo(xml, charsetName);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   304
                    System.out.println("** XML: "+xml+" -> "+charsetName);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   305
                    xmlMap.put(kx, info);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   306
                    all.add(info);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   307
                }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   308
                if (!javaInfos.containsKey(k)) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   309
                    javaInfos.put(k, info);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   310
                    if (!preferred.containsKey(k)) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   311
                        preferred.put(k, xml);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   312
                    }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   313
                    sb.append("** Java: ").append(k).append(" -> ")
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   314
                            .append(xml).append(" (charset: ")
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   315
                            .append(charsetName).append(")\n");
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   316
                }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   317
                if (!javaInfos.containsKey(kc)) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   318
                    if (!preferred.containsKey(kc)) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   319
                        preferred.put(kc, xml);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   320
                    }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   321
                    javaInfos.put(kc, info);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   322
                    sb.append("** Java: ").append(kc).append(" -> ")
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   323
                            .append(xml).append(" (charset: ")
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   324
                            .append(charsetName).append(")\n");
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   325
                }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   326
                if (!javaInfos.containsKey(c.name().toUpperCase())) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   327
                    if (!preferred.containsKey(c.name().toUpperCase())) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   328
                        preferred.put(c.name().toUpperCase(), xml);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   329
                    }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   330
                    javaInfos.put(c.name().toUpperCase(), info);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   331
                    sb.append("** Java: ").append(c.name().toUpperCase()).append(" -> ")
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   332
                            .append(xml).append(" (charset: ")
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   333
                            .append(charsetName).append(")\n");
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   334
                }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   335
            }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   336
            if (sb.length() == 0) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   337
                System.out.println("Nothing new for "+charsetName+": "+e.getKey()+" -> "+e.getValue());
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   338
            } else {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   339
                System.out.print(sb);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   340
            }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   341
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   342
        }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   343
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   344
        // Now we're going to verify that Encodings.java has done its job
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   345
        // correctly. We're going to ask Encodings to convert java names to mime
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   346
        // names and mime names to java names - and verify that the returned
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   347
        // java names do map to recognized charsets.
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   348
        //
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   349
        // We're also going to verify that Encodings has recorded the preferred
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   350
        // mime name correctly.
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   351
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   352
        Method m = Encodings.class.getDeclaredMethod("getMimeEncoding", String.class);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   353
        m.setAccessible(true);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   354
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   355
        Set<String> xNames = new HashSet<>();
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   356
        Set<String> jNames = new HashSet<>();
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   357
        for (String name: xmlMap.keySet()) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   358
            final String javaName = checkConvertMime2Java(name);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   359
            checkPreferredMime(m, javaName, preferred);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   360
            jNames.add(javaName);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   361
            xNames.add(name);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   362
        }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   363
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   364
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   365
        for (String javaName : lines.keySet()) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   366
            final String javaCharsetName = mapping.getCharsetNameFor(javaName.toUpperCase());
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   367
            if (javaCharsetName == null) continue;
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   368
            if (!jNames.contains(javaName)) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   369
                checkPreferredMime(m, javaName, preferred);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   370
                jNames.add(javaName);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   371
            }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   372
            for (String xml : lines.get(javaName)) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   373
                if (xNames.contains(xml)) continue;
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   374
                final String jName = checkConvertMime2Java(xml);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   375
                xNames.add(xml);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   376
                if (jNames.contains(jName)) continue;
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   377
                checkPreferredMime(m, jName, preferred);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   378
            }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   379
        }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   380
    }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   381
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   382
    private static String checkConvertMime2Java(String xml) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   383
        final String jName = Encodings.convertMime2JavaEncoding(xml);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   384
        final String jCharsetName;
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   385
        try {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   386
            jCharsetName = Charset.forName(jName).name();
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   387
        } catch (Exception x) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   388
            throw new Error("Unrecognized charset returned by Encodings.convertMime2JavaEncoding(\""+xml+"\")", x);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   389
        }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   390
        System.out.println("Encodings.convertMime2JavaEncoding(\""+xml+"\") = \""+jName+"\" ("+jCharsetName+")");
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   391
        return jName;
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   392
    }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   393
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   394
    private static void checkPreferredMime(Method m, String javaName, Map<String,String> preferred)
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   395
            throws Exception {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   396
        final String mime = (String) m.invoke(null, javaName);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   397
        final String expected = preferred.get(javaName.toUpperCase());
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   398
        if (Arrays.deepEquals(new String[] {mime}, new String[] {expected})) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   399
            System.out.println("Encodings.getMimeEncoding(\""+javaName+"\") = \""+mime+"\"");
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   400
        } else {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   401
            throw new Error("Bad preferred mime type for: '"+javaName+"': expected '"+
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   402
                expected+"' but got '"+mime+"'");
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   403
        }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   404
    }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   405
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   406
    private static Collection<String> getValues(String val) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   407
        int pos = val.indexOf(' ');
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   408
        if (pos < 0) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   409
            return Collections.singletonList(val);
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   410
        }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   411
        //lastPrintable =
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   412
        //    Integer.decode(val.substring(pos).trim()).intValue();
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   413
        StringTokenizer st =
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   414
            new StringTokenizer(val.substring(0, pos), ",");
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   415
        final List<String> values = new ArrayList<>(st.countTokens());
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   416
        while (st.hasMoreTokens()) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   417
            values.add(st.nextToken());
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   418
        }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   419
        return values;
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   420
    }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   421
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   422
    // can be called in main() to help debugging.
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   423
    // Prints out all available charsets and their recognized aliases
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   424
    // as returned by the Charset API.
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   425
    private static void printAllCharsets() {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   426
        Map<String, Charset> all = Charset.availableCharsets();
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   427
        System.out.println("\n=========================================\n");
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   428
        for (String can : all.keySet()) {
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   429
            System.out.println(can + ": " + all.get(can).aliases());
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   430
        }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   431
    }
c29f8d00fc0b 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents:
diff changeset
   432
}