Example usage for java.util ResourceBundle getString

List of usage examples for java.util ResourceBundle getString

Introduction

In this page you can find the example usage for java.util ResourceBundle getString.

Prototype

public final String getString(String key) 

Source Link

Document

Gets a string for the given key from this resource bundle or one of its parents.

Usage

From source file:it.infn.ct.security.utilities.LDAPUtils.java

public static List<Organization> getOrgList(String country) {
    List<Organization> OrgList = new ArrayList<Organization>();
    NamingEnumeration resultCountries = null;
    DirContext ctx = null;/*from   w w  w .j  av a2 s  .co  m*/
    try {
        ctx = getContext();
        SearchControls controls = new SearchControls();
        controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
        ResourceBundle rb = ResourceBundle.getBundle("ldap");

        String filter;
        if (country == null) {
            filter = "(objectclass=country)";
        } else {
            filter = "(&(objectclass=country)(c=" + country + "))";
        }
        resultCountries = ctx.search(rb.getString("organisationsRoot"), filter, controls);

        while (resultCountries.hasMore()) {
            SearchResult searchResult = (SearchResult) resultCountries.next();
            Attributes attributes = searchResult.getAttributes();
            String countryCode = (String) attributes.get("c").get();
            String countryName = (String) attributes.get("co").get();

            NamingEnumeration resultsOrgs = ctx.search(
                    "c=" + countryCode + "," + rb.getString("organisationsRoot"), "(objectclass=organization)",
                    controls);
            while (resultsOrgs.hasMore()) {
                SearchResult srOrg = (SearchResult) resultsOrgs.next();
                Attributes orgAttrs = srOrg.getAttributes();
                String description = "";
                if ((orgAttrs.get("description")) != null) {
                    description = (String) orgAttrs.get("description").get();
                }

                OrgList.add(new Organization((String) orgAttrs.get("o").get(), countryName, countryCode,
                        description, srOrg.getNameInNamespace()));
            }
            resultsOrgs.close();

        }
    } catch (NameNotFoundException ex) {
        _log.error(ex);
    } catch (NamingException e) {
        throw new RuntimeException(e);
    } finally {
        if (resultCountries != null) {
            try {
                resultCountries.close();
            } catch (Exception e) {
                // Never mind this.
            }
        }
        if (ctx != null) {
            try {
                ctx.close();
            } catch (Exception e) {
                // Never mind this.
            }
        }
    }

    Collections.sort(OrgList, new Comparator<Organization>() {

        public int compare(Organization o1, Organization o2) {
            return o1.getKey().compareTo(o2.getKey());
        }

    });

    return OrgList;

}

From source file:org.codehaus.mojo.chronos.chart.SummaryResponsetimeChartSource.java

public JFreeChart getChart(ResourceBundle bundle, ReportConfig config) {
    return createResponseChart(bundle.getString("chronos.label.testcases"), samples, bundle, config);
}

From source file:org.codehaus.mojo.chronos.chart.SummaryHistogramChartSource.java

public JFreeChart getChart(ResourceBundle bundle, ReportConfig config) {
    return createHistogramChart(samples, bundle.getString("chronos.label.histogram.alltests"), bundle, config);
}

From source file:com.ejisto.modules.vertx.handler.Translations.java

private Map<String, String> dumpMessages(ResourceBundle bundle) {
    return bundle.keySet().stream().map(k -> Pair.of(k, bundle.getString(k))).collect(HashMap::new,
            (m, p) -> m.put(p.getKey(), p.getValue()), Map::putAll);
}

From source file:com.marand.thinkmed.medications.MedicationsTestDictionary.java

@Override
public String getEntry(final String key, final GrammaticalGender gender, final Locale locale) {
    if (StringUtils.isBlank(key)) {
        return null;
    } else {/*from w  ww.j  av  a2s.  c o  m*/
        final ResourceBundle bundle = locale != null ? getBundle(locale) : BUNDLE;
        return bundle.getString(key);
    }
}

From source file:com.feilong.core.util.ResourceBundleUtil.java

/**
 * ?Properties? , {@link java.util.ResourceBundle#getBundle(String)} ??.
 * /*from w  ww  . java 2 s . c  om*/
 * <p>
 * ????? <code>arguments</code> , {@link MessageFormatUtil#format(String, Object...)} ??
 * </p>
 * 
 * <h3>:</h3>
 * 
 * <blockquote>
 * 
 * <p>
 * ? messages\feilong-core-test.properties ,:
 * </p>
 * 
 * <pre class="code">
 * test.arguments=my name is {0},age is {1}
 * </pre>
 * 
 * :
 * 
 * <pre class="code">
 * ResourceBundleUtil.getValueWithArguments(resourceBundle, "test.arguments", "feilong", "18")
 * </pre>
 * 
 * <b>:</b>
 * 
 * <pre class="code">
 * my name is feilong,age is 18
 * </pre>
 * 
 * </blockquote>
 *
 * @param resourceBundle
 *            the resource bundle
 * @param key
 *            Properties???
 * @param arguments
 *            ?Object[]?
 * @return ?,
 *         <ul>
 *         <li>key?,LOGGER.warn ,? {@link StringUtils#EMPTY}</li>
 *         <li>key,valuenull  empty,value</li>
 *         </ul>
 * @throws NullPointerException
 *              <code>resourceBundle</code>  <code>key</code> null
 * @throws IllegalArgumentException
 *              <code>key</code> blank, {@link IllegalArgumentException}
 * @see java.util.ResourceBundle#getString(String)
 * @see MessageFormatUtil#format(String, Object...)
 * @since 1.8.1 support arguments param
 */
public static String getValue(ResourceBundle resourceBundle, String key, Object... arguments) {
    Validate.notNull(resourceBundle, "resourceBundle can't be null!");
    Validate.notBlank(key, "key can't be null/empty!");

    if (!resourceBundle.containsKey(key)) {
        LOGGER.warn("resourceBundle:[{}] don't containsKey:[{}]", resourceBundle, key);
        return EMPTY;
    }

    String value = resourceBundle.getString(key);
    if (isNullOrEmpty(value)) {
        LOGGER.trace("resourceBundle has key:[{}],but value is null/empty", key);
    }
    return isNullOrEmpty(value) ? EMPTY : MessageFormatUtil.format(value, arguments);// ? arguments null,
}

From source file:com.uniquesoft.uidl.servlet.UploadServlet.java

/**
 * Returns the localized text of a key./*from   w  w w.  j  a  va 2s.c  o m*/
 */
public static String getMessage(String key, Object... pars) {
    Locale loc = getThreadLocalRequest() == null || getThreadLocalRequest().getLocale() == null
            ? new Locale("en")
            : getThreadLocalRequest().getLocale();

    ResourceBundle res = ResourceBundle.getBundle(UploadServlet.class.getName(), loc);

    String msg = res.getString(key);
    return new MessageFormat(msg, loc).format(pars);
}

From source file:org.synyx.sample.ResourceBundleMessageSourceTest.java

@Test
public void test_util_resource_bundle_with_ok() {
    ResourceBundle bundle = ResourceBundle.getBundle("ok_messages");
    String msg = bundle.getString("test.1");
    assertEquals("david", msg);
}

From source file:com.learning.mocks.account.DefaultAccountManager1.java

/**
 * Finds an account for user with the given userID.
 * //from   w  ww  .  j  ava  2s .c  om
 * @param
 */
public Account findAccountForUser(String userId) {
    LOGGER.debug("Getting account for user [" + userId + "]");
    ResourceBundle bundle = PropertyResourceBundle.getBundle("technical");
    String sql = bundle.getString("FIND_ACCOUNT_FOR_USER");

    // Some code logic to load a user account using JDBC
    // []
    return null;
}

From source file:com.manning.junitbook.ch07.mocks.account.DefaultAccountManager1.java

/**
 * Finds an account for user with the given userID.
 * //from  w w  w .  j  av a  2  s .co  m
 * @param
 */
public Account findAccountForUser(String userId) {
    LOGGER.debug("Getting account for user [" + userId + "]");
    ResourceBundle bundle = PropertyResourceBundle.getBundle("technical");
    String sql = bundle.getString("FIND_ACCOUNT_FOR_USER");

    // Some code logic to load a user account using JDBC
    // []
    return null;
}