src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/Encodings.java
author joehw
Wed, 04 Oct 2017 10:54:18 -0700
changeset 47312 d4f959806fe9
parent 47216 71c04702a3d5
child 47359 e1a6c0168741
permissions -rw-r--r--
8187593: Cleanup: removing SecuritySupport files Reviewed-by: lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     1
/*
47312
d4f959806fe9 8187593: Cleanup: removing SecuritySupport files
joehw
parents: 47216
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
d4f959806fe9 8187593: Cleanup: removing SecuritySupport files
joehw
parents: 47216
diff changeset
     3
 * @LastModified: Sep 2017
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     4
 */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     5
/*
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     6
 * Licensed to the Apache Software Foundation (ASF) under one or more
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     7
 * contributor license agreements.  See the NOTICE file distributed with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     8
 * this work for additional information regarding copyright ownership.
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     9
 * The ASF licenses this file to You under the Apache License, Version 2.0
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    10
 * (the "License"); you may not use this file except in compliance with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    11
 * the License.  You may obtain a copy of the License at
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    12
 *
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    13
 *      http://www.apache.org/licenses/LICENSE-2.0
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    14
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    15
 * Unless required by applicable law or agreed to in writing, software
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    16
 * distributed under the License is distributed on an "AS IS" BASIS,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    18
 * See the License for the specific language governing permissions and
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    19
 * limitations under the License.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    20
 */
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    21
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    22
package com.sun.org.apache.xml.internal.serializer;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    23
47312
d4f959806fe9 8187593: Cleanup: removing SecuritySupport files
joehw
parents: 47216
diff changeset
    24
import java.io.BufferedWriter;
d4f959806fe9 8187593: Cleanup: removing SecuritySupport files
joehw
parents: 47216
diff changeset
    25
import java.io.IOException;
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    26
import java.io.InputStream;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    27
import java.io.OutputStream;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    28
import java.io.OutputStreamWriter;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    29
import java.io.UnsupportedEncodingException;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    30
import java.io.Writer;
47312
d4f959806fe9 8187593: Cleanup: removing SecuritySupport files
joehw
parents: 47216
diff changeset
    31
import java.net.MalformedURLException;
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    32
import java.net.URL;
17533
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
    33
import java.nio.charset.Charset;
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
    34
import java.nio.charset.IllegalCharsetNameException;
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
    35
import java.nio.charset.UnsupportedCharsetException;
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
    36
import java.util.Collections;
47312
d4f959806fe9 8187593: Cleanup: removing SecuritySupport files
joehw
parents: 47216
diff changeset
    37
import java.util.Enumeration;
d4f959806fe9 8187593: Cleanup: removing SecuritySupport files
joehw
parents: 47216
diff changeset
    38
import java.util.HashMap;
17533
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
    39
import java.util.Map.Entry;
47312
d4f959806fe9 8187593: Cleanup: removing SecuritySupport files
joehw
parents: 47216
diff changeset
    40
import java.util.Map;
d4f959806fe9 8187593: Cleanup: removing SecuritySupport files
joehw
parents: 47216
diff changeset
    41
import java.util.Properties;
d4f959806fe9 8187593: Cleanup: removing SecuritySupport files
joehw
parents: 47216
diff changeset
    42
import java.util.StringTokenizer;
d4f959806fe9 8187593: Cleanup: removing SecuritySupport files
joehw
parents: 47216
diff changeset
    43
import jdk.xml.internal.SecuritySupport;
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    44
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    45
/**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    46
 * Provides information about encodings. Depends on the Java runtime
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    47
 * to provides writers for the different encodings, but can be used
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    48
 * to override encoding names and provide the last printable character
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    49
 * for each encoding.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    50
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    51
 * @author <a href="mailto:arkin@intalio.com">Assaf Arkin</a>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    52
 */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    53
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    54
public final class Encodings extends Object
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    55
{
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    56
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    57
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    58
     * The last printable character for unknown encodings.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    59
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    60
    private static final int m_defaultLastPrintable = 0x7F;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    61
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    62
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    63
     * Standard filename for properties file with encodings data.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    64
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    65
    private static final String ENCODINGS_FILE = "com/sun/org/apache/xml/internal/serializer/Encodings.properties";
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    66
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    67
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    68
     * Standard filename for properties file with encodings data.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    69
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    70
    private static final String ENCODINGS_PROP = "com.sun.org.apache.xalan.internal.serialize.encodings";
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    71
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    72
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    73
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    74
     * Returns a writer for the specified encoding based on
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    75
     * an output stream.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    76
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    77
     * @param output The output stream
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    78
     * @param encoding The encoding
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    79
     * @return A suitable writer
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    80
     * @throws UnsupportedEncodingException There is no convertor
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    81
     *  to support this encoding
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    82
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    83
    static Writer getWriter(OutputStream output, String encoding)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    84
        throws UnsupportedEncodingException
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    85
    {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    86
17533
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
    87
        final EncodingInfo ei = _encodingInfos.findEncoding(toUpperCaseFast(encoding));
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
    88
        if (ei != null) {
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
    89
            try {
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
    90
                return new BufferedWriter(new OutputStreamWriter(
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
    91
                        output, ei.javaName));
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
    92
            } catch (UnsupportedEncodingException usee) {
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
    93
                // keep trying
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    94
            }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    95
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    96
17533
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
    97
        return new BufferedWriter(new OutputStreamWriter(output, encoding));
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    98
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    99
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   100
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   101
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   102
     * Returns the last printable character for an unspecified
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   103
     * encoding.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   104
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   105
     * @return the default size
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   106
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   107
    public static int getLastPrintable()
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   108
    {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   109
        return m_defaultLastPrintable;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   110
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   111
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   112
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   113
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   114
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   115
     * Returns the EncodingInfo object for the specified
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   116
     * encoding.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   117
     * <p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   118
     * This is not a public API.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   119
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   120
     * @param encoding The encoding
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   121
     * @return The object that is used to determine if
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   122
     * characters are in the given encoding.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   123
     * @xsl.usage internal
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   124
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   125
    static EncodingInfo getEncodingInfo(String encoding)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   126
    {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   127
        EncodingInfo ei;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   128
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   129
        String normalizedEncoding = toUpperCaseFast(encoding);
17533
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   130
        ei = _encodingInfos.findEncoding(normalizedEncoding);
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   131
        if (ei == null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   132
            // We shouldn't have to do this, but just in case.
17533
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   133
            try {
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   134
                // This may happen if the caller tries to use
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   135
                // an encoding that wasn't registered in the
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   136
                // (java name)->(preferred mime name) mapping file.
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   137
                // In that case we attempt to load the charset for the
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   138
                // given encoding, and if that succeeds - we create a new
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   139
                // EncodingInfo instance - assuming the canonical name
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   140
                // of the charset can be used as the mime name.
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   141
                final Charset c = Charset.forName(encoding);
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   142
                final String name = c.name();
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   143
                ei = new EncodingInfo(name, name);
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   144
                _encodingInfos.putEncoding(normalizedEncoding, ei);
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   145
            } catch (IllegalCharsetNameException | UnsupportedCharsetException x) {
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   146
                ei = new EncodingInfo(null,null);
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   147
            }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   148
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   149
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   150
        return ei;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   151
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   152
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   153
    /**
25834
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   154
     * Determines if the encoding specified was recognized by the
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   155
     * serializer or not.
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   156
     *
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   157
     * @param encoding The encoding
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   158
     * @return boolean - true if the encoding was recognized else false
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   159
     */
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   160
    public static boolean isRecognizedEncoding(String encoding)
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   161
    {
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   162
        EncodingInfo ei;
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   163
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   164
        String normalizedEncoding = toUpperCaseFast(encoding);
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   165
        ei = _encodingInfos.findEncoding(normalizedEncoding);
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   166
        if (ei != null)
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   167
            return true;
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   168
        return false;
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   169
    }
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   170
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   171
    /**
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   172
     * A fast and cheap way to uppercase a String that is
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   173
     * only made of printable ASCII characters.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   174
     * <p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   175
     * This is not a public API.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   176
     * @param s a String of ASCII characters
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   177
     * @return an uppercased version of the input String,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   178
     * possibly the same String.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   179
     * @xsl.usage internal
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   180
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   181
    static private String toUpperCaseFast(final String s) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   182
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   183
        boolean different = false;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   184
        final int mx = s.length();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   185
                char[] chars = new char[mx];
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   186
        for (int i=0; i < mx; i++) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   187
                char ch = s.charAt(i);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   188
            // is the character a lower case ASCII one?
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   189
                if ('a' <= ch && ch <= 'z') {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   190
                // a cheap and fast way to uppercase that is good enough
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   191
                        ch = (char) (ch + ('A' - 'a'));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   192
                        different = true; // the uppercased String is different
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   193
                }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   194
                chars[i] = ch;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   195
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   196
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   197
        // A little optimization, don't call String.valueOf() if
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   198
        // the uppercased string is the same as the input string.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   199
        final String upper;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   200
        if (different)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   201
                upper = String.valueOf(chars);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   202
        else
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   203
                upper = s;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   204
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   205
        return upper;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   206
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   207
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   208
    /** The default encoding, ISO style, ISO style.   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   209
    static final String DEFAULT_MIME_ENCODING = "UTF-8";
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   210
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   211
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   212
     * Get the proper mime encoding.  From the XSLT recommendation: "The encoding
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   213
     * attribute specifies the preferred encoding to use for outputting the result
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   214
     * tree. XSLT processors are required to respect values of UTF-8 and UTF-16.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   215
     * For other values, if the XSLT processor does not support the specified
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   216
     * encoding it may signal an error; if it does not signal an error it should
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   217
     * use UTF-8 or UTF-16 instead. The XSLT processor must not use an encoding
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   218
     * whose name does not match the EncName production of the XML Recommendation
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   219
     * [XML]. If no encoding attribute is specified, then the XSLT processor should
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   220
     * use either UTF-8 or UTF-16."
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   221
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   222
     * @param encoding Reference to java-style encoding string, which may be null,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   223
     * in which case a default will be found.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   224
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   225
     * @return The ISO-style encoding string, or null if failure.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   226
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   227
    static String getMimeEncoding(String encoding)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   228
    {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   229
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   230
        if (null == encoding)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   231
        {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   232
            try
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   233
            {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   234
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   235
                // Get the default system character encoding.  This may be
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   236
                // incorrect if they passed in a writer, but right now there
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   237
                // seems to be no way to get the encoding from a writer.
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12458
diff changeset
   238
                encoding = SecuritySupport.getSystemProperty("file.encoding", "UTF8");
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   239
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   240
                if (null != encoding)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   241
                {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   242
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   243
                    /*
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   244
                    * See if the mime type is equal to UTF8.  If you don't
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   245
                    * do that, then  convertJava2MimeEncoding will convert
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   246
                    * 8859_1 to "ISO-8859-1", which is not what we want,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   247
                    * I think, and I don't think I want to alter the tables
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   248
                    * to convert everything to UTF-8.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   249
                    */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   250
                    String jencoding =
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   251
                        (encoding.equalsIgnoreCase("Cp1252")
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   252
                            || encoding.equalsIgnoreCase("ISO8859_1")
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   253
                            || encoding.equalsIgnoreCase("8859_1")
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   254
                            || encoding.equalsIgnoreCase("UTF8"))
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   255
                            ? DEFAULT_MIME_ENCODING
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   256
                            : convertJava2MimeEncoding(encoding);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   257
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   258
                    encoding =
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   259
                        (null != jencoding) ? jencoding : DEFAULT_MIME_ENCODING;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   260
                }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   261
                else
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   262
                {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   263
                    encoding = DEFAULT_MIME_ENCODING;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   264
                }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   265
            }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   266
            catch (SecurityException se)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   267
            {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   268
                encoding = DEFAULT_MIME_ENCODING;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   269
            }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   270
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   271
        else
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   272
        {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   273
            encoding = convertJava2MimeEncoding(encoding);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   274
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   275
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   276
        return encoding;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   277
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   278
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   279
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   280
     * Try the best we can to convert a Java encoding to a XML-style encoding.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   281
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   282
     * @param encoding non-null reference to encoding string, java style.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   283
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   284
     * @return ISO-style encoding string.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   285
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   286
    private static String convertJava2MimeEncoding(String encoding)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   287
    {
17533
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   288
        final EncodingInfo enc =
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   289
             _encodingInfos.getEncodingFromJavaKey(toUpperCaseFast(encoding));
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   290
        if (null != enc)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   291
            return enc.name;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   292
        return encoding;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   293
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   294
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   295
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   296
     * Try the best we can to convert a Java encoding to a XML-style encoding.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   297
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   298
     * @param encoding non-null reference to encoding string, java style.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   299
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   300
     * @return ISO-style encoding string.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   301
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   302
    public static String convertMime2JavaEncoding(String encoding)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   303
    {
17533
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   304
        final EncodingInfo info = _encodingInfos.findEncoding(toUpperCaseFast(encoding));
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   305
        return info != null ? info.javaName : encoding;
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   306
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   307
17533
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   308
    // Using an inner static class here prevent initialization races
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   309
    // where the hash maps could be used before they were populated.
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   310
    //
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   311
    private final static class EncodingInfos {
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   312
        // These maps are final and not modified after initialization.
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   313
        private final Map<String, EncodingInfo> _encodingTableKeyJava = new HashMap<>();
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   314
        private final Map<String, EncodingInfo> _encodingTableKeyMime = new HashMap<>();
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   315
        // This map will be added to after initialization: make sure it's
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   316
        // thread-safe. This map should not be used frequently - only in cases
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   317
        // where the mapping requested was not declared in the Encodings.properties
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   318
        // file.
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   319
        private final Map<String, EncodingInfo> _encodingDynamicTable =
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   320
                Collections.synchronizedMap(new HashMap<String, EncodingInfo>());
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   321
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   322
        private EncodingInfos() {
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   323
            loadEncodingInfo();
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   324
        }
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   325
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   326
        // Opens the file/resource containing java charset name -> preferred mime
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   327
        // name mapping and returns it as an InputStream.
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   328
        private InputStream openEncodingsFileStream() throws MalformedURLException, IOException {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   329
            String urlString = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   330
            InputStream is = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   331
17533
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   332
            try {
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12458
diff changeset
   333
                urlString = SecuritySupport.getSystemProperty(ENCODINGS_PROP, "");
17533
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   334
            } catch (SecurityException e) {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   335
            }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   336
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   337
            if (urlString != null && urlString.length() > 0) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   338
                URL url = new URL(urlString);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   339
                is = url.openStream();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   340
            }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   341
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   342
            if (is == null) {
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   343
                is = SecuritySupport.getResourceAsStream(ENCODINGS_FILE);
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   344
            }
17533
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   345
            return is;
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   346
        }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   347
17533
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   348
        // Loads the Properties resource containing the mapping:
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   349
        //    java charset name -> preferred mime name
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   350
        // and returns it.
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   351
        private Properties loadProperties() throws MalformedURLException, IOException {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   352
            Properties props = new Properties();
17533
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   353
            try (InputStream is = openEncodingsFileStream()) {
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   354
                if (is != null) {
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   355
                    props.load(is);
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   356
                } else {
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   357
                    // Seems to be no real need to force failure here, let the
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   358
                    // system do its best... The issue is not really very critical,
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   359
                    // and the output will be in any case _correct_ though maybe not
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   360
                    // always human-friendly... :)
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   361
                    // But maybe report/log the resource problem?
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   362
                    // Any standard ways to report/log errors (in static context)?
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   363
                }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   364
            }
17533
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   365
            return props;
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   366
        }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   367
17533
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   368
        // Parses the mime list associated to a java charset name.
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   369
        // The first mime name in the list is supposed to be the preferred
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   370
        // mime name.
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   371
        private String[] parseMimeTypes(String val) {
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   372
            int pos = val.indexOf(' ');
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   373
            //int lastPrintable;
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   374
            if (pos < 0) {
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   375
                // Maybe report/log this problem?
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   376
                //  "Last printable character not defined for encoding " +
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   377
                //  mimeName + " (" + val + ")" ...
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   378
                return new String[] { val };
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   379
                //lastPrintable = 0x00FF;
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   380
            }
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   381
            //lastPrintable =
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   382
            //    Integer.decode(val.substring(pos).trim()).intValue();
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   383
            StringTokenizer st =
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   384
                    new StringTokenizer(val.substring(0, pos), ",");
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   385
            String[] values = new String[st.countTokens()];
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   386
            for (int i=0; st.hasMoreTokens(); i++) {
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   387
                values[i] = st.nextToken();
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   388
            }
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   389
            return values;
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   390
        }
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   391
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   392
        // This method here attempts to find the canonical charset name for the
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   393
        // the given name - which is supposed to be either a java name or a mime
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   394
        // name.
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   395
        // For that, it attempts to load the charset using the given name, and
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   396
        // then returns the charset's canonical name.
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   397
        // If the charset could not be loaded from the given name,
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   398
        // the method returns null.
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   399
        private String findCharsetNameFor(String name) {
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   400
            try {
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   401
                return Charset.forName(name).name();
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   402
            } catch (Exception x) {
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   403
                return null;
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   404
            }
17533
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   405
        }
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   406
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   407
        // This method here attempts to find the canonical charset name for the
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   408
        // the set javaName+mimeNames - which are supposed to all refer to the
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   409
        // same charset.
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   410
        // For that it attempts to load the charset using the javaName, and if
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   411
        // not found, attempts again using each of the mime names in turn.
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   412
        // If the charset could be loaded from the javaName, then the javaName
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   413
        // itself is returned as charset name. Otherwise, each of the mime names
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   414
        // is tried in turn, until a charset can be loaded from one of the names,
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   415
        // and the loaded charset's canonical name is returned.
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   416
        // If no charset can be loaded from either the javaName or one of the
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   417
        // mime names, then null is returned.
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   418
        //
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   419
        // Note that the returned name is the 'java' name that will be used in
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   420
        // instances of EncodingInfo.
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   421
        // This is important because EncodingInfo uses that 'java name' later on
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   422
        // in calls to String.getBytes(javaName).
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   423
        // As it happens, sometimes only one element of the set mime names/javaName
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   424
        // is known by Charset: sometimes only one of the mime names is known,
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   425
        // sometime only the javaName is known, sometimes all are known.
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   426
        //
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   427
        // By using this method here, we fix the problem where one of the mime
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   428
        // names is known but the javaName is unknown, by associating the charset
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   429
        // loaded from one of the mime names with the unrecognized javaName.
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   430
        //
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   431
        // When none of the mime names or javaName are known - there's not much we can
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   432
        // do... It can mean that this encoding is not supported for this
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   433
        // OS. If such a charset is ever use it will result in having all characters
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   434
        // escaped.
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   435
        //
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   436
        private String findCharsetNameFor(String javaName, String[] mimes) {
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   437
            String cs = findCharsetNameFor(javaName);
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   438
            if (cs != null) return javaName;
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   439
            for (String m : mimes) {
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   440
                cs = findCharsetNameFor(m);
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   441
                if (cs != null) break;
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   442
            }
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   443
            return cs;
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   444
        }
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   445
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   446
        /**
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   447
         * Loads a list of all the supported encodings.
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   448
         *
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   449
         * System property "encodings" formatted using URL syntax may define an
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   450
         * external encodings list. Thanks to Sergey Ushakov for the code
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   451
         * contribution!
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   452
         */
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   453
        private void loadEncodingInfo() {
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   454
            try {
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   455
                // load (java name)->(preferred mime name) mapping.
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   456
                final Properties props = loadProperties();
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   457
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   458
                // create instances of EncodingInfo from the loaded mapping
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   459
                Enumeration keys = props.keys();
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   460
                Map<String, EncodingInfo> canonicals = new HashMap<>();
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   461
                while (keys.hasMoreElements()) {
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   462
                    final String javaName = (String) keys.nextElement();
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   463
                    final String[] mimes = parseMimeTypes(props.getProperty(javaName));
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   464
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   465
                    final String charsetName = findCharsetNameFor(javaName, mimes);
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   466
                    if (charsetName != null) {
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   467
                        final String kj = toUpperCaseFast(javaName);
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   468
                        final String kc = toUpperCaseFast(charsetName);
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   469
                        for (int i = 0; i < mimes.length; ++i) {
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   470
                            final String mimeName = mimes[i];
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   471
                            final String km = toUpperCaseFast(mimeName);
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   472
                            EncodingInfo info = new EncodingInfo(mimeName, charsetName);
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   473
                            _encodingTableKeyMime.put(km, info);
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   474
                            if (!canonicals.containsKey(kc)) {
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   475
                                // canonicals will map the charset name to
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   476
                                //   the info containing the prefered mime name
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   477
                                //   (the preferred mime name is the first mime
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   478
                                //   name in the list).
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   479
                                canonicals.put(kc, info);
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   480
                                _encodingTableKeyJava.put(kc, info);
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   481
                            }
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   482
                            _encodingTableKeyJava.put(kj, info);
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   483
                        }
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   484
                    } else {
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   485
                        // None of the java or mime names on the line were
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   486
                        // recognized => this charset is not supported?
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   487
                    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   488
                }
17533
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   489
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   490
                // Fix up the _encodingTableKeyJava so that the info mapped to
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   491
                // the java name contains the preferred mime name.
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   492
                // (a given java name can correspond to several mime name,
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   493
                //  but we want the _encodingTableKeyJava to point to the
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   494
                //  preferred mime name).
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   495
                for (Entry<String, EncodingInfo> e : _encodingTableKeyJava.entrySet()) {
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   496
                    e.setValue(canonicals.get(toUpperCaseFast(e.getValue().javaName)));
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   497
                }
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   498
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   499
            } catch (java.net.MalformedURLException mue) {
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   500
                throw new com.sun.org.apache.xml.internal.serializer.utils.WrappedRuntimeException(mue);
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   501
            } catch (java.io.IOException ioe) {
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   502
                throw new com.sun.org.apache.xml.internal.serializer.utils.WrappedRuntimeException(ioe);
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   503
            }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   504
        }
17533
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   505
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   506
        EncodingInfo findEncoding(String normalizedEncoding) {
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   507
            EncodingInfo info = _encodingTableKeyJava.get(normalizedEncoding);
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   508
            if (info == null) {
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   509
                info = _encodingTableKeyMime.get(normalizedEncoding);
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   510
            }
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   511
            if (info == null) {
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   512
                info = _encodingDynamicTable.get(normalizedEncoding);
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   513
            }
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   514
            return info;
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   515
        }
17533
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   516
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   517
        EncodingInfo getEncodingFromMimeKey(String normalizedMimeName) {
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   518
            return _encodingTableKeyMime.get(normalizedMimeName);
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   519
        }
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   520
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   521
        EncodingInfo getEncodingFromJavaKey(String normalizedJavaName) {
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   522
            return _encodingTableKeyJava.get(normalizedJavaName);
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   523
        }
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   524
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   525
        void putEncoding(String key, EncodingInfo info) {
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   526
            _encodingDynamicTable.put(key, info);
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   527
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   528
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   529
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   530
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   531
     * Return true if the character is the high member of a surrogate pair.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   532
     * <p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   533
     * This is not a public API.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   534
     * @param ch the character to test
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   535
     * @xsl.usage internal
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   536
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   537
    static boolean isHighUTF16Surrogate(char ch) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   538
        return ('\uD800' <= ch && ch <= '\uDBFF');
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   539
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   540
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   541
     * Return true if the character is the low member of a surrogate pair.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   542
     * <p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   543
     * This is not a public API.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   544
     * @param ch the character to test
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   545
     * @xsl.usage internal
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   546
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   547
    static boolean isLowUTF16Surrogate(char ch) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   548
        return ('\uDC00' <= ch && ch <= '\uDFFF');
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   549
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   550
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   551
     * Return the unicode code point represented by the high/low surrogate pair.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   552
     * <p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   553
     * This is not a public API.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   554
     * @param highSurrogate the high char of the high/low pair
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   555
     * @param lowSurrogate the low char of the high/low pair
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   556
     * @xsl.usage internal
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   557
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   558
    static int toCodePoint(char highSurrogate, char lowSurrogate) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   559
        int codePoint =
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   560
            ((highSurrogate - 0xd800) << 10)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   561
                + (lowSurrogate - 0xdc00)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   562
                + 0x10000;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   563
        return codePoint;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   564
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   565
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   566
     * Return the unicode code point represented by the char.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   567
     * A bit of a dummy method, since all it does is return the char,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   568
     * but as an int value.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   569
     * <p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   570
     * This is not a public API.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   571
     * @param ch the char.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   572
     * @xsl.usage internal
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   573
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   574
    static int toCodePoint(char ch) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   575
        int codePoint = ch;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   576
        return codePoint;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   577
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   578
17533
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   579
    private final static EncodingInfos _encodingInfos = new EncodingInfos();
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   580
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   581
}