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.pentaho.di.junit.rules.RestorePDIEnvironment.java

@Override
protected void before() throws Throwable {
    originalProperties = System.getProperties();
    System.setProperties(copyOf(originalProperties));

    originalLocale = Locale.getDefault();
    originalFormatLocale = Locale.getDefault(Locale.Category.FORMAT);
    originalTimezone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
    Locale.setDefault(Locale.US);
    Locale.setDefault(Locale.Category.FORMAT, Locale.US);
    LanguageChoice.getInstance().setDefaultLocale(Locale.US);

    tmpKettleHome = Files.createTempDirectory(Long.toString(System.nanoTime()));
    System.setProperty("file.encoding", "UTF-8");
    System.setProperty("user.timezone", "UTC");
    System.setProperty("KETTLE_HOME", tmpKettleHome.toString());
    System.setProperty(Const.KETTLE_DISABLE_CONSOLE_LOGGING, "Y");
    System.clearProperty(Const.VFS_USER_DIR_IS_ROOT);
    System.clearProperty(Const.KETTLE_LENIENT_STRING_TO_NUMBER_CONVERSION);
    System.clearProperty(Const.KETTLE_COMPATIBILITY_DB_IGNORE_TIMEZONE);
    System.clearProperty(Const.KETTLE_DEFAULT_INTEGER_FORMAT);
    System.clearProperty(Const.KETTLE_DEFAULT_NUMBER_FORMAT);
    System.clearProperty(Const.KETTLE_DEFAULT_BIGNUMBER_FORMAT);
    System.clearProperty(Const.KETTLE_DEFAULT_DATE_FORMAT);
    System.clearProperty(Const.KETTLE_DEFAULT_TIMESTAMP_FORMAT);
    System.clearProperty(Const.KETTLE_EMPTY_STRING_DIFFERS_FROM_NULL);

    defaultInit();// w  ww.  jav  a2  s. c o  m
}

From source file:no.abmu.questionnaire.webflow.QuestionnaireFormAction.java

protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
    if (logger.isDebugEnabled()) {
        logger.info("Executing initBinder");
    }//from   w w  w  . j av  a2  s. c o m

    SessionLocaleResolver sessionLocaleResolver = new SessionLocaleResolver();
    Locale.setDefault(sessionLocaleResolver.resolveLocale(request));

    if (logger.isDebugEnabled()) {
        logger.info("Setting locale:" + sessionLocaleResolver.resolveLocale(request));
    }
}

From source file:xtrememp.XtremeMP.java

public static void main(String... args) throws Exception {
    // Load Settings
    Settings.loadSettings();//from  w w  w .j  a  va2 s.com
    // Configure logback
    Settings.configureLogback();

    // Enable uncaught exception catching.
    Thread.setDefaultUncaughtExceptionHandler((Thread t, Throwable e) -> {
        logger.error(t.getName(), e);
    });

    // Close error stream
    System.err.close();
    // First, look up for other instances running
    if (!MultipleInstancesHandler.getInstance().isFirstInstance()) {
        MultipleInstancesHandler.getInstance().sendArgumentsToFirstInstance(args);
    } else {
        // NORMAL APPLICATION STARTUP
        // Set language
        Locale locale = Utilities.getLanguages()[Settings.getLanguageIndex()];
        Locale.setDefault(locale);
        LanguageBundle.setLanguage(locale);

        // Animation configurations
        AnimationConfigurationManager.getInstance().disallowAnimations(AnimationFacet.ICON_GLOW, JTable.class);
        AnimationConfigurationManager.getInstance().disallowAnimations(AnimationFacet.ROLLOVER, JTable.class);
        AnimationConfigurationManager.getInstance().disallowAnimations(AnimationFacet.SELECTION, JTable.class);

        // Init
        getInstance().init(args);

        // Check for updates
        if (Settings.isAutomaticUpdatesEnabled()) {
            // wait 5 sec
            SoftwareUpdate.scheduleCheckForUpdates(5 * 1000);
        }
    }
}

From source file:com.gisgraphy.domain.valueobject.FeatureCodeTest.java

@Test
public void testGetLocalizedDescriptionShouldReturnLocalizedDescription() {

    assertEquals("The bundle should ignore the country if a bundle with only the language exists",
            ResourceBundle.getBundle(Constants.FEATURECODE_BUNDLE_KEY, localeaa).getString(
                    FeatureCode.P_PPL.toString()),
            FeatureCode.P_PPL.getLocalizedDescription(localeaacc));

    assertEquals("The bundle should take the country and language if a bundle with both exists", ResourceBundle
            .getBundle(Constants.FEATURECODE_BUNDLE_KEY, localebbdd).getString(FeatureCode.P_PPL.toString()),
            FeatureCode.P_PPL.getLocalizedDescription(localebbdd));

    assertEquals("The bundle should be able to only take the language into account",
            ResourceBundle.getBundle(Constants.FEATURECODE_BUNDLE_KEY, localeaa).getString("P_PPL"),
            FeatureCode.P_PPL.getLocalizedDescription(localeaa));

    // null//from   w ww  .  j  a  va  2s. c om
    Locale savedcontext = LocaleContextHolder.getLocale();
    LocaleContextHolder.setLocale(localeaa);// force an existing
    // translation bundle
    assertEquals("if the locale is null, the LocaleContextHolder one should be used",
            FeatureCode.P_PPL.getLocalizedDescription(LocaleContextHolder.getLocale()),
            FeatureCode.P_PPL.getLocalizedDescription(null));
    LocaleContextHolder.setLocale(savedcontext);

    // no bundle for the specified Locale
    LocaleContextHolder.setLocale(localeaa);// force an existing
    // translation bundle
    assertEquals("If no bundle for the specified locale exists the thread one should be used",
            FeatureCode.P_PPL.getLocalizedDescription(LocaleContextHolder.getLocale()),
            FeatureCode.P_PPL.getLocalizedDescription(localeWithOutBundle));
    LocaleContextHolder.setLocale(savedcontext);

    // no bundle exists for the thread locale

    LocaleContextHolder.setLocale(localeWithOutBundle);
    assertEquals("If no bundle for the specified locale exists and the default"
            + " thread one does not exists, the locale.getDefault should be used : " + Locale.getDefault(),
            FeatureCode.P_PPL.getLocalizedDescription(Locale.getDefault()),
            FeatureCode.P_PPL.getLocalizedDescription(localeWithOutBundle));
    // restore
    LocaleContextHolder.setLocale(savedcontext);

    // no bundle exists for the thread locale and default one,
    Locale savedDefault = Locale.getDefault();
    LocaleContextHolder.setLocale(localeWithOutBundle);
    Locale.setDefault(localeWithOutBundle);
    assertEquals(
            "If no bundle for the specified locale exists and no bundle for the default "
                    + "thread one exists and no bundle for the default one exists,"
                    + " the DEFAULT_FALLBACK_LOCALE should be used : " + FeatureCode.DEFAULT_FALLBACK_LOCALE,
            FeatureCode.P_PPL.getLocalizedDescription(localeWithOutBundle),
            FeatureCode.P_PPL.getLocalizedDescription(null));
    // restore
    Locale.setDefault(savedDefault);
    LocaleContextHolder.setLocale(savedcontext);

    // existing locale and non existing translation
    assertEquals(
            "if no translation for the locale is found," + " default translation should be used : "
                    + FeatureCode.DEFAULT_TRANSLATION,
            FeatureCode.DEFAULT_TRANSLATION, FeatureCode.UNKNOW.getLocalizedDescription(localeaa));//

}

From source file:org.mifos.config.Localization.java

private void readLoacaleSetting() {
    String lang = localeSetting.getLanguageCode().toLowerCase();
    String country = localeSetting.getCountryCode().toUpperCase();
    Locale locale = new Locale(lang, country);

    if (!LOCALE_MAP.containsValue(locale)) {
        configuredLocaleId = newLocaleId;
        LOCALE_MAP.put(newLocaleId, locale);
    } else {/*ww w . ja  va 2 s  .com*/
        configuredLocaleId = getLocaleId(locale);
    }
    configuredLocale = locale;
    // workaround for MIFOS-5138
    Locale.setDefault(locale);
}

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

@Test
public void testEnforceEnglishLanguageBySettingUnitedStatesLocale() {
    Locale.setDefault(Locale.FRENCH);
    LocalizedMessage.setLocale(Locale.US);
    LocalizedMessage localizedMessage = createSampleLocalizedMessage();

    assertEquals("Empty statement.", localizedMessage.getMessage());
}

From source file:org.apache.maven.doxia.siterenderer.DefaultSiteRendererTest.java

/**
 * @throws java.lang.Exception if something goes wrong.
 * @see org.codehaus.plexus.PlexusTestCase#tearDown()
 *///from w w w  .  j  a va  2  s. c o  m
@Override
protected void tearDown() throws Exception {
    release(renderer);
    super.tearDown();

    Locale.setDefault(oldLocale);
}

From source file:cc.redpen.Main.java

@SuppressWarnings("static-access")
public static int run(String... args) throws RedPenException {
    Options options = new Options();
    options.addOption("h", "help", false, "Displays this help information and exits");

    options.addOption(OptionBuilder.withLongOpt("format")
            .withDescription("Input file format (markdown,plain,wiki,asciidoc,latex,rest)").hasArg()
            .withArgName("FORMAT").create("f"));

    options.addOption(OptionBuilder.withLongOpt("conf").withDescription("Configuration file (REQUIRED)")
            .hasArg().withArgName("CONF FILE").create("c"));

    options.addOption(OptionBuilder.withLongOpt("result-format")
            .withDescription("Output result format (json,json2,plain,plain2,xml)").hasArg()
            .withArgName("RESULT FORMAT").create("r"));

    options.addOption(OptionBuilder.withLongOpt("limit").withDescription("Error limit number").hasArg()
            .withArgName("LIMIT NUMBER").create("l"));

    options.addOption(OptionBuilder.withLongOpt("sentence").withDescription("Input sentences").hasArg()
            .withArgName("INPUT SENTENCES").create("s"));

    options.addOption(OptionBuilder.withLongOpt("lang").withDescription("Language of error messages").hasArg()
            .withArgName("LANGUAGE").create("L"));

    options.addOption(OptionBuilder.withLongOpt("threshold")
            .withDescription("Threshold of error level (info, warn, error)").hasArg().withArgName("THRESHOLD")
            .create("t"));

    options.addOption(OptionBuilder.withLongOpt("version")
            .withDescription("Displays version information and exits").create("v"));

    CommandLineParser commandLineParser = new BasicParser();
    CommandLine commandLine;//from w w  w  .  j  a  v a  2 s  .co  m
    try {
        commandLine = commandLineParser.parse(options, args);
    } catch (ParseException e) {
        LOG.error("Error occurred in parsing command line options ");
        printHelp(options);
        return -1;
    }

    String inputFormat = "plain";
    String configFileName = null;
    String resultFormat = "plain";
    String inputSentence = null;
    String language = "en";
    String threshold = "error";

    int limit = DEFAULT_LIMIT;

    if (commandLine.hasOption("h")) {
        printHelp(options);
        return 0;
    }
    if (commandLine.hasOption("v")) {
        System.out.println(RedPen.VERSION);
        return 0;
    }
    if (commandLine.hasOption("f")) {
        inputFormat = commandLine.getOptionValue("f");
    }
    if (commandLine.hasOption("c")) {
        configFileName = commandLine.getOptionValue("c");
    }
    if (commandLine.hasOption("r")) {
        resultFormat = commandLine.getOptionValue("r");
    }
    if (commandLine.hasOption("l")) {
        limit = Integer.valueOf(commandLine.getOptionValue("l"));
    }
    if (commandLine.hasOption("L")) {
        language = commandLine.getOptionValue("L");
    }
    if (commandLine.hasOption("s")) {
        inputSentence = commandLine.getOptionValue("s");
    }
    if (commandLine.hasOption("t")) {
        threshold = commandLine.getOptionValue("t");
    }

    // set language
    if (language.equals("ja")) {
        Locale.setDefault(new Locale("ja", "JA"));
    } else {
        Locale.setDefault(new Locale("en", "EN"));
    }

    String[] inputFileNames = commandLine.getArgs();
    if (!commandLine.hasOption("f")) {
        inputFormat = guessInputFormat(inputFileNames);
    }

    File configFile = resolveConfigLocation(configFileName);
    if (configFile == null) {
        LOG.error("Configuration file is not found.");
        printHelp(options);
        return 1;
    }

    if (inputFileNames.length == 0 && inputSentence == null) {
        LOG.error("Input is not given");
        printHelp(options);
        return 1;
    }

    RedPen redPen;
    try {
        redPen = new RedPen(configFile);
    } catch (RedPenException e) {
        LOG.error("Failed to parse input files: " + e);
        return -1;
    }

    List<Document> documents = getDocuments(inputFormat, inputSentence, inputFileNames, redPen);
    Map<Document, List<ValidationError>> documentListMap = redPen.validate(documents, threshold);

    Formatter formatter = FormatterUtils.getFormatterByName(resultFormat);
    if (formatter == null) {
        LOG.error("Unsupported format: " + resultFormat + " - please use xml, plain, plain2, json or json2");
        return -1;
    }
    String result = formatter.format(documentListMap);
    System.out.println(result);

    long errorCount = documentListMap.values().stream().mapToLong(List::size).sum();

    if (errorCount > limit) {
        LOG.error("The number of errors \"{}\" is larger than specified (limit is \"{}\").", errorCount, limit);
        return 1;
    } else {
        return 0;
    }
}

From source file:mondrian.test.loader.MondrianFoodMartLoader.java

/**
 * Command-line entry point.//from  www  . jav a  2  s  .co m
 *
 * @param args Command-line arguments
 */
public static void main(String[] args) {
    // Set locale to English, so that '.' and ',' in numbers are parsed
    // correctly.
    Locale.setDefault(Locale.ENGLISH);

    LOGGER.warn("Starting load at: " + (new Date()));
    try {
        new MondrianFoodMartLoader(args).load();
    } catch (Throwable e) {
        LOGGER.error("Main error", e);
    }
    LOGGER.warn("Finished load at: " + (new Date()));
}

From source file:com.nxp.nfc_demo.activities.MainActivity.java

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

    // Application package name to be used by the AAR record
    PACKAGE_NAME = getApplicationContext().getPackageName();
    String languageToLoad = "en";
    Locale locale = new Locale(languageToLoad);
    Locale.setDefault(locale);
    Configuration config = new Configuration();
    config.locale = locale;/*from   w w  w.  j a  v  a2 s.  co  m*/
    getBaseContext().getResources().updateConfiguration(config,
            getBaseContext().getResources().getDisplayMetrics());
    setContentView(R.layout.activity_main);
    mTabHost = (TabHost) findViewById(android.R.id.tabhost);
    mTabHost.setup();
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mTabsAdapter = new TabsAdapter(this, mTabHost, mViewPager);
    mTabsAdapter.addTab(mTabHost.newTabSpec("leds").setIndicator(getString(R.string.leds)), LedFragment.class,
            null);
    mTabsAdapter.addTab(mTabHost.newTabSpec("ndef").setIndicator(getString(R.string.ndefs)), NdefFragment.class,
            null);
    mTabsAdapter.addTab(mTabHost.newTabSpec("ntag_rf").setIndicator(getString(R.string.ntag_rf_text)),
            SpeedTestFragment.class, null);
    mTabsAdapter.addTab(mTabHost.newTabSpec("config").setIndicator(getString(R.string.settings)),
            ConfigFragment.class, null);

    // set current Tag to the Speedtest, so it loads the values
    if (savedInstanceState != null) {
        mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab"));
    }
    // Get App version
    appVersion = "";
    try {
        PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        appVersion = pInfo.versionName;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }

    // Board firmware version
    boardFirmwareVersion = "Unknown";

    // Notifier to be used for the demo changing
    mTabHost.setOnTabChangedListener(new OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            if (demo.isReady()) {
                demo.finishAllTasks();
                if (tabId.equalsIgnoreCase("leds") && demo.isConnected()) {
                    launchDemo(tabId);
                }
            }
            mTabsAdapter.onTabChanged(tabId);
        }
    });
    // When we open the application by default we set the status to disabled (we don't know the product yet)
    mAuthStatus = AuthStatus.Disabled.getValue();

    // Initialize the demo in order to handle tab change events
    demo = new Ntag_I2C_Demo(null, this, null, 0);
    mAdapter = NfcAdapter.getDefaultAdapter(this);
    setNfcForeground();
    checkNFC();
}