List of usage examples for java.util Locale getLanguage
public String getLanguage()
From source file:com.doculibre.constellio.services.FacetServicesImpl.java
public static SolrQuery toSolrQuery(SimpleSearch simpleSearch, int start, int row, boolean includeSingleValueFacets, boolean notIncludedOnly, List<String> customFieldFacets, List<String> customQueryFacets, ConstellioUser user) { String solrServerName = simpleSearch.getCollectionName(); RecordCollectionServices collectionServices = ConstellioSpringUtils.getRecordCollectionServices(); RecordCollection collection = collectionServices.get(solrServerName); SolrServices solrServices = ConstellioSpringUtils.getSolrServices(); Boolean usesDisMax = solrServices.usesDisMax(collection); SolrQuery query;/* ww w.j a va 2 s .co m*/ if (!collection.isOpenSearch()) { query = SearchServicesImpl.toSolrQuery(simpleSearch, usesDisMax, true, includeSingleValueFacets, notIncludedOnly); } else { query = SearchServicesImpl.toSolrQuery(simpleSearch, usesDisMax, false, true, false); } query.setParam(ConstellioSolrQueryParams.COLLECTION_NAME, simpleSearch.getCollectionName()); query.setParam(ConstellioSolrQueryParams.LUCENE_QUERY, simpleSearch.getLuceneQuery(includeSingleValueFacets, true)); query.setParam(ConstellioSolrQueryParams.SIMPLE_SEARCH, simpleSearch.toSimpleParams().toString()); if (user != null) { query.setParam(ConstellioSolrQueryParams.USER_ID, "" + user.getId()); } if (StringUtils.isEmpty(query.getQuery())) { query.setQuery(SimpleSearch.SEARCH_ALL); query.setRequestHandler("/elevate"); } query.set("shards.qt", "/elevate"); query.setRequestHandler("/elevate"); query.setRows(row); query.setStart(start); query.setHighlight(true); query.setHighlightFragsize(100); query.setHighlightSnippets(2); query.setFacet(true); query.setFacetLimit(400); query.setFacetMinCount(1); if (collection.isOpenSearch()) { query.setParam("openSearchURL", collection.getOpenSearchURL()); Locale locale = simpleSearch.getSingleSearchLocale(); if (locale != null) { query.setParam("lang", locale.getLanguage()); } } else { for (CollectionFacet collectionFacet : collection.getCollectionFacets()) { if (customFieldFacets == null && collectionFacet.isFieldFacet()) { IndexField indexField = collectionFacet.getFacetField(); String indexFieldName = indexField.getName(); if (!notIncludedOnly) { query.addFacetField(indexFieldName); } else { SearchedFacet searchedFacet = simpleSearch.getSearchedFacet(indexFieldName); if (searchedFacet != null) { if (!searchedFacet.getIncludedValues().isEmpty()) { StringBuffer sbEx = new StringBuffer(); sbEx.append("{!ex=dt}"); // sbEx.append("{!ex="); // boolean first = true; // for (String includedValue : searchedFacet.getIncludedValues()) { // if (first) { // first = false; // } else { // sbEx.append(","); // } // sbEx.append(includedValue); // } // sbEx.append("}"); // query.setParam("facet.field", sbEx.toString() + indexFieldName); query.addFacetField(sbEx.toString() + indexFieldName); } else { query.addFacetField(indexFieldName); } } } } else if (customQueryFacets == null && collectionFacet.isQueryFacet()) { // Modification Rida, remplacement de collectionFacet.getLabels() par // collectionFacet.getLabelledValues() // for (I18NLabel valueLabels : collectionFacet.getLabels()) { for (I18NLabel valueLabels : collectionFacet.getLabelledValues()) { String facetQuery = valueLabels.getKey(); query.addFacetQuery(facetQuery); } } } if (customFieldFacets != null) { for (String facetField : customFieldFacets) { if (!notIncludedOnly) { query.addFacetField(facetField); } else { StringBuffer sbEx = new StringBuffer(); sbEx.append("{!ex=dt}"); // sbEx.append("{!ex="); // boolean first = true; // for (String includedValue : searchedFacet.getIncludedValues()) { // if (first) { // first = false; // } else { // sbEx.append(","); // } // sbEx.append(includedValue); // } // sbEx.append("}"); query.setParam("facet.field", sbEx.toString() + facetField); } } } if (customQueryFacets != null) { for (String facetQuery : customQueryFacets) { query.addFacetQuery(facetQuery); } } } return query; }
From source file:com.cburch.logisim.util.LocaleManager.java
public static void setLocale(Locale loc) { Locale cur = getLocale();// w w w . ja v a2s . c o m if (!loc.equals(cur)) { Locale[] opts = LocaleString.getUtilLocaleManager().getLocaleOptions(); Locale select = null; Locale backup = null; String locLang = loc.getLanguage(); for (Locale opt : opts) { if (select == null && opt.equals(loc)) { select = opt; } if (backup == null && opt.getLanguage().equals(locLang)) { backup = opt; } } if (select == null) { if (backup == null) { select = new Locale("en"); } else { select = backup; } } curLocale = select; Locale.setDefault(select); for (LocaleManager man : managers) { man.loadDefault(); } repl = replaceAccents ? fetchReplaceAccents() : null; fireLocaleChanged(); } }
From source file:com.kubotaku.android.openweathermap.lib.util.GeocodeUtil.java
/** * Get location name from Address./*from w ww .java 2 s. c o m*/ * <p/> * Use Google Maps Geocode api. * <p/> * * @param locale Locale. * @param latlng Address. * @return Location name of target address. */ public static String pointToName(final Locale locale, final LatLng latlng) { String name = ""; try { String requestURL = String.format(API_FROM_LOCATION, latlng.latitude, latlng.longitude); String lang = locale.getLanguage(); requestURL += "&language=" + lang; URL url = new URL(requestURL); InputStream is = url.openConnection().getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); StringBuilder sb = new StringBuilder(); String line; while (null != (line = reader.readLine())) { sb.append(line); } String data = sb.toString(); name = GeocodeParser.parseLocationName(data); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return name; }
From source file:com.carlomicieli.jtrains.value.objects.LocalizedField.java
private static String sanitizeLanguage(String lang) { Locale l = Locale.forLanguageTag(lang); if (!ISOValidationUtils.countryIsValid(l.getCountry())) { throw new IllegalArgumentException("'" + lang + "' is not a valid locale code (country)."); }// w ww .j a v a 2 s .c om if (!ISOValidationUtils.languageIsValid(l.getLanguage())) { throw new IllegalArgumentException("'" + lang + "' is not a valid locale code (language)."); } return l.getLanguage(); }
From source file:edu.jhuapl.openessence.i18n.SupportedLocale.java
/** * @param messageSource to translate displayLanguage *///from ww w. j ava2 s . c o m public static SupportedLocale fromLocale(Locale locale, MessageSource messageSource) { SupportedLocale sl = new SupportedLocale(); sl.setCode(locale.toString()); // display language in target locale, i.e. "espaol" instead of "Spanish" String defaultDisplayLanguage = locale.getDisplayLanguage(locale); // Java doesn't have every language display name in every language // (e.g. doesn't have "Khmer" in Khmer), so use message bundle as fallback String lang = messageSource.getMessage("language." + locale.getLanguage(), null, defaultDisplayLanguage, locale); sl.setDisplayLanguage(lang); return sl; }
From source file:it.eng.spagobi.commons.utilities.PortletUtilities.java
/** * Gets the language code of the user portal language. If it's not possible to gather * the locale of the portal it returns the default language code * //from www . j ava 2 s. co m * @return A string containing the language code */ public static String getPortalLanguageCode() { try { Locale portalLocale = PortletAccess.getPortalLocale(); if (portalLocale == null) { logger.error("Portal locale not found by PortletAccess.getPortalLocale() method!! " + "May be there is not a portlet request"); } else { String portalLang = portalLocale.getLanguage(); return portalLang; } } catch (Exception e) { logger.error("Error while getting portal locale", e); } // get the configuration sourceBean/language code/country code of the default language String languageConfig = SingletonConfig.getInstance() .getConfigValue("SPAGOBI.LANGUAGE_SUPPORTED.LANGUAGE.default"); return languageConfig.substring(0, 2); }
From source file:it.uniud.ailab.dcore.annotation.annotators.RawTdidfAnnotator.java
private static void loadFile(File f, Locale locale) { BufferedReader br = null;//w w w . ja va 2s .com StringBuilder document = new StringBuilder(); String line; int tokenCount = 0; try { br = new BufferedReader(new FileReader(f)); while ((line = br.readLine()) != null) { String[] tokenizedDocument = OpenNlpBootstrapperAnnotator.tokenizeText(line, locale.getLanguage()); SnowballStemmer stemmer = SnowballStemmerSelector.getStemmerForLanguage(locale); for (int i = 0; i < tokenizedDocument.length; i++) { stemmer.setCurrent(tokenizedDocument[i]); if (stemmer.stem()) { tokenizedDocument[i] = stemmer.getCurrent(); } } tokenCount += tokenizedDocument.length; document.append(String.join(" ", markTokens(tokenizedDocument)).trim()); document.append(" "); } } catch (FileNotFoundException e) { throw new AnnotationException(new RawTdidfAnnotator(), "Can't read the tf-idf database.", e); } catch (IOException e) { throw new AnnotationException(new RawTdidfAnnotator(), "Can't read the tf-idf database.", e); } finally { if (br != null) { try { br.close(); } catch (IOException e) { // don't care } } } String documentText = document.toString().trim(); documents.put(f.getAbsolutePath(), documentText); docLengths.put(f.getAbsolutePath(), tokenCount); }
From source file:com.kubotaku.android.openweathermap.lib.util.GeocodeUtil.java
/** * Get location address from target location name. * <p/>//from w w w . j a v a 2s . co m * Use Google Maps Geocode api. * <p/> * * @param locale Locale. * @param name Location name. * @return Location address. */ public static LatLng nameToPoint(final Locale locale, final String name) { LatLng address = null; try { String utf8Name = URLEncoder.encode(name, "UTF-8"); String requestURL = String.format(API_FROM_NAME, utf8Name); String lang = locale.getLanguage(); requestURL += "&language=" + lang; URL url = new URL(requestURL); InputStream is = url.openConnection().getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); StringBuilder sb = new StringBuilder(); String line; while (null != (line = reader.readLine())) { sb.append(line); } String data = sb.toString(); address = GeocodeParser.parseLocation(data); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return address; }
From source file:com.aurel.track.admin.customize.category.report.ReportBL.java
/** * Get a localized /* w w w. j a va 2 s . c o m*/ * @param map * @param tag can be "listing", "description", or "tool-tip" * @param locale * @return */ public static String getLocalizedText(Map<String, Object> map, String tag, Locale locale) { Map<String, String> localizedStuff = null; String ret = null; if (locale != null) { localizedStuff = (Map<String, String>) map.get("locale_" + locale.getLanguage()); if (localizedStuff != null) { ret = localizedStuff.get(tag); return ret; } } localizedStuff = (Map<String, String>) map.get("locale_" + Locale.getDefault().getLanguage()); if (localizedStuff != null) { ret = localizedStuff.get(tag); return ret; } localizedStuff = (Map<String, String>) map.get("locale_"); if (localizedStuff != null) { ret = localizedStuff.get(tag); return ret; } return ret; }
From source file:it.eng.spagobi.commons.utilities.PortletUtilities.java
/** * Get the locale of the portal or the one setted into the configuration files * @return locale for message resolution */// ww w. j a v a 2 s. c om public static Locale getLocaleForMessage() { logger.info("IN"); Locale locale = null; Locale portalLocale; try { portalLocale = PortletAccess.getPortalLocale(); if (portalLocale == null) { logger.error("Portal locale not found by PortletAccess.getPortalLocale() method"); } else { logger.debug("Portal locale read succesfully: [" + portalLocale.getLanguage() + "," + portalLocale.getCountry() + "]"); } if (isLocaleSupported(portalLocale)) { logger.debug("Portal locale [" + portalLocale.getLanguage() + "," + portalLocale.getCountry() + "] is supported by SpagoBI"); locale = portalLocale; } else { logger.warn("Portal locale [" + portalLocale.getLanguage() + "," + portalLocale.getCountry() + "] is not supported by SpagoBI"); locale = GeneralUtilities.getDefaultLocale(); logger.debug( "Default locale [" + locale.getLanguage() + "," + locale.getCountry() + "] will be used"); } } catch (Exception e) { logger.error("Error while getting portal locale", e); } logger.info("OUT"); return locale; }