List of usage examples for java.util Locale getISO3Country
public String getISO3Country() throws MissingResourceException
From source file:com.ethercamp.harmony.service.PeersService.java
/** * Create MaxMind lookup service to find country by IP. * IPv6 is not used./*from w w w . ja v a 2 s . c om*/ */ private void createGeoDatabase() { final String[] countries = Locale.getISOCountries(); final Optional<String> dbFilePath = Optional.ofNullable(env.getProperty("maxmind.file")); for (String country : countries) { Locale locale = new Locale("", country); localeMap.put(locale.getISO3Country().toUpperCase(), locale); } lookupService = dbFilePath.flatMap(path -> { try { return Optional.ofNullable(new LookupService(path, LookupService.GEOIP_MEMORY_CACHE | LookupService.GEOIP_CHECK_CACHE)); } catch (IOException e) { log.error("Problem finding maxmind database at " + path + ". " + e.getMessage()); log.error( "Wasn't able to create maxmind location service. Country information will not be available."); return Optional.empty(); } }); }
From source file:com.ethercamp.harmony.service.PeersService.java
private String iso2CountryCodeToIso3CountryCode(String iso2CountryCode) { Locale locale = new Locale("", iso2CountryCode); try {/*from ww w . j a v a 2 s . co m*/ return locale.getISO3Country(); } catch (MissingResourceException e) { // silent } return ""; }
From source file:org.mili.core.resource.ResourceUtilImpl.java
private String getInfo(Locale l, String baseName, String key) { final String pattern = "[locale=%1-%2, baseName=%3, key=%4]"; return pattern.replace("%1", l.getISO3Country()).replace("%2", l.getISO3Language()).replace("%3", baseName) .replace("%4", key); }
From source file:org.mobicents.servlet.restcomm.provisioning.number.voxbone.VoxbonePhoneNumberProvisioningManager.java
@Override public List<PhoneNumber> searchForNumbers(String country, PhoneNumberSearchFilters listFilters) { Locale locale = new Locale("en", country); String iso3Country = locale.getISO3Country(); if (logger.isDebugEnabled()) { logger.debug("searchPattern " + listFilters.getFilterPattern()); }// ww w. j av a2s . c om Client jerseyClient = Client.create(); jerseyClient.addFilter(new HTTPBasicAuthFilter(username, password)); WebResource webResource = jerseyClient.resource(searchURI); // https://developers.voxbone.com/docs/v3/inventory#path__didgroup.html webResource = webResource.queryParam(COUNTRY_CODE_PARAM, iso3Country); // Pattern filterPattern = listFilters.getFilterPattern(); // if(filterPattern != null) { // webResource = webResource.queryParam("cityNamePattern" , filterPattern.toString()); // } if (listFilters.getAreaCode() != null) { webResource = webResource.queryParam("areaCode", listFilters.getAreaCode()); } if (listFilters.getInRateCenter() != null) { webResource = webResource.queryParam("rateCenter", listFilters.getInRateCenter()); } if (listFilters.getSmsEnabled() != null) { webResource = webResource.queryParam("featureIds", "6"); } if (listFilters.getFaxEnabled() != null) { webResource = webResource.queryParam("featureIds", "25"); } if (listFilters.getRangeIndex() != -1) { webResource = webResource.queryParam(PAGE_NUMBER, "" + listFilters.getRangeIndex()); } else { webResource = webResource.queryParam(PAGE_NUMBER, "0"); } if (listFilters.getRangeSize() != -1) { webResource = webResource.queryParam(PAGE_SIZE, "" + listFilters.getRangeSize()); } else { webResource = webResource.queryParam(PAGE_SIZE, "50"); } ClientResponse clientResponse = webResource.accept(CONTENT_TYPE).type(CONTENT_TYPE) .get(ClientResponse.class); String response = clientResponse.getEntity(String.class); if (logger.isDebugEnabled()) logger.debug("response " + response); JsonParser parser = new JsonParser(); JsonObject jsonResponse = parser.parse(response).getAsJsonObject(); // long count = jsonResponse.getAsJsonPrimitive("count").getAsLong(); // if(logger.isDebugEnabled()) { // logger.debug("Number of numbers found : "+count); // } JsonArray voxboneNumbers = jsonResponse.getAsJsonArray("didGroups"); final List<PhoneNumber> numbers = toAvailablePhoneNumbers(voxboneNumbers, listFilters); return numbers; // } else { // logger.warn("Couldn't reach uri for getting Phone Numbers. Response status was: "+response.getStatusLine().getStatusCode()); // } // // return new ArrayList<PhoneNumber>(); }
From source file:com.github.olga_yakovleva.rhvoice.android.RHVoiceService.java
@Override protected String[] onGetLanguage() { String[] result = { "rus", "RUS", "" }; AndroidVoiceInfo voice = currentVoice; if (voice == null) { Tts tts = ttsManager.get();/*from ww w .j a va 2 s . c om*/ if (tts != null) { Locale locale = Locale.getDefault(); Candidate bestMatch = findBestVoice(tts, locale.getISO3Language(), locale.getISO3Country(), "", "", getLanguageSettings(tts)); if (bestMatch.voice != null) voice = bestMatch.voice; } } if (voice == null) return result; result[0] = voice.getLanguage(); result[1] = voice.getCountry(); return result; }
From source file:org.fao.geonet.api.groups.GroupsApi.java
/** * Writes the group logo image to the response. If no image is found it * writes a 1x1 transparent PNG. If the request contain cache related * headers it checks if the resource has changed and return a 304 Not * Modified response if not changed./*from w w w . jav a 2s . c o m*/ * * @param groupId the group identifier. * @param webRequest the web request. * @param request the native HTTP Request. * @param response the servlet response. * @throws ResourceNotFoundException if no group exists with groupId. */ @ApiOperation(value = "Get the group logo image.", nickname = "get", notes = API_GET_LOGO_NOTE) @RequestMapping(value = "/{groupId}/logo", method = RequestMethod.GET) public void getGroupLogo( @ApiParam(value = "Group identifier", required = true) @PathVariable(value = "groupId") final Integer groupId, @ApiIgnore final WebRequest webRequest, HttpServletRequest request, HttpServletResponse response) throws ResourceNotFoundException { Locale locale = languageUtils.parseAcceptLanguage(request.getLocales()); ApplicationContext context = ApplicationContextHolder.get(); ServiceContext serviceContext = ApiUtils.createServiceContext(request, locale.getISO3Country()); if (context == null) { throw new RuntimeException("ServiceContext not available"); } GroupRepository groupRepository = context.getBean(GroupRepository.class); Group group = groupRepository.findOne(groupId); if (group == null) { throw new ResourceNotFoundException( messages.getMessage("api.groups.group_not_found", new Object[] { groupId }, locale)); } try { final Path logosDir = Resources.locateLogosDir(serviceContext); final Path harvesterLogosDir = Resources.locateHarvesterLogosDir(serviceContext); final String logoUUID = group.getLogo(); Path imagePath = null; FileTime lastModifiedTime = null; if (StringUtils.isNotBlank(logoUUID) && !logoUUID.startsWith("http://") && !logoUUID.startsWith("https//")) { imagePath = Resources.findImagePath(logoUUID, logosDir); if (imagePath == null) { imagePath = Resources.findImagePath(logoUUID, harvesterLogosDir); } if (imagePath != null) { lastModifiedTime = Files.getLastModifiedTime(imagePath); if (webRequest.checkNotModified(lastModifiedTime.toMillis())) { // webRequest.checkNotModified sets the right HTTP headers response.setDateHeader("Expires", System.currentTimeMillis() + SIX_HOURS * 1000L); return; } response.setContentType(AttachmentsApi.getFileContentType(imagePath)); response.setContentLength((int) Files.size(imagePath)); response.addHeader("Cache-Control", "max-age=" + SIX_HOURS + ", public"); response.setDateHeader("Expires", System.currentTimeMillis() + SIX_HOURS * 1000L); FileUtils.copyFile(imagePath.toFile(), response.getOutputStream()); } } if (imagePath == null) { // no logo image found. Return a transparent 1x1 png lastModifiedTime = FileTime.fromMillis(0); if (webRequest.checkNotModified(lastModifiedTime.toMillis())) { return; } response.setContentType("image/png"); response.setContentLength(TRANSPARENT_1_X_1_PNG.length); response.addHeader("Cache-Control", "max-age=" + SIX_HOURS + ", public"); response.getOutputStream().write(TRANSPARENT_1_X_1_PNG); } } catch (IOException e) { Log.error(LOGGER, String.format("There was an error accessing the logo of the group with id '%d'", groupId)); throw new RuntimeException(e); } }
From source file:no.abmu.common.locale.LocaleUtil.java
/** * Method for logging of locale. Used under test and development. * /*from ww w . j a va 2s .c om*/ * @param request current HTTP request */ public void logLocale(HttpServletRequest request) { HttpSession session = request.getSession(false); String parameterSiteLocale = request.getParameter("siteLocale"); String parameterStartLocale = request.getParameter("startLocale"); String rcSiteLocale = (String) request.getAttribute("siteLocale"); // String seSiteLocale = (String) session.getAttribute("siteLocale"); Locale locale = RequestContextUtils.getLocale(request); logger.info("request siteLocale: " + rcSiteLocale); logger.info("request parameter siteLocale: " + parameterSiteLocale); logger.info("request parameter startLocale: " + parameterStartLocale); // logger.info("session siteLocale: " + seSiteLocale); logger.info("Locale getDisplayCountry: " + locale.getDisplayCountry()); logger.info("Locale getDisplayLanguage: " + locale.getDisplayLanguage()); logger.info("Locale getDisplayVariant: " + locale.getDisplayVariant()); logger.info("Locale getDisplayName: " + locale.getDisplayName()); logger.info("Locale getISO3Country: " + locale.getISO3Country()); logger.info("Locale getLanguage: " + locale.getLanguage()); logger.info("Locale getVariant: " + locale.getVariant()); logger.info("Locale toString: " + locale.toString()); }
From source file:it.cnr.icar.eric.client.ui.thin.RegistryBrowser.java
@SuppressWarnings("unused") private boolean isAsianLocale(Locale locale) { String iso3Country = locale.getISO3Country(); return (iso3Country.equalsIgnoreCase("CHN") || iso3Country.equalsIgnoreCase("JPN") || iso3Country.equalsIgnoreCase("KOR")); /*/*w w w . j a v a 2 s . c o m*/ if (iso3Country.equalsIgnoreCase("CHN") || iso3Country.equalsIgnoreCase("JPN") || iso3Country.equalsIgnoreCase("KOR")) { return true; } else { return false; } */ }
From source file:com.landenlabs.all_devtool.SystemFragment.java
public void updateList() { // Time today = new Time(Time.getCurrentTimezone()); // today.setToNow(); // today.format(" %H:%M:%S") Date dt = new Date(); m_titleTime.setText(m_timeFormat.format(dt)); boolean expandAll = m_list.isEmpty(); m_list.clear();//from w ww. ja va 2 s .co m // Swap colors int color = m_rowColor1; m_rowColor1 = m_rowColor2; m_rowColor2 = color; ActivityManager actMgr = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE); try { String androidIDStr = Settings.Secure.getString(getContext().getContentResolver(), Settings.Secure.ANDROID_ID); addBuild("Android ID", androidIDStr); try { AdvertisingIdClient.Info adInfo = AdvertisingIdClient.getAdvertisingIdInfo(getContext()); final String adIdStr = adInfo.getId(); final boolean isLAT = adInfo.isLimitAdTrackingEnabled(); addBuild("Ad ID", adIdStr); } catch (IOException e) { // Unrecoverable error connecting to Google Play services (e.g., // the old version of the service doesn't support getting AdvertisingId). } catch (GooglePlayServicesNotAvailableException e) { // Google Play services is not available entirely. } /* try { InstanceID instanceID = InstanceID.getInstance(getContext()); if (instanceID != null) { // Requires a Google Developer project ID. String authorizedEntity = "<need to make this on google developer site>"; instanceID.getToken(authorizedEntity, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null); addBuild("Instance ID", instanceID.getId()); } } catch (Exception ex) { } */ ConfigurationInfo info = actMgr.getDeviceConfigurationInfo(); addBuild("OpenGL", info.getGlEsVersion()); } catch (Exception ex) { m_log.e(ex.getMessage()); } try { long heapSize = Debug.getNativeHeapSize(); // long maxHeap = Runtime.getRuntime().maxMemory(); // ConfigurationInfo cfgInfo = actMgr.getDeviceConfigurationInfo(); int largHeapMb = actMgr.getLargeMemoryClass(); int heapMb = actMgr.getMemoryClass(); MemoryInfo memInfo = new MemoryInfo(); actMgr.getMemoryInfo(memInfo); final String sFmtMB = "%.2f MB"; Map<String, String> listStr = new TreeMap<String, String>(); listStr.put("Mem Available (now)", String.format(sFmtMB, (double) memInfo.availMem / MB)); listStr.put("Mem LowWhenOnlyAvail", String.format(sFmtMB, (double) memInfo.threshold / MB)); if (Build.VERSION.SDK_INT >= 16) { listStr.put("Mem Installed", String.format(sFmtMB, (double) memInfo.totalMem / MB)); } listStr.put("Heap (this app)", String.format(sFmtMB, (double) heapSize / MB)); listStr.put("HeapMax (default)", String.format(sFmtMB, (double) heapMb)); listStr.put("HeapMax (large)", String.format(sFmtMB, (double) largHeapMb)); addBuild("Memory...", listStr); } catch (Exception ex) { m_log.e(ex.getMessage()); } try { List<ProcessErrorStateInfo> procErrList = actMgr.getProcessesInErrorState(); int errCnt = (procErrList == null ? 0 : procErrList.size()); procErrList = null; // List<RunningAppProcessInfo> procList = actMgr.getRunningAppProcesses(); int procCnt = actMgr.getRunningAppProcesses().size(); int srvCnt = actMgr.getRunningServices(100).size(); Map<String, String> listStr = new TreeMap<String, String>(); listStr.put("#Processes", String.valueOf(procCnt)); listStr.put("#Proc With Err", String.valueOf(errCnt)); listStr.put("#Services", String.valueOf(srvCnt)); // Requires special permission // int taskCnt = actMgr.getRunningTasks(100).size(); // listStr.put("#Tasks", String.valueOf(taskCnt)); addBuild("Processes...", listStr); } catch (Exception ex) { m_log.e("System-Processes %s", ex.getMessage()); } try { Map<String, String> listStr = new LinkedHashMap<String, String>(); listStr.put("LargeIconDensity", String.valueOf(actMgr.getLauncherLargeIconDensity())); listStr.put("LargeIconSize", String.valueOf(actMgr.getLauncherLargeIconSize())); putIf(listStr, "isRunningInTestHarness", "Yes", ActivityManager.isRunningInTestHarness()); putIf(listStr, "isUserAMonkey", "Yes", ActivityManager.isUserAMonkey()); addBuild("Misc...", listStr); } catch (Exception ex) { m_log.e("System-Misc %s", ex.getMessage()); } // --------------- Locale / Timezone ------------- try { Locale ourLocale = Locale.getDefault(); Date m_date = new Date(); TimeZone tz = TimeZone.getDefault(); Map<String, String> localeListStr = new LinkedHashMap<String, String>(); localeListStr.put("Locale Name", ourLocale.getDisplayName()); localeListStr.put(" Variant", ourLocale.getVariant()); localeListStr.put(" Country", ourLocale.getCountry()); localeListStr.put(" Country ISO", ourLocale.getISO3Country()); localeListStr.put(" Language", ourLocale.getLanguage()); localeListStr.put(" Language ISO", ourLocale.getISO3Language()); localeListStr.put(" Language Dsp", ourLocale.getDisplayLanguage()); localeListStr.put("TimeZoneID", tz.getID()); localeListStr.put(" DayLightSavings", tz.useDaylightTime() ? "Yes" : "No"); localeListStr.put(" In DLS", tz.inDaylightTime(m_date) ? "Yes" : "No"); localeListStr.put(" Short Name", tz.getDisplayName(false, TimeZone.SHORT, ourLocale)); localeListStr.put(" Long Name", tz.getDisplayName(false, TimeZone.LONG, ourLocale)); addBuild("Locale TZ...", localeListStr); } catch (Exception ex) { m_log.e("Locale/TZ %s", ex.getMessage()); } // --------------- Location Services ------------- try { Map<String, String> listStr = new LinkedHashMap<String, String>(); final LocationManager locMgr = (LocationManager) getActivity() .getSystemService(Context.LOCATION_SERVICE); GpsStatus gpsStatus = locMgr.getGpsStatus(null); if (gpsStatus != null) { listStr.put("Sec ToGetGPS", String.valueOf(gpsStatus.getTimeToFirstFix())); Iterable<GpsSatellite> satellites = gpsStatus.getSatellites(); Iterator<GpsSatellite> sat = satellites.iterator(); while (sat.hasNext()) { GpsSatellite satellite = sat.next(); putIf(listStr, String.format("Azm:%.0f, Elev:%.0f", satellite.getAzimuth(), satellite.getElevation()), String.format("%.2f Snr", satellite.getSnr()), satellite.usedInFix()); } } Location location = null; if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { location = locMgr.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (null == location) location = locMgr.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (null == location) location = locMgr.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER); } if (null != location) { listStr.put(location.getProvider() + " lat,lng", String.format("%.3f, %.3f", location.getLatitude(), location.getLongitude())); } if (listStr.size() != 0) { List<String> gpsProviders = locMgr.getAllProviders(); int idx = 1; for (String providerName : gpsProviders) { LocationProvider provider = locMgr.getProvider(providerName); if (null != provider) { listStr.put(providerName, (locMgr.isProviderEnabled(providerName) ? "On " : "Off ") + String.format("Accuracy:%d Pwr:%d", provider.getAccuracy(), provider.getPowerRequirement())); } } addBuild("GPS...", listStr); } else addBuild("GPS", "Off"); } catch (Exception ex) { m_log.e(ex.getMessage()); } // --------------- Application Info ------------- ApplicationInfo appInfo = getActivity().getApplicationInfo(); if (null != appInfo) { Map<String, String> appList = new LinkedHashMap<String, String>(); try { appList.put("ProcName", appInfo.processName); appList.put("PkgName", appInfo.packageName); appList.put("DataDir", appInfo.dataDir); appList.put("SrcDir", appInfo.sourceDir); // appList.put("PkgResDir", getActivity().getPackageResourcePath()); // appList.put("PkgCodeDir", getActivity().getPackageCodePath()); String[] dbList = getActivity().databaseList(); if (dbList != null && dbList.length != 0) appList.put("DataBase", dbList[0]); // getActivity().getComponentName(). } catch (Exception ex) { } addBuild("AppInfo...", appList); } // --------------- Account Services ------------- final AccountManager accMgr = (AccountManager) getActivity().getSystemService(Context.ACCOUNT_SERVICE); if (null != accMgr) { Map<String, String> strList = new LinkedHashMap<String, String>(); try { for (Account account : accMgr.getAccounts()) { strList.put(account.name, account.type); } } catch (Exception ex) { m_log.e(ex.getMessage()); } addBuild("Accounts...", strList); } // --------------- Package Features ------------- PackageManager pm = getActivity().getPackageManager(); FeatureInfo[] features = pm.getSystemAvailableFeatures(); if (features != null) { Map<String, String> strList = new LinkedHashMap<String, String>(); for (FeatureInfo featureInfo : features) { strList.put(featureInfo.name, ""); } addBuild("Features...", strList); } // --------------- Sensor Services ------------- final SensorManager senMgr = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); if (null != senMgr) { Map<String, String> strList = new LinkedHashMap<String, String>(); // Sensor accelerometer = senMgr.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); // senMgr.registerListener(foo, accelerometer, SensorManager.SENSOR_DELAY_NORMAL); List<Sensor> listSensor = senMgr.getSensorList(Sensor.TYPE_ALL); try { for (Sensor sensor : listSensor) { strList.put(sensor.getName(), sensor.getVendor()); } } catch (Exception ex) { m_log.e(ex.getMessage()); } addBuild("Sensors...", strList); } try { if (Build.VERSION.SDK_INT >= 17) { final UserManager userMgr = (UserManager) getActivity().getSystemService(Context.USER_SERVICE); if (null != userMgr) { try { addBuild("UserName", userMgr.getUserName()); } catch (Exception ex) { m_log.e(ex.getMessage()); } } } } catch (Exception ex) { } try { Map<String, String> strList = new LinkedHashMap<String, String>(); int screenTimeout = Settings.System.getInt(getActivity().getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT); strList.put("ScreenTimeOut", String.valueOf(screenTimeout / 1000)); int rotate = Settings.System.getInt(getActivity().getContentResolver(), Settings.System.ACCELEROMETER_ROTATION); strList.put("RotateEnabled", String.valueOf(rotate)); if (Build.VERSION.SDK_INT >= 17) { // Global added in API 17 int adb = Settings.Global.getInt(getActivity().getContentResolver(), Settings.Global.ADB_ENABLED); strList.put("AdbEnabled", String.valueOf(adb)); } addBuild("Settings...", strList); } catch (Exception ex) { } if (expandAll) { // updateList(); int count = m_list.size(); for (int position = 0; position < count; position++) m_listView.expandGroup(position); } m_adapter.notifyDataSetChanged(); }
From source file:eu.apenet.dpt.standalone.gui.eaccpf.EacCpfDescriptionPanel.java
/** * Fill all list used into main-frame panel *//*ww w .ja va2s. c o m*/ private void fillListModels() { //fill countries String[] locales = Locale.getISOCountries(); countriesListWithEmpty = new ArrayList<String>(); countriesListWithEmpty.add(TextFieldWithComboBoxEacCpf.DEFAULT_VALUE); countriesMap = new HashMap<String, String>(); for (String countryCode : locales) { Locale obj = new Locale("", countryCode); countriesListWithEmpty.add(obj.getDisplayCountry(Locale.ENGLISH)); countriesMap.put(obj.getDisplayCountry(Locale.ENGLISH), obj.getISO3Country()); } //DATES this.placesDates = new HashMap<Integer, List<TextFieldsWithRadioButtonForDates>>(); this.functionsDates = new HashMap<Integer, List<TextFieldsWithRadioButtonForDates>>(); this.occupationsDates = new HashMap<Integer, List<TextFieldsWithRadioButtonForDates>>(); }