jaxp/src/com/sun/org/apache/xml/internal/serializer/Encodings.java
author joehw
Tue, 29 Jul 2014 20:52:36 -0700
changeset 25834 aba3efbf4ec5
parent 25264 040625ce9b72
permissions -rw-r--r--
8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer. 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
/*
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     2
 * reserved comment block
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
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
/*
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     6
 * Copyright 1999-2004 The Apache Software Foundation.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     7
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     8
 * Licensed under the Apache License, Version 2.0 (the "License");
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     9
 * you may not use this file except in compliance with the License.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    10
 * You may obtain a copy of the License at
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    11
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    12
 *     http://www.apache.org/licenses/LICENSE-2.0
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    13
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    14
 * Unless required by applicable law or agreed to in writing, software
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    15
 * distributed under the License is distributed on an "AS IS" BASIS,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    17
 * See the License for the specific language governing permissions and
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    18
 * limitations under the License.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    19
 */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    20
/*
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    21
 * $Id: Encodings.java,v 1.3 2005/09/28 13:49:04 pvedula Exp $
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    22
 */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    23
package com.sun.org.apache.xml.internal.serializer;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    24
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    25
import java.io.InputStream;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    26
import java.io.OutputStream;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    27
import java.io.OutputStreamWriter;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    28
import java.io.UnsupportedEncodingException;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    29
import java.io.Writer;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    30
import java.io.BufferedWriter;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    31
import java.net.URL;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    32
import java.util.Enumeration;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    33
import java.util.HashMap;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    34
import java.util.Properties;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    35
import java.util.StringTokenizer;
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
    36
import java.io.IOException;
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
    37
import java.net.MalformedURLException;
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
    38
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
    39
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
    40
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
    41
import java.util.Collections;
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
    42
import java.util.Map;
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
    43
import java.util.Map.Entry;
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    44
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
    45
import com.sun.org.apache.xalan.internal.utils.SecuritySupport;
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    46
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    47
/**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    48
 * Provides information about encodings. Depends on the Java runtime
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    49
 * to provides writers for the different encodings, but can be used
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    50
 * to override encoding names and provide the last printable character
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    51
 * for each encoding.
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
 * @author <a href="mailto:arkin@intalio.com">Assaf Arkin</a>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    54
 */
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
public final class Encodings extends Object
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
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
     * The last printable character for unknown encodings.
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
    private static final int m_defaultLastPrintable = 0x7F;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    63
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
     * Standard filename for properties file with encodings data.
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
    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
    68
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
     * Standard filename for properties file with encodings data.
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
    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
    73
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    74
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    75
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    76
     * Returns a writer for the specified encoding based on
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    77
     * an output stream.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    78
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    79
     * @param output The output stream
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    80
     * @param encoding The encoding
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    81
     * @return A suitable writer
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    82
     * @throws UnsupportedEncodingException There is no convertor
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    83
     *  to support this encoding
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    84
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    85
    static Writer getWriter(OutputStream output, String encoding)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    86
        throws UnsupportedEncodingException
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    87
    {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    88
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
    89
        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
    90
        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
    91
            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
    92
                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
    93
                        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
    94
            } 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
    95
                // keep trying
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    96
            }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    97
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    98
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
    99
        return new BufferedWriter(new OutputStreamWriter(output, encoding));
12005
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
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   103
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   104
     * Returns the last printable character for an unspecified
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   105
     * encoding.
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
     * @return the default size
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
    public static int getLastPrintable()
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
        return m_defaultLastPrintable;
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
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   116
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   117
     * Returns the EncodingInfo object for the specified
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   118
     * encoding.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   119
     * <p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   120
     * This is not a public API.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   121
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   122
     * @param encoding The encoding
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   123
     * @return The object that is used to determine if
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   124
     * characters are in the given encoding.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   125
     * @xsl.usage internal
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
    static EncodingInfo getEncodingInfo(String encoding)
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
        EncodingInfo ei;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   130
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   131
        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
   132
        ei = _encodingInfos.findEncoding(normalizedEncoding);
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   133
        if (ei == null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   134
            // 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
   135
            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
   136
                // 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
   137
                // 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
   138
                // (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
   139
                // 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
   140
                // 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
   141
                // 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
   142
                // 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
   143
                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
   144
                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
   145
                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
   146
                _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
   147
            } 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
   148
                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
   149
            }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   150
        }
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
        return ei;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   153
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   154
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   155
    /**
25834
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   156
     * 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
   157
     * serializer or not.
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   158
     *
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   159
     * @param encoding The encoding
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   160
     * @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
   161
     */
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   162
    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
   163
    {
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   164
        EncodingInfo ei;
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   165
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   166
        String normalizedEncoding = toUpperCaseFast(encoding);
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   167
        ei = _encodingInfos.findEncoding(normalizedEncoding);
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   168
        if (ei != null)
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   169
            return true;
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   170
        return false;
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   171
    }
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   172
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   173
    /**
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   174
     * A fast and cheap way to uppercase a String that is
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   175
     * only made of printable ASCII characters.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   176
     * <p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   177
     * This is not a public API.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   178
     * @param s a String of ASCII characters
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   179
     * @return an uppercased version of the input String,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   180
     * possibly the same String.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   181
     * @xsl.usage internal
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
    static private String toUpperCaseFast(final String s) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   184
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   185
        boolean different = false;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   186
        final int mx = s.length();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   187
                char[] chars = new char[mx];
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   188
        for (int i=0; i < mx; i++) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   189
                char ch = s.charAt(i);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   190
            // is the character a lower case ASCII one?
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   191
                if ('a' <= ch && ch <= 'z') {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   192
                // a cheap and fast way to uppercase that is good enough
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   193
                        ch = (char) (ch + ('A' - 'a'));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   194
                        different = true; // the uppercased String is different
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
                chars[i] = ch;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   197
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   198
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   199
        // A little optimization, don't call String.valueOf() if
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   200
        // the uppercased string is the same as the input string.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   201
        final String upper;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   202
        if (different)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   203
                upper = String.valueOf(chars);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   204
        else
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   205
                upper = s;
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
        return upper;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   208
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   209
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   210
    /** The default encoding, ISO style, ISO style.   */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   211
    static final String DEFAULT_MIME_ENCODING = "UTF-8";
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   212
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   213
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   214
     * Get the proper mime encoding.  From the XSLT recommendation: "The encoding
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   215
     * attribute specifies the preferred encoding to use for outputting the result
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   216
     * 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
   217
     * For other values, if the XSLT processor does not support the specified
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   218
     * 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
   219
     * 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
   220
     * whose name does not match the EncName production of the XML Recommendation
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   221
     * [XML]. If no encoding attribute is specified, then the XSLT processor should
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   222
     * use either UTF-8 or UTF-16."
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   223
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   224
     * @param encoding Reference to java-style encoding string, which may be null,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   225
     * in which case a default will be found.
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
     * @return The ISO-style encoding string, or null if failure.
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
    static String getMimeEncoding(String encoding)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   230
    {
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
        if (null == encoding)
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
            try
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   235
            {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   236
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   237
                // Get the default system character encoding.  This may be
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   238
                // incorrect if they passed in a writer, but right now there
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   239
                // seems to be no way to get the encoding from a writer.
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12458
diff changeset
   240
                encoding = SecuritySupport.getSystemProperty("file.encoding", "UTF8");
12005
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
                if (null != encoding)
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
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   245
                    /*
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   246
                    * 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
   247
                    * do that, then  convertJava2MimeEncoding will convert
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   248
                    * 8859_1 to "ISO-8859-1", which is not what we want,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   249
                    * 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
   250
                    * to convert everything to UTF-8.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   251
                    */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   252
                    String jencoding =
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   253
                        (encoding.equalsIgnoreCase("Cp1252")
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   254
                            || encoding.equalsIgnoreCase("ISO8859_1")
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   255
                            || encoding.equalsIgnoreCase("8859_1")
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   256
                            || encoding.equalsIgnoreCase("UTF8"))
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   257
                            ? DEFAULT_MIME_ENCODING
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   258
                            : convertJava2MimeEncoding(encoding);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   259
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   260
                    encoding =
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   261
                        (null != jencoding) ? jencoding : DEFAULT_MIME_ENCODING;
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
                else
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
                    encoding = DEFAULT_MIME_ENCODING;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   266
                }
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
            catch (SecurityException se)
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
                encoding = DEFAULT_MIME_ENCODING;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   271
            }
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
        else
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
            encoding = convertJava2MimeEncoding(encoding);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   276
        }
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
        return encoding;
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
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
     * 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
   283
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   284
     * @param encoding non-null reference to encoding string, java style.
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
     * @return ISO-style encoding string.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   287
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   288
    private static String convertJava2MimeEncoding(String encoding)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   289
    {
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
   290
        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
   291
             _encodingInfos.getEncodingFromJavaKey(toUpperCaseFast(encoding));
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   292
        if (null != enc)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   293
            return enc.name;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   294
        return encoding;
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
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
     * 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
   299
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   300
     * @param encoding non-null reference to encoding string, java style.
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
     * @return ISO-style encoding string.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   303
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   304
    public static String convertMime2JavaEncoding(String encoding)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   305
    {
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
   306
        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
   307
        return info != null ? info.javaName : encoding;
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   308
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   309
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
   310
    // 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
   311
    // 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
   312
    //
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 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
   314
        // 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
   315
        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
   316
        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
   317
        // 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
   318
        // 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
   319
        // 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
   320
        // 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
   321
        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
   322
                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
   323
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
        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
   325
            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
   326
        }
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
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
        // 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
   329
        // 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
   330
        private InputStream openEncodingsFileStream() throws MalformedURLException, IOException {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   331
            String urlString = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   332
            InputStream is = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   333
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
            try {
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12458
diff changeset
   335
                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
   336
            } catch (SecurityException e) {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   337
            }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   338
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   339
            if (urlString != null && urlString.length() > 0) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   340
                URL url = new URL(urlString);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   341
                is = url.openStream();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   342
            }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   343
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   344
            if (is == null) {
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   345
                is = SecuritySupport.getResourceAsStream(ENCODINGS_FILE);
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   346
            }
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
   347
            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
   348
        }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   349
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
   350
        // 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
   351
        //    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
   352
        // 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
   353
        private Properties loadProperties() throws MalformedURLException, IOException {
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   354
            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
   355
            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
   356
                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
   357
                    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
   358
                } 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
   359
                    // 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
   360
                    // 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
   361
                    // 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
   362
                    // 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
   363
                    // 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
   364
                    // 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
   365
                }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   366
            }
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
   367
            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
   368
        }
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   369
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
   370
        // 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
   371
        // 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
   372
        // 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
   373
        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
   374
            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
   375
            //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
   376
            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
   377
                // 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
   378
                //  "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
   379
                //  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
   380
                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
   381
                //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
   382
            }
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
            //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
   384
            //    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
   385
            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
   386
                    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
   387
            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
   388
            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
   389
                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
   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
            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
   392
        }
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
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
        // 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
   395
        // 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
   396
        // 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
        // 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
   398
        // 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
   399
        // 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
   400
        // 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
   401
        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
   402
            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
   403
                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
   404
            } 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
   405
                return null;
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   406
            }
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
   407
        }
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
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
        // 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
   410
        // 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
   411
        // 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
   412
        // 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
   413
        // 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
   414
        // 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
   415
        // 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
   416
        // 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
   417
        // 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
   418
        // 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
   419
        // 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
   420
        //
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
        // 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
   422
        // 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
   423
        // 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
   424
        // 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
   425
        // 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
   426
        // 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
   427
        // 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
   428
        //
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
        // 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
   430
        // 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
   431
        // 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
   432
        //
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
        // 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
   434
        // 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
   435
        // 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
   436
        // 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
   437
        //
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
        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
   439
            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
   440
            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
   441
            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
   442
                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
   443
                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
   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
            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
   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
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
         * 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
   450
         *
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
         * 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
   452
         * 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
   453
         * 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
   454
         */
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
        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
   456
            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
   457
                // 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
   458
                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
   459
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
                // 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
   461
                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
   462
                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
   463
                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
   464
                    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
   465
                    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
   466
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 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
   468
                    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
   469
                        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
   470
                        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
   471
                        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
   472
                            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
   473
                            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
   474
                            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
   475
                            _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
   476
                            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
   477
                                // 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
   478
                                //   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
   479
                                //   (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
   480
                                //   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
   481
                                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
   482
                                _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
   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
                            _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
   485
                        }
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
                    } 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
   487
                        // 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
   488
                        // recognized => this charset is not supported?
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   489
                    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   490
                }
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
   491
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
                // 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
   493
                // 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
   494
                // (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
   495
                //  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
   496
                //  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
   497
                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
   498
                    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
   499
                }
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
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.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
   502
                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
   503
            } 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
   504
                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
   505
            }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   506
        }
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
   507
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
        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
   509
            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
   510
            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
   511
                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
   512
            }
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
            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
   514
                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
   515
            }
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
            return info;
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   517
        }
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
   518
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
        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
   520
            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
   521
        }
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
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
        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
   524
            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
   525
        }
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
93a2cadbbd33 8008738: Issue in com.sun.org.apache.xml.internal.serializer.Encodings causes some JCK tests to fail intermittently
dfuchs
parents: 16953
diff changeset
   527
        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
   528
            _encodingDynamicTable.put(key, info);
12005
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
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   532
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   533
     * 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
   534
     * <p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   535
     * This is not a public API.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   536
     * @param ch the character to test
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   537
     * @xsl.usage internal
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   538
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   539
    static boolean isHighUTF16Surrogate(char ch) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   540
        return ('\uD800' <= ch && ch <= '\uDBFF');
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   541
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   542
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   543
     * 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
   544
     * <p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   545
     * This is not a public API.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   546
     * @param ch the character to test
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   547
     * @xsl.usage internal
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   548
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   549
    static boolean isLowUTF16Surrogate(char ch) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   550
        return ('\uDC00' <= ch && ch <= '\uDFFF');
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   551
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   552
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   553
     * Return the unicode code point represented by the high/low surrogate pair.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   554
     * <p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   555
     * This is not a public API.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   556
     * @param highSurrogate the high char of the high/low pair
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   557
     * @param lowSurrogate the low char of the high/low pair
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   558
     * @xsl.usage internal
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   559
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   560
    static int toCodePoint(char highSurrogate, char lowSurrogate) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   561
        int codePoint =
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   562
            ((highSurrogate - 0xd800) << 10)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   563
                + (lowSurrogate - 0xdc00)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   564
                + 0x10000;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   565
        return codePoint;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   566
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   567
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   568
     * Return the unicode code point represented by the char.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   569
     * 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
   570
     * but as an int value.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   571
     * <p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   572
     * This is not a public API.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   573
     * @param ch the char.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   574
     * @xsl.usage internal
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   575
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   576
    static int toCodePoint(char ch) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   577
        int codePoint = ch;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   578
        return codePoint;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   579
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   580
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
   581
    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
   582
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   583
}