1 /**
2 *
3 * Copyright 2006 The Apache Software Foundation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * 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
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79 package org.apache.geronimo.system.configuration;
80
81 /**
82 * Provides information about encodings. Depends on the Java runtime
83 * to provides writers for the different encodings, but can be used
84 * to override encoding names and provide the last printable character
85 * for each encoding.
86 *
87 * @version $Id: Encodings.java 410741 2006-06-01 04:35:48Z jsisson $
88 * @author <a href="mailto:arkin@intalio.com">Assaf Arkin</a>
89 */
90 public class Encodings
91 {
92
93
94 /**
95 * The last printable character for unknown encodings.
96 */
97 static final int DefaultLastPrintable = 0x7F;
98
99 /**
100 * @param encoding a MIME charset name, or null.
101 */
102 static EncodingInfo getEncodingInfo(String encoding) {
103 if (encoding == null)
104 return new EncodingInfo(null, DefaultLastPrintable);
105 for (int i = 0; i < _encodings.length; i++) {
106 if (_encodings[i].name.equalsIgnoreCase(encoding))
107 return _encodings[i];
108 }
109 return new SieveEncodingInfo(encoding, DefaultLastPrintable);
110 }
111
112 static final String JIS_DANGER_CHARS
113 = "\\\u007e\u007f\u00a2\u00a3\u00a5\u00ac"
114 +"\u2014\u2015\u2016\u2026\u203e\u203e\u2225\u222f\u301c"
115 +"\uff3c\uff5e\uffe0\uffe1\uffe2\uffe3";
116
117 /**
118 * Constructs a list of all the supported encodings.
119 */
120 private static final EncodingInfo[] _encodings = new EncodingInfo[] {
121 new EncodingInfo("ASCII", 0x7F),
122 new EncodingInfo("US-ASCII", 0x7F),
123 new EncodingInfo("ISO-8859-1", 0xFF),
124 new EncodingInfo("ISO-8859-2", 0xFF),
125 new EncodingInfo("ISO-8859-3", 0xFF),
126 new EncodingInfo("ISO-8859-4", 0xFF),
127 new EncodingInfo("ISO-8859-5", 0xFF),
128 new EncodingInfo("ISO-8859-6", 0xFF),
129 new EncodingInfo("ISO-8859-7", 0xFF),
130 new EncodingInfo("ISO-8859-8", 0xFF),
131 new EncodingInfo("ISO-8859-9", 0xFF),
132 /**
133 * Does JDK's converter supprt surrogates?
134 * A Java encoding name "UTF-8" is suppoted by JDK 1.2 or later.
135 */
136 new EncodingInfo("UTF-8", "UTF8", 0x10FFFF),
137 /**
138 * JDK 1.1 supports "Shift_JIS" as an alias of "SJIS".
139 * But JDK 1.2 treats "Shift_JIS" as an alias of "MS932".
140 * The JDK 1.2's behavior is invalid against IANA registrations.
141 */
142 new SieveEncodingInfo("Shift_JIS", "SJIS", 0x7F, JIS_DANGER_CHARS),
143 /**
144 * "MS932" is supported by JDK 1.2 or later.
145 */
146 new SieveEncodingInfo("Windows-31J", "MS932", 0x7F, JIS_DANGER_CHARS),
147 new SieveEncodingInfo("EUC-JP", null, 0x7F, JIS_DANGER_CHARS),
148 new SieveEncodingInfo("ISO-2022-JP", null, 0x7F, JIS_DANGER_CHARS),
149 };
150 }