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:org.jfree.data.time.QuarterTest.java

/**
 * Some checks for the getFirstMillisecond() method.
 *//*from w  w  w .ja  v  a 2 s  .  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"));
    Quarter q = new Quarter(3, 1970);
    assertEquals(15634800000L, q.getFirstMillisecond());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}

From source file:de.mpg.escidoc.pubman.util.InternationalizationHelper.java

public void toggleLocale(ActionEvent event) {
    FacesContext fc = FacesContext.getCurrentInstance();

    ///*from ww  w  .  jav a2  s .c om*/
    // toggle the locale
    Locale locale = null;
    Map<String, String> map = fc.getExternalContext().getRequestParameterMap();
    String language = (String) map.get("language");
    String country = (String) map.get("country");
    this.locale = language;
    try {
        locale = new Locale(language, country);
        fc.getViewRoot().setLocale(locale);
        Locale.setDefault(locale);
        userLocale = locale;
        logger.debug("New locale: " + language + "_" + country + " : " + locale);
    } catch (Exception e) {
        logger.error("unable to switch to locale using language = " + language + " and country = " + country,
                e);
    }
    if (language.equals("de")) {
        selectedHelpPage = HELP_PAGE_DE;
    } else {
        selectedHelpPage = HELP_PAGE_EN;
    }
}

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

/**
 * Some checks for the getLastMillisecond() method.
 *//*from  w  w  w. ja  va2  s .co  m*/
@Test
public void testGetLastMillisecond() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.UK);
    TimeZone savedZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Millisecond m = new Millisecond(750, 1, 1, 1, 1, 1, 1970);
    assertEquals(61750L, m.getLastMillisecond());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}

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

/**
 * Some checks for the getLastMillisecond() method.
 *//*from  ww  w.  java2s .  c  o m*/
public void testGetLastMillisecond() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.UK);
    TimeZone savedZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Minute m = new Minute(1, 1, 1, 1, 1970);
    assertEquals(119999L, m.getLastMillisecond());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}

From source file:org.apache.solr.cloud.TestSolrCloudWithKerberos.java

@Override
public void distribTearDown() throws Exception {
    System.clearProperty("java.security.auth.login.config");
    System.clearProperty("solr.kerberos.jaas.appname");
    System.clearProperty("solr.cookie.domain");
    System.clearProperty("solr.kerberos.principal");
    System.clearProperty("solr.kerberos.keytab");
    System.clearProperty("solr.jaas.debug");
    System.clearProperty("solr.kerberos.name.rules");
    Configuration.setConfiguration(originalConfig);
    if (kdc != null) {
        kdc.stop();/*  www.j  a v  a2  s .co  m*/
    }
    //SSLTestConfig.clearSSLSystemProperties();
    Locale.setDefault(savedLocale);
    super.distribTearDown();
}

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

/**
 * Some checks for the getLastMillisecond() method.
 *//*from w w w.j  a  va2 s .c  o  m*/
public void testGetLastMillisecond() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.UK);
    TimeZone savedZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Second s = new Second(1, 1, 1, 1, 1, 1970);
    assertEquals(61999L, s.getLastMillisecond());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}

From source file:de.cenote.jasperstarter.Report.java

public void fill() throws InterruptedException {
    if (initialInputType != InputType.JASPER_PRINT) {
        // get commandLineReportParams
        Map<String, Object> parameters = getCmdLineReportParams();
        // if prompt...
        if (config.hasAskFilter()) {
            JRParameter[] reportParams = jasperReport.getParameters();
            parameters = promptForParams(reportParams, parameters, jasperReport.getName());
        }//from   w w w  .  ja v  a 2 s .  c o  m
        try {
            if (parameters.containsKey("REPORT_LOCALE")) {
                if (parameters.get("REPORT_LOCALE") != null) {
                    Locale.setDefault((Locale) parameters.get("REPORT_LOCALE"));
                }
            }
            if (DsType.none.equals(config.getDbType())) {
                jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, new JREmptyDataSource());
            } else if (DsType.csv.equals(config.getDbType())) {
                Db db = new Db();
                JRCsvDataSource ds = db.getCsvDataSource(config);
                jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, ds);
            } else if (DsType.xml.equals(config.getDbType())) {
                Db db = new Db();
                JRXmlDataSource ds = db.getXmlDataSource(config);
                jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, ds);
            } else if (DsType.json.equals(config.getDbType())) {
                Db db = new Db();
                JsonDataSource ds = db.getJsonDataSource(config);
                jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, ds);
            } else {
                Db db = new Db();
                Connection con = db.getConnection(config);
                jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, con);
                con.close();
            }
            // reset to default
            Locale.setDefault(defaultLocale);
        } catch (SQLException ex) {
            throw new IllegalArgumentException("Unable to connect to database: " + ex.getMessage(), ex);
        } catch (JRException e) {
            throw new IllegalArgumentException("Error filling report" + e.getMessage(), e);
        } catch (ClassNotFoundException e) {
            throw new IllegalArgumentException("Unable to load driver: " + e.getMessage(), e);
        } finally {
            // reset to default
            Locale.setDefault(defaultLocale);
        }
        List<OutputFormat> formats = config.getOutputFormats();
        try {
            if (formats.contains(OutputFormat.jrprint)) {
                JRSaver.saveObject(jasperPrint, this.output.getAbsolutePath() + ".jrprint");
            }
        } catch (JRException e) {
            throw new IllegalArgumentException(
                    "Unable to write to file: " + this.output.getAbsolutePath() + ".jrprint", e);
        }
    }
}

From source file:com.mendhak.gpslogger.GpsMainActivity.java

private void setLocale() {

    if (!Strings.isNullOrEmpty(preferenceHelper.getUserSpecifiedLocale())) {
        LOG.debug("Setting language to " + preferenceHelper.getUserSpecifiedLocale());

        String language, country = "";

        if (preferenceHelper.getUserSpecifiedLocale().contains("-")) {
            language = preferenceHelper.getUserSpecifiedLocale().split("-")[0];
            country = preferenceHelper.getUserSpecifiedLocale().split("-")[1];
        } else {/*from  w  ww. j  a va 2 s  .  c  o m*/
            language = preferenceHelper.getUserSpecifiedLocale();
        }

        Locale locale = new Locale(language, country);
        Locale.setDefault(locale);
        getResources().getConfiguration().locale = locale;
        getBaseContext().getResources().updateConfiguration(getResources().getConfiguration(),
                getBaseContext().getResources().getDisplayMetrics());
    }
}

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

/**
 * Some checks for the getLastMillisecond() method.
 *//*from   w w w .j av a2  s . c  o  m*/
@Test
public void testGetLastMillisecond() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.UK);
    TimeZone savedZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Hour h = new Hour(1, 1, 1, 1970);
    assertEquals(3599999L, h.getLastMillisecond());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}

From source file:org.marketcetera.util.log.I18NMessageProviderTest.java

@Test
public void customClassLoader() throws Exception {
    // Verify that the resource is not available.

    I18NMessageProvider provider = new I18NMessageProvider(TEST_MEM_PROVIDER);
    Iterator<LoggingEvent> events = getAppender().getEvents().iterator();
    assertEvent(//from   w w  w  .java 2 s  . co m
            events.next(), Level.ERROR, TEST_CATEGORY, "Message file missing: provider '" + TEST_MEM_PROVIDER
                    + "'; base name '" + TEST_MEM_PROVIDER + I18NMessageProvider.MESSAGE_FILE_EXTENSION + "'",
            TEST_LOCATION);
    assertEvent(events.next(), Level.ERROR, TEST_CATEGORY, "Abnormal exception: stack trace", TEST_LOCATION);
    assertFalse(events.hasNext());
    getAppender().clear();

    // Create a provider with a custom classloader.

    Properties messages = new Properties();
    messages.put("hello.msg", "Hello");
    messages.put("hello.title", "Hello {0}!");
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    try {
        messages.store(output, StringUtils.EMPTY);
    } finally {
        output.close();
    }
    final byte[] inputStream = output.toByteArray();
    final String propertiesName = TEST_MEM_PROVIDER + I18NMessageProvider.MESSAGE_FILE_EXTENSION
            + ".properties";
    provider = new I18NMessageProvider(TEST_MEM_PROVIDER, new ClassLoader() {
        @Override
        public InputStream getResourceAsStream(String name) {
            if (propertiesName.equals(name)) {
                return new ByteArrayInputStream(inputStream);
            }
            return super.getResourceAsStream(name);
        }
    });
    assertNoEvents();

    // Messages can now be translated.

    I18NLoggerProxy logger = new I18NLoggerProxy(provider);
    I18NMessage0P helloMsg = new I18NMessage0P(logger, "hello");
    I18NMessage1P helloTitle = new I18NMessage1P(logger, "hello", "title");
    Locale saved = Locale.getDefault();
    try {
        Locale.setDefault(Locale.ROOT);
        assertEquals("Hello", provider.getText(helloMsg));
        assertEquals("Hello World!", provider.getText(helloTitle, "World"));
    } finally {
        Locale.setDefault(saved);
    }
}