KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > system > configuration > Encodings


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /*
19  * This code has been borrowed from the Apache Xerces project. We're copying the code to
20  * keep from adding a dependency on Xerces in the Geronimo kernel.
21  */

22
23 package org.apache.geronimo.system.configuration;
24
25 /**
26  * Provides information about encodings. Depends on the Java runtime
27  * to provides writers for the different encodings, but can be used
28  * to override encoding names and provide the last printable character
29  * for each encoding.
30  *
31  * @version $Id: Encodings.java 482336 2006-12-04 20:12:19Z kevan $
32  * @author <a HREF="mailto:arkin@intalio.com">Assaf Arkin</a>
33  */

34 public class Encodings
35 {
36
37
38     /**
39      * The last printable character for unknown encodings.
40      */

41     static final int DefaultLastPrintable = 0x7F;
42
43     /**
44      * @param encoding a MIME charset name, or null.
45      */

46     static EncodingInfo getEncodingInfo(String JavaDoc encoding) {
47         if (encoding == null)
48             return new EncodingInfo(null, DefaultLastPrintable);
49         for (int i = 0; i < _encodings.length; i++) {
50             if (_encodings[i].name.equalsIgnoreCase(encoding))
51                 return _encodings[i];
52         }
53         return new SieveEncodingInfo(encoding, DefaultLastPrintable);
54     }
55
56     static final String JavaDoc JIS_DANGER_CHARS
57     = "\\\u007e\u007f\u00a2\u00a3\u00a5\u00ac"
58     +"\u2014\u2015\u2016\u2026\u203e\u203e\u2225\u222f\u301c"
59     +"\uff3c\uff5e\uffe0\uffe1\uffe2\uffe3";
60
61     /**
62      * Constructs a list of all the supported encodings.
63      */

64     private static final EncodingInfo[] _encodings = new EncodingInfo[] {
65         new EncodingInfo("ASCII", 0x7F),
66         new EncodingInfo("US-ASCII", 0x7F),
67         new EncodingInfo("ISO-8859-1", 0xFF),
68         new EncodingInfo("ISO-8859-2", 0xFF),
69         new EncodingInfo("ISO-8859-3", 0xFF),
70         new EncodingInfo("ISO-8859-4", 0xFF),
71         new EncodingInfo("ISO-8859-5", 0xFF),
72         new EncodingInfo("ISO-8859-6", 0xFF),
73         new EncodingInfo("ISO-8859-7", 0xFF),
74         new EncodingInfo("ISO-8859-8", 0xFF),
75         new EncodingInfo("ISO-8859-9", 0xFF),
76         /**
77          * Does JDK's converter supprt surrogates?
78          * A Java encoding name "UTF-8" is suppoted by JDK 1.2 or later.
79          */

80         new EncodingInfo("UTF-8", "UTF8", 0x10FFFF),
81         /**
82          * JDK 1.1 supports "Shift_JIS" as an alias of "SJIS".
83          * But JDK 1.2 treats "Shift_JIS" as an alias of "MS932".
84          * The JDK 1.2's behavior is invalid against IANA registrations.
85          */

86         new SieveEncodingInfo("Shift_JIS", "SJIS", 0x7F, JIS_DANGER_CHARS),
87         /**
88          * "MS932" is supported by JDK 1.2 or later.
89          */

90         new SieveEncodingInfo("Windows-31J", "MS932", 0x7F, JIS_DANGER_CHARS),
91         new SieveEncodingInfo("EUC-JP", null, 0x7F, JIS_DANGER_CHARS),
92         new SieveEncodingInfo("ISO-2022-JP", null, 0x7F, JIS_DANGER_CHARS),
93     };
94 }
95
Popular Tags