List of usage examples for java.util Locale setDefault
public static synchronized void setDefault(Locale newLocale)
From source file:org.jfree.data.time.QuarterTest.java
/** * Some checks for the getStart() method. *//*from ww w.j ava 2 s . c o m*/ @Test public void testGetStart() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(2006, Calendar.JULY, 1, 0, 0, 0); cal.set(Calendar.MILLISECOND, 0); Quarter q = new Quarter(3, 2006); assertEquals(cal.getTime(), q.getStart()); Locale.setDefault(saved); }
From source file:org.jfree.data.time.WeekTest.java
/** * Some checks for the getLastMillisecond() method. *///ww w. j a v a 2 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")); Week w = new Week(31, 1970); assertEquals(18485999999L, w.getLastMillisecond()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); }
From source file:org.jfree.data.time.MonthTest.java
/** * Some checks for the getEnd() method./* w w w . ja v a 2s . c om*/ */ @Test public void testGetEnd() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(2006, Calendar.JANUARY, 31, 23, 59, 59); cal.set(Calendar.MILLISECOND, 999); Month m = new Month(1, 2006); assertEquals(cal.getTime(), m.getEnd()); Locale.setDefault(saved); }
From source file:hudson.FunctionsTest.java
@Test @Issue("JENKINS-16630") public void testHumanReadableFileSize() { Locale defaultLocale = Locale.getDefault(); try {//from w w w. ja v a 2 s .co m Locale.setDefault(Locale.ENGLISH); assertEquals("0 B", Functions.humanReadableByteSize(0)); assertEquals("1023 B", Functions.humanReadableByteSize(1023)); assertEquals("1.00 KB", Functions.humanReadableByteSize(1024)); assertEquals("1.50 KB", Functions.humanReadableByteSize(1536)); assertEquals("20.00 KB", Functions.humanReadableByteSize(20480)); assertEquals("1023.00 KB", Functions.humanReadableByteSize(1047552)); assertEquals("1.00 MB", Functions.humanReadableByteSize(1048576)); assertEquals("1.50 GB", Functions.humanReadableByteSize(1610612700)); } finally { Locale.setDefault(defaultLocale); } }
From source file:org.jfree.data.time.junit.MillisecondTest.java
/** * Some checks for the getStart() method. *//*from w w w. j a v a 2 s . c om*/ public void testGetStart() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(2006, Calendar.JANUARY, 16, 3, 47, 55); cal.set(Calendar.MILLISECOND, 555); Millisecond m = new Millisecond(555, 55, 47, 3, 16, 1, 2006); assertEquals(cal.getTime(), m.getStart()); Locale.setDefault(saved); }
From source file:org.yccheok.jstock.gui.JTableUtilities.java
/** * Get the keys for a given string and locale. * * @param string the string for the desired key * @param locale the locale for the desired key * @return the keys for a given string and locale *//*from w w w . j a v a 2 s. c o m*/ private static java.util.List<String> getKeys(String string, Locale locale) { if (string2KeyMap.containsKey(locale)) { final Map<String, java.util.List<String>> string2Key = string2KeyMap.get(locale); final java.util.List<String> result = string2Key.get(string); if (result == null) { return java.util.Collections.EMPTY_LIST; } return result; } final Map<String, java.util.List<String>> string2Key = new HashMap<String, java.util.List<String>>(); // Ensure correct resource file is being loaded. // When ResourceBundle.getBundle(..., locale) is being called, the // system will try to search in the following sequence. // 1. gui_<locale>.properties. // 2. gui_<default_locale>.properties. // 3. gui.properties. final Locale oldLocale = Locale.getDefault(); Locale.setDefault(locale); try { final ResourceBundle bundle = ResourceBundle.getBundle("org.yccheok.jstock.data.gui", locale); final Enumeration<String> enumeration = bundle.getKeys(); while (enumeration.hasMoreElements()) { final String key = enumeration.nextElement(); final String str = bundle.getString(key); java.util.List list = string2Key.get(str); if (list == null) { list = new ArrayList<String>(); string2Key.put(str, list); } list.add(key); } string2KeyMap.put(locale, string2Key); } finally { Locale.setDefault(oldLocale); } final java.util.List<String> result = string2Key.get(string); if (result == null) { return java.util.Collections.EMPTY_LIST; } return result; }
From source file:org.apache.jmeter.util.JMeterUtils.java
/** * Changes the current locale: re-reads resource strings and notifies * listeners./*from w w w . ja va 2 s.c om*/ * * @param loc - * new locale */ public static void setLocale(Locale loc) { log.info("Setting Locale to " + loc.toString()); /* * See bug 29920. getBundle() defaults to the property file for the * default Locale before it defaults to the base property file, so we * need to change the default Locale to ensure the base property file is * found. */ Locale def = null; boolean isDefault = false; // Are we the default language? if (loc.getLanguage().equals(ENGLISH_LANGUAGE)) { isDefault = true; def = Locale.getDefault(); // Don't change locale from en_GB to en if (!def.getLanguage().equals(ENGLISH_LANGUAGE)) { Locale.setDefault(Locale.ENGLISH); } else { def = null; // no need to reset Locale } } if (loc.toString().equals("ignoreResources")) { // $NON-NLS-1$ log.warn("Resource bundles will be ignored"); ignoreResorces = true; // Keep existing settings } else { ignoreResorces = false; ResourceBundle resBund = ResourceBundle.getBundle("org.apache.jmeter.resources.messages", loc); // $NON-NLS-1$ resources = resBund; locale = loc; final Locale resBundLocale = resBund.getLocale(); if (isDefault || resBundLocale.equals(loc)) {// language change worked // Check if we at least found the correct language: } else if (resBundLocale.getLanguage().equals(loc.getLanguage())) { log.info("Could not find resources for '" + loc.toString() + "', using '" + resBundLocale.toString() + "'"); } else { log.error("Could not find resources for '" + loc.toString() + "'"); } } notifyLocaleChangeListeners(); /* * Reset Locale if necessary so other locales are properly handled */ if (def != null) { Locale.setDefault(def); } }
From source file:org.jfree.data.time.junit.HourTest.java
/** * Some checks for the getEnd() method.//ww w.ja va2 s .c o m */ public void testGetEnd() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(2006, Calendar.JANUARY, 8, 1, 59, 59); cal.set(Calendar.MILLISECOND, 999); Hour h = new Hour(1, 8, 1, 2006); assertEquals(cal.getTime(), h.getEnd()); Locale.setDefault(saved); }
From source file:org.b3log.latke.remote.RepositoryAccessor.java
/** * Puts data to repository.//from w w w .j a va 2s . c om * * <p> * Query parameters: * /latke/remote/repository/data?<em>userName=xxx&password=xxx&repositoryName=xxx</em><br/> * All parameters are required. * </p> * * <p> * The post body, for example, "data": {....} or [] // JSON object or JSON array, content of the backup file * </p> * * <p> * Renders response like the following: * <pre> * { * "sc":200, * "msg":"Put data" * } * </pre> * </p> * * @param context the specified HTTP request context * @param request the specified HTTP servlet request * @param response the specified HTTP servlet response */ @RequestProcessing(value = "/latke/remote/repository/data", method = HTTPRequestMethod.POST) public void putData(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) { final JSONRenderer renderer = new JSONRenderer(); context.setRenderer(renderer); final JSONObject jsonObject = new JSONObject(); renderer.setJSONObject(jsonObject); jsonObject.put(Keys.STATUS_CODE, HttpServletResponse.SC_OK); jsonObject.put(Keys.MSG, "Put data"); final StringBuilder dataBuilder = new StringBuilder(); if (badPutDataRequest(request, jsonObject, dataBuilder) || !authSucc(request, jsonObject)) { return; } final String repositoryName = request.getParameter("repositoryName"); Repository repository = Repositories.getRepository(repositoryName); if (null == repository) { repository = new AbstractRepository(repositoryName) { }; } repository.setCacheEnabled(false); final Transaction transaction = repository.beginTransaction(); try { final String dataContent = dataBuilder.toString(); final JSONArray data = new JSONArray(dataContent); for (int i = 0; i < data.length(); i++) { final JSONObject record = data.getJSONObject(i); // Date type fixing final JSONArray keysDescription = Repositories.getRepositoryKeysDescription(repositoryName); for (int j = 0; j < keysDescription.length(); j++) { final JSONObject keyDescription = keysDescription.optJSONObject(j); final String key = keyDescription.optString("name"); final String type = keyDescription.optString("type"); if ("Date".equals(type)) { final Locale defaultLocale = Locale.getDefault(); Locale.setDefault(Locale.US); record.put(key, DateUtils.parseDate(record.optString(key), new String[] { "EEE MMM dd HH:mm:ss z yyyy", "EEE MMM d HH:mm:ss z yyyy", "yyyy-MM-dd HH:mm:ss.SSS" })); Locale.setDefault(defaultLocale); } } repository.add(record); } transaction.commit(); } catch (final Exception e) { if (transaction.isActive()) { transaction.rollback(); } LOGGER.log(Level.SEVERE, "Puts data failed", e); jsonObject.put(Keys.STATUS_CODE, HttpServletResponse.SC_INTERNAL_SERVER_ERROR); jsonObject.put(Keys.MSG, "Puts data failed[errorMsg=" + e.getMessage() + "]"); } finally { repository.setCacheEnabled(true); } }
From source file:org.jfree.data.time.junit.DayTest.java
/** * Some checks for the getStart() method. *//*from w ww . j a v a 2 s . com*/ public void testGetStart() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(2006, Calendar.NOVEMBER, 3, 0, 0, 0); cal.set(Calendar.MILLISECOND, 0); Day d = new Day(3, 11, 2006); assertEquals(cal.getTime(), d.getStart()); Locale.setDefault(saved); }