ResourceBundleWrapper.java
8.17 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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.agl.impl;
import com.adobe.agl.impl.ICUDebug;
import com.adobe.agl.util.ULocale;
import com.adobe.agl.util.UResourceBundle;
import java.io.BufferedInputStream;
import java.io.InputStream;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.*;
public class ResourceBundleWrapper
extends UResourceBundle {
private ResourceBundle bundle = null;
private String localeID = null;
private String baseName = null;
private Vector keys = null;
private static final boolean DEBUG = ICUDebug.enabled("resourceBundleWrapper");
private ResourceBundleWrapper(ResourceBundle bundle) {
this.bundle = bundle;
}
protected Object handleGetObject(String aKey) {
Object obj = null;
for (ResourceBundleWrapper current = this; current != null; current = (ResourceBundleWrapper)current.getParent()) {
try {
obj = current.bundle.getObject(aKey);
break;
}
catch (MissingResourceException ex) {
continue;
}
}
if (obj == null) {
throw new MissingResourceException("Can't find resource for bundle " + this.baseName + ", key " + aKey, this.getClass().getName(), aKey);
}
return obj;
}
public Enumeration getKeys() {
return this.keys.elements();
}
private void initKeysVector() {
this.keys = new Vector();
for (ResourceBundleWrapper current = this; current != null; current = (ResourceBundleWrapper)current.getParent()) {
Enumeration<String> e = current.bundle.getKeys();
while (e.hasMoreElements()) {
String elem = e.nextElement();
if (this.keys.contains(elem)) continue;
this.keys.add(elem);
}
}
}
protected String getLocaleID() {
return this.localeID;
}
protected String getBaseName() {
return this.bundle.getClass().getName().replace('.', '/');
}
public ULocale getULocale() {
return new ULocale(this.localeID);
}
public UResourceBundle getParent() {
return (UResourceBundle)this.parent;
}
public static UResourceBundle getBundleInstance(String baseName, String localeID, ClassLoader root, boolean disableFallback) {
UResourceBundle b = ResourceBundleWrapper.instantiateBundle(baseName, localeID, root, disableFallback);
if (b == null) {
String separator = "_";
if (baseName.indexOf(47) >= 0) {
separator = "/";
}
throw new MissingResourceException("Could not find the bundle " + baseName + separator + localeID, "", "");
}
return b;
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
* Loose catch block
* Enabled aggressive block sorting
* Enabled unnecessary exception pruning
* Enabled aggressive exception aggregation
* Lifted jumps to return sites
*/
protected static synchronized UResourceBundle instantiateBundle(String baseName, String localeID, ClassLoader root, boolean disableFallback) {
ResourceBundleWrapper b;
if (root == null) {
root = ClassLoader.getSystemClassLoader();
}
final ClassLoader cl = root;
String name = baseName;
ULocale defaultLocale = ULocale.getDefault();
if (localeID.length() != 0) {
name = name + "_" + localeID;
}
if ((b = (ResourceBundleWrapper)ResourceBundleWrapper.loadFromCache(cl, name, defaultLocale)) == null) {
block29 : {
ResourceBundleWrapper parent = null;
int i = localeID.lastIndexOf(95);
if (i != -1) {
String locName = localeID.substring(0, i);
parent = (ResourceBundleWrapper)ResourceBundleWrapper.loadFromCache(cl, baseName + "_" + locName, defaultLocale);
if (parent == null) {
parent = (ResourceBundleWrapper)ResourceBundleWrapper.instantiateBundle(baseName, locName, cl, disableFallback);
}
} else if (localeID.length() > 0 && (parent = (ResourceBundleWrapper)ResourceBundleWrapper.loadFromCache(cl, baseName, defaultLocale)) == null) {
parent = (ResourceBundleWrapper)ResourceBundleWrapper.instantiateBundle(baseName, "", cl, disableFallback);
}
try {
Class cls = cl.loadClass(name);
ResourceBundle bx = (ResourceBundle)cls.newInstance();
b = new ResourceBundleWrapper(bx);
if (parent != null) {
b.setParent(parent);
}
b.baseName = baseName;
b.localeID = localeID;
}
catch (ClassNotFoundException e) {
block28 : {
final String resName = name.replace('.', '/') + ".properties";
InputStream stream = (InputStream)AccessController.doPrivileged(new PrivilegedAction(){
public Object run() {
if (cl != null) {
return cl.getResourceAsStream(resName);
}
return ClassLoader.getSystemResourceAsStream(resName);
}
});
if (stream != null) {
stream = new BufferedInputStream(stream);
b = new ResourceBundleWrapper(new PropertyResourceBundle(stream));
if (parent != null) {
b.setParent(parent);
}
b.baseName = baseName;
b.localeID = localeID;
try {
stream.close();
}
catch (Exception ex) {}
break block28;
catch (Exception ex) {
try {
stream.close();
}
catch (Exception ex) {}
break block28;
catch (Throwable throwable) {
try {
stream.close();
throw throwable;
}
catch (Exception ex) {
// empty catch block
}
throw throwable;
}
}
}
}
if (b == null) {
String defaultName = defaultLocale.toString();
if (localeID.length() > 0 && localeID.indexOf(95) < 0 && defaultName.indexOf(localeID) == -1 && (b = (ResourceBundleWrapper)ResourceBundleWrapper.loadFromCache(cl, baseName + "_" + defaultName, defaultLocale)) == null) {
b = (ResourceBundleWrapper)ResourceBundleWrapper.instantiateBundle(baseName, defaultName, cl, disableFallback);
}
}
if (b == null) {
b = parent;
}
}
catch (Exception e) {
if (DEBUG) {
System.out.println("failure");
}
if (!DEBUG) break block29;
System.out.println(e);
}
}
ResourceBundleWrapper.addToCache(cl, name, defaultLocale, b);
}
if (b != null) {
b.initKeysVector();
return b;
}
if (!DEBUG) return b;
System.out.println("Returning null for " + baseName + "_" + localeID);
return b;
}
}