List of usage examples for java.util Locale setDefault
public static synchronized void setDefault(Locale newLocale)
From source file:ca.oson.json.gson.functional.DefaultTypeAdaptersTest.java
@Override protected void setUp() { super.setUp(); this.oldTimeZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles")); Locale.setDefault(Locale.US); gson = new Gson(); }
From source file:org.silverpeas.core.util.AbstractUnitTest.java
@SuppressWarnings("unchecked") @Before//from w ww. jav a2s. c om public void setup() throws Exception { currentLocale = Locale.getDefault(); Locale.setDefault(Locale.FRANCE); reflectionRule.setField(DisplayI18NHelper.class, Locale.getDefault().getLanguage(), "defaultLanguage"); bundleCache = (Map) FieldUtils.readStaticField(ResourceLocator.class, "bundles", true); LocalizationBundle unitsBundle = mock(LocalizationBundle.class); when(unitsBundle.handleGetObject(anyString())).thenAnswer(invocation -> { String key = (String) invocation.getArguments()[0]; return bundle.get(key); }); bundleCache.put("org.silverpeas.util.multilang.util", unitsBundle); bundleCache.put("org.silverpeas.util.multilang.util_" + Locale.getDefault().getLanguage(), unitsBundle); }
From source file:org.parosproxy.paros.Paros.java
/** * Initialization without dependence on any data model nor view creation. * @param args// w ww . ja v a 2 s .c om */ private void init(String[] args) { HttpSender.setUserAgent(Constant.USER_AGENT); try { cmdLine = new CommandLine(args); } catch (Exception e) { System.out.println(CommandLine.getHelpGeneral()); System.exit(1); } Locale.setDefault(Locale.ENGLISH); try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { } // System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog"); // System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true"); // System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "error"); }
From source file:com.desno365.mods.DesnoUtils.java
public static void setSavedLanguage(Context context) { SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); String[] language = sharedPrefs.getString("selected_language", "not_changed").split("-r"); if (!language[0].equals("default") && !language[0].equals("not_changed")) { Locale locale;//from w w w.j av a2s.c o m if (language.length == 1) locale = new Locale(language[0]); else locale = new Locale(language[0], language[1]); Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics()); } // this will be removed when languages become more accurate // languages that I'm sure are accurate are not affected if (language[0].equals("not_changed") && !Locale.getDefault().getCountry().equals("IT")) { Locale locale = new Locale("en"); Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics()); } }
From source file:org.parosproxy.paros.Andiparos.java
/** * Initialization without dependence on any data model nor view creation. * /*from w ww. java 2s . c o m*/ * @param args */ private void init(String[] args) { try { cmdLine = new CommandLine(args); } catch (Exception e) { System.out.println(CommandLine.getHelpGeneral()); System.exit(1); } Locale.setDefault(Locale.ENGLISH); try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { } // Andiparos: Use Nimbus if it is enforced and installed if (Constant.useNimbus) { try { for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (UnsupportedLookAndFeelException e) { // handle exception } catch (ClassNotFoundException e) { // handle exception } catch (InstantiationException e) { // handle exception } catch (IllegalAccessException e) { // handle exception } } }
From source file:org.silverpeas.core.test.extention.LocalizationBundleStub.java
@SuppressWarnings("unchecked") private void init() throws IllegalAccessException { currentLocale = Locale.getDefault(); Locale.setDefault(Locale.FRANCE); final String newDefaultLocale = Locale.getDefault().getLanguage(); reflectionRule.setField(DisplayI18NHelper.class, newDefaultLocale, "defaultLanguage"); bundleCache = (Map) FieldUtils.readStaticField(ResourceLocator.class, "bundles", true); bundleCache.put(bundleName, new LocalizationBundleTest(newDefaultLocale, bundleMap)); bundleNames.add(bundleName);/*w w w .j a v a 2 s .co m*/ DisplayI18NHelper.getLanguages().forEach(l -> { final String bundleLocaleName = bundleName + "_" + l; bundleCache.put(bundleLocaleName, new LocalizationBundleTest(l, bundleMap)); bundleNames.add(bundleLocaleName); }); }
From source file:richtercloud.document.scanner.it.LargeBinaryStorageIT.java
@Test public void testLargeBinaryStorage() throws IOException, StorageConfValidationException, StorageCreationException, StorageException, InterruptedException, OSNotRecognizedException, ArchitectureNotRecognizedException, ExtractionException, MissingSystemBinary, BuildFailureException, ModuleBuildFailureException, FieldOrderValidationException { LOGGER.info("testLargeBinaryStorage"); PersistenceStorage<Long> storage = null; Locale.setDefault(Locale.ENGLISH); try {/*from www . j ava 2 s.c o m*/ Set<Class<?>> entityClasses = new HashSet<>(Arrays.asList(LargeBinaryEntity.class)); File databaseDir = Files.createTempDirectory("document-scanner-large-binary-it").toFile(); FileUtils.forceDelete(databaseDir); File schemeChecksumFile = File.createTempFile("document-scanner-large-binary-it", null); schemeChecksumFile.delete(); String persistenceUnitName = "document-scanner-it"; String username = "document-scanner"; String password = "document-scanner"; String databaseName = "document-scanner"; //build PostgreSQL File postgresqlInstallationPrefixDir = Files .createTempDirectory(LargeBinaryStorageIT.class.getSimpleName()).toFile(); LOGGER.debug(String.format("using '%s' as PostgreSQL installation prefix", postgresqlInstallationPrefixDir.getAbsolutePath())); File downloadDir = Files.createTempDirectory(LargeBinaryStorageIT.class.getSimpleName()).toFile(); //SystemUtils.getUserHome() causes trouble //($HOME/jhbuild/checkout might be jhbuilds default extraction //directory) LOGGER.debug(String.format("using '%s' as JHBuild Java wrapper download directory", downloadDir)); IssueHandler issueHandler = new LoggerIssueHandler(LOGGER); JHBuildJavaWrapper jHBuildJavaWrapper = new JHBuildJavaWrapper(postgresqlInstallationPrefixDir, //installationPrefixDir downloadDir, //downloadDir ActionOnMissingBinary.DOWNLOAD, ActionOnMissingBinary.DOWNLOAD, new AutoDownloader(), //downloader false, true, //silenceStdout true, //silenceStderr issueHandler); String moduleName = "postgresql-9.6.3"; LOGGER.info( String.format("building module %s from JHBuild Java wrapper's default moduleset", moduleName)); jHBuildJavaWrapper.installModuleset(moduleName); //moduleset shipped with jhbuild-java-wrapper String initdb = new File(postgresqlInstallationPrefixDir, String.join(File.separator, "bin", "initdb")) .getAbsolutePath(); String postgres = new File(postgresqlInstallationPrefixDir, String.join(File.separator, "bin", "postgres")).getAbsolutePath(); String createdb = new File(postgresqlInstallationPrefixDir, String.join(File.separator, "bin", "createdb")).getAbsolutePath(); String pgCtl = new File(postgresqlInstallationPrefixDir, String.join(File.separator, "bin", "pg_ctl")) .getAbsolutePath(); PostgresqlAutoPersistenceStorageConf storageConf = new PostgresqlAutoPersistenceStorageConf( entityClasses, "localhost", //hostname username, password, databaseName, schemeChecksumFile, databaseDir.getAbsolutePath(), initdb, //initdbBinaryPath postgres, //postgresBinaryPath createdb, //createdbBinaryPath pgCtl); FieldRetriever fieldRetriever = new JPAOrderedCachedFieldRetriever( Constants.QUERYABLE_AND_EMBEDDABLE_CLASSES); storage = new PostgresqlAutoPersistenceStorage(storageConf, persistenceUnitName, 1, //parallelQueryCount fieldRetriever, issueHandler); storage.start(); long randomSeed = System.currentTimeMillis(); LOGGER.debug(String.format("random seed is %d", randomSeed)); Random random = new Random(randomSeed); int entityCount = 20; for (int i = 0; i < entityCount; i++) { int mbSize = random.nextInt(64); //64 MB max. //128 MB cause trouble on Travis CI (crash because of //limited `vm.max_map_count` which causes //`Native memory allocation (mmap) failed to map 109576192 bytes for committing reserved memory.` //) and it's not worth figuring this out for now int byteCount = 1024 * 1024 * mbSize; LOGGER.debug(String.format("generating %d MB random bytes", mbSize)); byte[] largeRandomBytes = new byte[byteCount]; random.nextBytes(largeRandomBytes); LargeBinaryEntity entity1 = new LargeBinaryEntity(largeRandomBytes); LOGGER.debug(String.format("storing large binary entity (%d of %d)", i, entityCount)); entity1.setId(MemorySequentialIdGenerator.getInstance().getNextId(entity1)); storage.store(entity1); } storage.shutdown(); Thread.sleep(20000); //10000 causes //`Caused by: org.postgresql.util.PSQLException: FATAL: the database system is starting up` storage = new PostgresqlAutoPersistenceStorage(storageConf, persistenceUnitName, 1, //parallelQueryCount fieldRetriever, issueHandler); storage.start(); LOGGER.debug("querying large binary entity"); storage.runQueryAll(LargeBinaryEntity.class); LOGGER.debug("query completed"); } finally { if (storage != null) { storage.shutdown(); } } }
From source file:org.apache.solr.morphlines.solr.AbstractSolrMorphlineTestBase.java
@AfterClass public static void afterClass() throws Exception { if (savedLocale != null) { Locale.setDefault(savedLocale); }/*from w w w . j av a2 s.c om*/ savedLocale = null; }
From source file:com.bitplan.vzjava.resources.PowerPlotResource.java
/** * http://stackoverflow.com/a/10257341/1497139 * Sends the file if modified and "not modified" if not modified * future work may put each file with a unique id in a separate folder in * tomcat/*w ww. j a v a 2 s. co m*/ * * use that static URL for each file * * if file is modified, URL of file changes * * -> client always fetches correct file * * method header for calling method public Response * getXY(@HeaderParam("If-Modified-Since") String modified) { * * @param file * to send * @param modified * - HeaderField "If-Modified-Since" - may be "null" * @return Response to be sent to the client */ public static Response returnFile(File file, String modified) { if (!file.exists()) { return Response.status(Status.NOT_FOUND).build(); } // do we really need to send the file or can send "not modified"? if (modified != null) { Date modifiedDate = null; // we have to switch the locale to ENGLISH as parseDate parses in the // default locale Locale old = Locale.getDefault(); Locale.setDefault(Locale.ENGLISH); try { modifiedDate = DateUtils.parseDate(modified, DEFAULT_PATTERNS); } catch (ParseException e) { LOGGER.log(Level.WARNING, e.getMessage()); } Locale.setDefault(old); if (modifiedDate != null) { // modifiedDate does not carry milliseconds, but fileDate does // therefore we have to do a range-based comparison // 1000 milliseconds = 1 second if (file.lastModified() - modifiedDate.getTime() < DateUtils.MILLIS_PER_SECOND) { return Response.status(Status.NOT_MODIFIED).build(); } } } // we really need to send the file try { Date fileDate = new Date(file.lastModified()); return Response.ok(new FileInputStream(file)).lastModified(fileDate).build(); } catch (FileNotFoundException e) { return Response.status(Status.NOT_FOUND).build(); } }
From source file:net.bible.android.BibleApplication.java
/** Allow user interface locale override by changing Settings *///from ww w . j a va 2s . com private void allowLocaleOverride() { // Has the user selected a custom locale? Configuration config = getBaseContext().getResources().getConfiguration(); String lang = CommonUtils.getLocalePref(); if (!"".equals(lang) && !config.locale.getLanguage().equals(lang)) { overrideLocale = new Locale(lang); Locale.setDefault(overrideLocale); config.locale = overrideLocale; getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics()); } }