public DBManager() { ResourceBundle rb = PropertyResourceBundle.getBundle( "com.gint.app.bisisadmin.Config"); String driver = rb.getString("driver"); String URL = rb.getString("url"); String username = rb.getString("username"); String password = rb.getString("password"); try { Class.forName(driver); GenericObjectPool connectionPool = new GenericObjectPool(null); DriverManagerConnectionFactory connectionFactory = new DriverManagerConnectionFactory(URL, username, password); PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, false); poolingDataSource = new PoolingDataSource(connectionPool); } catch (Exception ex) { ex.printStackTrace(); } }
private void addData(FileOutputStream fos, PropertyResourceBundle bundle, PropertyResourceBundle backupBundle, String localeName, List <String> propertiesNames) throws IOException { String propertyName; String localizedString; addData(fos, localeName, true); Enumeration <String> en = bundle.getKeys(); for(int i=0;i<propertiesNames.size();i++) { String str = null; try { str = bundle.getString(propertiesNames.get(i)); } catch (MissingResourceException e) { if(backupBundle!=null) { str = backupBundle.getString(propertiesNames.get(i)); } } str = changeJavaPropertyCounter(str); addData(fos, str, true); // localized string as UNICODE } }
/** * Return a ref to a new or existing RefCapablePropertyResourceBundle, * or throw a MissingResourceException. */ static private RefCapablePropertyResourceBundle getRef(String baseName, ResourceBundle rb, ClassLoader loader) { if (!(rb instanceof PropertyResourceBundle)) throw new MissingResourceException( "Found a Resource Bundle, but it is a " + rb.getClass().getName(), PropertyResourceBundle.class.getName(), null); if (allBundles.containsKey(rb)) return (RefCapablePropertyResourceBundle) allBundles.get(rb); RefCapablePropertyResourceBundle newPRAFP = new RefCapablePropertyResourceBundle(baseName, (PropertyResourceBundle) rb, loader); allBundles.put(rb, newPRAFP); return newPRAFP; }
/** * Gets a resource bundle using the specified base name and locale, and the caller's class loader. * @param bundle the base name of the resource bundle, a fully qualified class name * @param locale the locale for which a resource bundle is desired * @return a resource bundle for the given base name and locale */ public static ResourceBundle getResourceBundle(final String bundle, final Locale locale) { return AccessController.doPrivileged(new PrivilegedAction<ResourceBundle>() { public ResourceBundle run() { try { return PropertyResourceBundle.getBundle(bundle, locale); } catch (MissingResourceException e) { try { return PropertyResourceBundle.getBundle(bundle, new Locale("en", "US")); } catch (MissingResourceException e2) { throw new MissingResourceException( "Could not load any resource bundle by " + bundle, bundle, ""); } } } }); }
public Bug6204853() { String srcDir = System.getProperty("test.src", "."); try (FileInputStream fis8859_1 = new FileInputStream(new File(srcDir, "Bug6204853.properties")); FileInputStream fisUtf8 = new FileInputStream(new File(srcDir, "Bug6204853_Utf8.properties")); InputStreamReader isrUtf8 = new InputStreamReader(fisUtf8, "UTF-8")) { PropertyResourceBundle bundleUtf8 = new PropertyResourceBundle(isrUtf8); PropertyResourceBundle bundle = new PropertyResourceBundle(fis8859_1); String[] arrayUtf8 = createKeyValueArray(bundleUtf8); String[] array = createKeyValueArray(bundle); if (!Arrays.equals(arrayUtf8, array)) { throw new RuntimeException("PropertyResourceBundle constructed from a UTF-8 encoded property file is not equal to the one constructed from ISO-8859-1 encoded property file."); } } catch (FileNotFoundException fnfe) { throw new RuntimeException(fnfe); } catch (IOException ioe) { throw new RuntimeException(ioe); } }
private final String[] createKeyValueArray(PropertyResourceBundle b) { List<String> keyValueList = new ArrayList<String>(); StringBuilder sb = new StringBuilder(); for (String key : b.keySet()) { sb.setLength(0); sb.append(key); sb.append(" = "); sb.append(b.getString(key)); keyValueList.add(sb.toString()); } String[] keyValueArray = keyValueList.toArray(new String[0]); Arrays.sort(keyValueArray); return keyValueArray; }
public static void initLabels() { // custom bundle to be able to read the UTF-8 Japanese property file String name = "Labels"; if (Env.INSTANCE.getAppliLanguage() != null) { switch (Env.INSTANCE.getAppliLanguage()) { case JAPANESE: name += "_ja_JP"; break; case FRENCH: name += "_fr_FR"; break; case GERMAN: name += "_de_DE"; break; default: break; } } name += ".properties"; final InputStream stream = Resources.class.getResourceAsStream(name); try { LABEL_BUNDLE = new PropertyResourceBundle(new InputStreamReader(stream, "UTF-8")); } catch (final Exception e) { LOGGER.error("Failed to load resource bundle", e); } }
public static PropertyResourceBundle newBundle(java.io.File propertiesFile) throws IOException { InputStream stream = new FileInputStream(propertiesFile); try { // stream = new FileInputStream(propertiesFile); return new PropertyResourceBundle(new InputStreamReader(stream, ENCODING)); // } catch (IOException e) { // // e.printStackTrace(); } finally { // try { stream.close(); // } catch (IOException e) { // } // if (stream != null) { // stream.close(); // } } }
public VirtualChestTranslation(VirtualChestPlugin plugin) { Locale locale = Locale.getDefault(); AssetManager assets = Sponge.getAssetManager(); logger = plugin.getLogger(); try { Asset asset = assets.getAsset(plugin, "i18n/" + locale.toString() + ".properties").orElse(assets. getAsset(plugin, "i18n/en_US.properties").orElseThrow(() -> new IOException(I18N_ERROR))); resourceBundle = new PropertyResourceBundle(new InputStreamReader(asset.getUrl().openStream(), Charsets.UTF_8)); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) throws IllegalAccessException, InstantiationException, IOException { if (LOGGER.isDebugEnabled()) { LOGGER.debug("New bundle: {}, locale {}", baseName, locale); } if (locale.equals(Locale.ROOT)) { //MCR-1064 fallback should be default language, if property key does not exist locale = defaultLocale; } String bundleName = baseName.substring(baseName.indexOf(':') + 1); String filename = CONTROL_HELPER.toBundleName(bundleName, locale) + ".properties"; try (MCRConfigurationInputStream propertyStream = new MCRConfigurationInputStream(filename)) { if (propertyStream.isEmpty()) { throw new MissingResourceException( "Can't find bundle for base name " + baseName + ", locale " + locale, bundleName + "_" + locale, // className ""); } return new PropertyResourceBundle(propertyStream); } }
private JmolResourceHandler() { String language = "en"; String country = ""; String localeString = GT.getLanguage(); // String localeString = System.getProperty("user.language"); if (localeString != null) { StringTokenizer st = new StringTokenizer(localeString, "_"); if (st.hasMoreTokens()) { language = st.nextToken(); } if (st.hasMoreTokens()) { country = st.nextToken(); } } Locale locale = new Locale(language, country); stringsResourceBundle = ResourceBundle.getBundle("org.openscience.jmol.app.jmolpanel.Properties.Jmol", locale); try { String t = "/org/openscience/jmol/app/jmolpanel/Properties/Jmol-resources.properties"; generalResourceBundle = new PropertyResourceBundle(getClass().getResourceAsStream(t)); } catch (IOException ex) { throw new RuntimeException(ex.toString()); } }
@Override public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) throws IllegalAccessException, InstantiationException, IOException { String bundleName = toBundleName(baseName, locale); String resourceName = toResourceName(bundleName, "properties"); final URL resourceURL = loader.getResource(resourceName); if (resourceURL == null) return null; BufferedReader in = new BufferedReader(new InputStreamReader(resourceURL.openStream(), StandardCharsets.UTF_8)); try { return new PropertyResourceBundle(in); } finally { in.close(); } }
void method6() throws Exception { String srcDir = System.getProperty("test.src", "."); try (FileInputStream fis8859_1 = new FileInputStream(new File(srcDir, "Bug6204853.properties")); FileInputStream fisUTF8 = new FileInputStream(new File(srcDir, "Bug6204853_Utf8.properties")); InputStreamReader isrutf8 = new InputStreamReader(fisUTF8, "UTF-8")) { PropertyResourceBundle bundleUtf8 = new PropertyResourceBundle(isrutf8); PropertyResourceBundle bundle = new PropertyResourceBundle(fis8859_1); String[] arrayUtf8 = {"1", "2", "3"}; String[] array = {"key1", "key2"}; if (!Arrays.equals(arrayUtf8, array)) { throw new RuntimeException("Error message"); } } catch (IOException ioe) { throw new RuntimeException(ioe); } }
@Override public String getString(String key) { try { String localeProp = configurationService.getLiderLocale(); if (localeProp != null && !localeProp.equalsIgnoreCase(lastLocaleProp)) { PropertyResourceBundle.clearCache(); lastLocaleProp = localeProp; } Locale targetLocale = localeProp.contains("-") || localeProp.contains("_") ? Locale.forLanguageTag(localeProp) : new Locale(localeProp); ResourceBundle resourceBundle = PropertyResourceBundle.getBundle(BUNDLE_NAME, targetLocale); return resourceBundle.getString(key); } catch (Exception e) { logger.error(e.getMessage(), e); return '!' + key + '!'; } }
/** * Provides an <CODE>Application</CODE> with a chance to perform any * initialisation. This implementation checks for the -help option. * Derived classes may extend the functionality. * @since TFP 1.0 */ protected void startUp () { if (helpOption.isPresent ()) { System.err.println ("Usage:\n java " + this.getClass ().getName () + Option.listOptions () + describeArguments ()); System.err.println (); System.err.println ("Options:"); Option.describeOptions (); System.exit (1); } // Load settings bundle if defined. try { settings = PropertyResourceBundle.getBundle (getClass ().getName ()); } catch (MissingResourceException error) { settings = null; } }
/** * Construct a JPEGImageWriteParam with the following state: tiling * is not supported, progressive mode is supported, initial * progressive mode is MODE_DISABLED, compression is supported, one * compression type named "JPEG" is supported and the default * compression quality is 0.75f. Compression type names and * compression quality descriptions are localized to the given * locale. * * @param locale the locale used for message localization */ public JPEGImageWriteParam(Locale locale) { super(locale); // Get localized compression type and compression quality // description strings for the given locale. messages = PropertyResourceBundle.getBundle ("javax/imageio/plugins/jpeg/MessagesBundle", locale); // Initialize inherited ImageWriter fields. canWriteTiles = false; canWriteProgressive = true; progressiveMode = MODE_DISABLED; canWriteCompressed = true; compressionTypes = new String[] { messages.getString("compression.types.jpeg") }; compressionType = compressionTypes[0]; compressionQuality = 0.75f; }
private ResourceBundle getBundleFromPropertiesFile(final String propertiesFileName) { try { final URL url = this.getClass().getClassLoader().getResource(propertiesFileName); if (url == null){ return null; } final InputStream inputStream = url.openStream(); if (inputStream == null) { return null; } else { return new PropertyResourceBundle(inputStream); } } catch (IllegalArgumentException iae) { return null; } catch (MissingResourceException mrex) { return null; } catch (IOException e) { return null; } }
public static void compareTwoTranslations(String langFile1, String langFile2) { int errors = 0; PropertyResourceBundle lang1 = getLanguageFile(langFile1 + ".properties"); PropertyResourceBundle lang2 = getLanguageFile(langFile2 + ".properties"); ArrayList<String> keys1 = new ArrayList<String>(); Enumeration<String> enum1 = lang1.getKeys(); while (enum1.hasMoreElements()) { keys1.add(enum1.nextElement()); } ArrayList<String> keys2 = new ArrayList<String>(); Enumeration<String> enum2 = lang2.getKeys(); while (enum2.hasMoreElements()) { keys2.add(enum2.nextElement()); } errors = errors + compareTwoTranslations(langFile1, keys1, keys2); errors = errors + compareTwoTranslations(langFile2, keys2, keys1); }
public WidgetColorPopOver(final ColorWidgetProperty color_prop, final Consumer<WidgetColor> colorChangeConsumer) { try { URL fxml = WidgetColorPopOver.class.getResource("WidgetColorPopOver.fxml"); InputStream iStream = WidgetColorPopOver.class.getResourceAsStream("messages.properties"); ResourceBundle bundle = new PropertyResourceBundle(iStream); FXMLLoader fxmlLoader = new FXMLLoader(fxml, bundle); Node content = (Node) fxmlLoader.load(); setContent(content); WidgetColorPopOverController controller = fxmlLoader.<WidgetColorPopOverController>getController(); controller.setInitialConditions(this, color_prop.getValue(), color_prop.getDefaultValue(), color_prop.getDescription(), colorChangeConsumer); } catch (IOException ex) { logger.log(Level.WARNING, "Unable to edit color.", ex); setContent(new Label("Unable to edit color.")); } }
public List<String> registerLocaleMessages(String prefix, String baseName, Locale locale, ClassLoader classLoader) { ArrayList<String> keys = new ArrayList<String>(); try { ResourceBundle bundle = PropertyResourceBundle.getBundle(baseName, locale, classLoader); Enumeration<String> enumKeys = bundle.getKeys(); while (enumKeys.hasMoreElements()) { String key = enumKeys.nextElement(); keys.add(key); } if (keys.size() > 0) { MessageBundle messageBundle = new ResourceBundleMessageSource(bundle); registerPrefixMessageBundle(prefix, messageBundle); } } catch (MissingResourceException e) { // looks like no properties files for this prefix } return keys; }