List of usage examples for java.util ResourceBundle getString
public final String getString(String key)
From source file:it.eng.spagobi.commons.utilities.PortletUtilities.java
/** * Gets a localized message given its code and bundle * information. If there isn't any message matching to these infromation, a * warning is traced.//from ww w . j a v a2 s .co m * * @param code The message's code string * @param bundle The message's bundel string * * @return A string containing the message */ public static String getMessage(String code, String bundle) { Locale locale = getLocaleForMessage(); ResourceBundle messages = ResourceBundle.getBundle(bundle, locale); if (messages == null) { return null; } String message = code; try { message = messages.getString(code); } catch (Exception ex) { logger.warn("code [" + code + "] not found ", ex); } return message; }
From source file:mSearch.tool.Functions.java
public static String getCompileDate() { final ResourceBundle rb; String propToken = "DATE"; String msg = ""; try {// w w w. ja v a 2 s. com ResourceBundle.clearCache(); rb = ResourceBundle.getBundle("version"); msg = rb.getString(propToken); } catch (Exception e) { Log.errorLog(807293847, e); } return msg; }
From source file:mSearch.tool.Functions.java
public static String getBuildNr() { final ResourceBundle rb; String propToken = "BUILD"; String msg = ""; try {//from ww w. j a v a 2 s . c o m ResourceBundle.clearCache(); rb = ResourceBundle.getBundle("version"); msg = rb.getString(propToken); } catch (Exception e) { Log.errorLog(134679898, e); } return msg; }
From source file:com.hypersocket.i18n.I18N.java
public static String getResourceNoOveride(Locale locale, String resourceBundle, String key, Object... arguments) {//w w w. ja v a 2 s . c o m if (key == null) { throw new IllegalArgumentException("You must specify a key!"); } if (resourceBundle == null) { throw new IllegalArgumentException("You must specify a resource bundle for key " + key); } if (!resourceBundle.startsWith("i18n/")) { resourceBundle = "i18n/" + resourceBundle; } try { ResourceBundle resource = ResourceBundle.getBundle(resourceBundle, locale, I18N.class.getClassLoader()); String localizedString = resource.getString(key); if (arguments == null || arguments.length == 0) { return localizedString; } MessageFormat messageFormat = new MessageFormat(localizedString); messageFormat.setLocale(locale); return messageFormat.format(formatParameters(arguments)); } catch (MissingResourceException mre) { return "[i18n/" + resourceBundle + "/" + key + "]"; } }
From source file:CachedConnectionServlet.java
public static final Connection getConnection(String baseName) { Connection conn = null;/*from www .j a va2s .c om*/ String driver = null; String url = null; String username = null; String password = null; try { ResourceBundle resb = ResourceBundle.getBundle(baseName); driver = resb.getString("database.driver"); url = resb.getString("database.url"); username = resb.getString("database.username"); password = resb.getString("database.password"); Class.forName(driver); } catch (MissingResourceException e) { System.err.println("Missing Resource: " + e.getMessage()); return conn; } catch (ClassNotFoundException e) { System.err.println("Class not found: " + e.getMessage()); return conn; } try { if (verbose) { System.out.println("baseName=" + baseName); System.out.println("driver=" + driver); System.out.println("url=" + url); System.out.println("username=" + username); System.out.println("password=" + password); } conn = DriverManager.getConnection(url, username, password); } catch (SQLException e) { System.err.println(e.getMessage()); System.err.println("in Database.getConnection"); System.err.println("on getConnection"); conn = null; } finally { return conn; } }
From source file:es.mityc.firmaJava.configuracion.Configuracion.java
private static String getNombreFicheroExterno() { String resultado = FICHERO_PROPIEDADES; try {/*from ww w . j ava2s.co m*/ ResourceBundle propiedadesPorDefecto = ResourceBundle.getBundle(FICHERO_RESOURCE); resultado = propiedadesPorDefecto.getString(CONFIG_EXT_FILE); } catch (MissingResourceException ex) { } return resultado; }
From source file:es.mityc.firmaJava.configuracion.Configuracion.java
public static String getNombreDirExterno() { String resultado = ""; try {//from w ww . j ava2 s . co m ResourceBundle propiedadesPorDefecto = ResourceBundle.getBundle(FICHERO_RESOURCE); resultado = propiedadesPorDefecto.getString(CONFIG_EXT_DIR); } catch (MissingResourceException ex) { } return resultado; }
From source file:es.mityc.firmaJava.configuracion.Configuracion.java
private static boolean chequeaPermiteFicheroExterno() { boolean resultado = false; try {/*from w w w. j a va 2 s. c o m*/ ResourceBundle propiedadesPorDefecto = ResourceBundle.getBundle(FICHERO_RESOURCE); String ficherExt = propiedadesPorDefecto.getString(CONFIG_EXT); resultado = isTrue(ficherExt); } catch (MissingResourceException ex) { // En caso de que no exista la clave en el SignXML por defecto, se recupera el externo resultado = true; } return resultado; }
From source file:de.elbe5.base.util.StringUtil.java
public static String getString(String key, Locale locale) { String s = ""; try {/*from ww w . j a va 2s . c o m*/ ResourceBundle bundle = ResourceBundle.getBundle(bundleName, locale); if (bundle == null || key == null || !bundle.containsKey(key)) { Log.warn("resource string not found for key " + key + " of locale " + locale); return "..."; } s = bundle.getString(key); } catch (MissingResourceException ignore) { } if (s.isEmpty()) { Log.warn("resource string is empty for key " + key + " of locale " + locale); return ".."; } return s; }
From source file:com.hypersocket.i18n.I18N.java
public static String getResource(Locale locale, String resourceBundle, String key, Object... arguments) { if (key == null) { throw new IllegalArgumentException("You must specify a key!"); }/*from w ww .ja va2 s .c o m*/ if (resourceBundle == null) { throw new IllegalArgumentException("You must specify a resource bundle for key " + key); } File overideFile = getOverrideFile(locale, resourceBundle); if (overideFile.exists()) { if (!overideProperties.containsKey(overideFile)) { Properties properties = new Properties(); try { InputStream in = new FileInputStream(overideFile); try { properties.load(in); } catch (IOException ex) { } finally { FileUtils.closeQuietly(in); } overideProperties.put(overideFile, properties); } catch (FileNotFoundException e) { } } if (overideProperties.containsKey(overideFile)) { Properties properties = overideProperties.get(overideFile); if (properties.containsKey(key)) { String localizedString = properties.getProperty(key); if (arguments == null || arguments.length == 0) { return localizedString; } MessageFormat messageFormat = new MessageFormat(localizedString); messageFormat.setLocale(locale); return messageFormat.format(formatParameters(arguments)); } } } String bundlePath = resourceBundle; if (!bundlePath.startsWith("i18n/")) { bundlePath = "i18n/" + resourceBundle; } try { ResourceBundle resource = ResourceBundle.getBundle(bundlePath, locale, I18N.class.getClassLoader()); String localizedString = resource.getString(key); if (arguments == null || arguments.length == 0) { return localizedString; } MessageFormat messageFormat = new MessageFormat(localizedString); messageFormat.setLocale(locale); return messageFormat.format(formatParameters(arguments)); } catch (MissingResourceException mre) { return "Missing resource key [i18n/" + resourceBundle + "/" + key + "]"; } }