Example usage for java.util Locale setDefault

List of usage examples for java.util Locale setDefault

Introduction

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

Prototype

public static synchronized void setDefault(Locale newLocale) 

Source Link

Document

Sets the default locale for this instance of the Java Virtual Machine.

Usage

From source file:net.jawr.web.test.JawrIntegrationServer.java

/**
 * Initialize the application server before the test
 * /*from  ww w  .  ja va 2 s . co m*/
 * @throws IOException
 */
public void initBeforeTestCase() throws IOException {

    LOGGER.info("Init Jawr integration server before testcase");
    webAppConfigInitialized = false;
    // Set default locale to en_US
    Locale.setDefault(new Locale("en", "US"));
}

From source file:ch.ralscha.extdirectspring_itest.InfoServiceTest.java

@Test
public void testUpdateInfoUser1() throws IOException {

    Locale.setDefault(Locale.US);

    testUserPost("updateInfoUser1", "not a well-formed email address", entry("lc", "ralph"),
            entry("success", Boolean.FALSE));
}

From source file:de.interseroh.report.webconfig.WebMvcConfig.java

@Bean
public LocaleResolver localeResolver() {
    Locale.setDefault(Locale.ENGLISH);
    CookieLocaleResolver cookieLocaleResolver = new CookieLocaleResolver();
    cookieLocaleResolver.setCookieName("reportengine-language");
    return cookieLocaleResolver;
}

From source file:org.apache.avalon.repository.cli.Main.java

private static void doHelp(CommandLine line) {
    if (line.hasOption("lang")) {
        ResourceManager.clearResourceCache();
        String language = line.getOptionValue("lang");
        Locale locale = new Locale(language, "");
        Locale.setDefault(locale);
        REZ = ResourceManager.getPackageResources(Main.class);
    }//from w w  w .j  av a  2s  .co  m

    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp("repository [artifact]", " ", buildCommandLineOptions(), "", true);
}

From source file:it.cnr.icar.eric.client.xml.registry.ConnectionFactoryImpl.java

/**
 * Sets initial Locale.// w w w. j a v  a2 s. c  om
 *
 * The Locale is defined by 3 properties:
 * <ul>
 * <li>jaxr-ebxml.initial-locale.language</li>
 * <li>jaxr-ebxml.initial-locale.country</li>
 * <li>jaxr-ebxml.initial-locale.variant</li>
 * </ul>
 * Locale.setDefault will be called with a new Locale created using language,
 * country and variant (if defined, up to the first missing of the 3
 * properties). If language property is not defined, Locale WILL NOT be
 * changed. See http://java.sun.com/j2se/1.4.1/docs/api/java/util/Locale.html
 * for possible values for language, country and variant.
 *
 * @param props The source for the properties.
 */
private void initLocale(Properties props) {
    String language = props.getProperty("jaxr-ebxml.initial-locale.language");

    String country = props.getProperty("jaxr-ebxml.initial-locale.country");
    String variant = props.getProperty("jaxr-ebxml.initial-locale.variant");

    if ((language == null) || (language.length() == 0)) {
        return;
    } else if ((country == null) || (country.length() == 0)) {
        Locale.setDefault(new Locale(language));
    } else if ((variant == null) || (variant.length() == 0)) {
        Locale.setDefault(new Locale(language, country));
    } else {
        Locale.setDefault(new Locale(language, country, variant));
    }
}

From source file:com.morphoss.jumble.frontend.SettingsActivity.java

/**
 * This method set a particular language as the current language
 * /*from w  w  w  .  ja  va2  s .c om*/
 * @param v
 */
public void setLanguage(String language) {
    languageToLoad = language;
    Log.d(TAG, "the language chosen is: " + language);
    Locale locale = new Locale(languageToLoad);
    Locale.setDefault(locale);
    Configuration config = new Configuration();
    config.locale = locale;
    getResources().updateConfiguration(config, getResources().getDisplayMetrics());
    initControls();
}

From source file:edu.ku.brc.specify.prefs.SystemPrefs.java

/**
 * Constructor.//from   w ww  .j  a  v a  2  s. c  o  m
 */
public SystemPrefs() {
    createForm("Preferences", "System");

    JButton clearCache = form.getCompById("clearcache");

    clearCache.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            clearCache();
        }
    });

    ValBrowseBtnPanel browse = form.getCompById("7");
    if (browse != null) {
        oldSplashPath = localPrefs.get(SPECIFY_BG_IMG_PATH, null);
        browse.setValue(oldSplashPath, null);
    }

    final ValComboBox localeCBX = form.getCompById("5");
    localeCBX.getComboBox().setRenderer(new LocaleRenderer());
    localeCBX.setEnabled(false);

    SwingWorker workerThread = new SwingWorker() {
        protected int inx = -1;

        @Override
        public Object construct() {

            Vector<Locale> locales = new Vector<Locale>();
            Collections.addAll(locales, Locale.getAvailableLocales());
            Collections.sort(locales, new Comparator<Locale>() {
                public int compare(Locale o1, Locale o2) {
                    return o1.getDisplayName().compareTo(o2.getDisplayName());
                }
            });

            int i = 0;
            String language = AppPreferences.getLocalPrefs().get("locale.lang",
                    Locale.getDefault().getLanguage());
            String country = AppPreferences.getLocalPrefs().get("locale.country",
                    Locale.getDefault().getCountry());
            String variant = AppPreferences.getLocalPrefs().get("locale.var", Locale.getDefault().getVariant());

            Locale prefLocale = new Locale(language, country, variant);

            int justLangIndex = -1;
            Locale cachedLocale = Locale.getDefault();
            for (Locale l : locales) {
                try {
                    Locale.setDefault(l);
                    ResourceBundle rb = ResourceBundle.getBundle("resources", l);

                    boolean isOK = (l.getLanguage().equals("en") && StringUtils.isEmpty(l.getCountry()))
                            || (l.getLanguage().equals("pt") && l.getCountry().equals("PT"));

                    if (isOK && rb.getKeys().hasMoreElements()) {
                        if (l.getLanguage().equals(prefLocale.getLanguage())) {
                            justLangIndex = i;
                        }
                        if (l.equals(prefLocale)) {
                            inx = i;
                        }
                        localeCBX.getComboBox().addItem(l);
                        i++;
                    }

                } catch (MissingResourceException ex) {
                }
            }

            if (inx == -1 && justLangIndex > -1) {
                inx = justLangIndex;
            }
            Locale.setDefault(cachedLocale);

            return null;
        }

        @Override
        public void finished() {
            UIValidator.setIgnoreAllValidation("SystemPrefs", true);
            localeCBX.setEnabled(true);
            localeCBX.getComboBox().setSelectedIndex(inx);
            JTextField loadingLabel = form.getCompById("6");
            if (loadingLabel != null) {
                loadingLabel.setText(UIRegistry.getResourceString("LOCALE_RESTART_REQUIRED"));
            }
            UIValidator.setIgnoreAllValidation("SystemPrefs", false);
        }
    };

    // start the background task
    workerThread.start();

    ValCheckBox chk = form.getCompById("2");
    chk.setValue(localPrefs.getBoolean(VERSION_CHECK, true), "true");

    chk = form.getCompById("3");
    chk.setValue(remotePrefs.getBoolean(SEND_STATS, true), "true");

    chk = form.getCompById("9");
    chk.setValue(remotePrefs.getBoolean(SEND_ISA_STATS, true), "true");
    chk.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Collection collection = AppContextMgr.getInstance().getClassObject(Collection.class);
            if (collection != null) {
                String isaNumber = collection.getIsaNumber();
                if (StringUtils.isNotEmpty(isaNumber) && !((JCheckBox) e.getSource()).isSelected()) {
                    UIRegistry.showLocalizedMsg("ISA_STATS_WARNING");
                }
            }
        }
    });

    // Not sure why the form isn't picking up the pref automatically
    /* remove if worldwind is broken*/ValCheckBox useWWChk = form.getCompById(USE_WORLDWIND);
    /* remove if worldwind is broken*/ValCheckBox hasOGLChk = form.getCompById(SYSTEM_HasOpenGL);

    /* remove if worldwind is broken*/useWWChk.setValue(localPrefs.getBoolean(USE_WORLDWIND, false), null);
    /* remove if worldwind is broken*/hasOGLChk.setValue(localPrefs.getBoolean(SYSTEM_HasOpenGL, false), null);
    /* remove if worldwind is broken*/hasOGLChk.setEnabled(false);

    //ValCheckBox askCollChk = form.getCompById(ALWAYS_ASK_COLL);
    //askCollChk.setValue(localPrefs.getBoolean(ALWAYS_ASK_COLL, false), null);
}

From source file:com.puppycrawl.tools.checkstyle.api.LocalizedMessageTest.java

@After
public void tearDown() {
    Locale.setDefault(DEFAULT_LOCALE);
    LocalizedMessage.clearCache();
    LocalizedMessage.setLocale(DEFAULT_LOCALE);
}

From source file:org.jfree.data.time.MinuteTest.java

/**
 * Some checks for the getFirstMillisecond() method.
 */// w w w.j  ava2  s .co  m
@Test
public void testGetFirstMillisecond() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.UK);
    TimeZone savedZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Minute m = new Minute(43, 15, 1, 4, 2006);
    assertEquals(1143902580000L, m.getFirstMillisecond());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}

From source file:org.jfree.data.time.SecondTest.java

/**
 * Some checks for the getFirstMillisecond() method.
 */// w  w w.j ava  2s.c  o m
@Test
public void testGetFirstMillisecond() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.UK);
    TimeZone savedZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Second s = new Second(15, 43, 15, 1, 4, 2006);
    assertEquals(1143902595000L, s.getFirstMillisecond());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}