List of usage examples for java.util ResourceBundle containsKey
public boolean containsKey(String key)
key
is contained in this ResourceBundle
or its parent bundles. From source file:br.com.tcc.rest.config.TccExceptionHandler.java
private String getBundleMessage(String key) { ResourceBundle bundle = ResourceBundle.getBundle("tcc-messages"); String message = key;// www.j a va 2 s . c o m if (bundle.containsKey(key)) { message = bundle.getString(key); } return message; }
From source file:de.Keyle.MyPet.util.locale.Locales.java
public String getText(String key, String localeString) { localeString = Util.cutString(localeString, 2).toLowerCase(); if (!locales.containsKey(localeString)) { loadLocale(localeString);/*from w ww. jav a 2s . c o m*/ } java.util.ResourceBundle locale = locales.get(localeString); if (locale.containsKey(key)) { return Colorizer.setColors(locale.getString(key)); } locale = locales.get("en"); if (locale.containsKey(key)) { return Colorizer.setColors(locale.getString(key)); } return key; }
From source file:py.una.pol.karaku.util.I18nHelper.java
protected String getStringOrNull(String key) { if (bundles == null) { initialize();// w w w . j av a 2 s . co m } for (ResourceBundle bundle : getBundles()) { if (bundle.containsKey(key)) { return bundle.getString(key); } } return null; }
From source file:com.kenai.redminenb.issue.JournalDisplay.java
public static JournalData buildJournalData(RedmineIssue ri, Journal jd, int index) { RedmineRepository repo = ri.getRepository(); String noteText = jd.getNotes(); StringWriter writer = new StringWriter(); if (jd.getDetails() != null && jd.getDetails().size() > 0) { writer.append("<ul>"); for (JournalDetail detail : jd.getDetails()) { writer.append("<li>"); String fieldName = detail.getName(); String translatedFieldName = fieldName; try { translatedFieldName = NbBundle.getMessage(JournalDisplay.class, "field." + fieldName); } catch (MissingResourceException ex) { // Ok, was not translated }/*from ww w. j av a 2 s . co m*/ String oldValue = detail.getOldValue(); String newValue = detail.getNewValue(); switch (fieldName) { case "category_id": oldValue = formatCategory(repo, ri, oldValue); newValue = formatCategory(repo, ri, newValue); break; case "fixed_version_id": oldValue = formatVersion(repo, ri, oldValue); newValue = formatVersion(repo, ri, newValue); break; case "priority_id": oldValue = formatPriority(repo, oldValue); newValue = formatPriority(repo, newValue); break; case "status_id": oldValue = formatStatus(repo, oldValue); newValue = formatStatus(repo, newValue); break; case "tracker_id": oldValue = formatTracker(repo, oldValue); newValue = formatTracker(repo, newValue); break; case "assigned_to_id": oldValue = formatUser(repo, ri, oldValue); newValue = formatUser(repo, ri, newValue); break; case "project_id": oldValue = formatProject(repo, ri, oldValue); newValue = formatProject(repo, ri, newValue); break; default: // Identity (silence findbugs) break; } if ("cf".equals(detail.getProperty())) { try { int fieldId = Integer.parseInt(fieldName); CustomFieldDefinition cfd = ri.getRepository().getCustomFieldDefinitionById(fieldId); if (cfd != null) { translatedFieldName = cfd.getName(); switch (cfd.getFieldFormat()) { case "user": oldValue = formatUser(repo, ri, oldValue); newValue = formatUser(repo, ri, newValue); break; case "version": oldValue = formatVersion(repo, ri, oldValue); newValue = formatVersion(repo, ri, newValue); break; case "bool": oldValue = formatBool(repo, ri, oldValue); newValue = formatBool(repo, ri, newValue); break; default: // Identity (silence findbugs) break; } } else { translatedFieldName = "Custom field ID " + fieldId; } } catch (NumberFormatException ex) { } } Object[] formatParams = new Object[] { escapeHTML(fieldName), escapeHTML(translatedFieldName), escapeHTML(oldValue), escapeHTML(newValue) }; ResourceBundle rb = NbBundle.getBundle(JournalDisplay.class); String key; String alternativeKey; if ("description".equals(fieldName) || (oldValue == null && newValue == null)) { key = detail.getProperty() + ".baseChanged"; alternativeKey = "attr.baseChanged"; } else if (oldValue != null && newValue != null) { key = detail.getProperty() + ".changed"; alternativeKey = "attr.changed"; } else if (oldValue != null) { key = detail.getProperty() + ".deleted"; alternativeKey = "attr.deleted"; } else { key = detail.getProperty() + ".added"; alternativeKey = "attr.added"; } String info; if (!rb.containsKey(key)) { info = NbBundle.getMessage(JournalDisplay.class, alternativeKey, formatParams); } else { info = NbBundle.getMessage(JournalDisplay.class, key, formatParams); } writer.append(info); writer.append("</li>"); } writer.append("</ul>"); } if (StringUtils.isNotBlank(noteText)) { writer.append("<div class='note'>"); TextileUtil.convertToHTML(noteText, writer); writer.append("</div>"); } return new JournalData(jd.getId(), index + 1, jd.getUser().getFullName(), jd.getCreatedOn(), writer.toString()); }
From source file:edu.toronto.cs.phenotips.measurements.internal.DefaultMeasurementsChartConfigurationsFactory.java
/** * Read and return a setting from the configuration, falling back on the provided default value. * // w w w. j a v a 2 s .c o m * @param settingName the name of the setting to read * @param defaultValue the default value to use when there's no value specified in the configuration; can be * {@code null} or the empty string * @param configuration the configuration bundle with all the settings * @return the configured value, if one is configured (even as an empty string), or the default value otherwise */ private String getStringSetting(String settingName, String defaultValue, ResourceBundle configuration) { String result = defaultValue; if (configuration.containsKey(settingName)) { result = configuration.getString(settingName); } return result; }
From source file:edu.toronto.cs.phenotips.measurements.internal.DefaultMeasurementsChartConfigurationsFactory.java
/** * Read and return a setting from the configuration, parsing it as an {@code int} number, falling back on the * provided default value./*w w w . ja va 2s . c o m*/ * * @param settingName the name of the setting to read * @param defaultValue the default value to use when there's no value specified in the configuration, or the * specified value is not a valid number * @param configuration the configuration bundle with all the settings * @return the configured value, if one is configured as a valid {@code int} number, or the default value otherwise */ private int getIntSetting(String settingName, int defaultValue, ResourceBundle configuration) { int result = defaultValue; if (configuration.containsKey(settingName)) { try { result = Integer.parseInt(configuration.getString(settingName)); if (result < 0) { this.logger.warn( "Invalid chart settings for [{}]: value should be a positive integer, was [{}]", settingName, configuration.getString(settingName)); result = defaultValue; } } catch (NumberFormatException ex) { // Fall back to the default value this.logger.warn("Invalid chart settings for [{}]: invalid integer [{}]", settingName, configuration.getString(settingName)); } } return result; }
From source file:edu.toronto.cs.phenotips.measurements.internal.DefaultMeasurementsChartConfigurationsFactory.java
/** * Read and return a setting from the configuration, parsing it as a {@code double} number, falling back on the * provided default value.//from w w w.j a va2 s .c om * * @param settingName the name of the setting to read * @param defaultValue the default value to use when there's no value specified in the configuration, or the * specified value is not a valid double number * @param configuration the configuration bundle with all the settings * @return the configured value, if one is configured as a valid {@code double} number, or the default value * otherwise */ private double getDoubleSetting(String settingName, double defaultValue, ResourceBundle configuration) { double result = defaultValue; if (configuration.containsKey(settingName)) { try { result = Double.parseDouble(configuration.getString(settingName)); if (Double.isNaN(result) || Double.isInfinite(result)) { this.logger.warn("Invalid chart settings for [{}]: value should be finite, was [{}]", settingName, configuration.getString(settingName)); result = defaultValue; } } catch (NumberFormatException ex) { // Fall back to the default value this.logger.warn("Invalid chart settings for [{}]: invalid double [{}]", settingName, configuration.getString(settingName)); } } return result; }
From source file:edu.toronto.cs.phenotips.measurements.internal.DefaultMeasurementsChartConfigurationsFactory.java
@Override public List<MeasurementsChartConfiguration> loadConfigurationsForMeasurementType(String measurementType) { ResourceBundle configuration = ResourceBundle.getBundle("measurementsChartsConfigurations"); String key = "charts." + measurementType + ".configurations"; if (!configuration.containsKey(key)) { return Collections.emptyList(); }// ww w . j av a 2s . c o m String[] charts = configuration.getString(key).split(","); List<MeasurementsChartConfiguration> result = new ArrayList<MeasurementsChartConfiguration>(charts.length); for (String chart : charts) { SimpleMeasurementsChartConfiguration chartSettings = loadChart(key + '.' + chart + '.', configuration); if (validateChart(chartSettings)) { chartSettings.measurementType = measurementType; result.add(chartSettings); } } return result; }
From source file:cz.incad.kramerius.pdf.impl.FirstPagePDFServiceImpl.java
public String i18nValue(ResourceBundle bundle, String modsKey) { String key = i18nKey(modsKey); if (key != null) { if (bundle.containsKey(key)) { return bundle.getString(key); } else {// w w w.j a va2 s. co m LOGGER.log(Level.WARNING, "cannot find key '" + key + "'"); return modsKey; } } else return modsKey; }
From source file:org.gitana.platform.client.Gitana.java
/** * Creates a Gitana instance bound to a given client on an environment. * * @param environmentId// w w w . ja v a2 s .c o m * @param clientKey * @param clientSecret */ public Gitana(String environmentId, String clientKey, String clientSecret) { if (environmentId == null) { environmentId = Environment.DEFAULT; } this.environmentId = environmentId; // load environment properties ResourceBundle bundle = readBundle("gitana-environments"); this.baseUrl = bundle.getString("gitana.environment." + environmentId + ".uri"); // load client properties if not provided if (clientKey == null && clientSecret == null) { bundle = readBundle("gitana"); if (bundle.containsKey("gitana.clientKey")) { this.clientKey = bundle.getString("gitana.clientKey"); } // legacy support if (this.clientKey == null && bundle.containsKey("gitana.clientId")) { this.clientKey = bundle.getString("gitana.clientId"); } this.clientSecret = bundle.getString("gitana.clientSecret"); } else { this.clientKey = clientKey; this.clientSecret = clientSecret; } }