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:com.msopentech.odatajclient.engine.it.AbstractTest.java

/**
 * This is needed for correct number handling (Double, for example).
 */// www.  j a v a 2 s .c o  m
@BeforeClass
public static void setEnglishLocale() {
    Locale.setDefault(Locale.ENGLISH);
}

From source file:de.pezeshki.bahaicalendar.MainActivity.java

private void setParameters() {
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    dateFormat = sharedPref.getString(SettingsActivity.KEY_PREF_DATE_FORMAT, "");
    String languageToLoad = sharedPref.getString(SettingsActivity.KEY_PREF_LANGUAGE, "");
    locale = new Locale(languageToLoad);
    Locale.setDefault(locale);
    Configuration config = new Configuration();
    config.locale = locale;//  w w  w .  j  a va  2s .c  om
    getBaseContext().getResources().updateConfiguration(config,
            getBaseContext().getResources().getDisplayMetrics());
}

From source file:org.opennms.netmgt.syslogd.SyslogMessageTest.java

@Test
public void testCustomParserNms5242() throws Exception {
    final Locale startLocale = Locale.getDefault();
    try {//from   w  ww .j av  a  2s.  c  om
        Locale.setDefault(Locale.FRANCE);
        final InputStream stream = new ByteArrayInputStream(("<?xml version=\"1.0\"?>\n"
                + "<syslogd-configuration>\n" + "    <configuration\n" + "            syslog-port=\"10514\"\n"
                + "            new-suspect-on-message=\"false\"\n"
                + "            parser=\"org.opennms.netmgt.syslogd.CustomSyslogParser\"\n"
                + "            forwarding-regexp=\"^((.+?) (.*))\\n?$\"\n"
                + "            matching-group-host=\"2\"\n" + "            matching-group-message=\"3\"\n"
                + "            discard-uei=\"DISCARD-MATCHING-MESSAGES\"\n" + "            />\n" + "\n"
                + "    <hideMessage>\n" + "        <hideMatch>\n"
                + "            <match type=\"substr\" expression=\"TEST\"/>\n" + "        </hideMatch>\n"
                + "    </hideMessage>\n" + "</syslogd-configuration>\n").getBytes());
        final SyslogdConfigFactory config = new SyslogdConfigFactory(stream);

        final SyslogParser parser = new CustomSyslogParser(config,
                "<0>Mar 14 17:10:25 petrus sudo:  cyrille : user NOT in sudoers ; TTY=pts/2 ; PWD=/home/cyrille ; USER=root ; COMMAND=/usr/bin/vi /etc/aliases");
        assertTrue(parser.find());
        final SyslogMessage message = parser.parse();
        LOG.debug("message = {}", message);
        final Calendar cal = Calendar.getInstance();
        cal.setTimeZone(TimeZone.getTimeZone("UTC"));
        cal.set(Calendar.MONTH, Calendar.MARCH);
        cal.set(Calendar.DAY_OF_MONTH, 14);
        cal.set(Calendar.HOUR_OF_DAY, 17);
        cal.set(Calendar.MINUTE, 10);
        cal.set(Calendar.SECOND, 25);
        cal.set(Calendar.MILLISECOND, 0);
        assertEquals(SyslogFacility.KERNEL, message.getFacility());
        assertEquals(SyslogSeverity.EMERGENCY, message.getSeverity());
        assertNull(message.getMessageID());
        assertEquals(cal.getTime(), message.getDate());
        assertEquals("petrus", message.getHostName());
        assertEquals("sudo", message.getProcessName());
        assertEquals(0, message.getProcessId().intValue());
        assertEquals(
                "cyrille : user NOT in sudoers ; TTY=pts/2 ; PWD=/home/cyrille ; USER=root ; COMMAND=/usr/bin/vi /etc/aliases",
                message.getMessage());
    } finally {
        Locale.setDefault(startLocale);
    }
}

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

@Test
public void testUpdateInfoUser2() throws IOException {
    Locale.setDefault(Locale.GERMAN);
    testUserPost("updateInfoUser2", "keine gltige E-Mail-Adresse", entry("lc", "ralph"),
            entry("success", Boolean.FALSE));

}

From source file:com.example.oris1991.anotherme.ExternalCalendar.CalendarAdapter.java

public void refreshDays() {
    // clear items
    items.clear();// w w  w.ja v a  2  s. c  o  m
    dayString.clear();
    Locale.setDefault(Locale.US);
    pmonth = (GregorianCalendar) month.clone();
    // month start day. ie; sun, mon, etc
    firstDay = month.get(GregorianCalendar.DAY_OF_WEEK);
    // finding number of weeks in current month.
    maxWeeknumber = month.getActualMaximum(GregorianCalendar.WEEK_OF_MONTH);
    // allocating maximum row number for the gridview.
    mnthlength = maxWeeknumber * 7;
    maxP = getMaxP(); // previous month maximum day 31,30....
    calMaxP = maxP - (firstDay - 1);// main_content offday starting 24,25 ...
    /**
     * Calendar instance for getting a complete gridview including the three
     * month's (previous,current,next) dates.
     */
    pmonthmaxset = (GregorianCalendar) pmonth.clone();
    /**
     * setting the start date as previous month's required date.
     */
    pmonthmaxset.set(GregorianCalendar.DAY_OF_MONTH, calMaxP + 1);

    /**
     * filling main_content gridview.
     */
    for (int n = 0; n < mnthlength; n++) {

        itemvalue = df.format(pmonthmaxset.getTime());
        pmonthmaxset.add(GregorianCalendar.DATE, 1);
        dayString.add(itemvalue);

    }
}

From source file:freenet.support.TimeUtil.java

@Override
    protected void setUp() throws Exception {
        Locale.setDefault(Locale.US);
    }

From source file:hudson.UtilTest.java

@Test
public void testTimeSpanString() {
    // Check that amounts less than 365 days are not rounded up to a whole year.
    // In the previous implementation there were 360 days in a year.
    // We're still working on the assumption that a month is 30 days, so there will
    // be 5 days at the end of the year that will be "12 months" but not "1 year".
    // First check 359 days.
    assertEquals(Messages.Util_month(11), Util.getTimeSpanString(31017600000L));
    // And 362 days.
    assertEquals(Messages.Util_month(12), Util.getTimeSpanString(31276800000L));

    // 11.25 years - Check that if the first unit has 2 or more digits, a second unit isn't used.
    assertEquals(Messages.Util_year(11), Util.getTimeSpanString(354780000000L));
    // 9.25 years - Check that if the first unit has only 1 digit, a second unit is used.
    assertEquals(Messages.Util_year(9) + " " + Messages.Util_month(3), Util.getTimeSpanString(291708000000L));
    // 67 seconds
    assertEquals(Messages.Util_minute(1) + " " + Messages.Util_second(7), Util.getTimeSpanString(67000L));
    // 17 seconds - Check that times less than a minute only use seconds.
    assertEquals(Messages.Util_second(17), Util.getTimeSpanString(17000L));
    // 1712ms -> 1.7sec
    assertEquals(Messages.Util_second(1.7), Util.getTimeSpanString(1712L));
    // 171ms -> 0.17sec
    assertEquals(Messages.Util_second(0.17), Util.getTimeSpanString(171L));
    // 101ms -> 0.10sec
    assertEquals(Messages.Util_second(0.1), Util.getTimeSpanString(101L));
    // 17ms//from  ww w.j a  va2s.c  o m
    assertEquals(Messages.Util_millisecond(17), Util.getTimeSpanString(17L));
    // 1ms
    assertEquals(Messages.Util_millisecond(1), Util.getTimeSpanString(1L));
    // Test HUDSON-2843 (locale with comma as fraction separator got exception for <10 sec)
    Locale saveLocale = Locale.getDefault();
    Locale.setDefault(Locale.GERMANY);
    try {
        // Just verifying no exception is thrown:
        assertNotNull("German locale", Util.getTimeSpanString(1234));
        assertNotNull("German locale <1 sec", Util.getTimeSpanString(123));
    } finally {
        Locale.setDefault(saveLocale);
    }
}

From source file:com.grarak.kerneladiutor.utils.Utils.java

public static void setLocale(String lang, Context context) {
    Locale locale = new Locale(lang);
    Locale.setDefault(locale);
    Configuration config = new Configuration();
    config.locale = locale;/*from  ww w  . j  a  v  a 2s  .  c om*/
    context.getApplicationContext().getResources().updateConfiguration(config, null);
}

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

@Test
public void testUpdateInfoUser3() throws IOException {
    Locale.setDefault(Locale.US);
    testUserPost("updateInfoUser3", "Wrong E-Mail", entry("lc", "ralph"), entry("success", Boolean.FALSE));
}

From source file:org.pentaho.di.junit.rules.RestorePDIEnvironment.java

@Override
protected void after() {
    cleanUp();/*ww w . j  a  va2 s  . c om*/

    System.setProperties(originalProperties);
    Locale.setDefault(originalLocale);
    Locale.setDefault(Locale.Category.FORMAT, originalFormatLocale);
    LanguageChoice.getInstance().setDefaultLocale(originalLocale);
    TimeZone.setDefault(originalTimezone);
    FileUtils.deleteQuietly(tmpKettleHome.toFile());
}