ICULocaleService.java
12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.agl.impl;
import com.adobe.agl.impl.ICUResourceBundle;
import com.adobe.agl.impl.ICUService;
import com.adobe.agl.impl.LocaleUtility;
import com.adobe.agl.util.ULocale;
import java.util.*;
public class ICULocaleService
extends ICUService {
private ULocale fallbackLocale;
private String fallbackLocaleName;
public ICULocaleService(String name) {
super(name);
}
public Object get(ULocale locale, ULocale[] actualReturn) {
return this.get(locale, -1, actualReturn);
}
public Object get(ULocale locale, int kind, ULocale[] actualReturn) {
ICUService.Key key = this.createKey(locale, kind);
if (actualReturn == null) {
return this.getKey(key);
}
String[] temp = new String[1];
Object result = this.getKey(key, temp);
if (result != null) {
int n = temp[0].indexOf("/");
if (n >= 0) {
temp[0] = temp[0].substring(n + 1);
}
actualReturn[0] = new ULocale(temp[0]);
}
return result;
}
public ICUService.Factory registerObject(Object obj, ULocale locale) {
return this.registerObject(obj, locale, -1, true);
}
public ICUService.Factory registerObject(Object obj, ULocale locale, int kind) {
return this.registerObject(obj, locale, kind, true);
}
public ICUService.Factory registerObject(Object obj, ULocale locale, int kind, boolean visible) {
SimpleLocaleKeyFactory factory = new SimpleLocaleKeyFactory(obj, locale, kind, visible);
return this.registerFactory(factory);
}
public Locale[] getAvailableLocales() {
Set visIDs = this.getVisibleIDs();
Iterator iter = visIDs.iterator();
Locale[] locales = new Locale[visIDs.size()];
int n = 0;
while (iter.hasNext()) {
Locale loc = LocaleUtility.getLocaleFromName((String)iter.next());
locales[n++] = loc;
}
return locales;
}
public ULocale[] getAvailableULocales() {
Set visIDs = this.getVisibleIDs();
Iterator iter = visIDs.iterator();
ULocale[] locales = new ULocale[visIDs.size()];
int n = 0;
while (iter.hasNext()) {
locales[n++] = new ULocale((String)iter.next());
}
return locales;
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public String validateFallbackLocale() {
ULocale loc = ULocale.getDefault();
if (loc != this.fallbackLocale) {
ICULocaleService iCULocaleService = this;
synchronized (iCULocaleService) {
if (loc != this.fallbackLocale) {
this.fallbackLocale = loc;
this.fallbackLocaleName = loc.getBaseName();
this.clearServiceCache();
}
}
}
return this.fallbackLocaleName;
}
public ICUService.Key createKey(String id) {
return LocaleKey.createWithCanonicalFallback(id, this.validateFallbackLocale());
}
public ICUService.Key createKey(ULocale l, int kind) {
return LocaleKey.createWithCanonical(l, this.validateFallbackLocale(), kind);
}
public static class ICUResourceBundleFactory
extends LocaleKeyFactory {
protected final String bundleName;
public ICUResourceBundleFactory() {
this("com/adobe/agl/impl/data/icudt40b");
}
public ICUResourceBundleFactory(String bundleName) {
super(true);
this.bundleName = bundleName;
}
protected Set getSupportedIDs() {
return ICUResourceBundle.getFullLocaleNameSet(this.bundleName);
}
public void updateVisibleIDs(Map result) {
Set visibleIDs = ICUResourceBundle.getAvailableLocaleNameSet(this.bundleName);
Iterator iter = visibleIDs.iterator();
while (iter.hasNext()) {
String id = (String)iter.next();
result.put(id, this);
}
}
protected Object handleCreate(ULocale loc, int kind, ICUService service) {
return ICUResourceBundle.getBundleInstance(this.bundleName, loc);
}
public String toString() {
return super.toString() + ", bundle: " + this.bundleName;
}
}
public static class SimpleLocaleKeyFactory
extends LocaleKeyFactory {
private final Object obj;
private final String id;
private final int kind;
public SimpleLocaleKeyFactory(Object obj, ULocale locale, int kind, boolean visible) {
this(obj, locale, kind, visible, null);
}
public SimpleLocaleKeyFactory(Object obj, ULocale locale, int kind, boolean visible, String name) {
super(visible, name);
this.obj = obj;
this.id = locale.getBaseName();
this.kind = kind;
}
public Object create(ICUService.Key key, ICUService service) {
String keyID;
LocaleKey lkey = (LocaleKey)key;
if ((this.kind == -1 || this.kind == lkey.kind()) && this.id.equals(keyID = lkey.currentID())) {
return this.obj;
}
return null;
}
public void updateVisibleIDs(Map result) {
if (this.visible) {
result.put(this.id, this);
} else {
result.remove(this.id);
}
}
public String toString() {
StringBuffer buf = new StringBuffer(super.toString());
buf.append(", id: ");
buf.append(this.id);
buf.append(", kind: ");
buf.append(this.kind);
return buf.toString();
}
}
public static abstract class LocaleKeyFactory
implements ICUService.Factory {
protected final String name;
protected final boolean visible;
protected LocaleKeyFactory(boolean visible) {
this.visible = visible;
this.name = null;
}
protected LocaleKeyFactory(boolean visible, String name) {
this.visible = visible;
this.name = name;
}
public Object create(ICUService.Key key, ICUService service) {
if (this.handlesKey(key)) {
LocaleKey lkey = (LocaleKey)key;
int kind = lkey.kind();
ULocale uloc = lkey.currentLocale();
return this.handleCreate(uloc, kind, service);
}
return null;
}
protected boolean handlesKey(ICUService.Key key) {
if (key != null) {
String id = key.currentID();
Set supported = this.getSupportedIDs();
return supported.contains(id);
}
return false;
}
public void updateVisibleIDs(Map result) {
Set cache = this.getSupportedIDs();
Iterator iter = cache.iterator();
while (iter.hasNext()) {
String id = (String)iter.next();
if (this.visible) {
result.put(id, this);
continue;
}
result.remove(id);
}
}
public String getDisplayName(String id, ULocale locale) {
if (locale == null) {
return id;
}
ULocale loc = new ULocale(id);
return loc.getDisplayName(locale);
}
protected Object handleCreate(ULocale loc, int kind, ICUService service) {
return null;
}
protected Set getSupportedIDs() {
return Collections.EMPTY_SET;
}
public String toString() {
StringBuffer buf = new StringBuffer(super.toString());
if (this.name != null) {
buf.append(", name: ");
buf.append(this.name);
}
buf.append(", visible: ");
buf.append(this.visible);
return buf.toString();
}
}
public static class LocaleKey
extends ICUService.Key {
private int kind;
private int varstart;
private String primaryID;
private String fallbackID;
private String currentID;
public static LocaleKey createWithCanonicalFallback(String primaryID, String canonicalFallbackID) {
return LocaleKey.createWithCanonicalFallback(primaryID, canonicalFallbackID, -1);
}
public static LocaleKey createWithCanonicalFallback(String primaryID, String canonicalFallbackID, int kind) {
if (primaryID == null) {
return null;
}
if (primaryID.length() == 0) {
primaryID = "root";
}
String canonicalPrimaryID = ULocale.getName(primaryID);
return new LocaleKey(primaryID, canonicalPrimaryID, canonicalFallbackID, kind);
}
public static LocaleKey createWithCanonical(ULocale locale, String canonicalFallbackID, int kind) {
if (locale == null) {
return null;
}
String canonicalPrimaryID = locale.getName();
return new LocaleKey(canonicalPrimaryID, canonicalPrimaryID, canonicalFallbackID, kind);
}
protected LocaleKey(String primaryID, String canonicalPrimaryID, String canonicalFallbackID, int kind) {
super(primaryID);
this.kind = kind;
if (canonicalPrimaryID == null) {
this.primaryID = "";
} else {
this.primaryID = canonicalPrimaryID;
this.varstart = this.primaryID.indexOf(64);
}
this.fallbackID = this.primaryID.equals("") ? null : (canonicalFallbackID == null || this.primaryID.equals(canonicalFallbackID) ? "" : canonicalFallbackID);
this.currentID = this.varstart == -1 ? this.primaryID : this.primaryID.substring(0, this.varstart);
}
public String prefix() {
return this.kind == -1 ? null : Integer.toString(this.kind());
}
public int kind() {
return this.kind;
}
public String canonicalID() {
return this.primaryID;
}
public String currentID() {
return this.currentID;
}
public String currentDescriptor() {
String result = this.currentID();
if (result != null) {
StringBuffer buf = new StringBuffer();
if (this.kind != -1) {
buf.append(this.prefix());
}
buf.append('/');
buf.append(result);
if (this.varstart != -1) {
buf.append(this.primaryID.substring(this.varstart, this.primaryID.length()));
}
result = buf.toString();
}
return result;
}
public ULocale currentLocale() {
if (this.varstart == -1) {
return new ULocale(this.currentID);
}
return new ULocale(this.currentID + this.primaryID.substring(this.varstart));
}
public boolean fallback() {
int x = this.currentID.lastIndexOf(95);
if (x != -1) {
while (--x >= 0 && this.currentID.charAt(x) == '_') {
}
this.currentID = this.currentID.substring(0, x + 1);
return true;
}
if (this.fallbackID != null) {
if (this.fallbackID.length() == 0) {
this.currentID = "root";
this.fallbackID = null;
} else {
this.currentID = this.fallbackID;
this.fallbackID = "";
}
return true;
}
this.currentID = null;
return false;
}
public boolean isFallbackOf(String id) {
return LocaleUtility.isFallbackOf(this.canonicalID(), id);
}
}
}