Example usage for java.util ResourceBundle getBundle

List of usage examples for java.util ResourceBundle getBundle

Introduction

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

Prototype

@CallerSensitive
public static ResourceBundle getBundle(String baseName, Module module) 

Source Link

Document

Gets a resource bundle using the specified base name and the default locale on behalf of the specified module.

Usage

From source file:info.magnolia.cms.i18n.DefaultMessagesImpl.java

/**
 * @return Returns the bundle for the current basename
 */// w  w w .j a v  a2s.  com
protected ResourceBundle getBundle() {
    if (bundle == null) {
        try {
            InputStream stream = ClasspathResourcesUtil.getStream("/" + StringUtils.replace(basename, ".", "/")
                    + "_" + getLocale().getLanguage() + "_" + getLocale().getCountry() + ".properties", false);
            if (stream == null) {
                stream = ClasspathResourcesUtil.getStream("/" + StringUtils.replace(basename, ".", "/") + "_"
                        + getLocale().getLanguage() + ".properties", false);
            }
            if (stream == null) {
                stream = ClasspathResourcesUtil.getStream("/" + StringUtils.replace(basename, ".", "/") + "_"
                        + MessagesManager.getDefaultLocale().getLanguage() + ".properties", false);
            }
            if (stream == null) {
                stream = ClasspathResourcesUtil
                        .getStream("/" + StringUtils.replace(basename, ".", "/") + ".properties", false);
            }

            if (stream != null) {
                bundle = new PropertyResourceBundle(stream);
            } else {
                bundle = ResourceBundle.getBundle(getBasename(), getLocale());
            }
        } catch (IOException e) {
            log.error("can't load messages for " + basename);
        }
    }
    return bundle;
}

From source file:cn.edu.zjnu.acm.judge.config.JudgeConfiguration.java

@PostConstruct
public void init() {
    {/*  w w  w.  j av a  2 s .com*/
        ResourceBundle bundle = ResourceBundle.getBundle(WEB_PROPERTIES, Locale.US);
        bundle.keySet().forEach(key -> servletContext.setAttribute(key, bundle.getObject(key)));
    }

    contextPath = fixContextPath(servletContext.getContextPath());
    dataFilesPath = Paths.get(getValue("DataFilesPath"));
    workingPath = Paths.get(getValue("WorkingPath"));
    uploadDirectory = Paths.get(getValue("UploadPath"));
    deleteTempFile = Boolean.parseBoolean(getValue("DeleteTempFile"));
}

From source file:es.pode.empaquetador.presentacion.archivos.modificar.ModificarArchivoControllerImpl.java

/**
 * @see es.pode.empaquetador.presentacion.archivos.modificar.ModificarArchivoController#modificar(org.apache.struts.action.ActionMapping, es.pode.empaquetador.presentacion.archivos.modificar.ModificarForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 *//* w  w w. j a  va 2 s . c  o  m*/
public final void modificar(ActionMapping mapping,
        es.pode.empaquetador.presentacion.archivos.modificar.ModificarForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    EmpaquetadorSession sesEmpaq = this.getEmpaquetadorSession(request);
    GestorArchivosSession sesArch = this.getGestorArchivosSession(request);

    java.util.Locale locale = (Locale) request.getSession().getAttribute(ConstantesAgrega.DEFAULT_LOCALE);
    ResourceBundle i18n = ResourceBundle.getBundle("application-resources", locale);

    String opcion = form.getAction();

    if (opcion.equals(i18n.getString("portal_empaquetado.modificarNombre"))) {

        //nuevoNombre debe ser la concatenacin de la extensin y el nuevo nombre
        String extension = form.getExtension();
        String nuevoNombre;
        if (extension.equals("")) {
            nuevoNombre = form.getNuevoNombre();
        } else {
            StringBuffer nombre = new StringBuffer(form.getNuevoNombre());
            nombre.append(".").append(extension);
            nuevoNombre = nombre.toString();
        }
        GestorSesion gs = new GestorSesion();
        gs.validarNombreFichero(nuevoNombre);

        ArchivoVO archivo = (ArchivoVO) request.getSession().getAttribute("archivoVO");
        String nombre = archivo.getNombre();

        if (!extension.equals("")) {
            nombre = nombre + "." + extension;
        }

        if (!nombre.equals(nuevoNombre)) {

            // obtengo el identificador del ODEVO
            String identificador = sesEmpaq.getIdLocalizador();

            List path = sesArch.getPath();
            ArchivoVO ultimoPath = (ArchivoVO) path.get(path.size() - 1);
            // obtengo la carpetaDestino
            String carpetaPadre = null;
            if (path.size() > 1 && ultimoPath.getCarpetaPadre() == null) {
                carpetaPadre = ultimoPath.getNombre();
            } else if (path.size() > 1 && ultimoPath.getCarpetaPadre() != null) {
                carpetaPadre = ultimoPath.getCarpetaPadre().concat("/").concat(ultimoPath.getNombre());
            }

            try {
                this.getSrvEmpaquetadorBasicoService().renombrar(identificador, carpetaPadre, nombre,
                        nuevoNombre);
            } catch (Exception e) {
                throw new ValidatorException("{portalempaquetado.archivos.error.renombrar}");
            }
        }
    }
}

From source file:org.gofleet.internacionalization.I18n.java

/**
 * @param locale
 * @return
 */
private ResourceBundle getResourceBundle(Locale locale) {
    return ResourceBundle.getBundle(defaultBundle, locale);
}

From source file:com.sun.faces.demotest.cardemo.TestCarDemo.java

/**
 * <p>Load the main page.  Assumptions: there are exactly four
 * buttons, in a certain order, to select each locale.  For each
 * button, press it, and call doStoreFront() on the result.</p>
 *//*from  w  ww.  j  a va2  s.c o  m*/

public void testCarDemo() throws Exception {

    // for each of the language links run the test
    HtmlPage page = (HtmlPage) getInitialPage();
    List buttons = getAllElementsOfGivenClass(page, null, HtmlSubmitInput.class);
    HtmlSubmitInput button = null;
    int i, j = 0;
    Locale[] locales = { Locale.ENGLISH, Locale.GERMAN, Locale.FRENCH, new Locale("es", "") };

    for (i = 0; i < locales.length; i++) {
        resources = ResourceBundle.getBundle("carstore.bundles.Resources", locales[i]);
        carBundles = new ResourceBundle[carBundleNames.length];
        for (j = 0; j < carBundleNames.length; j++) {
            carBundles[j] = ResourceBundle.getBundle(carBundleNames[j], locales[i]);
        }

        button = (HtmlSubmitInput) buttons.get(i);
        if (log.isTraceEnabled()) {
            log.trace("Running test for language: " + button.asText());
        }
        doStoreFront((HtmlPage) button.click());
    }
}

From source file:es.pode.empaquetador.presentacion.archivos.crearcarpeta.CrearCarpetaControllerImpl.java

/**
  * @see es.pode.empaquetador.presentacion.archivos.crearcarpeta.CrearCarpetaController#crearCarpeta(org.apache.struts.action.ActionMapping, es.pode.empaquetador.presentacion.archivos.crearcarpeta.CrearCarpetaForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
  *///from   ww  w  .j a v  a2s  . com
public final void crearCarpeta(ActionMapping mapping,
        es.pode.empaquetador.presentacion.archivos.crearcarpeta.CrearCarpetaForm form,
        HttpServletRequest request, HttpServletResponse response) throws Exception {
    EmpaquetadorSession sesEmpaq = this.getEmpaquetadorSession(request);
    GestorArchivosSession sesArch = this.getGestorArchivosSession(request);
    java.util.Locale locale = (Locale) request.getSession().getAttribute(ConstantesAgrega.DEFAULT_LOCALE);
    ResourceBundle i18n = ResourceBundle.getBundle("application-resources", locale);

    String accion = form.getAction();

    String nombreCarpeta = form.getNombre();
    if ((accion.equals(i18n.getString("portal_empaquetado.aceptarCrearCarpeta")))) {

        logger.debug("voy a validar los caracteres del nombre de la carpeta");
        GestorSesion gs = new GestorSesion();
        gs.validarNombreCarpeta(nombreCarpeta);
        logger.debug("nombre de la carpeta validado");

        //obtengo el identificador el ultimo ODEVO
        String identificador = sesEmpaq.getIdLocalizador();
        List path = sesArch.getPath();
        ArchivoVO ultimoPath = (ArchivoVO) path.get(path.size() - 1);
        //obtengo la carpetaDestino

        String carpetaPadre = null;
        if (path.size() > 1 && ultimoPath.getCarpetaPadre() == null) {
            carpetaPadre = ultimoPath.getNombre();
        } else if (path.size() > 1 && ultimoPath.getCarpetaPadre() != null) {
            carpetaPadre = ultimoPath.getCarpetaPadre().concat("/").concat(ultimoPath.getNombre());
        }
        try {
            this.getSrvGestorArchivosService().crearCarpeta(identificador, carpetaPadre, nombreCarpeta);
        } catch (Exception e) {
            throw new ValidatorException("{portal_empaquetado.exception.crearCarpetaDuplicada}");
        }
    }
}

From source file:it.cnr.icar.eric.client.ui.thin.WebUIResourceBundle.java

private ResourceBundle getLocalizedResourceBundle() {
    Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
    return ResourceBundle.getBundle(messageBundleName, locale);
}

From source file:dk.netarkivet.common.utils.I18n.java

/**
 * Get a localized message for a given resource bundle, locale and label.
 *
 * In contrast to {@link java.util.ResourceBundle#getString}, this method is
 * forgiving on errors/*from  www  .  ja v  a 2 s  .  c  o m*/
 *
 * I18n.getString("dk.netarkivet.common.Translations",
 * Locale.default, "job.unknown.id", 17)
 *
 * @param bundleName The name of the resource bundle, fully qualified, but
 * without the properties.
 * See {@link java.util.ResourceBundle#getBundle(String)}
 * @param locale The locale to get the string for
 * @param label The label of the string in the resource bundle
 * @param args Any args required for formatting the label
 * @return The localised string, or the label if the string could not be
 * found or the format is invalid or does not match the args.
 * @throws ArgumentNotValid on null bundleName, locale or label.
 */
public static String getString(String bundleName, Locale locale, String label, Object... args) {
    ArgumentNotValid.checkNotNullOrEmpty(bundleName, "String bundleName");
    ArgumentNotValid.checkNotNull(locale, "Locale locale");
    ArgumentNotValid.checkNotNullOrEmpty(label, "String label");
    try {
        ResourceBundle bundle = ResourceBundle.getBundle(bundleName, locale);
        String message = bundle.getString(label);
        try {
            return new MessageFormat(message, locale).format(args);
        } catch (IllegalArgumentException e) {
            log.warn("I18n bundle '" + bundleName + "' has wrong format '" + message + "' for label '" + label
                    + "'", e);
            return label;
        }
    } catch (MissingResourceException e) {
        log.warn("I18n bundle '" + bundleName + "' is missing label '" + label + "'", e);
        return label;
    }
}

From source file:modelibra.swing.app.config.NatLang.java

/**
 * Sets the language with the location for text resources.
 * //w  ww.  j ava  2 s .  com
 * @param language
 *            language
 * @param textResources
 *            text resources
 */
public void setNaturalLanguage(String language, String textResources) {
    try {
        if ((language == null) || (language.equals("en"))) {
            locale = Locale.ENGLISH;
        } else if (language.equals("fr")) {
            locale = Locale.FRENCH;
        } else if (language.equals("ba")) {
            locale = new Locale("ba"); // bosnian language
        } else if (language.equals("hr")) {
            locale = new Locale("hr"); // croatian language
        } else if (language.equals("sr")) {
            locale = new Locale("sr"); // serbian language
        } else { // other languages are not supported, English used
            locale = Locale.ENGLISH;
        }
        resource = ResourceBundle.getBundle(textResources, locale);
    } catch (MissingResourceException e) {
        System.out.println(e.getMessage());
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }
}

From source file:org.obiba.onyx.jade.instrument.gehealthcare.CardiosoftInstrumentRunner.java

public void afterPropertiesSet() throws Exception {
    setEcgResourceBundle(ResourceBundle.getBundle("ecg-instrument", getLocale()));
}