51 |
48 |
52 instance = this; |
49 instance = this; |
53 |
50 |
54 } |
51 } |
55 |
52 |
56 private boolean initialized = false; |
|
57 |
|
58 // If the sun.nio.cs.map property is defined on the command line we won't |
|
59 // see it in the system-properties table until after the charset subsystem |
|
60 // has been initialized. We therefore delay the effect of this property |
|
61 // until after the JRE has completely booted. |
|
62 // |
|
63 // At the moment following values for this property are supported, property |
|
64 // value string is case insensitive. |
|
65 // |
|
66 // (1)"Windows-31J/Shift_JIS" |
|
67 // In 1.4.1 we added a correct implementation of the Shift_JIS charset |
|
68 // but in previous releases this charset name had been treated as an alias |
|
69 // for Windows-31J, aka MS932. Users who have existing code that depends |
|
70 // upon this alias can restore the previous behavior by defining this |
|
71 // property to have this value. |
|
72 // |
|
73 // (2)"x-windows-50221/ISO-2022-JP" |
|
74 // "x-windows-50220/ISO-2022-JP" |
|
75 // "x-windows-iso2022jp/ISO-2022-JP" |
|
76 // The charset ISO-2022-JP is a "standard based" implementation by default, |
|
77 // which supports ASCII, JIS_X_0201 and JIS_X_0208 mappings based encoding |
|
78 // and decoding only. |
|
79 // There are three Microsoft iso-2022-jp variants, namely x-windows-50220, |
|
80 // x-windows-50221 and x-windows-iso2022jp which behaves "slightly" differently |
|
81 // compared to the "standard based" implementation. See ISO2022_JP.java for |
|
82 // detailed description. Users who prefer the behavior of MS iso-2022-jp |
|
83 // variants should use these names explicitly instead of using "ISO-2022-JP" |
|
84 // and its aliases. However for those who need the ISO-2022-JP charset behaves |
|
85 // exactly the same as MS variants do, above properties can be defined to |
|
86 // switch. |
|
87 // |
|
88 // If we need to define other charset-alias mappings in the future then |
|
89 // this property could be further extended, the general idea being that its |
|
90 // value should be of the form |
|
91 // |
|
92 // new-charset-1/old-charset-1,new-charset-2/old-charset-2,... |
|
93 // |
|
94 // where each charset named to the left of a slash is intended to replace |
|
95 // (most) uses of the charset named to the right of the slash. |
|
96 // |
|
97 protected void init() { |
|
98 if (initialized) |
|
99 return; |
|
100 if (!jdk.internal.misc.VM.isBooted()) |
|
101 return; |
|
102 |
|
103 String map = getProperty("sun.nio.cs.map"); |
|
104 boolean sjisIsMS932 = false; |
|
105 boolean iso2022jpIsMS50221 = false; |
|
106 boolean iso2022jpIsMS50220 = false; |
|
107 boolean iso2022jpIsMSISO2022JP = false; |
|
108 if (map != null) { |
|
109 String[] maps = map.split(","); |
|
110 for (int i = 0; i < maps.length; i++) { |
|
111 if (maps[i].equalsIgnoreCase("Windows-31J/Shift_JIS")) { |
|
112 sjisIsMS932 = true; |
|
113 } else if (maps[i].equalsIgnoreCase("x-windows-50221/ISO-2022-JP")) { |
|
114 iso2022jpIsMS50221 = true; |
|
115 } else if (maps[i].equalsIgnoreCase("x-windows-50220/ISO-2022-JP")) { |
|
116 iso2022jpIsMS50220 = true; |
|
117 } else if (maps[i].equalsIgnoreCase("x-windows-iso2022jp/ISO-2022-JP")) { |
|
118 iso2022jpIsMSISO2022JP = true; |
|
119 } |
|
120 } |
|
121 } |
|
122 if (sjisIsMS932 && hasCharset("Shift_JIS")) { |
|
123 deleteCharset("Shift_JIS", |
|
124 new String[] { |
|
125 // IANA aliases |
|
126 "sjis", // historical |
|
127 "shift_jis", |
|
128 "shift-jis", |
|
129 "ms_kanji", |
|
130 "x-sjis", |
|
131 "csShiftJIS" |
|
132 }); |
|
133 deleteCharset("windows-31j", |
|
134 new String[] { |
|
135 "MS932", // JDK historical |
|
136 "windows-932", |
|
137 "csWindows31J" |
|
138 }); |
|
139 charset("Shift_JIS", "SJIS", |
|
140 new String[] { |
|
141 // IANA aliases |
|
142 "sjis" // JDK historical |
|
143 }); |
|
144 charset("windows-31j", "MS932", |
|
145 new String[] { |
|
146 "MS932", // JDK historical |
|
147 "windows-932", |
|
148 "csWindows31J", |
|
149 "shift-jis", |
|
150 "ms_kanji", |
|
151 "x-sjis", |
|
152 "csShiftJIS", |
|
153 // This alias takes precedence over the actual |
|
154 // Shift_JIS charset itself since aliases are always |
|
155 // resolved first, before looking up canonical names. |
|
156 "shift_jis" |
|
157 }); |
|
158 } |
|
159 if (iso2022jpIsMS50221 || |
|
160 iso2022jpIsMS50220 || |
|
161 iso2022jpIsMSISO2022JP) { |
|
162 deleteCharset("ISO-2022-JP", |
|
163 new String[] { |
|
164 "iso2022jp", |
|
165 "jis", |
|
166 "csISO2022JP", |
|
167 "jis_encoding", |
|
168 "csjisencoding" |
|
169 }); |
|
170 if (iso2022jpIsMS50221) { |
|
171 deleteCharset("x-windows-50221", |
|
172 new String[] { |
|
173 "cp50221", |
|
174 "ms50221" |
|
175 }); |
|
176 charset("x-windows-50221", "MS50221", |
|
177 new String[] { |
|
178 "cp50221", |
|
179 "ms50221", |
|
180 "iso-2022-jp", |
|
181 "iso2022jp", |
|
182 "jis", |
|
183 "csISO2022JP", |
|
184 "jis_encoding", |
|
185 "csjisencoding" |
|
186 }); |
|
187 } else if (iso2022jpIsMS50220) { |
|
188 deleteCharset("x-windows-50220", |
|
189 new String[] { |
|
190 "cp50220", |
|
191 "ms50220" |
|
192 }); |
|
193 charset("x-windows-50220", "MS50220", |
|
194 new String[] { |
|
195 "cp50220", |
|
196 "ms50220", |
|
197 "iso-2022-jp", |
|
198 "iso2022jp", |
|
199 "jis", |
|
200 "csISO2022JP", |
|
201 "jis_encoding", |
|
202 "csjisencoding" |
|
203 }); |
|
204 } else { |
|
205 deleteCharset("x-windows-iso2022jp", |
|
206 new String[] { |
|
207 "windows-iso2022jp" |
|
208 }); |
|
209 charset("x-windows-iso2022jp", "MSISO2022JP", |
|
210 new String[] { |
|
211 "windows-iso2022jp", |
|
212 "iso-2022-jp", |
|
213 "iso2022jp", |
|
214 "jis", |
|
215 "csISO2022JP", |
|
216 "jis_encoding", |
|
217 "csjisencoding" |
|
218 }); |
|
219 |
|
220 |
|
221 } |
|
222 } |
|
223 initialized = true; |
|
224 } |
|
225 |
|
226 private static String getProperty(String key) { |
|
227 // this method may be called during initialization of |
|
228 // system class loader and thus not using lambda |
|
229 return AccessController.doPrivileged( |
|
230 new PrivilegedAction<String>() { |
|
231 @Override |
|
232 public String run() { |
|
233 return System.getProperty(key); |
|
234 } |
|
235 }); |
|
236 } |
|
237 |
|
238 public static String[] aliasesFor(String charsetName) { |
53 public static String[] aliasesFor(String charsetName) { |
239 if (instance == null) |
54 if (instance == null) |
240 return null; |
55 return null; |
241 return instance.aliases(charsetName); |
56 return instance.aliases(charsetName); |
242 } |
57 } |