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:com.willwinder.universalgcodesender.i18n.Localization.java

public static String getString(String id) {
    String result = "";
    try {/* ww  w  .j a v  a  2 s . c o  m*/
        String val = bundle.getString(id);
        result = new String(val.getBytes("ISO-8859-1"), "UTF-8");
    } catch (Exception e) {
        // Ignore this error, we will later try to fetch the string from the english bundle
    }

    if (StringUtils.isEmpty(StringUtils.trimToEmpty(result))) {
        try {
            if (english == null) {
                english = ResourceBundle.getBundle("resources.MessagesBundle", new Locale("en", "US"));
            }
            String val = english.getString(id);
            result = new String(val.getBytes("ISO-8859-1"), "UTF-8");
        } catch (Exception e) {
            result = "<" + id + ">";
        }
    }

    return result;
}

From source file:fr.hoteia.qalingo.core.service.impl.ReferentialDataServiceImpl.java

private ResourceBundle getCountriesBundleByLocale(final Locale locale) {
    return ResourceBundle.getBundle(Constants.COUNTRIES_RESOURCE_BUNDLE, locale);
}

From source file:it.cilea.osd.common.validation.BaseValidator.java

protected String getValidationMessage(String errors) {
    String message = "";
    if (errors != null && errors.length() != 0) {
        WebContext ctx = WebContextFactory.get();
        MessageSource messageSource = WebApplicationContextUtils
                .getWebApplicationContext(ctx.getServletContext());
        //il messaggio deve essere ripescato dal resource bundle
        ResourceBundle resourceBundle = ResourceBundle.getBundle(Constants.BUNDLE_KEY,
                ctx.getHttpServletRequest().getLocale());
        message = resourceBundle.getString(errors);
    }//from  w  ww . j  av a2 s . co  m
    return message;
}

From source file:org.shredzone.cilla.admin.header.HeaderBean.java

/**
 * Commits the changes to the selected or newly created {@link HeaderDto}.
 *///from   w w w  .jav  a2  s  .co  m
public String commit() throws CillaServiceException {
    if (header.getId() == 0) {
        FacesContext ctx = FacesContext.getCurrentInstance();
        Locale loc = ctx.getViewRoot().getLocale();
        ResourceBundle bundle = ResourceBundle.getBundle(ctx.getApplication().getMessageBundle(), loc);

        boolean missing = false;

        if (header.getUploadHeaderFile() == null) {
            FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
                    bundle.getString("header.edit.error.image"), null);
            ctx.addMessage("editForm:headerPicture", message);
            missing = true;
        }

        if (header.getUploadFullFile() == null) {
            FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
                    bundle.getString("header.edit.error.full"), null);
            ctx.addMessage("editForm:headerFullPicture", message);
            missing = true;
            return null;
        }

        if (missing) {
            // at least one file was missing, abort...
            return null;
        }
    }

    setHeader(headerWs.commit(header));

    return "/admin/header/list.xhtml";
}

From source file:es.pode.gestorFlujo.presentacion.objetosPersonales.importarURL.ImportarURLControllerImpl.java

/**
 * @see es.pode.gestorFlujo.presentacion.objetosPersonales.importarURL.ImportarURLController#crear(org.apache.struts.action.ActionMapping, es.pode.gestorFlujo.presentacion.objetosPersonales.importarURL.CrearForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 */// ww w  . ja  va  2  s  .c  om
public final void crear(ActionMapping mapping,
        es.pode.gestorFlujo.presentacion.objetosPersonales.importarURL.CrearForm form,
        HttpServletRequest request, HttpServletResponse response) throws ValidatorException {
    String VACIA = "";

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

    String url = VACIA;
    String comentarios = VACIA;
    String idiomaPpal = VACIA;
    String idiomaDestinatario = VACIA;
    String titulo = VACIA;
    String idUsuario = LdapUserDetailsUtils.getUsuario();
    ;
    String action = VACIA;
    String tipo = "thematic or corporate webs/web portals";

    if (form != null) {
        logger.debug("Recuperamos campos del formulario");
        url = form.getUrl() != null ? form.getUrl() : VACIA;
        comentarios = form.getComentarios() != null ? form.getComentarios() : VACIA;
        idiomaPpal = form.getIdioma() != null ? form.getIdioma() : VACIA;
        try {
            idiomaPpal = I18n.getInstance().obtenerIdiomaIso(idiomaPpal, idioma);
        } catch (Exception e1) {
            logger.error("No se ha podido recuperar traduccin de trmino " + idiomaPpal);
            throw new ValidatorException("{gestorFlujo.error.inesperado}");
        }
        idiomaDestinatario = form.getIdiomaDestinatario() != null ? form.getIdiomaDestinatario() : VACIA;
        try {
            idiomaDestinatario = I18n.getInstance().obtenerIdiomaIso(idiomaDestinatario, idioma);
        } catch (Exception e1) {
            logger.error("No se ha podido recuperar traduccin de trmino " + idiomaDestinatario);
            throw new ValidatorException("{gestorFlujo.error.inesperado}");
        }
        titulo = form.getTitulo() != null ? form.getTitulo() : VACIA;
        action = form.getAction() != null ? form.getAction() : VACIA;
        tipo = form.getTipo() != null ? form.getTipo() : tipo;
        try {
            TerminoYPadreVO termino = getSrvVocabulariosControladosService()
                    .crearTraduccionAIngles(new String[] { tipo })[0];
            tipo = termino.getNomTermino() != null ? termino.getNomTermino() : tipo;
        } catch (Exception e) {
            logger.error("No se ha podido recuperar traduccin al ingls de trmino " + tipo);
            throw new ValidatorException("{gestorFlujo.error.inesperado}");
        }
    }
    //Comprobamos entrada
    if (url.equals(VACIA) || comentarios.equals(VACIA) || idioma.equals(VACIA)
            || idiomaDestinatario.equals(VACIA) || titulo.equals(VACIA)) {
        logger.debug("No se introdujeron campos");
        throw new ValidatorException("{gestorFlujos.error.camposVacios}");
    }

    if (action.equals(i18n.getString("gestorFlujo.importarURL.guardar"))) {
        try {
            logger.debug("Llamamos a crearDesdeURL con url=" + url + ", usuario=" + idUsuario + ", comentarios="
                    + comentarios + ", titulo=" + titulo + ", idioma=" + idioma + ", idiomaDestinatario="
                    + idiomaDestinatario);
            ResultadoOperacionVO result = getSrvPublicacionService().crearDesdeURL(url, idUsuario, comentarios,
                    titulo, idioma, idiomaDestinatario, tipo);
            logger.debug(
                    "Resultado de crearDesdeURL = " + result.getIdResultado() + ", " + result.getDescripcion());
        } catch (Exception e) {
            logger.error("Excepcin al importar url: " + url + " ,error: " + e);
            throw new ValidatorException("{gestorFlujo.error.inesperado}");
        }
    }
}

From source file:es.pode.empaquetador.presentacion.agregar.personales.AgregarPersonalesControllerImpl.java

/**
 * @see es.pode.empaquetador.presentacion.agregar.personales.AgregarPersonalesController#recuperarDatos(org.apache.struts.action.ActionMapping, es.pode.empaquetador.presentacion.agregar.personales.RecuperarDatosForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 */// ww  w.j a va 2  s  .  co  m
public final void recuperarDatos(ActionMapping mapping,
        es.pode.empaquetador.presentacion.agregar.personales.RecuperarDatosForm form,
        HttpServletRequest request, HttpServletResponse response) throws Exception {

    java.util.Locale locale = (Locale) request.getSession().getAttribute(ConstantesAgrega.DEFAULT_LOCALE);
    ResourceBundle i18n = ResourceBundle.getBundle("application-resources", locale);
    String user = this.gestorSesion.obtenerUsuario(request);
    String isCompartidos = request.getParameter("compartidos");
    TransicionVO[] objetosPersonales = null;
    if (isCompartidos == null || this.getEmpaquetadorSession(request).getEsOffline()) {
        form.setCompartidos("false");
        objetosPersonales = this.getSrvGestorManifestService().obtenerObjetosPersonales(user);
    } else {
        form.setCompartidos("true");
        objetosPersonales = this.getSrvGestorManifestService().obtenerObjetosCompartidos();
    }
    List objetosPersonalesReturn = new ArrayList();
    try {
        boolean encontrado = false;
        for (int i = 0; i < objetosPersonales.length && !encontrado; i++) {
            if (!objetosPersonales[i].getIdODE()
                    .equals(this.getEmpaquetadorSession(request).getIdLocalizador())) {
                objetosPersonalesReturn.add(objetosPersonales[i]);
            }
        }
        logger.debug("Cargado el array de objetos personales con " + objetosPersonales.length + " elementos");
    } catch (Exception e) {
        objetosPersonalesReturn = new ArrayList();
        saveErrorMessage(request,
                i18n.getString("portalempaquetado.avanzado.subsistemas.agregarpersonales.recuperardatos"));
    }
    form.setPersonales(objetosPersonalesReturn);

}

From source file:it.cnr.icar.eric.common.CommonResourceBundle.java

public ResourceBundle getBundle(Locale locale) {
    return ResourceBundle.getBundle(BASE_NAME, locale);
}

From source file:org.wso2.carbon.event.output.adaptor.http.HTTPEventAdaptor.java

private void populateAdapterMessageProps() {
    this.outputAdapterProps = new ArrayList<Property>();
    this.outputMessageProps = new ArrayList<Property>();
    ResourceBundle resourceBundle = ResourceBundle
            .getBundle("org.wso2.carbon.event.output.adaptor.http.i18n.Resources", Locale.getDefault());
    Property urlProp = new Property(HTTPEventAdaptorConstants.ADAPTER_MESSAGE_URL);
    urlProp.setDisplayName(resourceBundle.getString(HTTPEventAdaptorConstants.ADAPTER_MESSAGE_URL));
    urlProp.setHint(resourceBundle.getString(HTTPEventAdaptorConstants.ADAPTER_MESSAGE_URL_HINT));
    urlProp.setRequired(true);/*from  w  ww . jav  a 2  s . c o m*/
    Property usernameProp = new Property(HTTPEventAdaptorConstants.ADAPTER_USERNAME);
    usernameProp.setDisplayName(resourceBundle.getString(HTTPEventAdaptorConstants.ADAPTER_USERNAME));
    usernameProp.setHint(resourceBundle.getString(HTTPEventAdaptorConstants.ADAPTER_USERNAME_HINT));
    usernameProp.setRequired(false);
    Property passwordProp = new Property(HTTPEventAdaptorConstants.ADAPTER_PASSWORD);
    passwordProp.setDisplayName(resourceBundle.getString(HTTPEventAdaptorConstants.ADAPTER_PASSWORD));
    passwordProp.setHint(resourceBundle.getString(HTTPEventAdaptorConstants.ADAPTER_PASSWORD_HINT));
    passwordProp.setRequired(false);
    passwordProp.setSecured(true);
    Property headersProp = new Property(HTTPEventAdaptorConstants.ADAPTER_HEADERS);
    headersProp.setDisplayName(resourceBundle.getString(HTTPEventAdaptorConstants.ADAPTER_HEADERS));
    headersProp.setHint(resourceBundle.getString(HTTPEventAdaptorConstants.ADAPTER_HEADERS_HINT));
    headersProp.setRequired(false);
    Property proxyHostProp = new Property(HTTPEventAdaptorConstants.ADAPTER_PROXY_HOST);
    proxyHostProp.setDisplayName(resourceBundle.getString(HTTPEventAdaptorConstants.ADAPTER_PROXY_HOST));
    proxyHostProp.setHint(resourceBundle.getString(HTTPEventAdaptorConstants.ADAPTER_PROXY_HOST_HINT));
    proxyHostProp.setRequired(false);
    Property proxyPortProp = new Property(HTTPEventAdaptorConstants.ADAPTER_PROXY_PORT);
    proxyPortProp.setDisplayName(resourceBundle.getString(HTTPEventAdaptorConstants.ADAPTER_PROXY_PORT));
    proxyPortProp.setHint(resourceBundle.getString(HTTPEventAdaptorConstants.ADAPTER_PROXY_PORT_HINT));
    proxyPortProp.setRequired(false);
    this.outputMessageProps.add(urlProp);
    this.outputMessageProps.add(usernameProp);
    this.outputMessageProps.add(passwordProp);
    this.outputMessageProps.add(headersProp);
    this.outputAdapterProps.add(proxyHostProp);
    this.outputAdapterProps.add(proxyPortProp);
}

From source file:net.sf.jasperreports.swing.JRViewerController.java

/**
 * /*from  w w w.  j ava 2 s. c o m*/
 */
public JRViewerController(JasperReportsContext jasperReportsContext, Locale locale, ResourceBundle resBundle) {
    this.jasperReportsContext = jasperReportsContext;

    if (locale != null) {
        this.locale = locale;
    } else {
        this.locale = Locale.getDefault();
    }

    if (resBundle == null) {
        this.resourceBundle = ResourceBundle.getBundle("net/sf/jasperreports/view/viewer", getLocale());
    } else {
        this.resourceBundle = resBundle;
    }
}

From source file:es.pode.empaquetador.presentacion.avanzado.organizaciones.gestor.GestorOrganizacionesControllerImpl.java

public final void submit(ActionMapping mapping,
        es.pode.empaquetador.presentacion.avanzado.organizaciones.gestor.SubmitForm form,
        HttpServletRequest request, HttpServletResponse response) throws Exception {

    java.util.Locale locale = (Locale) request.getSession().getAttribute(ConstantesAgrega.DEFAULT_LOCALE);
    ResourceBundle i18n = ResourceBundle.getBundle("application-resources", locale);
    String action = form.getAction();
    if (action.equals(i18n.getString("portal_empaquetado_gestorOrganizaciones.eliminar"))) {
        if ((form.getIdentifierRowSelectionAsArray() == null)
                || (form.getIdentifierRowSelectionAsArray().length == 0)) {
            throw new ValidatorException("{portal_empaquetado.exception.gestorOrganizaciones}");
        }//from w w  w.  java  2  s  .c  o  m
    }

    String[] identificadores = form.getIdentifierRowSelectionAsArray();

    form.setOrganizacionesAsArray(identificadores);
}