27 |
27 |
28 import java.security.AccessController; |
28 import java.security.AccessController; |
29 import java.security.PrivilegedAction; |
29 import java.security.PrivilegedAction; |
30 import java.security.PrivilegedActionException; |
30 import java.security.PrivilegedActionException; |
31 import java.security.PrivilegedExceptionAction; |
31 import java.security.PrivilegedExceptionAction; |
|
32 import java.util.Locale; |
|
33 import java.util.MissingResourceException; |
|
34 import java.util.PropertyResourceBundle; |
|
35 import java.util.ResourceBundle; |
32 |
36 |
33 /** |
37 /** |
34 * This class is duplicated for each subpackage so keep it in sync. |
38 * This class is duplicated for each subpackage so keep it in sync. |
35 * It is package private and therefore is not exposed as part of any API. |
39 * It is package private and therefore is not exposed as part of any API. |
36 * |
40 * |
139 return ris; |
143 return ris; |
140 } |
144 } |
141 }); |
145 }); |
142 } |
146 } |
143 |
147 |
|
148 /** |
|
149 * Gets a resource bundle using the specified base name, the default locale, and the caller's class loader. |
|
150 * @param bundle the base name of the resource bundle, a fully qualified class name |
|
151 * @return a resource bundle for the given base name and the default locale |
|
152 */ |
|
153 public static ResourceBundle getResourceBundle(String bundle) { |
|
154 return getResourceBundle(bundle, Locale.getDefault()); |
|
155 } |
|
156 |
|
157 /** |
|
158 * Gets a resource bundle using the specified base name and locale, and the caller's class loader. |
|
159 * @param bundle the base name of the resource bundle, a fully qualified class name |
|
160 * @param locale the locale for which a resource bundle is desired |
|
161 * @return a resource bundle for the given base name and locale |
|
162 */ |
|
163 public static ResourceBundle getResourceBundle(final String bundle, final Locale locale) { |
|
164 return AccessController.doPrivileged(new PrivilegedAction<ResourceBundle>() { |
|
165 public ResourceBundle run() { |
|
166 try { |
|
167 return PropertyResourceBundle.getBundle(bundle, locale); |
|
168 } catch (MissingResourceException e) { |
|
169 try { |
|
170 return PropertyResourceBundle.getBundle(bundle, new Locale("en", "US")); |
|
171 } catch (MissingResourceException e2) { |
|
172 throw new MissingResourceException( |
|
173 "Could not load any resource bundle by " + bundle, bundle, ""); |
|
174 } |
|
175 } |
|
176 } |
|
177 }); |
|
178 } |
|
179 |
144 static boolean getFileExists(final File f) { |
180 static boolean getFileExists(final File f) { |
145 return ((Boolean) |
181 return ((Boolean) |
146 AccessController.doPrivileged(new PrivilegedAction() { |
182 AccessController.doPrivileged(new PrivilegedAction() { |
147 public Object run() { |
183 public Object run() { |
148 return f.exists() ? Boolean.TRUE : Boolean.FALSE; |
184 return f.exists() ? Boolean.TRUE : Boolean.FALSE; |