Example usage for java.util ResourceBundle containsKey

List of usage examples for java.util ResourceBundle containsKey

Introduction

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

Prototype

public boolean containsKey(String key) 

Source Link

Document

Determines whether the given key is contained in this ResourceBundle or its parent bundles.

Usage

From source file:org.talend.dataprep.i18n.ActionsBundle.java

private String getMessage(Object action, Locale locale, String code, Object... args) {
    ResourceBundle bundle = findBundle(action, locale);
    // We can put some cache here if default internal caching it is not enough
    MessageFormat messageFormat;//from  w w  w.  j a v a 2s .  com
    if (bundle.containsKey(code)) {
        messageFormat = new MessageFormat(bundle.getString(code));
    } else {
        try {
            messageFormat = new MessageFormat(actionToResourceBundle.get(fallBackKey).getString(code));
        } catch (MissingResourceException e) {
            LOGGER.info("Unable to find key '{}' using context '{}'.", code, action, e);
            throw new TalendRuntimeException(BaseErrorCodes.MISSING_I18N, e);
        }
    }
    return messageFormat.format(args);
}

From source file:org.vulpe.commons.util.VulpeEmailUtil.java

/**
 * Send Mail to many recipients./*from www .j a  v  a 2  s.c  o m*/
 *
 * @param recipients
 *            Recipients
 * @param subject
 *            Subject
 * @param body
 *            Body
 * @throws VulpeSystemException
 *             exception
 */
public static boolean sendMail(final String[] recipients, final String subject, final String body) {
    boolean sended = true;
    if (!checkValidEmail(recipients)) {
        LOG.error("Invalid mails: " + recipients);
        sended = false;
    }
    if (isDebugEnabled) {
        LOG.debug("Entering in sendMail...");
        for (int i = 0; i < recipients.length; i++) {
            LOG.debug("recipient: " + recipients[i]);
        }
        LOG.debug("subject: " + subject);
        LOG.debug("body: " + body);
    }
    try {
        final ResourceBundle bundle = ResourceBundle.getBundle("mail");
        if (bundle != null) {
            final HtmlEmail mail = new HtmlEmail();
            String mailFrom = "";
            if (bundle.containsKey("mail.smtp.auth") && Boolean.valueOf(bundle.getString("mail.smtp.auth"))) {
                final String username = bundle.getString("mail.smtp.user");
                final String password = bundle.getString("mail.smtp.password");
                mail.setAuthentication(username, password);
            }
            if (bundle.containsKey("mail.from")) {
                mailFrom = bundle.getString("mail.from");
            }
            mail.setFrom(mailFrom);
            for (final String recipient : recipients) {
                mail.addTo(recipient);
            }
            mail.setHostName(bundle.getString("mail.smtp.host"));
            final String port = bundle.getString("mail.smtp.port");
            mail.setSmtpPort(Integer.valueOf(port));
            if (bundle.containsKey("mail.smtp.starttls.enable")
                    && Boolean.valueOf(bundle.getString("mail.smtp.starttls.enable"))) {
                mail.setTLS(true);
                mail.setSSL(true);
                if (bundle.containsKey("mail.smtp.socketFactory.port")) {
                    String factoryPort = bundle.getString("mail.smtp.socketFactory.port");
                    mail.setSslSmtpPort(factoryPort);
                }
            }
            String encoding = "UTF-8";
            if (bundle.containsKey("mail.encode")) {
                encoding = bundle.getString("mail.encode");
            }
            mail.setCharset(encoding);
            mail.setSubject(subject);
            mail.setHtmlMsg(body);
            mail.send();
        } else {
            LOG.error("Send Mail properties not setted");
            sended = false;
        }
    } catch (Exception e) {
        LOG.error("Error on send mail", e);
        sended = false;
    }
    LOG.debug("Out of sendMail...");
    return sended;
}

From source file:org.vulpe.commons.util.VulpeEmailUtil.java

/**
 * Send mail to recipients by Web Service.
 *
 * @param recipients/*from ww w .ja v  a  2s .  co  m*/
 *
 * @param subject
 *
 * @param body
 *
 * @param mailerService
 *
 * @throws VulpeSystemException
 *             exception
 */
public static void sendMailByService(final String[] recipients, final String subject, final String body,
        final String mailerService) {
    try {
        final ResourceBundle bundle = ResourceBundle.getBundle("mail");
        String mailFrom = "";
        if (bundle.containsKey("mail.from")) {
            mailFrom = bundle.getString("mail.from");
        }
        final InitialContext initialContext = new InitialContext();
        final Session session = (Session) initialContext.lookup(mailerService);
        final Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress(mailFrom));
        for (String recipient : recipients) {
            message.addRecipient(Message.RecipientType.TO, new InternetAddress(recipient));
        }
        // msg.setRecipient(Message.RecipientType.TO, new
        // InternetAddress(to));
        message.setSubject(subject);
        message.setText(body);
        Transport.send(message);
    } catch (Exception e) {
        LOG.error(e.getMessage());
    }

}

From source file:password.pwm.PwmConstants.java

private static String readBuildInfoBundle(final String key, final String defaultValue) {
    final ResourceBundle resourceBundle = ResourceBundle.getBundle("password.pwm.BuildInformation");
    if (resourceBundle.containsKey(key)) {
        return resourceBundle.getString(key);
    }//  w  w  w .  jav  a2  s .  com

    return defaultValue;
}

From source file:pt.ist.vaadinframework.ui.CaptionUtils.java

private static String makeCaption(ResourceBundle bundle, Class<?> type, Object propertyId,
        Component uiContext) {/*  w  w  w . ja  v a2s  .  c  o  m*/
    String key = getBundleKey(bundle, type, propertyId, StringUtils.EMPTY);
    if (bundle.containsKey(key)) {
        return bundle.getString(key);
    }
    VaadinFrameworkLogger.getLogger().warn("i18n opportunity missed: " + key);
    return DefaultFieldFactory.createCaptionByPropertyId(propertyId);
}

From source file:pt.ist.vaadinframework.ui.CaptionUtils.java

public static String makeDescription(ResourceBundle bundle, Class<?> type, Object propertyId,
        Component uiContext) {/* w  w w  . j a v a2  s .  c o m*/
    String key = getBundleKey(bundle, type, propertyId, ".description");
    if (bundle.containsKey(key)) {
        return bundle.getString(key);
    }
    VaadinFrameworkLogger.getLogger().warn("i18n opportunity missed: " + key);
    return makeCaption(bundle, type, propertyId, uiContext);
}

From source file:pt.ist.vaadinframework.ui.CaptionUtils.java

private static String getBundleKey(ResourceBundle bundle, List<String> missed, Class<?> clazz,
        Object propertyId, String suffix) {

    String key = clazz.getName() + "." + propertyId + suffix;
    if (bundle.containsKey(key)) {
        return key;
    }/*from w ww . ja  va  2  s .co  m*/
    missed.add(key);
    CaptionUtilsWriter.addKey(key);
    if (!hasMoreClassesInHierarchy(clazz)) {
        return StringUtils.join(missed, " or ");
    }
    return getBundleKey(bundle, missed, clazz.getSuperclass(), propertyId, suffix);
}

From source file:ru.mystamps.web.tests.TranslationUtils.java

public static String tr(String key) {
    String msg = "";

    for (ResourceBundle bundle : BUNDLES) {
        if (bundle.containsKey(key)) {
            return bundle.getString(key);
        }//from  w ww. j  a v  a  2  s. com
    }

    return msg;
}

From source file:se.trixon.jota.server.JobExecutor.java

private String getRsyncErrorCode(int exitValue) {
    ResourceBundle bundle = BundleHelper.getBundle(getClass(), "ExitValues");
    String key = String.valueOf(exitValue);

    return bundle.containsKey(key) ? bundle.getString(key) : String.format((Dict.SYSTEM_CODE.toString()), key);
}