Example usage for java.util Locale Locale

List of usage examples for java.util Locale Locale

Introduction

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

Prototype

public Locale(String language) 

Source Link

Document

Construct a locale from a language code.

Usage

From source file:it.av.youeat.web.security.OpenIDAttributes2UserDetailsImpl.java

/**
 * {@inheritDoc}//from   w  w  w  . j  ava 2s.  c o  m
 */
@Override
public Eater extract(OpenIDAuthenticationToken token) {
    Eater user = new Eater();
    List<OpenIDAttribute> attributes = token.getAttributes();
    for (OpenIDAttribute openIDAttribute : attributes) {
        if (openIDAttribute.getName().equals("firstName")) {
            user.setFirstname(StringUtils.join(openIDAttribute.getValues(), ""));
        }

        if (openIDAttribute.getName().equals("email")) {
            user.setEmail(StringUtils.join(openIDAttribute.getValues(), ""));
        }

        if (openIDAttribute.getName().equals("lastName")) {
            user.setLastname(StringUtils.join(openIDAttribute.getValues(), ""));
        }

        if (openIDAttribute.getName().equals("language")) {
            String langage = StringUtils.join(openIDAttribute.getValues(), "");
            user.setLanguage(languageService.getSupportedLanguage(new Locale(langage)));
        }
        if (openIDAttribute.getName().equals("country")) {
            String country = StringUtils.join(openIDAttribute.getValues(), "");
            user.setCountry(countryService.getByIso2(country));
        }
    }
    if (user.getCountry() == null) {
        user.setCountry(countryService.getByIso2(user.getLanguage().getCountry()));
        //user.setLanguage(languageService.getSupportedLanguage(new Locale(user.getLocale())));
    }
    user.setEmail(user.getEmail());
    user.setSocialType(SocialType.GOOGLE);
    user.setSocialUID(token.getIdentityUrl());
    return user;
}

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

public static Locale getLocaleFromStoreEntity(MerchantStore store, String defaultLanguage) {
    Map countriesMap = RefCache.getAllcountriesmap(LanguageUtil.getLanguageNumberCode(defaultLanguage));
    if (countriesMap == null) {
        log.error("Cannnot get a Map of countries for language code " + defaultLanguage);
        return getDefaultLocale();
    }//  ww  w .jav a2s .  c o m
    Country country = (Country) countriesMap.get(store.getCountry());
    Locale locale = new Locale(country.getCountryIsoCode2());
    return locale;
}

From source file:net.sf.gazpachoquest.questionnaires.views.login.OldLoginView.java

private ComboBox createLanguageSelector() {
    ComboBox languageSelector = new ComboBox("com.vaadin.demo.dashboard.DashboardUI.Language");
    languageSelector.setImmediate(true);
    languageSelector.setNullSelectionAllowed(false);
    addLocale(Locale.ENGLISH, languageSelector);
    addLocale(Locale.FRENCH, languageSelector);
    addLocale(new Locale("es"), languageSelector);
    // languageSelector.setValue(I18NStaticService.getI18NServive().getLocale());
    /*-languageSelector.addValueChangeListener(new ValueChangeListener() {
            /*  w ww . jav a 2s. c o m*/
    private static final long serialVersionUID = 1L;
            
    @Override
    public void valueChange(ValueChangeEvent event) {
        Locale locale = (Locale) (event.getProperty().getValue());
        I18NStaticService.getI18NServive().setLocale(locale);
        getUI().requestRepaintAll();
    }
    });*/
    return languageSelector;
}

From source file:com.hiperium.bo.manager.mail.EmailMessageManager.java

/**
 * Sends an email with the new user password.
 * //from  w w  w. ja v a 2  s .com
 * @param user
 * @throws javax.mail.internet.AddressException
 * @throws javax.mail.MessagingException
 */
public void sendNewPassword(User user) {
    try {
        this.log.debug("sendNewPassword() - START");
        // Create the corresponding user locale.
        Locale locale = null;
        if (StringUtils.isBlank(user.getLanguageId())) {
            locale = Locale.getDefault();
        } else {
            locale = new Locale(user.getLanguageId());
        }
        ResourceBundle resource = ResourceBundle.getBundle(EnumI18N.COMMON.value(), locale);

        // Get system properties
        Properties properties = System.getProperties();
        // Setup mail server
        properties.setProperty("mail.smtp.host", CloudEmailUser.HOST);
        properties.setProperty("mail.user", CloudEmailUser.USERNAME);
        properties.setProperty("mail.password", CloudEmailUser.PASSWORD);
        // Get the default Session object.
        Session session = Session.getDefaultInstance(properties);
        // Create a default MimeMessage object.
        MimeMessage message = new MimeMessage(session);
        // Set From: header field of the header.
        message.setFrom(new InternetAddress(CloudEmailUser.ADDRESS));
        // Set To: header field of the header.
        message.addRecipient(Message.RecipientType.TO, new InternetAddress(user.getEmail()));
        // Set Subject: header field
        message.setSubject(resource.getString(GENERATED_USER_PASSWD_SUBJECT));
        // Send the actual HTML message, as big as you like
        message.setContent(MessageFormat.format(resource.getString(GENERATED_USER_PASSWD_CONTENT),
                user.getFirstname(), user.getLastname(), user.getPassword()), "text/html");
        // Send message
        Transport.send(message);
        this.log.debug("sendNewPassword() - END");
    } catch (AddressException e) {
        this.log.error("AddressException to send email to " + user.getEmail(), e);
    } catch (MessagingException e) {
        this.log.error("MessagingException to send email to " + user.getEmail(), e);
    }
}

From source file:com.inkubator.sms.gateway.web.LoginController.java

@PostConstruct
@Override//from   w w  w.ja va  2s.  c o  m
public void initialization() {
    selectedLanguage = "in";
    FacesUtil.setSessionAttribute(SMSGATEWAY.BAHASA_ACTIVE, selectedLanguage);
    FacesUtil.getFacesContext().getViewRoot().setLocale(new Locale(selectedLanguage));
    System.out.println(" Hehrherhehreh");
}

From source file:com.opensymphony.xwork2.util.StrutsLocalizedTextProvider.java

/**
 * Builds a {@link java.util.Locale} from a String of the form en_US_foo into a Locale
 * with language "en", country "US" and variant "foo". This will parse the output of
 * {@link java.util.Locale#toString()}.//  ww  w. j av  a2 s . c  o m
 *
 * @param localeStr     The locale String to parse.
 * @param defaultLocale The locale to use if localeStr is <tt>null</tt>.
 * @return requested Locale
 * @deprecated please use {@link org.apache.commons.lang3.LocaleUtils#toLocale(String)}
 */
@Deprecated
public static Locale localeFromString(String localeStr, Locale defaultLocale) {
    if ((localeStr == null) || (localeStr.trim().length() == 0) || ("_".equals(localeStr))) {
        if (defaultLocale != null) {
            return defaultLocale;
        }
        return Locale.getDefault();
    }

    int index = localeStr.indexOf('_');
    if (index < 0) {
        return new Locale(localeStr);
    }

    String language = localeStr.substring(0, index);
    if (index == localeStr.length()) {
        return new Locale(language);
    }

    localeStr = localeStr.substring(index + 1);
    index = localeStr.indexOf('_');
    if (index < 0) {
        return new Locale(language, localeStr);
    }

    String country = localeStr.substring(0, index);
    if (index == localeStr.length()) {
        return new Locale(language, country);
    }

    localeStr = localeStr.substring(index + 1);
    return new Locale(language, country, localeStr);
}

From source file:no.met.jtimeseries.marinogram.MarinogramPlot.java

public MarinogramPlot(int width, String language) {
    this.width = width;
    this.language = language;
    locale = new Locale(language);
    messages = ResourceBundle.getBundle("messages", locale);
}

From source file:com.loadsensing.app.ImatgeXarxaSensors.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Definimos idioma
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(ImatgeXarxaSensors.this);
    Locale locale = new Locale(settings.getString("location", "es"));
    Locale.setDefault(locale);/*  w  ww.j ava  2 s . c  o  m*/
    Configuration config = new Configuration();
    config.locale = locale;
    getApplicationContext().getResources().updateConfiguration(config,
            getBaseContext().getResources().getDisplayMetrics());

    setContentView(new TouchView(this));
}

From source file:com.project.framework.configuration.WebMvcConfig.java

@Bean
public LocaleResolver localeResolver() {
    SessionLocaleResolver resolver = new SessionLocaleResolver();
    resolver.setDefaultLocale(new Locale("es"));
    return resolver;
}

From source file:org.vaadin.spring.samples.i18n.TranslatedUI.java

@Override
protected void initUI(VaadinRequest request) {
    final VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);//from   w  ww .java 2s.  c  om
    layout.setSpacing(true);
    setContent(layout);

    english = new Button("English", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            setLocale(Locale.ENGLISH);
        }
    });
    layout.addComponent(english);

    swedish = new Button("Svenska", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            setLocale(new Locale("sv"));
        }
    });
    layout.addComponent(swedish);

    bigDecimalTextField = new TextField();
    bigDecimalTextField.setConverter(new StringToBigDecimalConverter());
    bigDecimalTextField.setPropertyDataSource(bigDecimalObjectProperty);
    bigDecimalTextField.setImmediate(true);
    bigDecimalTextField.setNullSettingAllowed(false);
    layout.addComponent(bigDecimalTextField);

    dateField = new DateField();
    dateField.setValue(new Date());
    layout.addComponent(dateField);
}