Example usage for java.util Locale getDefault

List of usage examples for java.util Locale getDefault

Introduction

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

Prototype

public static Locale getDefault() 

Source Link

Document

Gets the current value of the default locale for this instance of the Java Virtual Machine.

Usage

From source file:com.googlecode.jsfFlex.myFaces.LocaleUtils.java

/**
 * Converts a locale string to <code>Locale</code> class. Accepts both
 * '_' and '-' as separators for locale components.
 *
 * @param localeString string representation of a locale
 * @return Locale instance, compatible with the string representation
 *//*from  w ww .  ja  v  a 2s .  c o  m*/
public static Locale toLocale(String localeString) {
    if ((localeString == null) || (localeString.length() == 0)) {
        Locale locale = Locale.getDefault();
        if (log.isWarnEnabled())
            log.warn("Locale name in faces-config.xml null or empty, setting locale to default locale : "
                    + locale.toString());
        return locale;
    }

    int separatorCountry = localeString.indexOf('_');
    char separator;
    if (separatorCountry >= 0) {
        separator = '_';
    } else {
        separatorCountry = localeString.indexOf('-');
        separator = '-';
    }

    String language, country, variant;
    if (separatorCountry < 0) {
        language = localeString;
        country = variant = "";
    } else {
        language = localeString.substring(0, separatorCountry);

        int separatorVariant = localeString.indexOf(separator, separatorCountry + 1);
        if (separatorVariant < 0) {
            country = localeString.substring(separatorCountry + 1);
            variant = "";
        } else {
            country = localeString.substring(separatorCountry + 1, separatorVariant);
            variant = localeString.substring(separatorVariant + 1);
        }
    }

    return new Locale(language, country, variant);
}

From source file:com.liferay.util.LocaleUtil.java

public static Locale fromLanguageId(String languageId) {
    Locale locale = null;/*from www  . jav a 2 s  .c o  m*/

    try {
        int pos = languageId.indexOf(StringPool.UNDERLINE);

        String languageCode = languageId.substring(0, pos);
        String countryCode = languageId.substring(pos + 1, languageId.length());

        locale = new Locale(languageCode, countryCode);
    } catch (Exception e) {
        _log.warn(languageId + " is not a valid language id");
    }

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

    return locale;
}

From source file:adalid.commons.bundles.Bundle.java

/**
 * @param newLocale the locale to set// ww  w .j  av a2s. c  om
 */
public static void setLocale(Locale newLocale) {
    ResourceBundle prevResourceBundle = resourceBundle;
    if (newLocale == null) {
        locale = Locale.getDefault();
        resourceBundle = defaultResourceBundle;
    } else if (newLocale.equals(locale)) {
    } else {
        locale = newLocale;
        try {
            resourceBundle = ResourceBundle.getBundle(BASE_NAME, locale);
        } catch (MissingResourceException e) {
            resourceBundle = defaultResourceBundle;
        }
    }
    if (resourceBundle.equals(prevResourceBundle)) {
    } else {
        linguist = getLinguist(resourceBundle);
    }
}

From source file:Main.java

public void actionPerformed(ActionEvent e) {

    Locale locale = Locale.getDefault();
    Date date = new Date(e.getWhen());
    String s = DateFormat.getTimeInstance(DateFormat.SHORT, locale).format(date);

    if (!model.isEmpty()) {
        model.clear();//from   ww w .  ja  va  2  s . com
    }

    if (e.getID() == ActionEvent.ACTION_PERFORMED) {
        model.addElement(" Event Id: ACTION_PERFORMED");

    }

    model.addElement("Time: " + s);

    String source = e.getSource().getClass().getName();

    int mod = e.getModifiers();

    StringBuffer buffer = new StringBuffer("Modifiers: ");

    if ((mod & ActionEvent.ALT_MASK) > 0) {
        buffer.append("Alt ");

    }

    if ((mod & ActionEvent.SHIFT_MASK) > 0) {
        buffer.append("Shift ");

    }

    if ((mod & ActionEvent.META_MASK) > 0) {
        buffer.append("Meta ");

    }

    if ((mod & ActionEvent.CTRL_MASK) > 0) {
        buffer.append("Ctrl ");

    }
    model.addElement(buffer);

}

From source file:org.slc.sli.ingestion.util.spring.MessageSourceHelperTest.java

@Test
public void testMessageSourceHelper() {
    StaticMessageSource ms = new StaticMessageSource();

    ms.addMessage("MSG1", Locale.getDefault(), "This is message 1");

    ms.addMessage("MSG2", Locale.getDefault(), "This is message 2 with param: {0}");

    String actual = MessageSourceHelper.getMessage(ms, "MSG1");
    Assert.assertEquals("This is message 1", actual);

    actual = MessageSourceHelper.getMessage(ms, "MSG1", "Test Param");
    Assert.assertEquals("This is message 1", actual);

    actual = MessageSourceHelper.getMessage(ms, "MSG2", "Test Param");
    Assert.assertEquals("This is message 2 with param: Test Param", actual);
}

From source file:com.codecrate.shard.ui.table.ReadOnlyEventTableModel.java

private static String[] buildColumnNames(MessageSource messageSource, String[] propertyNames) {
    String[] columnNames = new String[propertyNames.length];
    for (int x = 0; x < propertyNames.length; x++) {
        columnNames[x] = messageSource.getMessage(propertyNames[x], null, propertyNames[x],
                Locale.getDefault());
    }//  w ww .ja va2  s  .co  m
    return columnNames;
}

From source file:gov.nih.nci.iso21090.Tel.java

/**
 * @param scheme the scheme part of a URI.
 * @param allowedSchemes the schemes that we consider to be valid.
 * @return true if allowedSchemes is null or if it contains scheme.
 *///w  w  w.  j ava  2s  .  c  o  m
protected static boolean isAllowed(String scheme, List<String> allowedSchemes) {
    if (scheme == null) {
        return false;
    }
    return allowedSchemes == null || allowedSchemes.contains(scheme.toLowerCase(Locale.getDefault()));
}

From source file:net.granoeste.validator.DateValidator.java

public DateValidator(final String errorMessage) {
    super(errorMessage);
    mValidator = org.apache.commons.validator.DateValidator.getInstance();
    mLocale = Locale.getDefault();
}

From source file:com.skubit.iab.activities.TransactionDetailsActivity.java

private static final String formatCurrencyAmount(BigDecimal balanceNumber) {
    NumberFormat numberFormat = NumberFormat.getInstance(Locale.getDefault());
    numberFormat.setMaximumFractionDigits(8);
    numberFormat.setMinimumFractionDigits(4);

    if (balanceNumber.compareTo(BigDecimal.ZERO) == -1) {
        balanceNumber = balanceNumber.multiply(new BigDecimal(-1));
    }/*  w ww  . ja v  a  2 s  . c o m*/

    return numberFormat.format(balanceNumber);
}

From source file:org.zenoss.zep.Messages.java

/**
 * Returns the message with the specified arguments substituted.
 *
 * @param code Message code./*from w  w  w  . ja  v  a2 s.  com*/
 * @param args Arguments used to build the message.
 * @return The substituted message in the default locale.
 */
public String getMessage(String code, Object... args) {
    return source.getMessage(code, args, Locale.getDefault());
}