List of usage examples for java.util Locale Locale
public Locale(String language, String country)
From source file:com.opensymphony.xwork2.conversion.impl.StringConverterTest.java
public void testDoubleToStringConversionPL() throws Exception { // given// w ww .j av a 2 s . c o m StringConverter converter = new StringConverter(); Map<String, Object> context = new HashMap<>(); context.put(ActionContext.LOCALE, new Locale("pl", "PL")); // when has max fraction digits Object value = converter.convertValue(context, null, null, null, Double.MIN_VALUE, null); // then does not lose fraction digits assertEquals("0," + StringUtils.repeat('0', 323) + "49", value); // when has max integer digits value = converter.convertValue(context, null, null, null, Double.MAX_VALUE, null); // then does not lose integer digits assertEquals("17976931348623157" + StringUtils.repeat('0', 292), value); // when cannot be represented exactly with a finite binary number value = converter.convertValue(context, null, null, null, 0.1d, null); // then produce the shortest decimal representation that can unambiguously identify the true value of the floating-point number assertEquals("0,1", value); }
From source file:rbcp.PropertiesResourceBundleControl.java
@Override public List<Locale> getCandidateLocales(String baseName, Locale locale) { if (baseName == null) throw new NullPointerException(); if (locale.equals(new Locale("zh", "HK"))) { return Arrays.asList(locale, Locale.TAIWAN, // no Locale.CHINESE here Locale.ROOT);/*from w w w.j a v a 2s .co m*/ } else if (locale.equals(Locale.TAIWAN)) { return Arrays.asList(locale, // no Locale.CHINESE here Locale.ROOT); } return super.getCandidateLocales(baseName, locale); }
From source file:coreexample.AppConfigTest.java
private ApplicationContext doTesting(Class<?> appConfigClass) { Locale expected = new Locale("en", "US"); ApplicationContext context = new AnnotationConfigApplicationContext(appConfigClass); Locale systemLocale = context.getBean("systemLocale", Locale.class); assertNotNull(systemLocale);//from w w w . ja va 2 s.com assertNotSame(expected, context); return context; }
From source file:com.relicum.ipsum.Locale.LocaleManager.java
/** * Set new locale/*from w ww . j a v a2s . c o m*/ * * @param langCode the lang code * @param countryCode the country code */ public void setLocale(String langCode, String countryCode) { Locale.setDefault(new Locale(langCode, countryCode)); }
From source file:net.fenyo.gnetwatch.Config.java
/** * Constructor.//from w w w. j av a2 s .c o m * Reads the configuration properties from the initialization file. * main thread * @param none. * @throws IOException file not found. */ public Config() throws IOException { properties = new Properties(); properties.loadFromXML(new FileInputStream("config.xml")); locale = new Locale(getProperty("language"), getProperty("country")); bundle = ResourceBundle.getBundle("i18n", locale); }
From source file:com.opensymphony.xwork2.conversion.impl.NumberConverterTest.java
public void testStringToNumberConversionUS() throws Exception { // given//from w w w . j ava2s .c o m NumberConverter converter = new NumberConverter(); Map<String, Object> context = new HashMap<>(); context.put(ActionContext.LOCALE, new Locale("en", "US")); SimpleFooAction foo = new SimpleFooAction(); // when Object value = converter.convertValue(context, foo, null, "id", ",1234", Integer.class); // then assertEquals(1234, value); }
From source file:sk.lazyman.gizmo.security.GizmoAuthWebSession.java
public GizmoAuthWebSession(Request request) { super(request); Injector.get().inject(this); if (getLocale() == null) { //default locale for web application setLocale(new Locale("en", "US")); }/*from w w w . j a v a 2s. co m*/ }
From source file:com.hurence.logisland.utils.DateUtils.java
public static Date getDateFromLogString(String dateString) { SimpleDateFormat sdf = new SimpleDateFormat("dd/MMM/yyyy:hh:mm:ss", new Locale("en", "US")); sdf.setTimeZone(tz);// w ww. j av a2 s. c om Date result = null; try { result = sdf.parse(dateString); } catch (ParseException e) { log.warn(e.getMessage()); } return result; }
From source file:com.inversoft.json.LocaleDeserializer.java
private Locale toLocale(String str) { if (str == null) { return null; }/*w w w . j av a 2 s. c om*/ int len = str.length(); if (len != 2 && len != 5 && len < 7) { throw new IllegalArgumentException("Invalid locale format: " + str); } char ch0 = str.charAt(0); char ch1 = str.charAt(1); if (ch0 < 'a' || ch0 > 'z' || ch1 < 'a' || ch1 > 'z') { throw new IllegalArgumentException("Invalid locale format: " + str); } if (len == 2) { return new Locale(str, ""); } else { if (str.charAt(2) != '_') { throw new IllegalArgumentException("Invalid locale format: " + str); } char ch3 = str.charAt(3); if (ch3 == '_') { return new Locale(str.substring(0, 2), "", str.substring(4)); } char ch4 = str.charAt(4); if (ch3 < 'A' || ch3 > 'Z' || ch4 < 'A' || ch4 > 'Z') { throw new IllegalArgumentException("Invalid locale format: " + str); } if (len == 5) { return new Locale(str.substring(0, 2), str.substring(3, 5)); } else { if (str.charAt(5) != '_') { throw new IllegalArgumentException("Invalid locale format: " + str); } return new Locale(str.substring(0, 2), str.substring(3, 5), str.substring(6)); } } }
From source file:com.geemvc.taglib.html.MessageTagSupport.java
@Override public void doTag() throws JspException { if (locale != null && (lang != null || country != null)) throw new JspException( "You can only set one of of either 'locale' or a 'language/country' combination."); if (lang != null && country != null) locale = new Locale(lang, country); else if (lang != null) locale = new Locale(lang); String label = null;//from w ww . j a v a 2s .com // Handle string keys normally. if (key instanceof String) { label = messageResolver.resolve((String) key, locale, requestContext(), true); } else if (key.getClass().isEnum()) { // Attempt to resolve <enun-fqn>.<enum-value>. label = messageResolver.resolve( new StringBuilder(key.getClass().getName()).append(Char.DOT).append(key).toString(), requestContext(), true); // Attempt to resolve <enun-simple-name>.<enum-value>. if (label == null) label = messageResolver.resolve( new StringBuilder(key.getClass().getSimpleName()).append(Char.DOT).append(key).toString(), requestContext(), true); } else if (key instanceof Boolean) { // Attempt to resolve Boolean.true or Boolean.false. label = messageResolver.resolve(new StringBuilder(Boolean.class.getSimpleName()).append(Char.DOT) .append(String.valueOf(key).toLowerCase()).toString(), requestContext(), true); } else { throw new JspException("The type '" + key.getClass().getName() + "' cannot be used as a message key in MessageTagSupport. Only the types String, Boolean or enums are supported."); } if (label != null) { if (escapeHTML) label = StringEscapeUtils.escapeHtml4(label); if (escapeJavascript) label = StringEscapeUtils.escapeEcmaScript(label); if (escapeJson) label = StringEscapeUtils.escapeJson(label); if (unescapeHTML) label = StringEscapeUtils.unescapeHtml4(label); if (unescapeJavascript) label = StringEscapeUtils.unescapeEcmaScript(label); if (unescapeJson) label = StringEscapeUtils.unescapeJson(label); } if (label == null) { label = getBodyContent(); if (label == null) label = String.format("???%s???", key); } // Deal with parameters. if (label != null) { List<Object> params = messageParameters(); if (params != null && !params.isEmpty()) label = MessageFormat.format(label, params.toArray()); } if (!Str.isEmpty(var)) { jspContext.setAttribute(var, label, scope()); } else { try { jspContext.getOut().write(label); } catch (IOException e) { throw new JspException(e); } } }