use of java.util.ResourceBundle in project intellij-community by JetBrains.
the class YAMLBundle method getBundle.
private static ResourceBundle getBundle() {
ResourceBundle bundle = SoftReference.dereference(ourBundle);
if (bundle == null) {
bundle = ResourceBundle.getBundle(BUNDLE);
ourBundle = new SoftReference<>(bundle);
}
return bundle;
}
use of java.util.ResourceBundle in project zm-mailbox by Zimbra.
the class L10nUtil method getBundleKeySet.
/**
* Gets the list of keys for a given bundle for a given locale
* @param basename The name of the bundle (ex ZMsgs)
* @param lc The locale, null will use the default system locale
* @return A set of keys if any found, will not return null
*/
public static Set<String> getBundleKeySet(String basename, Locale lc) {
ResourceBundle rb;
try {
if (lc == null) {
lc = Locale.getDefault();
}
rb = ResourceBundle.getBundle(basename, lc, sMsgClassLoader);
Set<String> result = new HashSet<String>();
Enumeration<String> keysEnum = rb.getKeys();
while (keysEnum.hasMoreElements()) {
result.add(keysEnum.nextElement());
}
return result;
} catch (MissingResourceException e) {
// just return an empty set if we can't find the bundle
return Collections.emptySet();
}
}
use of java.util.ResourceBundle in project zm-mailbox by Zimbra.
the class L10nUtil method getMessage.
public static String getMessage(String basename, String key, Locale lc, Object... args) {
ResourceBundle rb;
try {
if (lc == null) {
lc = Locale.getDefault();
}
rb = ResourceBundle.getBundle(basename, lc, sMsgClassLoader);
String fmt = rb.getString(key);
if (fmt != null && args != null && args.length > 0) {
return MessageFormat.format(fmt, args);
} else {
return fmt;
}
} catch (MissingResourceException e) {
ZimbraLog.misc.warn("no resource bundle for base name " + basename + " can be found, " + "(locale=" + key + ")", e);
return null;
}
}
use of java.util.ResourceBundle in project voltdb by VoltDB.
the class BundleHandler method getString.
/**
* Retrieves, from the <code>ResourceBundle</code> object corresponding
* to the specified handle, the <code>String</code> value corresponding
* to the specified key. <code>null</code> is retrieved if either there
* is no <code>ResourceBundle</code> object for the handle or there is no
* <code>String</code> value for the specified key. <p>
*
* @param handle an <code>int</code> handle to a
* <code>ResourceBundle</code> object
* @param key A <code>String</code> key to a <code>String</code> value
* @return The String value correspoding to the specified handle and key.
*/
public static String getString(int handle, String key) {
ResourceBundle bundle;
String s;
synchronized (mutex) {
if (handle < 0 || handle >= bundleList.size() || key == null) {
bundle = null;
} else {
bundle = (ResourceBundle) bundleList.get(handle);
}
}
if (bundle == null) {
s = null;
} else {
try {
s = bundle.getString(key);
} catch (Exception e) {
s = null;
}
}
return s;
}
use of java.util.ResourceBundle in project tdi-studio-se by Talend.
the class ComponentsFactory method getComponentResourceBundle.
private ResourceBundle getComponentResourceBundle(IComponent currentComp, String source, String cachedPathSource, AbstractComponentsProvider provider) {
try {
AbstractComponentsProvider currentProvider = provider;
if (currentProvider == null) {
ComponentsProviderManager componentsProviderManager = ComponentsProviderManager.getInstance();
Collection<AbstractComponentsProvider> providers = componentsProviderManager.getProviders();
for (AbstractComponentsProvider curProvider : providers) {
String path = new Path(curProvider.getInstallationFolder().toString()).toPortableString();
if (source.startsWith(path)) {
// fix for TDI-19889 and TDI-20507 to get the correct component provider
if (cachedPathSource != null) {
if (path.contains(cachedPathSource)) {
currentProvider = curProvider;
break;
}
} else {
currentProvider = curProvider;
break;
}
}
}
}
String installPath = currentProvider.getInstallationFolder().toString();
String label = ComponentFilesNaming.getInstance().getBundleName(currentComp.getName(), installPath.substring(installPath.lastIndexOf(IComponentsFactory.COMPONENTS_INNER_FOLDER)));
if (currentProvider.isUseLocalProvider()) {
// if the component use local provider as storage (for user / ecosystem components)
// then get the bundle resource from the current main component provider.
// note: code here to review later, service like this shouldn't be used...
ResourceBundle bundle = null;
IBrandingService brandingService = (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
if (brandingService.isPoweredOnlyCamel()) {
bundle = currentProvider.getResourceBundle(label);
} else {
ITisLocalProviderService service = (ITisLocalProviderService) GlobalServiceRegister.getDefault().getService(ITisLocalProviderService.class);
bundle = service.getResourceBundle(label);
}
return bundle;
} else {
ResourceBundle bundle = ResourceBundle.getBundle(label, Locale.getDefault(), new ResClassLoader(currentProvider.getClass().getClassLoader()));
return bundle;
}
} catch (IOException e) {
ExceptionHandler.process(e);
}
return null;
}
Aggregations