List of usage examples for java.util Locale getCountry
public String getCountry()
From source file:nz.co.senanque.localemanagement.XMLMessageSource.java
@Override protected MessageFormat resolveCode(String code, Locale locale) { String ret = null;//from w w w . j a v a 2 s . co m String country = locale.getCountry(); String language = locale.getLanguage(); String variant = locale.getVariant(); logger.debug("Code {} Initial locale {}", code, locale.toString()); Locale thisLocale = null; if (!StringUtils.isEmpty(variant)) { thisLocale = new Locale(language, country, variant); Map<String, String> m = m_map.get(thisLocale); if (m != null) { ret = m.get(code); } logger.debug("tried locale {} result: {}", thisLocale.toString(), ret); } if (ret == null) { if (!StringUtils.isEmpty(country)) { thisLocale = new Locale(language, country); Map<String, String> m = m_map.get(thisLocale); if (m != null) { ret = m.get(code); } logger.debug("tried locale {} result: {}", thisLocale.toString(), ret); } } if (ret == null) { if (!StringUtils.isEmpty(language)) { thisLocale = new Locale(language); Map<String, String> m = m_map.get(thisLocale); if (m != null) { ret = m.get(code); } logger.debug("tried locale {} result: {}", thisLocale.toString(), ret); } } if (ret == null) { thisLocale = Locale.getDefault(); Map<String, String> m = m_map.get(thisLocale); if (m != null) { ret = m.get(code); } logger.debug("tried locale {} result: {}", thisLocale.toString(), ret); } if (ret == null) { return null; } return new MessageFormat(ret, locale); }
From source file:SimpleRefDataExample.java
protected void processMessage(Message msg) throws Exception { HashMap<String, String> map = new HashMap<String, String>(); String[] locales = Locale.getISOCountries(); for (String countryCode : locales) { Locale loc = new Locale("", countryCode); map.put(loc.getDisplayCountry().toLowerCase(), loc.getCountry()); }//from ww w . j a v a 2 s . co m //System.out.println (map); // Gson gson = null; //StringBuffer sb = new StringBuffer(); String s = null; Element securityDataArray = msg.getElement(SECURITY_DATA); int numSecurities = securityDataArray.numValues(); for (int i = 0; i < numSecurities; ++i) { Element securityData = securityDataArray.getValueAsElement(i); //System.out.println(securityData.getElementAsString(SECURITY)); Element fieldData = securityData.getElement(FIELD_DATA); for (int j = 0; j < fieldData.numElements(); ++j) { Element field = fieldData.getElement(j); if (field.isNull()) { System.out.println(field.name() + " is NULL."); } else { String str = field.getValueAsString(); if (j % 2 == 0) s = str; else { String countryCode = map.get(s.toLowerCase()); if (countryCode != null) { // System.out.println(str + " " + countryCode); //if (map.containsKey(s)) obj.put(countryCode, Double.parseDouble(str)); } } //field.getValueAsString().put(obj); //obj.put(str[0], str[1]); } } Element fieldExceptionArray = securityData.getElement(FIELD_EXCEPTIONS); for (int k = 0; k < fieldExceptionArray.numValues(); ++k) { Element fieldException = fieldExceptionArray.getValueAsElement(k); /* System.out.println( fieldException.getElement(ERROR_INFO).getElementAsString("category") + ": " + fieldException.getElementAsString(FIELD_ID));*/ } } }
From source file:arena.translation.LocaleInModelInterceptor.java
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { super.postHandle(request, response, handler, modelAndView); if (modelAndView != null) { Locale locale = this.localeResolver.resolveLocale(request); if (this.countryCodeParamName != null) { modelAndView.addObject(this.countryCodeParamName, locale.getCountry()); }//from w ww. j a v a2 s .c o m if (this.languageCodeParamName != null) { modelAndView.addObject(this.languageCodeParamName, locale.getLanguage()); } if (this.localeParamName != null) { modelAndView.addObject(this.localeParamName, locale); } } }
From source file:com.stimulus.struts.BaseBean.java
protected Locale getLocale() { Locale locale = Locale.getDefault(); String country = locale.getCountry(); ActionContext context = ActionContext.getActionContext(); if (context != null) { HttpServletRequest request = context.getRequest(); if (request != null) locale = request.getLocale(); }/*from w w w . j a v a 2 s . c o m*/ if (locale.getCountry().length() < 1 && locale.getLanguage().length() > 0) { locale = new Locale(locale.getLanguage(), Locale.getDefault().getCountry()); } String country2 = locale.getCountry(); //if (locale.getCountry().equalsIgnoreCase("ZA")) // locale = Locale.UK; // bug in JVM concerning date formatting in South Africa return locale; }
From source file:org.atomserver.core.EntryCategory.java
public void setLocale(Locale locale) { setLanguage(locale == null ? null : locale.getLanguage()); setCountry(locale == null ? null : locale.getCountry()); }
From source file:LocaleMap.java
private String getFullKey(Locale locale) { return locale.getLanguage() + '-' + locale.getCountry() + '-' + locale.getVariant(); }
From source file:org.smigo.species.vernacular.JdbcVernacularDao.java
@Override public Vernacular getVernacularByName(String name, Locale locale) { final String sql = "SELECT * FROM VERNACULARS WHERE VERNACULAR_NAME=? AND LANGUAGE=? AND COUNTRY=?"; Object[] args = { name, locale.getLanguage(), locale.getCountry() }; return jdbcTemplate.queryForObject(sql, args, vernacularRowMapper); }
From source file:org.datacleaner.user.UsageLogger.java
@Inject protected UsageLogger(UserPreferences userPreferences) { _userPreferences = userPreferences;/*w ww.java2 s . co m*/ _executorService = SharedExecutorService.get(); _javaVendor = System.getProperty("java.vendor"); _javaVersion = System.getProperty("java.version"); _osName = System.getProperty("os.name"); _osArch = System.getProperty("os.arch"); final Locale defaultLocale = Locale.getDefault(); _country = defaultLocale.getCountry(); _language = defaultLocale.getLanguage(); logger.debug( "Determined installation details as:\nJava version: {}\nJava vendor: {}\nOS name: {}\nOS arch: {}\nUser country: {}\nUser language: {}", _javaVersion, _javaVendor, _osName, _osArch, _country, _language); }
From source file:com.salesmanager.central.shipping.ShippingfedexgroundAction.java
@Override public void prepareModule() throws Exception { Context ctx = (Context) super.getServletRequest().getSession().getAttribute(ProfileConstants.context); Integer merchantid = ctx.getMerchantid(); ReferenceService rservice = (ReferenceService) ServiceFactory.getService(ServiceFactory.ReferenceService); Locale locale = getLocale(); String country = locale.getCountry(); if (locale.getVariant().equals("EUR")) { country = "X1"; }// w ww . ja v a 2 s. c o m Map packages = ShippingUtil.buildPackageMap(moduleid, locale); if (packages != null) { setPackageMap(packages); } // get merchant configs MerchantService mservice = (MerchantService) ServiceFactory.getService(ServiceFactory.MerchantService); ConfigurationResponse config = mservice.getConfigurationByModule(moduleid, merchantid); this.setConfigurations(config); }
From source file:cn.vlabs.duckling.vwb.ui.servlet.AbstractLoginServlet.java
private void redirectToUmt(HttpServletRequest request, HttpServletResponse response, String viewUrl) throws IOException, ServletException { Oauth oauth = new Oauth(properties); int siteId = getVwbcontext(request).getSiteId(); VWBContainer container = VWBContainerImpl.findContainer(); Locale locale = request.getLocale(); String language = locale.getLanguage() + "_" + locale.getCountry(); if (!locale.equals(Locale.CHINA)) { language = Locale.US.getLanguage() + "_" + Locale.US.getCountry(); }//from w w w . j a v a2 s .c om if (StringUtils.isEmpty(language)) { language = container.getSiteConfig().getProperty(siteId, KeyConstants.SITE_LANGUAGE); } try { String redirectUrl = oauth.getAuthorizeURL(request) + "&state=" + URLEncoder.encode(viewUrl, "UTF-8") + "&locale=" + language; response.sendRedirect(redirectUrl); } catch (UMTOauthConnectException e) { throw new ServletException(e); } }