throws MissingResourceException Locale locale = Locale.getDefault(); return (ListResourceBundle)ResourceBundle.getBundle(className, locale); return (ListResourceBundle)ResourceBundle.getBundle( className, new Locale("en", "US")); throw new MissingResourceException( "Could not load any resource bundles." + className, className, "");
/** * Get a plugin bundle using the supplied Locale and classLoader * * @param baseName The bundle base name. * @param locale The Locale. * @param classLoader The classLoader * @return The bundle JSON. */ private static @CheckForNull ResourceBundle getBundle(@Nonnull String baseName, @Nonnull Locale locale, @Nonnull ClassLoader classLoader) { try { return ResourceBundle.getBundle(baseName, locale, classLoader); } catch (MissingResourceException e) { // fall through and return null. logger.finer(e.getMessage()); } return null; }
/** * Returns a {@link ResourceBundle} corresponding to the given {@link Locale} package and resource class. Falls-back * on the ROOT {@link Locale}, if the {@code fallbackOnRoot} flag is true and the requested Locale is not available. * * @param locale the {@link Locale} for which the {@link ResourceBundle} is being requested * @param packagePath * @param resourceClass * @param fallbackOnRoot if true, and a {@link ResourceBundle} cannot be found for the requested {@link Locale}, falls * back on the ROOT {@link Locale} * @return a {@link ResourceBundle} corresponding to the given {@link Locale} package and resource class */ public static ResourceBundle getBundle( final Locale locale, final String packagePath, final Class<?> resourceClass, final boolean fallbackOnRoot ) { final GlobalMessageControl control = new GlobalMessageControl( fallbackOnRoot ); final String resourceName = control.toResourceName( control.toBundleName( packagePath, locale ), "properties" ); ResourceBundle bundle; try { bundle = ResourceBundle.getBundle( packagePath, locale, resourceClass.getClassLoader(), new GlobalMessageControl( fallbackOnRoot ) ); } catch ( final MissingResourceException e ) { final StringBuilder msg = new StringBuilder(); msg.append( "Unable to find properties file '" ).append( resourceName ).append( "': " ).append( e.toString() ); throw new MissingResourceException( msg.toString(), resourceClass.getName(), packagePath ); } return bundle; }
resourceBundle = ResourceBundle.getBundle("org.apache.jena.ext.xerces.impl.msg.XMLSchemaMessages"); if (resourceBundle == null) throw new MissingResourceException("Property file not found!", "org.apache.jena.ext.xerces.impl.msg.XMLSchemaMessages", key); String msg = resourceBundle.getString(key); if (msg == null) { msg = resourceBundle.getString("BadMessageKey"); throw new MissingResourceException(msg, "org.apache.jena.ext.xerces.impl.msg.XMLSchemaMessages", key); msg = java.text.MessageFormat.format(msg, args); } catch (Exception e) { msg = resourceBundle.getString("FormatFailed");
/** * Get the strings from our resource localization bundle. */ private synchronized static String getString(String key, Object v1, Object v2, Object v3) { String fmt = "no text found: \"" + key + "\""; if (!resinit) { try { resinit = true; resources = ResourceBundle.getBundle ("org.apache.river.tool.resources.preflistgen"); } catch (MissingResourceException e) { e.printStackTrace(); } } if (resources != null) { try { fmt = resources.getString(key); } catch (MissingResourceException e) { } } return MessageFormat.format(fmt, new Object[]{v1, v2, v3}); }
/** * Tries to format a message using the error code. */ public static String formattedMessage(String code, Object[] args) { if (code == null) return null; String message; try { message = MessageFormat.format(_bundle.getString(code), args); } catch (java.util.MissingResourceException e) { return MessageFormat.format(_bundle.getString("message.missing.resource"), new Object[] { e.getMessage() }); } catch (IllegalArgumentException e) { return MessageFormat.format(_bundle.getString("message.pattern.invalid"), new Object[] { e.getMessage() }); } return message; }
/** * <p>Gets a string message from the resource bundle for the given key. The message may contain * variables that will be substituted with the given arguments. Variables have the format:</p> * <dir> This message has two variables: {0} and {1} </dir> * * @param key The resource key * @param array An array of objects to place in corresponding variables * @return The message */ public String getString(String key, Object[] array) throws MissingResourceException { String msg = null; if (resourceProperties != null) { msg = resourceProperties.getProperty(key); } if (msg == null) { throw new MissingResourceException("Cannot find resource key \"" + key + "\" in base name " + basePropertyFileName, basePropertyFileName, key); } msg = MessageFormat.format(msg, array); return msg; }
resourceBundle = PropertyResourceBundle.getBundle("com.sun.org.apache.xerces.internal.impl.msg.XMLSchemaMessages"); if (resourceBundle == null) throw new MissingResourceException("Property file not found!", "com.sun.org.apache.xerces.internal.impl.msg.XMLSchemaMessages", key); String msg = resourceBundle.getString(key); if (msg == null) { msg = resourceBundle.getString("BadMessageKey"); throw new MissingResourceException(msg, "com.sun.org.apache.xerces.internal.impl.msg.XMLSchemaMessages", key); msg = java.text.MessageFormat.format(msg, args); } catch (Exception e) { msg = resourceBundle.getString("FormatFailed"); msg += " " + resourceBundle.getString(key);
@VisibleForTesting static String calculateString( final String packageName, final Locale locale, final String key, final Object[] parameters, final Class<?> resourceClass, final String bundleName, final boolean fallbackOnRoot ) throws MissingResourceException { try { ResourceBundle bundle = getBundle( locale, packageName + "." + bundleName, resourceClass, fallbackOnRoot ); String unformattedString = bundle.getString( key ); String string = MessageFormat.format( unformattedString, parameters ); return string; } catch ( IllegalArgumentException e ) { final StringBuilder msg = new StringBuilder(); msg.append( "Format problem with key=[" ).append( key ).append( "], locale=[" ).append( locale ).append( "], package=" ).append( packageName ).append( " : " ).append( e.toString() ); log.error( msg.toString() ); log.error( Const.getStackTracker( e ) ); throw new MissingResourceException( msg.toString(), packageName, key ); } }
private static synchronized String getString(String key) { if (!resinit) { try { resources = ResourceBundle.getBundle( "org.apache.river.tool.resources.checkser"); resinit = true; } catch (MissingResourceException e) { e.printStackTrace(); } } try { return resources.getString(key); } catch (MissingResourceException e) { return null; } }
if (cl != null) { try { return ResourceBundle.getBundle(resourceBundleName, Locale.getDefault(), cl); } catch (MissingResourceException ignored) { if (cl != null) { try { return ResourceBundle.getBundle(resourceBundleName, Locale.getDefault(), cl); } catch (MissingResourceException ignored) { throw new MissingResourceException("Failed to load the specified resource bundle \"" + resourceBundleName + "\"", resourceBundleName, null);
return (XResourceBundle) ResourceBundle.getBundle(resourceName, locale); return (XResourceBundle) ResourceBundle.getBundle( XSLT_RESOURCE, new Locale("en", "US")); throw new MissingResourceException( "Could not load any resource bundles.", className, "");
private static TResourceBundle getBundleImpl(String bundleName, Locale locale, ClassLoader loader) throws MissingResourceException { if (bundleName != null) { TResourceBundle bundle; if (!locale.equals(Locale.getDefault())) { String localeName = locale.toString(); if (localeName.length() > 0) { localeName = "_" + localeName; } bundle = handleGetBundle(bundleName, localeName, false); if (bundle != null) { return bundle; } } String localeName = Locale.getDefault().toString(); if (localeName.length() > 0) { localeName = "_" + localeName; } bundle = handleGetBundle(bundleName, localeName, true); if (bundle != null) { return bundle; } throw new MissingResourceException("Bundle not found", bundleName + '_' + locale, ""); } throw new NullPointerException(); }
protected String getFormattedMessage(Object... params) { if (formatResourceBundle != null) { try { return MessageFormat.format(formatResourceBundle.getString(messageCode), params); } catch (MissingResourceException e) { e.printStackTrace(); return params.toString(); } } else { return params.toString(); } }
/** * Initializes resource bundle with the JVM's default locale. * <p> * If the JVM's default locale doesn't have any resource file, will take the en_US resources instead. * </p> */ I18n() { ResourceBundle bundle; try { bundle = ResourceBundle.getBundle(I18n.RESOURCE_FILE, Locale.getDefault()); } catch (MissingResourceException mre) { logger.error("{}", mre.getMessage()); logger.info("Will use default bundle (en_US) instead"); bundle = ResourceBundle.getBundle(I18n.RESOURCE_FILE, Locale.US); } resources = bundle; }
public static TResourceBundle getBundle(String bundleName, Locale locale, ClassLoader loader) throws MissingResourceException { if (loader == null) { throw new NullPointerException(); } if (bundleName != null) { TResourceBundle bundle; if (!locale.equals(Locale.getDefault())) { bundle = handleGetBundle(bundleName, "_" + locale, false); if (bundle != null) { return bundle; } } bundle = handleGetBundle(bundleName, "_" + Locale.getDefault(), true); if (bundle != null) { return bundle; } throw new MissingResourceException("Bundle not found", bundleName + "_" + locale, ""); } throw new NullPointerException(); }
/** * Prepares all statements to be used. * * @throws DatabaseException thrown if there is an error preparing the * statements */ private void prepareStatements() throws DatabaseException { for (PreparedStatementCveDb key : values()) { PreparedStatement preparedStatement = null; try { final String statementString = statementBundle.getString(key.name()); if (key == INSERT_VULNERABILITY || key == INSERT_CPE) { preparedStatement = connection.prepareStatement(statementString, new String[]{"id"}); } else { preparedStatement = connection.prepareStatement(statementString); } } catch (SQLException ex) { throw new DatabaseException(ex); } catch (MissingResourceException ex) { if (!ex.getMessage().contains("key MERGE_PROPERTY")) { throw new DatabaseException(ex); } } if (preparedStatement != null) { preparedStatements.put(key, preparedStatement); } } }
/** * Gets a value from baseName_locale.properties file with the specified key. If not found * baseName_(locale).properties configurations, using {@link Latkes#getLocale()} instead. * * @param baseName base name of resource bundle, options as the following: * <ul> * <li>{@link Keys#LANGUAGE}</li> * </ul> * @param key the specified key * @param locale the specified locale * @return the value of the specified key */ private String get(final String baseName, final String key, final Locale locale) { if (!Keys.LANGUAGE.equals(baseName)) { final RuntimeException e = new RuntimeException("i18n resource [baseName=" + baseName + "] not found"); LOGGER.log(Level.ERROR, e.getMessage(), e); throw e; } try { return replaceVars(ResourceBundle.getBundle(baseName, locale).getString(key)); } catch (final MissingResourceException e) { LOGGER.log(Level.WARN, "{0}, get it from default locale [{1}]", e.getMessage(), Latkes.getLocale()); return replaceVars(ResourceBundle.getBundle(baseName, Latkes.getLocale()).getString(key)); } }
private static String lookup(ResourceBundle b, String key) { if (b == null || key == null) { throw new MissingResourceException(null, null, null); } return b.getString(key); }
public String getString(String key, boolean translate) { ResourceBundle bundle = translate ? resourceBundle : untranslatedResourceBundle; if (bundle == null) { if (translate) { bundle = resourceBundle = Platform.getResourceBundle(getBundle()); } else { String resourceName = getBaseURL().toString() + "plugin.properties"; try { InputStream inputStream = new URL(resourceName).openStream(); bundle = untranslatedResourceBundle = new PropertyResourceBundle(inputStream); inputStream.close(); } catch (IOException ioException) { throw new MissingResourceException("Missing properties: " + resourceName, getClass().getName(), "plugin.properties"); } } } return bundle.getString(key); }