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:PmpEditor.java

/**
 * Loads the syntax data for an extension
 * //  w  w w .  j av  a  2  s  .com
 * @param extension
 *          the extension to load
 * @return SyntaxData
 */
private static SyntaxData loadSyntaxData(String extension) {
    SyntaxData sd = null;
    try {
        ResourceBundle rb = ResourceBundle.getBundle("examples.ch11." + extension);
        sd = new SyntaxData(extension);
        sd.setComment(rb.getString("comment"));
        sd.setMultiLineCommentStart(rb.getString("multilinecommentstart"));
        sd.setMultiLineCommentEnd(rb.getString("multilinecommentend"));

        // Load the keywords
        Collection keywords = new ArrayList();
        for (StringTokenizer st = new StringTokenizer(rb.getString("keywords"), " "); st.hasMoreTokens();) {
            keywords.add(st.nextToken());
        }
        sd.setKeywords(keywords);

        // Load the punctuation
        sd.setPunctuation(rb.getString("punctuation"));
    } catch (MissingResourceException e) {
        // Ignore
    }
    return sd;
}

From source file:DateLocaleServlet.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");
    String date = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.SHORT, locale).format(new Date());

    //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(date + "<br /><br />");

    java.util.Enumeration e = bundle.getKeys();
    while (e.hasMoreElements()) {

        out.println((String) e.nextElement());
        out.println("<br /><br />");

    }/*from   w w  w.  jav  a  2 s  .  com*/

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

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

}

From source file:jgnash.ui.commodity.SecurityItemLabelGenerator.java

/**
 * Creates a tool tip generator using the supplied date formatter.
 *
 * @param dateFormatter  the date formatter ({@code null} not permitted).
 * @param numberFormatter  the number formatter ({@code null} not permitted).
 *///from  ww w  .j a  v a  2  s. co m
private SecurityItemLabelGenerator(final DateFormat dateFormatter, final NumberFormat numberFormatter) {
    if (dateFormatter == null) {
        throw new IllegalArgumentException("Null 'dateFormatter' argument.");
    }
    if (numberFormatter == null) {
        throw new IllegalArgumentException("Null 'numberFormatter' argument.");
    }
    this.dateFormatter = dateFormatter;
    this.numberFormatter = numberFormatter;

    ResourceBundle rb = ResourceUtils.getBundle();

    dateLabel = rb.getString("Label.Date");

    closeLabel = rb.getString("Label.Close");
}

From source file:com.ibm.amc.data.ErrorResponseTest.java

@Test
public void testUserAction() {
    ResourceBundle bundle = ResourceBundle.getBundle(Constants.CWZBA_BUNDLE_NAME);
    assertTrue(responseJson.contains("\"userAction\":\"" + bundle.getString(KEY + ".useraction") + "\""));
}

From source file:com.ibm.amc.data.ErrorResponseTest.java

@Test
public void testExplanation() {
    ResourceBundle bundle = ResourceBundle.getBundle(Constants.CWZBA_BUNDLE_NAME);
    assertTrue(responseJson.contains("\"explanation\":\"" + bundle.getString(KEY + ".explanation") + "\""));
}

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

/**
 * Overwrite or implement method translate()
 *
 * @see com.cyclopsgroup.waterview.spi.I18NService#translate(java.lang.String, java.util.Locale)
 *///  www  . j ava 2  s .  co  m
public String translate(String key, Locale locale) throws Exception {
    for (Iterator i = resourceKeys.iterator(); i.hasNext();) {
        String resourceKey = (String) i.next();
        try {
            ResourceBundle rb = ResourceBundle.getBundle(resourceKey, locale);
            String s = rb.getString(key);
            if (StringUtils.isNotEmpty(s)) {
                return s;
            }
            continue;
        } catch (Exception e) {
            continue;
        }
    }
    return "%" + key;
}

From source file:com.gcrm.security.AuthenticationFilter.java

@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
        throws AuthenticationException {
    if (!request.getMethod().equals("POST")) {
        throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod());
    }//from  w w w. j av a  2s  . c o  m

    String username = obtainUsername(request);
    String password = obtainPassword(request);

    // Validates username and password
    username = username.trim();

    String localValue = obtainLanguage(request);
    String[] locals = localValue.split("_");
    Locale locale = new Locale(locals[0], locals[1]);
    request.getSession().setAttribute("WW_TRANS_I18N_LOCALE", locale);
    request.getSession().setAttribute("locale", localValue);
    Locale.setDefault(locale);

    User user = UserUtil.getUser(username);
    Md5PasswordEncoder encoder = new Md5PasswordEncoder();
    password = encoder.encodePassword(password, AuthenticationFilter.SALT);
    if (user == null || !user.getPassword().equals(password)) {
        ResourceBundle rb = CommonUtil.getResourceBundle();
        String errorMessage = rb.getString("error.login.denied");
        throw new AuthenticationServiceException(errorMessage);
    }

    UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username,
            password);
    setDetails(request, authRequest);

    // return authRequest;
    return this.getAuthenticationManager().authenticate(authRequest);
}

From source file:com.swtxml.i18n.ResourceBundleLabelTranslator.java

public String translate(String key) {
    for (ResourceBundle resourceBundle : resourceBundles) {
        try {// w  w w  . ja  v a2 s.  co m
            String value = resourceBundle.getString(key);
            if (value != null) {
                return value;
            }
        } catch (MissingResourceException e) {
            // ignore missing resources
        }
    }

    return "??? " + key + " ???";
}

From source file:es.pode.empaquetador.presentacion.previsualizar.PrevisualizarControllerImpl.java

@Override
public String submit(ActionMapping mapping, SubmitForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    GestorSesion gs = new GestorSesion();
    boolean esAvanzado = gs.esAvanzado();
    String action = form.getAction();
    String result = "Aceptar";
    if (logger.isDebugEnabled())
        logger.debug("submit con parametros action=" + action + " tipoVisualizador = "
                + form.getTipoVisualizador() + " esAvanzado = " + esAvanzado);
    java.util.Locale locale = (Locale) request.getSession().getAttribute(ConstantesAgrega.DEFAULT_LOCALE);
    ResourceBundle i18n = ResourceBundle.getBundle("application-resources", locale);
    if (i18n.getString("comunes.cancelar").equalsIgnoreCase(action)) {
        // Ha pulsado Cancelar
        if (esAvanzado)
            result = "CancelarAvanzado";
        else//  w w w .  j  av a  2 s.c om
            result = "CancelarBasico";
    }
    if (logger.isDebugEnabled())
        logger.debug("Retorno de submit = " + result);
    return result;
}

From source file:com.balero.controllers.LogoutController.java

/**
 * Simple. Set cookie's content to 'init'
 * init equals to empty or null/*  w  w w.  j  a  v  a2 s. c o m*/
 *
 * @param response HTTP headers
 * @param redirectAttributes Show in message center
 * @return View
 */
@RequestMapping(method = RequestMethod.GET)
public String logout(HttpServletResponse response, RedirectAttributes redirectAttributes) {

    // create cookie and set it in response
    Cookie cookie = new Cookie("baleroAdmin", "init");
    response.addCookie(cookie);

    /**
     * Base on:
     * stackoverflow.com/questions/19249049/
     * how-to-pass-parameters-
     * to-redirect-page-in-spring-mvc
     */
    ResourceBundle bundle = ResourceBundle.getBundle("messages");
    redirectAttributes.addFlashAttribute("message", bundle.getString("label.login.logout"));

    return "redirect:/";

}