List of usage examples for java.util Locale getISO3Language
public String getISO3Language() throws MissingResourceException
From source file:org.fao.geonet.api.records.MetadataWorkflowApi.java
@ApiOperation(value = "Get last workflow status for a record", notes = "", nickname = "getStatus") @RequestMapping(value = "/{metadataUuid}/status/workflow/last", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE }) @PreAuthorize("hasRole('Editor')") @ApiResponses(value = { @ApiResponse(code = 200, message = "Record status."), @ApiResponse(code = 403, message = ApiParams.API_RESPONSE_NOT_ALLOWED_CAN_EDIT) }) @ResponseStatus(HttpStatus.OK)// w ww . j av a2s . c o m @ResponseBody public MetadataWorkflowStatusResponse getStatus( @ApiParam(value = API_PARAM_RECORD_UUID, required = true) @PathVariable String metadataUuid, HttpServletRequest request) throws Exception { AbstractMetadata metadata = ApiUtils.canEditRecord(metadataUuid, request); ApplicationContext appContext = ApplicationContextHolder.get(); Locale locale = languageUtils.parseAcceptLanguage(request.getLocales()); ServiceContext context = ApiUtils.createServiceContext(request, locale.getISO3Language()); AccessManager am = appContext.getBean(AccessManager.class); //--- only allow the owner of the record to set its status if (!am.isOwner(context, String.valueOf(metadata.getId()))) { throw new SecurityException(String.format( "Only the owner of the metadata can get the status. User is not the owner of the metadata")); } IMetadataStatus metadataStatus = context.getBean(IMetadataStatus.class); MetadataStatus recordStatus = metadataStatus.getStatus(metadata.getId()); // List<StatusValue> elStatus = context.getBean(StatusValueRepository.class).findAll(); List<StatusValue> elStatus = context.getBean(StatusValueRepository.class) .findAllByType(StatusValueType.workflow); //--- get the list of content reviewers for this metadata record Set<Integer> ids = new HashSet<Integer>(); ids.add(Integer.valueOf(metadata.getId())); List<Pair<Integer, User>> reviewers = context.getBean(UserRepository.class) .findAllByGroupOwnerNameAndProfile(ids, Profile.Reviewer, SortUtils.createSort(User_.name)); List<User> listOfReviewers = new ArrayList<>(); for (Pair<Integer, User> reviewer : reviewers) { listOfReviewers.add(reviewer.two()); } return new MetadataWorkflowStatusResponse(recordStatus, listOfReviewers, am.hasEditPermission(context, metadata.getId() + ""), elStatus); }
From source file:org.opensextant.util.TextUtils.java
/** * Initialize language codes and metadata. This establishes a map for the * most common language codes/names that exist in at least ISO-639-1 and * have a non-zero 2-char ID.//w w w .j av a 2 s.co m * * <pre> * Based on: * http://stackoverflow.com/questions/674041/is-there-an-elegant-way * -to-convert-iso-639-2-3-letter-language-codes-to-java-lo * * Actual code mappings: en => eng eng => en * * cel => '' // Celtic; Avoid this. * * tr => tur tur => tr * * Names: tr => turkish tur => turkish turkish => tr // ISO2 only * * </pre> */ public static void initLanguageData() { Locale[] locales = Locale.getAvailableLocales(); for (Locale locale : locales) { Language l = new Language(locale.getISO3Language(), locale.getLanguage(), locale.getDisplayLanguage()); addLanguage(l); } }
From source file:org.fao.geonet.api.records.formatters.FormatterApi.java
@RequestMapping(value = { "/api/records/{metadataUuid}/formatters/{formatterId}", "/api/" + API.VERSION_0_1 + "/records/{metadataUuid}/formatters/{formatterId}" }, method = RequestMethod.GET, produces = { MediaType.TEXT_HTML_VALUE, MediaType.APPLICATION_XHTML_XML_VALUE, "application/pdf", MediaType.ALL_VALUE // TODO: PDF }) @ApiOperation(value = "Get a formatted metadata record", nickname = "getRecordFormattedBy") @ResponseBody/* w w w . ja v a 2 s .com*/ public void getRecordFormattedBy( @ApiParam(value = "Formatter type to use.") @RequestHeader(value = HttpHeaders.ACCEPT, defaultValue = MediaType.TEXT_HTML_VALUE) String acceptHeader, @PathVariable(value = "formatterId") final String formatterId, @ApiParam(value = API_PARAM_RECORD_UUID, required = true) @PathVariable String metadataUuid, @RequestParam(value = "width", defaultValue = "_100") final FormatterWidth width, @RequestParam(value = "mdpath", required = false) final String mdPath, @RequestParam(value = "output", required = false) FormatType formatType, @ApiIgnore final NativeWebRequest request, final HttpServletRequest servletRequest) throws Exception { ApplicationContext applicationContext = ApplicationContextHolder.get(); Locale locale = languageUtils.parseAcceptLanguage(servletRequest.getLocales()); // TODO : // if text/html > xsl_view // if application/pdf > xsl_view and PDF output // if application/x-gn-<formatterId>+(xml|html|pdf|text) // Force PDF ouutput when URL parameter is set. // This is useful when making GET link to PDF which // can not use headers. if (MediaType.ALL_VALUE.equals(acceptHeader)) { acceptHeader = MediaType.TEXT_HTML_VALUE; } if (formatType == null) { formatType = FormatType.find(acceptHeader); } if (formatType == null) { formatType = FormatType.xml; } final String language = LanguageUtils.locale2gnCode(locale.getISO3Language()); final ServiceContext context = createServiceContext(language, formatType, request.getNativeRequest(HttpServletRequest.class)); AbstractMetadata metadata = ApiUtils.canViewRecord(metadataUuid, servletRequest); Boolean hideWithheld = true; // final boolean hideWithheld = Boolean.TRUE.equals(hide_withheld) || // !context.getBean(AccessManager.class).canEdit(context, resolvedId); Key key = new Key(metadata.getId(), language, formatType, formatterId, hideWithheld, width); final boolean skipPopularityBool = false; ISODate changeDate = metadata.getDataInfo().getChangeDate(); Validator validator; if (changeDate != null) { final long changeDateAsTime = changeDate.toDate().getTime(); long roundedChangeDate = changeDateAsTime / 1000 * 1000; if (request.checkNotModified(language, roundedChangeDate) && context.getBean(CacheConfig.class).allowCaching(key)) { if (!skipPopularityBool) { context.getBean(DataManager.class).increasePopularity(context, String.valueOf(metadata.getId())); } return; } validator = new ChangeDateValidator(changeDateAsTime); } else { validator = new NoCacheValidator(); } final FormatMetadata formatMetadata = new FormatMetadata(context, key, request); byte[] bytes; if (hasNonStandardParameters(request)) { // the http headers can cause a formatter to output custom output due to the parameters. // because it is not known how the parameters may affect the output then we have two choices // 1. make a unique cache for each configuration of parameters // 2. don't cache anything that has extra parameters beyond the standard parameters used to // create the key // #1 has a major flaw because an attacker could simply make new requests always changing the parameters // and completely swamp the cache. So we go with #2. The formatters are pretty fast so it is a fine solution bytes = formatMetadata.call().data; } else { bytes = context.getBean(FormatterCache.class).get(key, validator, formatMetadata, false); } if (bytes != null) { if (!skipPopularityBool) { context.getBean(DataManager.class).increasePopularity(context, String.valueOf(metadata.getId())); } writeOutResponse(context, metadataUuid, locale.getISO3Language(), request.getNativeResponse(HttpServletResponse.class), formatType, bytes); } }
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 w w . j av a 2s . com*/ // 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(); }