List of usage examples for java.util Locale getVariant
public String getVariant()
From source file:org.openmrs.web.dwr.ConceptListItem.java
/** * Populate all of the attributes of this class * * @param concept/*from w ww . j av a 2 s. c om*/ * @param conceptName * @param locale */ private void initialize(Concept concept, ConceptName conceptName, Locale locale) { if (concept != null) { conceptId = concept.getConceptId(); ConceptName conceptShortName = concept.getShortNameInLocale(locale); name = ""; shortName = ""; description = ""; if (conceptName != null) { conceptNameId = conceptName.getConceptNameId(); if (conceptName.isIndexTerm() && concept.getName() == null) { name = WebUtil.escapeHTML(conceptName.getName()) + Context.getMessageSourceService().getMessage("Concept.no.fullySpecifiedName.found"); } else { name = WebUtil.escapeHTML(conceptName.getName()); } // if the name hit is not the preferred or fully specified one, put the fully specified one here if (!conceptName.isPreferred()) { ConceptName preferredNameObj = concept.getPreferredName(locale); if (preferredNameObj == null && !StringUtils.isBlank(locale.getCountry()) || !StringUtils.isBlank(locale.getVariant())) { preferredNameObj = concept.getPreferredName(new Locale(locale.getLanguage())); } if (preferredNameObj != null) { preferredName = preferredNameObj.getName(); } } } if (conceptShortName != null) { shortName = WebUtil.escapeHTML(conceptShortName.getName()); } ConceptDescription conceptDescription = concept.getDescription(locale, false); if (conceptDescription != null) { description = WebUtil.escapeHTML(conceptDescription.getDescription()); } isCodedDatatype = concept.getDatatype().isCoded(); retired = concept.isRetired(); hl7Abbreviation = concept.getDatatype().getHl7Abbreviation(); className = concept.getConceptClass().getName(); isSet = concept.isSet(); isNumeric = concept.isNumeric(); if (isNumeric) { // TODO: There's probably a better way to do this, but just doing "(ConceptNumeric) concept" throws "java.lang.ClassCastException: org.openmrs.Concept$$EnhancerByCGLIB$$85e62ac7" ConceptNumeric num = Context.getConceptService().getConceptNumeric(concept.getConceptId()); hiAbsolute = num.getHiAbsolute(); hiCritical = num.getHiCritical(); hiNormal = num.getHiNormal(); lowAbsolute = num.getLowAbsolute(); lowCritical = num.getLowCritical(); lowNormal = num.getLowNormal(); units = num.getUnits(); } } }
From source file:edu.ku.brc.specify.prefs.SystemPrefs.java
@Override public void savePrefs() { if (form.getValidator() == null || form.getValidator().hasChanged()) { super.savePrefs(); ValCheckBox chk = form.getCompById("2"); localPrefs.putBoolean(VERSION_CHECK, (Boolean) chk.getValue()); chk = form.getCompById("3"); remotePrefs.putBoolean(SEND_STATS, (Boolean) chk.getValue()); chk = form.getCompById("9"); remotePrefs.putBoolean(SEND_ISA_STATS, (Boolean) chk.getValue()); /* remove if worldwind is broken*/chk = form.getCompById(USE_WORLDWIND); /* remove if worldwind is broken*/localPrefs.putBoolean(USE_WORLDWIND, (Boolean) chk.getValue()); // /* remove if worldwind is broken*/chk = form.getCompById(SYSTEM_HasOpenGL); /* remove if worldwind is broken*/localPrefs.putBoolean(SYSTEM_HasOpenGL, (Boolean) chk.getValue()); // /* remove if worldwind is broken*/chk = form.getCompById(USE_WORLDWIND); /* remove if worldwind is broken*/localPrefs.putBoolean(USE_WORLDWIND, (Boolean) chk.getValue()); //chk = form.getCompById(ALWAYS_ASK_COLL); //localPrefs.putBoolean(ALWAYS_ASK_COLL, (Boolean)chk.getValue()); ValComboBox localeCBX = form.getCompById("5"); Locale item = (Locale) localeCBX.getComboBox().getSelectedItem(); if (item != null) { if (item.equals(UIRegistry.getPlatformLocale())) { localPrefs.remove("locale.lang"); localPrefs.remove("locale.country"); localPrefs.remove("locale.var"); //System.out.println("["+localPrefs.get("locale.lang", null)+"]"); Locale.setDefault(UIRegistry.getPlatformLocale()); } else { if (item.getLanguage() == null) { localPrefs.remove("locale.lang"); } else { localPrefs.put("locale.lang", item.getLanguage()); }//from w w w. java 2 s .c om if (item.getCountry() == null) { localPrefs.remove("locale.country"); } else { localPrefs.put("locale.country", item.getCountry()); } if (item.getVariant() == null) { localPrefs.remove("locale.var"); } else { localPrefs.put("locale.var", item.getVariant()); } } ValBrowseBtnPanel browse = form.getCompById("7"); if (browse != null) { String newSplashPath = browse.getValue().toString(); if (newSplashPath != null && (oldSplashPath == null || !oldSplashPath.equals(newSplashPath))) { if (newSplashPath.isEmpty()) { resetSplashImage(); localPrefs.remove(SPECIFY_BG_IMG_PATH); } else { localPrefs.put(SPECIFY_BG_IMG_PATH, newSplashPath); changeSplashImage(); } } } File cp = JasperReportsCache.getImagePath(); try { localPrefs.flush(); } catch (BackingStoreException ex) { } } } }
From source file:org.opencms.i18n.CmsLocaleManager.java
/** * Tries to find the given requested locale (eventually simplified) in the collection of available locales, * if the requested locale is not found it will return the first match from the given list of default locales.<p> * /*from w w w . j a v a 2 s . com*/ * @param requestedLocale the requested locale, if this (or a simplified version of it) is available it will be returned * @param defaults a list of default locales to use in case the requested locale is not available * @param available the available locales to find a match in * * @return the best matching locale name or null if no name matches */ public Locale getBestMatchingLocale(Locale requestedLocale, List<Locale> defaults, List<Locale> available) { if ((available == null) || available.isEmpty()) { // no locales are available at all return null; } // the requested locale is the match we want to find most if (available.contains(requestedLocale)) { // check if the requested locale is directly available return requestedLocale; } if (requestedLocale.getVariant().length() > 0) { // locale has a variant like "en_EN_whatever", try only with language and country Locale check = new Locale(requestedLocale.getLanguage(), requestedLocale.getCountry(), ""); if (available.contains(check)) { return check; } } if (requestedLocale.getCountry().length() > 0) { // locale has a country like "en_EN", try only with language Locale check = new Locale(requestedLocale.getLanguage(), "", ""); if (available.contains(check)) { return check; } } // available locales do not match the requested locale if ((defaults == null) || defaults.isEmpty()) { // if we have no default locales we are out of luck return null; } // no match found for the requested locale, return the first match from the default locales return getFirstMatchingLocale(defaults, available); }
From source file:org.gradle.integtests.fixtures.executer.AbstractGradleExecuter.java
/** * Returns the set of system properties that should be set on every JVM used by this executer. *//*from w ww .j ava 2s.c o m*/ protected Map<String, String> getImplicitJvmSystemProperties() { Map<String, String> properties = new LinkedHashMap<String, String>(); if (getUserHomeDir() != null) { properties.put("user.home", getUserHomeDir().getAbsolutePath()); } properties.put(DaemonBuildOptions.IdleTimeoutOption.GRADLE_PROPERTY, "" + (daemonIdleTimeoutSecs * 1000)); properties.put(DaemonBuildOptions.BaseDirOption.GRADLE_PROPERTY, daemonBaseDir.getAbsolutePath()); if (!noExplicitNativeServicesDir) { properties.put(NativeServices.NATIVE_DIR_OVERRIDE, buildContext.getNativeServicesDir().getAbsolutePath()); } properties.put(LoggingDeprecatedFeatureHandler.ORG_GRADLE_DEPRECATION_TRACE_PROPERTY_NAME, Boolean.toString(fullDeprecationStackTrace)); if (useOwnUserHomeServices || (gradleUserHomeDir != null && !gradleUserHomeDir.equals(buildContext.getGradleUserHomeDir()))) { properties.put(REUSE_USER_HOME_SERVICES, "false"); } if (!noExplicitTmpDir) { if (tmpDir == null) { tmpDir = getDefaultTmpDir(); } String tmpDirPath = tmpDir.createDir().getAbsolutePath(); if (!tmpDirPath.contains(" ") || (getDistribution().isSupportsSpacesInGradleAndJavaOpts() && supportsWhiteSpaceInEnvVars())) { properties.put("java.io.tmpdir", tmpDirPath); } } properties.put("file.encoding", getDefaultCharacterEncoding()); Locale locale = getDefaultLocale(); if (locale != null) { properties.put("user.language", locale.getLanguage()); properties.put("user.country", locale.getCountry()); properties.put("user.variant", locale.getVariant()); } if (eagerClassLoaderCreationChecksOn) { properties.put(DefaultClassLoaderScope.STRICT_MODE_PROPERTY, "true"); } if (interactive) { properties.put(ConsoleStateUtil.INTERACTIVE_TOGGLE, "true"); } if (!searchUpwards) { if (!isSettingsFileAvailable()) { properties.put(BuildLayoutParameters.NO_SEARCH_UPWARDS_PROPERTY_KEY, "true"); } } properties.put(CommandLineActionFactory.WELCOME_MESSAGE_ENABLED_SYSTEM_PROPERTY, Boolean.toString(renderWelcomeMessage)); return properties; }
From source file:it.cnr.icar.eric.client.ui.thin.RegistryBrowser.java
/** * Returns the localized version of an English html file * English file is something like <root dir>/doc/webUI/userGuide.html * the localized file will be <root dir>/doc/webUI/locale/userGuide.html *///from ww w . j ava 2 s. com public String getLocalizedHTMLFile(String htmlFile) { if (htmlFile == null || htmlFile.equals("")) return htmlFile; // split the file into directory and file name. file name could be followed // by #anchor or \#anchor or something else int dirIndex = htmlFile.lastIndexOf('/'); int extensionIndex = htmlFile.indexOf(".html"); if (dirIndex == -1 || extensionIndex == -1 || (dirIndex + 1) > extensionIndex) return htmlFile; String dirName = htmlFile.substring(0, dirIndex); String fileName = htmlFile.substring(dirIndex + 1, extensionIndex); String anchor = htmlFile.substring(extensionIndex + 5); UserPreferencesBean userBean = new UserPreferencesBean(); Locale uiLocale = userBean.getUiLocale(); ServletContext ctx = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext(); String localizedFile = dirName + "/" + uiLocale.toString() + "/" + fileName + ".html"; // start with .. because the callers are passing the context path String realPath = ctx.getRealPath("../" + localizedFile); File f = new File(realPath); if (f.exists()) return localizedFile + anchor; // try to use language country, without variant if (uiLocale.getVariant() != null && !"".equals(uiLocale.getVariant())) { localizedFile = dirName + "/" + uiLocale.getLanguage() + "_" + uiLocale.getCountry() + "/" + fileName + ".html"; realPath = ctx.getRealPath("../" + localizedFile); f = new File(realPath); if (f.exists()) return localizedFile + anchor; } // try to use language without country and variant if (uiLocale.getCountry() != null && !"".equals(uiLocale.getCountry())) { localizedFile = dirName + "/" + uiLocale.getLanguage() + "/" + fileName + ".html"; realPath = ctx.getRealPath("../" + localizedFile); f = new File(realPath); if (f.exists()) return localizedFile + anchor; } //fall back to original file return htmlFile; }
From source file:org.apache.cocoon.matching.LocaleMatcher.java
private boolean isValidResource(String pattern, Locale locale, Locale testLocale, Map map) { String url;//from w ww . j a va 2 s .co m String testLocaleStr = testLocale.toString(); if ("".equals(testLocaleStr)) { // If same character found before and after the '*', leave only one. int starPos = pattern.indexOf("*"); if (starPos < pattern.length() - 1 && starPos > 1 && pattern.charAt(starPos - 1) == pattern.charAt(starPos + 1)) { url = pattern.substring(0, starPos - 1) + pattern.substring(starPos + 1); } else { url = StringUtils.replace(pattern, "*", ""); } } else { url = StringUtils.replace(pattern, "*", testLocaleStr); } boolean result = true; if (testResourceExists) { Source source = null; try { source = resolver.resolveURI(url); result = source.exists(); } catch (IOException e) { result = false; } finally { if (source != null) { resolver.release(source); } } } if (result) { map.put("source", url); map.put("matched-locale", testLocaleStr); if (locale != null) { map.put("locale", locale.toString()); map.put("language", locale.getLanguage()); map.put("country", locale.getCountry()); map.put("variant", locale.getVariant()); } } return result; }
From source file:edu.ku.brc.specify.tools.StrLocalizerApp.java
/** * @param locale/*from w ww. j av a2 s .c om*/ * @return */ private String getFullLang(final Locale locale) { return locale.getLanguage() + (StringUtils.isNotEmpty(locale.getVariant()) ? ("_" + locale.getVariant()) : ""); }
From source file:edu.ku.brc.specify.config.init.TreeDefSetupPanel.java
/** * @param disciplineType//w w w . j a va 2 s . c o m */ private void loadTree(final STD_DISCIPLINES disciplineType) { treeDefList.clear(); DisciplineType dType = disciplineType == null ? null : DisciplineType.getDiscipline(disciplineType); String fileName = null; if (classType == TaxonTreeDef.class) { fileName = dType.getFolder() + File.separator + "taxon_init.xml"; } else if (classType == GeographyTreeDef.class) { fileName = "common" + File.separator + "geography_init.xml"; } else if (classType == StorageTreeDef.class) { fileName = "common" + File.separator + "storage_init.xml"; } Locale currLocale = SchemaI18NService.getCurrentLocale(); File file = getConfigDir(fileName); if (file.exists()) { try { Element root = readFileToDOM4J(file); for (Object levelObj : root.selectNodes("/tree/treedef/level")) { Element level = (Element) levelObj; String name = getAttr(level, "name", null); int rank = getAttr(level, "rank", -1); boolean enforced = getAttr(level, "enforced", false); boolean isInFullName = getAttr(level, "infullname", false); String title = name; String text = null; for (Object localeObj : level.selectNodes("locale")) { Element locale = (Element) localeObj; String lang = getAttr(locale, "lang", null); String country = getAttr(locale, "country", null); String var = getAttr(locale, "var", null); if (StringUtils.isNotEmpty(lang) && StringUtils.isNotEmpty(currLocale.getLanguage()) && lang.equals(currLocale.getLanguage())) { title = getAttr(locale, "text", null); if (StringUtils.isNotEmpty(country) && StringUtils.isNotEmpty(currLocale.getCountry()) && country.equals(currLocale.getCountry())) { title = getAttr(locale, "text", null); if (StringUtils.isNotEmpty(var) && StringUtils.isNotEmpty(currLocale.getVariant()) && var.equals(currLocale.getVariant())) { title = getAttr(locale, "text", null); } } } } if (rank > -1) { boolean required = false; if (classType == TaxonTreeDef.class) { required = TaxonTreeDef.isStdRequiredLevel(rank) || rank == 0; } else if (classType == GeographyTreeDef.class) { required = GeographyTreeDef.isStdRequiredLevel(rank) || rank == 0; } else { required = rank == 0; } String sep = classType == TaxonTreeDef.class ? " " : ", "; treeDefList.add(new TreeDefRow(name, title, rank, required, enforced, required && isInFullName, required || rank == 0, sep)); } } if (model != null) { model.fireTableDataChanged(); } } catch (Exception ex) { ex.printStackTrace(); } } }
From source file:org.openmrs18.Concept.java
/** * Returns concept name, the look up for the appropriate name is done in the following order; * <ul>/* ww w .jav a2s .com*/ * <li>First name found in any locale that is explicitly marked as preferred while searching * available locales in order of preference (the locales are traversed in their order as they * are listed in the 'locale.allowed.list' including english global property).</li> * <li>First "Fully Specified" name found while searching available locales in order of * preference.</li> * <li>The first fully specified name found while searching through all names for the concept</li> * <li>The first synonym found while searching through all names for the concept.</li> * <li>The first random name found(except index terms) while searching through all names.</li> * </ul> * * @return {@link ConceptName} in the current locale or any locale if none found * @since 1.5 * @see Concept#getNames(Locale) to get all the names for a locale * @see Concept#getPreferredName(Locale) for the preferred name (if any) * @should return the name explicitly marked as locale preferred if any is present * @should return the fully specified name in a locale if no preferred name is set * @should return null if the only added name is an index term * @should return name in broader locale incase none is found in specific one */ public ConceptName getName() { if (getNames().size() == 0) { if (log.isDebugEnabled()) log.debug("there are no names defined for: " + conceptId); return null; } for (Locale currentLocale : Context.getAdministrationService().getAllowedLocales()) { ConceptName preferredName = getPreferredName(currentLocale); if (preferredName != null) return preferredName; ConceptName fullySpecifiedName = getFullySpecifiedName(currentLocale); if (fullySpecifiedName != null) return fullySpecifiedName; //if the locale has an variants e.g en_GB, try names in the locale excluding the country code i.e en if (!StringUtils.isBlank(currentLocale.getCountry()) || !StringUtils.isBlank(currentLocale.getVariant())) { Locale broaderLocale = new Locale(currentLocale.getLanguage()); ConceptName prefNameInBroaderLoc = getPreferredName(broaderLocale); if (prefNameInBroaderLoc != null) return prefNameInBroaderLoc; ConceptName fullySpecNameInBroaderLoc = getFullySpecifiedName(broaderLocale); if (fullySpecNameInBroaderLoc != null) return fullySpecNameInBroaderLoc; } } for (ConceptName cn : getNames()) { if (cn.isFullySpecifiedName()) return cn; } if (getSynonyms().size() > 0) return getSynonyms().iterator().next(); //we dont expect to get here since every concept name must have atleast //one fully specified name, but just in case(probably inconsistent data) return null; }
From source file:org.olat.core.util.i18n.I18nManager.java
/** * Create a local that represents the overlay locale for the given locale * // ww w.j ava 2 s. c o m * @param locale The original locale * @return The overlay locale */ Locale createOverlay(Locale locale) { String lang = locale.getLanguage(); String country = (locale.getCountry() == null ? "" : locale.getCountry()); String variant = createOverlayKeyForLanguage(locale.getVariant() == null ? "" : locale.getVariant()); Locale overlay = new Locale(lang, country, variant); return overlay; }