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

/**
 * @param packageName package name, used for
 *        <code>Resources.properties</code> file look-up
 * @param messageKey message key/*from  w w w . ja  v a 2s . c  o m*/
 * @param locale locale to get message for
 * @param data data for parameter placeholders substitution, may be
 *        <code>Object</code>, <code>array</code> or
 *        <code>Collection</code>.
 * @return message for given locale
 */
public static String getMessage(final String packageName, final String messageKey, final Locale locale,
        final Object data) {
    Object obj = bundles.get(packageName + '|' + locale);
    if (obj == null) {
        try {
            obj = ResourceBundle.getBundle(packageName + ".Resources", //$NON-NLS-1$
                    locale);
        } catch (MissingResourceException mre) {
            obj = FAKE_BUNDLE;
        }
        bundles.put(packageName + '|' + locale, obj);
    }
    if (obj == FAKE_BUNDLE) {
        return "resource " + packageName + '.' + messageKey //$NON-NLS-1$
                + " not found for locale " + locale; //$NON-NLS-1$
    }
    try {
        String result = ((ResourceBundle) obj).getString(messageKey);
        return (data == null) ? result : processParams(result, data);
    } catch (MissingResourceException mre) {
        return "resource " + packageName + '.' + messageKey //$NON-NLS-1$
                + " not found for locale " + locale; //$NON-NLS-1$
    }
}

From source file:com.salesmanager.core.util.ShippingUtil.java

/**
 * Strip a map of configuration if built as <ID>|<SHIPPING
 * LABEL>;<ID>|<SHIPPING LABEL>
 * // w  ww .  j  a v  a2  s . c om
 * @param packageline
 * @return
 */
public static Map getConfigurationValuesMap(String packageline, String moduleid, Locale locale) {

    ResourceBundle bundle = ResourceBundle.getBundle(moduleid, locale);

    Map returnmap = new HashMap();
    StringTokenizer st = new StringTokenizer(packageline, ";");
    while (st.hasMoreTokens()) {
        String token = st.nextToken();
        StringTokenizer stst = new StringTokenizer(token, "|");
        int i = 0;
        String key = null;
        while (stst.hasMoreTokens()) {
            String ptoken = stst.nextToken();
            if (i == 0) {
                key = ptoken;
            }
            // get value from bundle
            String value = bundle.getString("shipping.quote.services.label." + key);
            if (i == 1 && token.contains("|")) {
                returnmap.put(key, value);
            } else {
                returnmap.put(key, value);
            }
            i++;
        }
    }
    return returnmap;
}

From source file:es.pode.modificador.presentacion.configurar.objetos.ruta.IndicarRutaControllerImpl.java

/**
 * @see es.pode.modificador.presentacion.configurar.objetos.ruta.IndicarRutaController#selectAction(org.apache.struts.action.ActionMapping, es.pode.modificador.presentacion.configurar.objetos.ruta.SelectActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 *///from  w  w w.ja va  2  s . c  o  m
public final java.lang.String selectAction(ActionMapping mapping,
        es.pode.modificador.presentacion.configurar.objetos.ruta.SelectActionForm form,
        HttpServletRequest request, HttpServletResponse response) throws Exception {
    java.util.Locale locale = (java.util.Locale) request.getSession()
            .getAttribute(ConstantesAgrega.DEFAULT_LOCALE);
    ResourceBundle i18n = ResourceBundle.getBundle("application-resources", locale);

    String botonCancelar = i18n.getString("comun.cancelar");
    // El punto de retorno es distinto para la version offline
    String cancelar = DecisorOffline.esOffline() ? "CancelarOffline" : "Cancelar";
    String continuar = i18n.getString("comun.aceptar");

    String action = form.getAction();
    if (action == null) {
        return cancelar;
    }

    //       if(action.equals(cancelar)) return cancelar;
    //       else 
    if (action.equals(continuar))
        return "Aceptar";

    return cancelar;
}

From source file:de.hska.ld.core.service.impl.MailServiceImpl.java

@Override
public void sendMail(String fullName, String email, String templateFileName, Map<String, Object> model) {
    ;//from   w w w .  jav  a 2  s.  c o  m
    if (Boolean.parseBoolean(env.getProperty("email.enabled"))) {
        Locale locale = LocaleContextHolder.getLocale();
        ResourceBundle bundle = ResourceBundle.getBundle("messages", locale);
        model.put("dear", bundle.getString("email.dear"));
        model.put("fullName", fullName);
        model.put("greeting", bundle.getString("email.greeting"));

        String text = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine,
                "templates/mail/" + templateFileName, "UTF-8", model);

        Properties properties = getMailProperties();

        Session session = Session.getInstance(properties, new javax.mail.Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(MAIL_PROPERTIES.getProperty("email.username"),
                        MAIL_PROPERTIES.getProperty("email.password"));
            }
        });

        try {
            MimeMessage message = new MimeMessage(session);
            MimeMessageHelper helper = new MimeMessageHelper(message, true);
            helper.setFrom(MAIL_PROPERTIES.getProperty("email.from.system"));
            helper.setTo(email);
            helper.setSubject(model.containsKey("subject") ? (String) model.get("subject") : "");
            helper.setText(text, true);
            Transport.send(message);
        } catch (MessagingException e) {
            e.printStackTrace();
        }
    }
}

From source file:io.github.swagger2markup.internal.document.builder.DefinitionsDocumentBuilder.java

public DefinitionsDocumentBuilder(Swagger2MarkupConverter.Context context,
        Swagger2MarkupExtensionRegistry extensionRegistry, Path outputPath) {
    super(context, extensionRegistry, outputPath);

    ResourceBundle labels = ResourceBundle.getBundle("io/github/swagger2markup/lang/labels",
            config.getOutputLanguage().toLocale());
    DEFINITIONS = labels.getString("definitions");
    POLYMORPHISM_COLUMN = labels.getString("polymorphism.column");
    DISCRIMINATOR_COLUMN = labels.getString("polymorphism.discriminator");
    POLYMORPHISM_NATURE = new HashMap<ObjectTypePolymorphism.Nature, String>() {
        {//from  ww  w  .j  ava  2 s .  c  o m
            put(ObjectTypePolymorphism.Nature.COMPOSITION, labels.getString("polymorphism.nature.COMPOSITION"));
            put(ObjectTypePolymorphism.Nature.INHERITANCE, labels.getString("polymorphism.nature.INHERITANCE"));
        }
    };
    TYPE_COLUMN = labels.getString("type_column");

    if (config.isSeparatedDefinitionsEnabled()) {
        if (logger.isDebugEnabled()) {
            logger.debug("Create separated definition files is enabled.");
        }
        Validate.notNull(outputPath, "Output directory is required for separated definition files!");
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("Create separated definition files is disabled.");
        }
    }
}

From source file:es.pode.empaquetador.presentacion.avanzado.recursos.crear.tipo.CrearRecursoAvanzadoTipoControllerImpl.java

public final java.lang.String selectAction(ActionMapping mapping,
        es.pode.empaquetador.presentacion.avanzado.recursos.crear.tipo.SelectActionForm form,
        HttpServletRequest request, HttpServletResponse response) throws Exception {
    /*//from  ww w.j  a  v a 2s  .  c  om
     * Metodo de decision para el action. Analiza los parametros
     * actionSubmit (value de los botones submit) para redirigir al caso de
     * uso correspondiente. El actionSubmit llegara internacionalizado, por
     * lo que es necesario acceder al ResouceBundle para obtener el valor
     * correcto en la comparacion.
     */

    String result = null;
    String actionSubmit = form.getAction();
    java.util.Locale locale = (Locale) request.getSession().getAttribute(ConstantesAgrega.DEFAULT_LOCALE);
    ResourceBundle i18n = ResourceBundle.getBundle("application-resources", locale);

    if (form.getAction() == (null)) {
        throw new ValidatorException("{portal_empaquetado.exception}");
    }
    // Cancelar
    else if (actionSubmit.equals(i18n.getString("portalempaquetado.avanzado.recursos.crear.paso1.cancelar"))) {
        result = "Cancelar";
    }
    // Aceptar
    else if (actionSubmit.equals(i18n.getString("portalempaquetado.avanzado.recursos.crear.paso1.continuar"))) {
        result = "Continuar";
    }
    // Aceptar
    else if (actionSubmit
            .equals(i18n.getString("portalempaquetado.avanzado.recursos.crear.paso1.anadirmetadatos"))) {
        result = "Metadato";
    } else {
        Logger.getLogger(this.getClass())
                .error("El valor del submit no es correcto (actionSubmit = " + actionSubmit + ";");
    }
    return result;
}

From source file:org.shredzone.cilla.admin.login.LoginBean.java

/**
 * Tries to login the user with the given credentials.
 *
 * @return name of the admin index page if the login was successful, {@code null} if
 *         the login was not successful.
 */// w  w  w .ja v a2 s. co  m
public String login() {
    try {
        remoteLoginService.login(getUserName(), getPassword());
    } catch (AuthenticationException ex) {
        log.error("Authentication failed, user: '" + getUserName() + "', password: '********'", ex);

        FacesContext ctx = FacesContext.getCurrentInstance();
        Locale loc = ctx.getViewRoot().getLocale();
        ResourceBundle bundle = ResourceBundle.getBundle(ctx.getApplication().getMessageBundle(), loc);
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, bundle.getString("login.failed"),
                ex.getMessage());
        ctx.addMessage(null, message);

        return null;
    }

    return "/admin/index.xhtml";
}

From source file:es.pode.empaquetador.presentacion.avanzado.organizaciones.principal.OrganizacionPrincipalControllerImpl.java

public final void fijarOrganizacionPrincipal(ActionMapping mapping,
        es.pode.empaquetador.presentacion.avanzado.organizaciones.principal.FijarOrganizacionPrincipalForm 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.principalAceptar"))) {
        String idOrganizacion = form.getIdentifier();
        EmpaquetadorSession sesEmpaq = this.getEmpaquetadorSession(request);
        List subman = sesEmpaq.getSubmanifestPath();

        if (subman != null && subman.size() > 0) {
            OdeVO ultimo = (OdeVO) subman.get(subman.size() - 1);
            Integer index = subman.size() - 1;
            String identificador = index == 0 ? sesEmpaq.getIdLocalizador() : ultimo.getIdentifier();

            this.getSrvGestorManifestService().fijarOrganizacionPorDefecto(identificador, idOrganizacion);
        } else {/*from w ww .  ja  v a 2 s . co m*/
            throw new ValidatorException("{portal_empaquetado.exception}");
        }
    }
}

From source file:it.cnr.icar.eric.client.ui.common.UICommonResourceBundle.java

private ResourceBundle getLocalizedResourceBundle() {
    try {//w  w w .jav a  2  s  .c om
        Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
        return ResourceBundle.getBundle(messageBundleName, locale);
    } catch (Exception e) {
        return ResourceBundle.getBundle(messageBundleName);
    }
}

From source file:com.agimatec.validation.jsr303.DefaultMessageInterpolator.java

public DefaultMessageInterpolator(ResourceBundle resourceBundle) {

    defaultLocale = Locale.getDefault();

    if (resourceBundle == null) {
        ResourceBundle bundle = getFileBasedResourceBundle(defaultLocale);
        if (bundle != null) {
            userBundlesMap.put(defaultLocale, bundle);
        }//from  w  ww.  j av  a2s .  c  om

    } else {
        userBundlesMap.put(defaultLocale, resourceBundle);
    }

    defaultBundlesMap.put(defaultLocale, ResourceBundle.getBundle(DEFAULT_VALIDATION_MESSAGES, defaultLocale));
}