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:org.codehaus.mojo.chronos.chart.SummaryGCChartSource.java

public JFreeChart getChart(ResourceBundle bundle, ReportConfig config) {
    String beforeLabel = bundle.getString("chronos.label.gc.before");
    String afterLabel = bundle.getString("chronos.label.gc.after");
    TimeSeriesCollection dataset1 = new TimeSeriesCollection();
    TimeSeries heapBeforeSeries = new TimeSeries(beforeLabel, Millisecond.class);
    samples.extractHeapBefore(heapBeforeSeries);
    TimeSeries heapAfterSeries = new TimeSeries(afterLabel, Millisecond.class);
    samples.extractHeapAfter(heapAfterSeries);

    dataset1.addSeries(heapBeforeSeries);
    dataset1.addSeries(heapAfterSeries);
    TimeSeriesCollection dataset = dataset1;

    String title = bundle.getString("chronos.label.gc");
    String timeLabel = bundle.getString("chronos.label.gc.time");
    String valueLabel = bundle.getString("chronos.label.gc.mem");
    JFreeChart chart = ChartFactory.createTimeSeriesChart(title, timeLabel, valueLabel, dataset, true, true,
            false);/* w ww . ja v  a2 s  . c o m*/
    ChartUtil.setupXYPlot(chart, new SimpleDateFormat("HH:mm:ss"));
    return chart;
}

From source file:WelcomeServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, java.io.IOException {

    //Get the client's Locale
    Locale locale = request.getLocale();

    ResourceBundle bundle = ResourceBundle.getBundle("i18n.WelcomeBundle", locale);

    String welcome = bundle.getString("Welcome");

    //Display the locale
    response.setContentType("text/html");
    java.io.PrintWriter out = response.getWriter();

    out.println("<html><head><title>" + welcome + "</title></head><body>");

    out.println("<h2>" + welcome + "</h2>");

    out.println("Locale: ");
    out.println(locale.getLanguage() + "_" + locale.getCountry());

    out.println("</body></html>");
    out.close();/* www . ja v  a  2 s . c o  m*/

}

From source file:CurrLocaleServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, java.io.IOException {

    //Get the client's Locale
    Locale locale = request.getLocale();
    ResourceBundle bundle = ResourceBundle.getBundle("i18n.WelcomeBundle", locale);
    String welcome = bundle.getString("Welcome");

    NumberFormat nft = NumberFormat.getCurrencyInstance(locale);
    String formatted = nft.format(1000000);

    //Display the locale
    response.setContentType("text/html");
    java.io.PrintWriter out = response.getWriter();
    out.println("<html><head><title>" + welcome + "</title></head><body>");

    out.println("<h2>" + bundle.getString("Hello") + " " + bundle.getString("and") + " " + welcome + "</h2>");

    out.println("Locale: ");
    out.println(locale.getLanguage() + "_" + locale.getCountry());

    out.println("<br /><br />");
    out.println(formatted);/*from   w w  w .j av a 2  s.  c  o  m*/

    out.println("</body></html>");
    out.close();

}

From source file:com.opensymphony.xwork2.util.LocalizedTextUtil.java

/**
 * Gets the message from the named resource bundle.
 *///  ww  w  .ja  va 2  s  .  com
private static String getMessage(String bundleName, Locale locale, String key, ValueStack valueStack,
        Object[] args) {
    ResourceBundle bundle = findResourceBundle(bundleName, locale);
    if (bundle == null) {
        return null;
    }
    reloadBundles(valueStack.getContext());
    try {
        String message = TextParseUtil.translateVariables(bundle.getString(key), valueStack);
        MessageFormat mf = buildMessageFormat(message, locale);
        return formatWithNullDetection(mf, args);
    } catch (MissingResourceException e) {
        return null;
    }
}

From source file:gemlite.core.internal.admin.service.ConfService.java

/**
 * ?sever?//  www .  j a  va  2  s .c o  m
 * 
 * @param cache
 * @return
 */
public String getSystemInfo(Cache cache) {
    StringBuilder sb = new StringBuilder();
    String ip = System.getProperty(ITEMS.BINDIP.name());
    // 1.??log
    sb.append("\n===================================================================\n");
    DistributedMember member = cache.getDistributedSystem().getDistributedMember();
    sb.append("IP:" + ip + " host:" + member.getHost() + "\n");
    sb.append("node:" + System.getProperty(ITEMS.NODE_NAME.name()) + "\n");
    sb.append("server ID:" + member.getId() + "\n");
    sb.append("server logLevel:" + cache.getLogger().getHandler().getLevel().getName() + "\n");
    //    sb.append("log4j logLevel:" + Logger.get Logger.getRootLogger().getLevel().toString() + "\n");

    String location = System.getenv("GS_WORK");
    if (StringUtils.isEmpty(location)) {
        try {
            ResourceBundle bundle = ResourceBundle.getBundle("env");
            location = bundle.getString("GS_WORK");
        } catch (Exception e) {
            LogUtil.getAppLog().error("env:" + e.getMessage());
        }
    }
    // ??work
    sb.append("disk:" + location + "\n");
    return sb.toString();
}

From source file:eu.dasish.annotation.backend.rest.ProjectInfoResource.java

/**
 * //from w  w w  .  j  ava 2s. com
 * @return a message string containing the number of the version of the backend.
 * @throws IOException if getting a principal or sending an error fails.
 */
@GET
@Produces(MediaType.TEXT_PLAIN)
@Path("version")
@Transactional(readOnly = true)
public String getVersion() throws IOException {
    Number principalID = this.getPrincipalID();
    String retVal = "?.?";
    ResourceBundle rb;
    try {
        rb = ResourceBundle.getBundle("projectinfo");
        retVal = rb.getString("application.version");
    } catch (MissingResourceException e) {
        httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e.getMessage());
    }
    return "DWAN backend " + retVal;
}

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

private TimeSeriesCollection createThreadCountdataset(ResourceBundle bundle, ReportConfig config) {
    String label = bundle.getString("chronos.label.threadcount");
    TimeSeries series = new TimeSeries(label, Millisecond.class);
    samples.appendThreadCounts(series, config.getThreadcountduration());
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(series);/* w  w w . j a v  a  2s  . co  m*/
    return dataset;
}

From source file:com.cyclopsgroup.waterview.core.DefaultI18N.java

/**
 * Overwrite or implement method doGetText()
 * @see com.cyclopsgroup.waterview.spi.BaseI18N#doGetText(java.lang.String)
 *///from ww w . j a va2  s.  c  om
protected String doGetText(String key) throws Exception {
    String text = null;
    for (Iterator i = resourceBundles.iterator(); i.hasNext();) {
        ResourceBundle resourceBundle = (ResourceBundle) i.next();
        try {
            text = resourceBundle.getString(key);
            if (StringUtils.isNotEmpty(text)) {
                break;
            }
        } catch (Exception ignored) {
        }
    }
    return text;
}

From source file:com.cybozu.kintone.gpsPunch.GpsPunchRequestManager.java

public GpsPunchRequestManager() {
    // ???/*from w  w w . j  a  v  a2  s . co  m*/
    try {
        ResourceBundle rb = ResourceBundle.getBundle("gpspunch");
        authorization = rb.getString("authorization");
        companyId = rb.getString("companyid");
        target = rb.getString("target");
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
    // HTTP Client??
    List<Header> headers = new ArrayList<Header>();
    headers.add(new BasicHeader("Authorization", authorization));
    // HTTP Client??
    this.httpClient = HttpClientBuilder.create().setDefaultHeaders(headers).build();
}

From source file:com.opensymphony.xwork2.util.LocalizedTextUtil.java

/**
 * Finds a localized text message for the given key, aTextName, in the specified resource
 * bundle.//from w  ww . ja  v  a 2s  .com
 * <p/>
 * If a message is found, it will also be interpolated.  Anything within <code>${...}</code>
 * will be treated as an OGNL expression and evaluated as such.
 * <p/>
 * If a message is <b>not</b> found a WARN log will be logged.
 *
 * @param bundle         the bundle
 * @param aTextName      the key
 * @param locale         the locale
 * @param defaultMessage the default message to use if no message was found in the bundle
 * @param args           arguments for the message formatter.
 * @param valueStack     the OGNL value stack.
 */
public static String findText(ResourceBundle bundle, String aTextName, Locale locale, String defaultMessage,
        Object[] args, ValueStack valueStack) {
    try {
        reloadBundles(valueStack.getContext());

        String message = TextParseUtil.translateVariables(bundle.getString(aTextName), valueStack);
        MessageFormat mf = buildMessageFormat(message, locale);

        return formatWithNullDetection(mf, args);
    } catch (MissingResourceException ex) {
        // ignore
    }

    GetDefaultMessageReturnArg result = getDefaultMessage(aTextName, locale, valueStack, args, defaultMessage);
    if (LOG.isWarnEnabled() && unableToFindTextForKey(result)) {
        LOG.warn("Unable to find text for key '" + aTextName + "' in ResourceBundles for locale '" + locale
                + "'");
    }
    return result != null ? result.message : null;
}