List of usage examples for java.util Locale setDefault
public static synchronized void setDefault(Locale newLocale)
From source file:org.openhab.binding.ntp.test.NtpOSGiTest.java
@BeforeClass public static void setUpClass() { // Initializing a new local server on this port timeServer = new SimpleNTPServer(TEST_PORT); // Starting the local server timeServer.startServer();/*from w ww . j a v a 2 s.c o m*/ /* * Store the initial system time zone and locale value, so that we can * restore them at the test end. */ systemTimeZone = TimeZone.getDefault(); locale = Locale.getDefault(); /* * Set new default time zone and locale, which will be used during the * tests execution. */ TimeZone.setDefault(TimeZone.getTimeZone(DEFAULT_TIME_ZONE_ID)); Locale.setDefault(Locale.US); }
From source file:org.xmlactions.action.config.LanguageLocale.java
/** * Get a value for key from a language (locale) file. * <p>/*from w w w .j a v a 2 s.c o m*/ * The replacementPattern format is "lang:key:resouce:language:country:variant" * <br/>or "lang:key" uses the default resource file and the default locale * <br/>or "lang:key:resource" uses the resource file and the default locale * <br/>or "lang:key::language" uses the default resource file and the language locale * </p> * * @param replacementPattern - the replacement pattern that was entered within the StrSubstitution * @return the value for key or null if not found. * */ public Object getLang(IExecContext execContext, String replacementPattern) { boolean hasLanguage = false; boolean hasCountry = false; boolean hasVariant = false; String parts[] = replacementPattern.split(seperatorChar); Validate.notEmpty(parts[1], "Missing key value for [" + replacementPattern + "]"); key = parts[1]; if (parts.length > 2) { resource = parts[2]; } if (StringUtils.isEmpty(resource)) { resource = execContext.getString(IExecContext.DEFAULT_LOCALE_FILE); Validate.notEmpty(resource, "No default locale file has been set for [" + IExecContext.DEFAULT_LOCALE_FILE + "] in [" + replacementPattern + "]"); } else { // try if resource is a key to a different value String mappedResource = execContext.getString(resource); if (mappedResource != null) { resource = mappedResource; } } if (parts.length > 3) { language = parts[3]; if (language != null) { hasLanguage = true; } } if (parts.length > 4) { country = parts[4]; if (country != null) { hasCountry = true; } } if (parts.length > 5) { variant = parts[5]; if (variant != null) { hasVariant = true; } } Locale locale = null; if (hasLanguage && !(hasCountry | hasVariant)) { locale = new Locale(language); Locale.setDefault(locale); } else if (hasLanguage && hasCountry && !hasVariant) { locale = new Locale(language, country); Locale.setDefault(locale); } else if (hasLanguage && hasCountry && hasVariant) { locale = new Locale(language, country, variant); Locale.setDefault(locale); } if (locale != null) { Locale defaultLocale = Locale.getDefault(); try { Locale.setDefault(locale); return execContext.getLocalizedString(resource, key); } finally { Locale.setDefault(defaultLocale); } } else { return execContext.getLocalizedString(resource, key); } }
From source file:com.puppycrawl.tools.checkstyle.api.LocalizedMessageTest.java
@Test public void testEnforceEnglishLanguageBySettingRootLocale() { Locale.setDefault(Locale.FRENCH); LocalizedMessage.setLocale(Locale.ROOT); LocalizedMessage localizedMessage = createSampleLocalizedMessage(); assertEquals("Empty statement.", localizedMessage.getMessage()); }
From source file:org.eclipse.smarthome.binding.ntp.test.NtpOSGiTest.java
@AfterClass public static void tearDownClass() { // Set the default time zone and locale to their initial value. TimeZone.setDefault(systemTimeZone); Locale.setDefault(locale); }
From source file:com.ibm.replication.iidr.warehouse.CollectCDCStats.java
public CollectCDCStats(CollectCDCStatsParms parms) throws ConfigurationException, EmbeddedScriptException, IllegalAccessException, InstantiationException, ClassNotFoundException, SQLException, IOException, CollectCDCStatsParmsException { this.parms = parms; PropertiesConfiguration versionInfo = new PropertiesConfiguration( "conf" + File.separator + "version.properties"); logger = LogManager.getLogger(); logger.info("Version: " + versionInfo.getString("buildVersion") + "." + versionInfo.getString("buildRelease") + "." + versionInfo.getString("buildMod") + ", date: " + versionInfo.getString("buildDate")); // Debug logging? if (parms.debug) { LoggerContext ctx = (LoggerContext) LogManager.getContext(false); Configuration config = ctx.getConfiguration(); LoggerConfig loggerConfig = config.getLoggerConfig("com.ibm.replication.iidr"); loggerConfig.setLevel(Level.DEBUG); ctx.updateLoggers();/*from ww w. j a v a 2 s .c om*/ } // Load settings settings = new Settings(parms.propertiesFile); // TODO Set locale hard-coded to avoid date conversion errors, to be // fixed later Locale.setDefault(new Locale("en", "US")); // Get current session's locale currentLocale = Locale.getDefault(); logger.debug("Current locale (language_country): " + currentLocale.toString() + ", metrics will be parsed according to this locale"); localNumberFormat = NumberFormat.getInstance(currentLocale); // Check if the event log bookmarks will be used if (settings.logEventsToDB || settings.logEventsToCsv) { bookmarks = new Bookmarks("EventLogBookmarks.properties"); } // Start the timer thread to flush the output on a regular basis timer = new Timer(settings); new Thread(timer).start(); // Create a script object to be used to execute CHCCLP commands script = new EmbeddedScript(); try { script.open(); while (keepOn) { processSubscriptions(); logger.info("Sleeping for " + settings.checkFrequencySeconds + " seconds"); Thread.sleep(settings.checkFrequencySeconds * 1000); } } catch (EmbeddedScriptException e1) { logger.error(e1.getMessage()); throw new EmbeddedScriptException(99, "Error in running CHCCLP script"); } catch (InterruptedException e) { logger.info("Stop of program requested"); } catch (Exception e2) { logger.error("Error while collecting status and statistics: " + e2.getMessage()); } finally { disconnectServerDS(); script.close(); disconnectFromDatabase(); } }
From source file:eu.focusnet.app.util.ApplicationHelper.java
/** * Reset language to the default language */// www . ja v a 2 s.c o m public static void resetLanguage() { Locale defaultLocale = ApplicationHelper.getDefaultLocale(); Locale.setDefault(defaultLocale); Configuration config = new Configuration(); config.locale = defaultLocale; getApplicationContext().getResources().updateConfiguration(config, getApplicationContext().getResources().getDisplayMetrics()); }
From source file:org.apache.jmeter.junit.JMeterTest.java
public void resetLocale() { JMeterUtils.setLocale(DEFAULT_LOCALE); Locale.setDefault(DEFAULT_LOCALE); }
From source file:edu.ku.brc.specify.utilapps.CreateTextSchema.java
/** * @param args/*from w ww . j a v a2 s .co m*/ */ public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @SuppressWarnings("synthetic-access") //$NON-NLS-1$ public void run() { try { UIHelper.OSTYPE osType = UIHelper.getOSType(); if (osType == UIHelper.OSTYPE.Windows) { UIManager.setLookAndFeel(new PlasticLookAndFeel()); PlasticLookAndFeel.setPlasticTheme(new ExperienceBlue()); } else if (osType == UIHelper.OSTYPE.Linux) { UIManager.setLookAndFeel(new PlasticLookAndFeel()); } } catch (Exception e) { } String schemaVersion = JOptionPane.showInputDialog("Enter Schema Version:"); Locale.setDefault(currLang); try { ResourceBundle.getBundle("resources", Locale.getDefault()); //$NON-NLS-1$ } catch (MissingResourceException ex) { Locale.setDefault(Locale.ENGLISH); UIRegistry.setResourceLocale(Locale.ENGLISH); } CreateTextSchema cts = new CreateTextSchema(); cts.process(schemaVersion); //File file = XMLHelper.getConfigDir(specifyDescFileName); //file.delete(); JOptionPane.showMessageDialog(null, "Done"); } }); }
From source file:org.fuin.kickstart4j.Kickstart4J.java
/** * Executes the installer/updater.//from w w w . j av a2s .c o m * * @throws CanceledException * The user canceled the installation. * @throws InvalidConfigException * The configuration is invalid. */ public final void execute() throws CanceledException, InvalidConfigException { Locale.setDefault(config.getLocale()); final File destDir = getDestDir(); config.getCmdLineOptions().put("destDir", destDir.toString()); // Check configuration AFTER destination directory is set // and logging is initialized config.check(); initLogging(); listener.initComplete(); // Start the update final UpdateSet updateSet = new UpdateSet(config.getSrcFiles(), config.getMkDirs(), destDir, config.isLazyLoading()); if (updateSet.isUpdateNecessary()) { if (LOG.isInfoEnabled()) { LOG.info("An update is available: New=" + updateSet.getNewFiles().size() + ", Changed=" + updateSet.getChangedFiles().size() + ", Deleted=" + updateSet.getDeletedFiles().size() + ", SilentInstall=" + config.isSilentInstall() + ", SilentUpdate=" + config.isSilentUpdate() + ", FirstInstallation=" + config.isFirstInstallation()); } if (config.isSilentUpdate() || config.isFirstInstallation() || isAnswerYes(config.getMessages().getUpdateAvailable())) { execute(updateSet); final File installationIncompleteFile = new File(destDir, INCOMPLETE_FILE); if (installationIncompleteFile.exists()) { installationIncompleteFile.delete(); } } } else { LOG.info("Files are up to date"); } final JFrame startFrame = showStartFrame(); config.getCmdLineOptions().put("classpath", updateSet.createClasspath()); // Write the config to the target directory saveConfigToTargetDir(destDir); // Run the target application final CommandLine commandLine = new CommandLine(config.getJavaExe()); commandLine.addArguments(config.getJavaArgs(), false); logStart(destDir, commandLine.toString()); new ApplicationStarter(destDir, commandLine, startFrame, listener, config).execute(); }