jdk/src/solaris/classes/sun/nio/cs/ext/CompoundTextSupport.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2001-2005 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.nio.cs.ext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.nio.charset.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
final class CompoundTextSupport {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    private static final class ControlSequence {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
        final int hash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
        final byte[] escSequence;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        final byte[] encoding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        ControlSequence(byte[] escSequence) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
            this(escSequence, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        ControlSequence(byte[] escSequence, byte[] encoding) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
            if (escSequence == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
                throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
            this.escSequence = escSequence;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
            this.encoding = encoding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
            int hash = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            int length = escSequence.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            for (int i = 0; i < escSequence.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                hash += (((int)escSequence[i]) & 0xff) << (i % 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            if (encoding != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                for (int i = 0; i < encoding.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                    hash += (((int)encoding[i]) & 0xff) << (i % 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                length += 2 /* M L */ + encoding.length + 1 /* 0x02 */;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            this.hash = hash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            if (MAX_CONTROL_SEQUENCE_LEN < length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                MAX_CONTROL_SEQUENCE_LEN = length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            if (this == obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            if (!(obj instanceof ControlSequence)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            ControlSequence rhs = (ControlSequence)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            if (escSequence != rhs.escSequence) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                if (escSequence.length != rhs.escSequence.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                for (int i = 0; i < escSequence.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                    if (escSequence[i] != rhs.escSequence[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            if (encoding != rhs.encoding) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                if (encoding == null || rhs.encoding == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                    encoding.length != rhs.encoding.length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                for (int i = 0; i < encoding.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                    if (encoding[i] != rhs.encoding[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            return hash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        ControlSequence concatenate(ControlSequence rhs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            if (encoding != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                    ("cannot concatenate to a non-standard charset escape " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                     "sequence");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            int len = escSequence.length + rhs.escSequence.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            byte[] newEscSequence = new byte[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            System.arraycopy(escSequence, 0, newEscSequence, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                             escSequence.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            System.arraycopy(rhs.escSequence, 0, newEscSequence,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                             escSequence.length, rhs.escSequence.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            return new ControlSequence(newEscSequence, rhs.encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    static int MAX_CONTROL_SEQUENCE_LEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * Maps a GL or GR escape sequence to an encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    private static final Map sequenceToEncodingMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * Indicates whether a particular encoding wants the high bit turned on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * or off.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    private static final Map highBitsMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * Maps an encoding to an escape sequence. Rather than manage two
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * converters in CharToByteCOMPOUND_TEXT, we output escape sequences which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * modify both GL and GR if necessary. This makes the output slightly less
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * efficient, but our code much simpler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    private static final Map encodingToSequenceMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * The keys of 'encodingToSequenceMap', sorted in preferential order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    private static final List encodings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        HashMap tSequenceToEncodingMap = new HashMap(33, 1.0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        HashMap tHighBitsMap = new HashMap(31, 1.0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        HashMap tEncodingToSequenceMap = new HashMap(21, 1.0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        ArrayList tEncodings = new ArrayList(21);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        if (!(isEncodingSupported("US-ASCII") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
              isEncodingSupported("ISO-8859-1")))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            throw new ExceptionInInitializerError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                ("US-ASCII and ISO-8859-1 unsupported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        ControlSequence leftAscii = // high bit off, leave off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            new ControlSequence(new byte[] { 0x1B, 0x28, 0x42 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        tSequenceToEncodingMap.put(leftAscii, "US-ASCII");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        tHighBitsMap.put(leftAscii, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            ControlSequence rightAscii = // high bit on, turn off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                new ControlSequence(new byte[] { 0x1B, 0x29, 0x42 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            tSequenceToEncodingMap.put(rightAscii, "US-ASCII");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            tHighBitsMap.put(rightAscii, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            ControlSequence rightHalf = // high bit on, leave on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                new ControlSequence(new byte[] { 0x1B, 0x2D, 0x41 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            tSequenceToEncodingMap.put(rightHalf, "ISO-8859-1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            tHighBitsMap.put(rightHalf, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            ControlSequence fullSet = leftAscii.concatenate(rightHalf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            tEncodingToSequenceMap.put("ISO-8859-1", fullSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            tEncodings.add("ISO-8859-1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        if (isEncodingSupported("ISO-8859-2")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            ControlSequence rightHalf = // high bit on, leave on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                new ControlSequence(new byte[] { 0x1B, 0x2D, 0x42 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            tSequenceToEncodingMap.put(rightHalf, "ISO-8859-2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            tHighBitsMap.put(rightHalf, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            ControlSequence fullSet = leftAscii.concatenate(rightHalf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            tEncodingToSequenceMap.put("ISO-8859-2", fullSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            tEncodings.add("ISO-8859-2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        if (isEncodingSupported("ISO-8859-3")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            ControlSequence rightHalf = // high bit on, leave on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                new ControlSequence(new byte[] { 0x1B, 0x2D, 0x43 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            tSequenceToEncodingMap.put(rightHalf, "ISO-8859-3");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            tHighBitsMap.put(rightHalf, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            ControlSequence fullSet = leftAscii.concatenate(rightHalf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            tEncodingToSequenceMap.put("ISO-8859-3", fullSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            tEncodings.add("ISO-8859-3");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        if (isEncodingSupported("ISO-8859-4")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            ControlSequence rightHalf = // high bit on, leave on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                new ControlSequence(new byte[] { 0x1B, 0x2D, 0x44 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            tSequenceToEncodingMap.put(rightHalf, "ISO-8859-4");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            tHighBitsMap.put(rightHalf, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            ControlSequence fullSet = leftAscii.concatenate(rightHalf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            tEncodingToSequenceMap.put("ISO-8859-4", fullSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            tEncodings.add("ISO-8859-4");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        if (isEncodingSupported("ISO-8859-5")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            ControlSequence rightHalf = // high bit on, leave on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                new ControlSequence(new byte[] { 0x1B, 0x2D, 0x4C });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            tSequenceToEncodingMap.put(rightHalf, "ISO-8859-5");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            tHighBitsMap.put(rightHalf, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            ControlSequence fullSet = leftAscii.concatenate(rightHalf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            tEncodingToSequenceMap.put("ISO-8859-5", fullSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            tEncodings.add("ISO-8859-5");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        if (isEncodingSupported("ISO-8859-6")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            ControlSequence rightHalf = // high bit on, leave on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                new ControlSequence(new byte[] { 0x1B, 0x2D, 0x47 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            tSequenceToEncodingMap.put(rightHalf, "ISO-8859-6");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            tHighBitsMap.put(rightHalf, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            ControlSequence fullSet = leftAscii.concatenate(rightHalf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            tEncodingToSequenceMap.put("ISO-8859-6", fullSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            tEncodings.add("ISO-8859-6");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        if (isEncodingSupported("ISO-8859-7")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            ControlSequence rightHalf = // high bit on, leave on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                new ControlSequence(new byte[] { 0x1B, 0x2D, 0x46 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            tSequenceToEncodingMap.put(rightHalf, "ISO-8859-7");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            tHighBitsMap.put(rightHalf, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            ControlSequence fullSet = leftAscii.concatenate(rightHalf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            tEncodingToSequenceMap.put("ISO-8859-7", fullSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            tEncodings.add("ISO-8859-7");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        if (isEncodingSupported("ISO-8859-8")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            ControlSequence rightHalf = // high bit on, leave on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                new ControlSequence(new byte[] { 0x1B, 0x2D, 0x48 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            tSequenceToEncodingMap.put(rightHalf, "ISO-8859-8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            tHighBitsMap.put(rightHalf, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            ControlSequence fullSet = leftAscii.concatenate(rightHalf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            tEncodingToSequenceMap.put("ISO-8859-8", fullSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            tEncodings.add("ISO-8859-8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        if (isEncodingSupported("ISO-8859-9")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            ControlSequence rightHalf = // high bit on, leave on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                new ControlSequence(new byte[] { 0x1B, 0x2D, 0x4D });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            tSequenceToEncodingMap.put(rightHalf, "ISO-8859-9");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            tHighBitsMap.put(rightHalf, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            ControlSequence fullSet = leftAscii.concatenate(rightHalf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            tEncodingToSequenceMap.put("ISO-8859-9", fullSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            tEncodings.add("ISO-8859-9");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        if (isEncodingSupported("JIS_X0201")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            ControlSequence glLeft = // high bit off, leave off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                new ControlSequence(new byte[] { 0x1B, 0x28, 0x4A });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            ControlSequence glRight = // high bit off, turn on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                new ControlSequence(new byte[] { 0x1B, 0x28, 0x49 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            ControlSequence grLeft = // high bit on, turn off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                new ControlSequence(new byte[] { 0x1B, 0x29, 0x4A });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            ControlSequence grRight = // high bit on, leave on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                new ControlSequence(new byte[] { 0x1B, 0x29, 0x49 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            tSequenceToEncodingMap.put(glLeft, "JIS_X0201");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            tSequenceToEncodingMap.put(glRight, "JIS_X0201");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            tSequenceToEncodingMap.put(grLeft, "JIS_X0201");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            tSequenceToEncodingMap.put(grRight, "JIS_X0201");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            tHighBitsMap.put(glLeft, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            tHighBitsMap.put(glRight, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            tHighBitsMap.put(grLeft, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            tHighBitsMap.put(grRight, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            ControlSequence fullSet = glLeft.concatenate(grRight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            tEncodingToSequenceMap.put("JIS_X0201", fullSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            tEncodings.add("JIS_X0201");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        if (isEncodingSupported("X11GB2312")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            ControlSequence leftHalf =  // high bit off, leave off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                new ControlSequence(new byte[] { 0x1B, 0x24, 0x28, 0x41 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            ControlSequence rightHalf = // high bit on, turn off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                new ControlSequence(new byte[] { 0x1B, 0x24, 0x29, 0x41 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            tSequenceToEncodingMap.put(leftHalf, "X11GB2312");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            tSequenceToEncodingMap.put(rightHalf, "X11GB2312");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            tHighBitsMap.put(leftHalf, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            tHighBitsMap.put(rightHalf, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            tEncodingToSequenceMap.put("X11GB2312", leftHalf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            tEncodings.add("X11GB2312");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        if (isEncodingSupported("x-JIS0208")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            ControlSequence leftHalf = // high bit off, leave off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                new ControlSequence(new byte[] { 0x1B, 0x24, 0x28, 0x42 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            ControlSequence rightHalf = // high bit on, turn off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                new ControlSequence(new byte[] { 0x1B, 0x24, 0x29, 0x42 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            tSequenceToEncodingMap.put(leftHalf, "x-JIS0208");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            tSequenceToEncodingMap.put(rightHalf, "x-JIS0208");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            tHighBitsMap.put(leftHalf, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            tHighBitsMap.put(rightHalf, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            tEncodingToSequenceMap.put("x-JIS0208", leftHalf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            tEncodings.add("x-JIS0208");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        if (isEncodingSupported("X11KSC5601")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            ControlSequence leftHalf = // high bit off, leave off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                new ControlSequence(new byte[] { 0x1B, 0x24, 0x28, 0x43 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            ControlSequence rightHalf = // high bit on, turn off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                new ControlSequence(new byte[] { 0x1B, 0x24, 0x29, 0x43 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            tSequenceToEncodingMap.put(leftHalf, "X11KSC5601");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            tSequenceToEncodingMap.put(rightHalf, "X11KSC5601");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            tHighBitsMap.put(leftHalf, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            tHighBitsMap.put(rightHalf, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            tEncodingToSequenceMap.put("X11KSC5601", leftHalf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            tEncodings.add("X11KSC5601");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        // Encodings not listed in Compound Text Encoding spec
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        // Esc seq: -b
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        if (isEncodingSupported("ISO-8859-15")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            ControlSequence rightHalf = // high bit on, leave on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                new ControlSequence(new byte[] { 0x1B, 0x2D, 0x62 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            tSequenceToEncodingMap.put(rightHalf, "ISO-8859-15");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            tHighBitsMap.put(rightHalf, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            ControlSequence fullSet = leftAscii.concatenate(rightHalf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            tEncodingToSequenceMap.put("ISO-8859-15", fullSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            tEncodings.add("ISO-8859-15");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        // Esc seq: -T
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        if (isEncodingSupported("TIS-620")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            ControlSequence rightHalf = // high bit on, leave on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                new ControlSequence(new byte[] { 0x1B, 0x2D, 0x54 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            tSequenceToEncodingMap.put(rightHalf, "TIS-620");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            tHighBitsMap.put(rightHalf, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            ControlSequence fullSet = leftAscii.concatenate(rightHalf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            tEncodingToSequenceMap.put("TIS-620", fullSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            tEncodings.add("TIS-620");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        if (isEncodingSupported("JIS_X0212-1990")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            ControlSequence leftHalf = // high bit off, leave off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                new ControlSequence(new byte[] { 0x1B, 0x24, 0x28, 0x44 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            ControlSequence rightHalf = // high bit on, turn off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                new ControlSequence(new byte[] { 0x1B, 0x24, 0x29, 0x44 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            tSequenceToEncodingMap.put(leftHalf, "JIS_X0212-1990");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            tSequenceToEncodingMap.put(rightHalf, "JIS_X0212-1990");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            tHighBitsMap.put(leftHalf, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            tHighBitsMap.put(rightHalf, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            tEncodingToSequenceMap.put("JIS_X0212-1990", leftHalf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            tEncodings.add("JIS_X0212-1990");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        if (isEncodingSupported("X11CNS11643P1")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            ControlSequence leftHalf = // high bit off, leave off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                new ControlSequence(new byte[] { 0x1B, 0x24, 0x28, 0x47 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            ControlSequence rightHalf = // high bit on, turn off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                new ControlSequence(new byte[] { 0x1B, 0x24, 0x29, 0x47 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            tSequenceToEncodingMap.put(leftHalf, "X11CNS11643P1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            tSequenceToEncodingMap.put(rightHalf, "X11CNS11643P1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            tHighBitsMap.put(leftHalf, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            tHighBitsMap.put(rightHalf, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            tEncodingToSequenceMap.put("X11CNS11643P1", leftHalf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            tEncodings.add("X11CNS11643P1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        if (isEncodingSupported("X11CNS11643P2")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            ControlSequence leftHalf = // high bit off, leave off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                new ControlSequence(new byte[] { 0x1B, 0x24, 0x28, 0x48 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            ControlSequence rightHalf = // high bit on, turn off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                new ControlSequence(new byte[] { 0x1B, 0x24, 0x29, 0x48 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            tSequenceToEncodingMap.put(leftHalf, "X11CNS11643P2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            tSequenceToEncodingMap.put(rightHalf, "X11CNS11643P2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            tHighBitsMap.put(leftHalf, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            tHighBitsMap.put(rightHalf, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            tEncodingToSequenceMap.put("X11CNS11643P2", leftHalf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            tEncodings.add("X11CNS11643P2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        if (isEncodingSupported("X11CNS11643P3")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            ControlSequence leftHalf = // high bit off, leave off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                new ControlSequence(new byte[] { 0x1B, 0x24, 0x28, 0x49 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            ControlSequence rightHalf = // high bit on, turn off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                new ControlSequence(new byte[] { 0x1B, 0x24, 0x29, 0x49 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            tSequenceToEncodingMap.put(leftHalf, "X11CNS11643P3");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            tSequenceToEncodingMap.put(rightHalf, "X11CNS11643P3");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            tHighBitsMap.put(leftHalf, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            tHighBitsMap.put(rightHalf, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            tEncodingToSequenceMap.put("X11CNS11643P3", leftHalf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            tEncodings.add("X11CNS11643P3");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        // Esc seq: %/2??SUN-KSC5601.1992-3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        if (isEncodingSupported("x-Johab")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            // 0x32 looks wrong. It's copied from the Sun X11 Compound Text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            // support code. It implies that all Johab characters comprise two
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            // octets, which isn't true. Johab supports the ASCII/KS-Roman
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            // characters from 0x21-0x7E with single-byte representations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            ControlSequence johab = new ControlSequence(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                new byte[] { 0x1b, 0x25, 0x2f, 0x32 },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                new byte[] { 0x53, 0x55, 0x4e, 0x2d, 0x4b, 0x53, 0x43, 0x35,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                             0x36, 0x30, 0x31, 0x2e, 0x31, 0x39, 0x39, 0x32,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                             0x2d, 0x33 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            tSequenceToEncodingMap.put(johab, "x-Johab");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            tEncodingToSequenceMap.put("x-Johab", johab);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            tEncodings.add("x-Johab");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        // Esc seq: %/2??SUN-BIG5-1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        if (isEncodingSupported("Big5")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            // 0x32 looks wrong. It's copied from the Sun X11 Compound Text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            // support code. It implies that all Big5 characters comprise two
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            // octets, which isn't true. Big5 supports the ASCII/CNS-Roman
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            // characters from 0x21-0x7E with single-byte representations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            ControlSequence big5 = new ControlSequence(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                new byte[] { 0x1b, 0x25, 0x2f, 0x32 },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                new byte[] { 0x53, 0x55, 0x4e, 0x2d, 0x42, 0x49, 0x47, 0x35,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                             0x2d, 0x31 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            tSequenceToEncodingMap.put(big5, "Big5");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            tEncodingToSequenceMap.put("Big5", big5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            tEncodings.add("Big5");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        sequenceToEncodingMap =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            Collections.unmodifiableMap(tSequenceToEncodingMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        highBitsMap = Collections.unmodifiableMap(tHighBitsMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        encodingToSequenceMap =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            Collections.unmodifiableMap(tEncodingToSequenceMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        encodings = Collections.unmodifiableList(tEncodings);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    private static boolean isEncodingSupported(String encoding) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            if (Charset.isSupported(encoding))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        } catch (IllegalArgumentException x) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        return (getDecoder(encoding) != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                getEncoder(encoding) != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    // For Decoder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    static CharsetDecoder getStandardDecoder(byte[] escSequence) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        return getNonStandardDecoder(escSequence, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    static boolean getHighBit(byte[] escSequence) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        Boolean bool = (Boolean)highBitsMap.get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            (new ControlSequence(escSequence));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        return (bool == Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    static CharsetDecoder getNonStandardDecoder(byte[] escSequence,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                                                       byte[] encoding) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        return getDecoder((String)sequenceToEncodingMap.get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            (new ControlSequence(escSequence, encoding)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    static CharsetDecoder getDecoder(String enc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        if (enc == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        Charset cs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            cs = Charset.forName(enc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            Class cls;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                cls = Class.forName("sun.awt.motif." + enc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            } catch (ClassNotFoundException ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                cs = (Charset)cls.newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            } catch (InstantiationException ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            } catch (IllegalAccessException ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            return cs.newDecoder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        } catch (UnsupportedOperationException e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    // For Encoder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    static byte[] getEscapeSequence(String encoding) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        ControlSequence seq = (ControlSequence)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            encodingToSequenceMap.get(encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        if (seq != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            return seq.escSequence;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    static byte[] getEncoding(String encoding) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        ControlSequence seq = (ControlSequence)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            encodingToSequenceMap.get(encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        if (seq != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            return seq.encoding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    static List getEncodings() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        return encodings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    static CharsetEncoder getEncoder(String enc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        if (enc == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        Charset cs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            cs = Charset.forName(enc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            Class cls;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                cls = Class.forName("sun.awt.motif." + enc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            } catch (ClassNotFoundException ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                cs = (Charset)cls.newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            } catch (InstantiationException ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            } catch (IllegalAccessException ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            return cs.newEncoder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        } catch (Throwable e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    // Not an instantiable class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    private CompoundTextSupport() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
}