List of usage examples for java.util Locale getCountry
public String getCountry()
From source file:org.opencms.workplace.CmsWorkplaceManager.java
/** * Initializes the workplace locale set.<p> * /*from w w w.j a v a 2 s. co m*/ * Currently, this is defined by the existence of a special folder * <code>/system/workplace/locales/{locale-name}/</code>. * This is likely to change in future implementations.<p> * * @param cms an OpenCms context object that must have been initialized with "Admin" permissions * * @return the workplace locale set */ private List<Locale> initWorkplaceLocales(CmsObject cms) { Set<Locale> locales = new HashSet<Locale>(); List<CmsResource> localeFolders; try { localeFolders = cms.getSubFolders(CmsWorkplace.VFS_PATH_LOCALES); } catch (CmsException e) { LOG.error(Messages.get().getBundle().key(Messages.LOG_WORKPLACE_INIT_NO_LOCALES_1, CmsWorkplace.VFS_PATH_LOCALES)); // can not throw exception here since then OpenCms would not even start in shell mode (runlevel 2) localeFolders = new ArrayList<CmsResource>(); } Iterator<CmsResource> i = localeFolders.iterator(); while (i.hasNext()) { CmsFolder folder = (CmsFolder) i.next(); Locale locale = CmsLocaleManager.getLocale(folder.getName()); // add locale locales.add(locale); // add less specialized locale locales.add(new Locale(locale.getLanguage(), locale.getCountry())); // add even less specialized locale locales.add(new Locale(locale.getLanguage())); } // sort the result ArrayList<Locale> result = new ArrayList<Locale>(); result.addAll(locales); Collections.sort(result, CmsLocaleComparator.getComparator()); return result; }
From source file:org.openmrs.api.db.hibernate.HibernateConceptDAO.java
private String newConceptNameQuery(final String name, final boolean searchKeywords, final Set<Locale> locales, final boolean searchExactLocale) { final String escapedName = LuceneQuery.escapeQuery(name); final List<String> tokenizedName = tokenizeConceptName(escapedName, locales); final StringBuilder query = new StringBuilder(); query.append("(concept.conceptMappings.conceptReferenceTerm.code:(").append(escapedName) .append(")^0.4 OR ("); final StringBuilder nameQuery = newNameQuery(tokenizedName, escapedName, searchKeywords); query.append(nameQuery);/* w w w . j a va2 s .com*/ query.append(" localePreferred:true)^0.4 OR ("); query.append(nameQuery); query.append(")^0.2)"); List<String> localeQueries = new ArrayList<String>(); for (Locale locale : locales) { if (searchExactLocale) { localeQueries.add(locale.toString()); } else { String localeQuery = locale.getLanguage() + "* "; if (!StringUtils.isBlank(locale.getCountry())) { localeQuery += " OR " + locale + "^2 "; } localeQueries.add(localeQuery); } } query.append(" locale:("); query.append(StringUtils.join(localeQueries, " OR ")); query.append(")"); query.append(" voided:false"); return query.toString(); }
From source file:org.openmrs18.Concept.java
/** * Returns concept name, the look up for the appropriate name is done in the following order; * <ul>/*from ww w . ja v a2 s.co m*/ * <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:io.selendroid.android.impl.DefaultAndroidEmulator.java
@Override public void start(Locale locale, int emulatorPort, Map<String, Object> options) throws AndroidDeviceException { if (isEmulatorStarted()) { throw new SelendroidException("Error - Android emulator is already started " + this); }/* w ww . j ava 2 s . co m*/ Long timeout = null; String emulatorOptions = null; String display = null; if (options != null) { if (options.containsKey(TIMEOUT_OPTION)) { timeout = (Long) options.get(TIMEOUT_OPTION); } if (options.containsKey(DISPLAY_OPTION)) { display = (String) options.get(DISPLAY_OPTION); } if (options.containsKey(EMULATOR_OPTIONS)) { emulatorOptions = (String) options.get(EMULATOR_OPTIONS); } } if (display != null) { log.info("Using display " + display + " for running the emulator"); } if (timeout == null) { timeout = 120000L; } log.info("Using timeout of '" + timeout / 1000 + "' seconds to start the emulator."); this.locale = locale; CommandLine cmd = new CommandLine(AndroidSdk.emulator()); cmd.addArgument("-no-snapshot-save", false); cmd.addArgument("-avd", false); cmd.addArgument(avdName, false); cmd.addArgument("-port", false); cmd.addArgument(String.valueOf(emulatorPort), false); if (locale != null) { cmd.addArgument("-prop", false); cmd.addArgument("persist.sys.language=" + locale.getLanguage(), false); cmd.addArgument("-prop", false); cmd.addArgument("persist.sys.country=" + locale.getCountry(), false); } if (emulatorOptions != null && emulatorOptions.isEmpty() == false) { cmd.addArgument(emulatorOptions, false); } long start = System.currentTimeMillis(); long timemoutEnd = start + timeout; try { ShellCommand.execAsync(display, cmd); } catch (ShellCommandException e) { throw new SelendroidException("unable to start the emulator: " + this); } setSerial(emulatorPort); Boolean adbKillServerAttempted = false; while (isDeviceReady() == false) { if (!adbKillServerAttempted && System.currentTimeMillis() - start > 10000) { CommandLine adbDevicesCmd = new CommandLine(AndroidSdk.adb()); adbDevicesCmd.addArgument("devices", false); String devices = ""; try { devices = ShellCommand.exec(adbDevicesCmd, 20000); } catch (ShellCommandException e) { // pass } if (!devices.contains(String.valueOf(emulatorPort))) { CommandLine resetAdb = new CommandLine(AndroidSdk.adb()); resetAdb.addArgument("kill-server", false); try { ShellCommand.exec(resetAdb, 20000); } catch (ShellCommandException e) { throw new SelendroidException("unable to kill the adb server"); } } adbKillServerAttempted = true; } if (timemoutEnd >= System.currentTimeMillis()) { try { Thread.sleep(2000); } catch (InterruptedException e) { } } else { throw new AndroidDeviceException("The emulator with avd '" + getAvdName() + "' was not started after " + (System.currentTimeMillis() - start) / 1000 + " seconds."); } } log.info("Emulator start took: " + (System.currentTimeMillis() - start) / 1000 + " seconds"); log.info("Please have in mind, starting an emulator takes usually about 45 seconds."); unlockEmulatorScreen(); waitForLauncherToComplete(); // we observed that emulators can sometimes not be 'fully loaded' // if we click on the All Apps button and wait for it to load it is more likely to be in a // usable state. allAppsGridView(); waitForLauncherToComplete(); setWasStartedBySelendroid(true); }
From source file:io.selendroid.standalone.android.impl.DefaultAndroidEmulator.java
@Override public void start(Locale locale, int emulatorPort, Map<String, Object> options) throws AndroidDeviceException { if (isEmulatorStarted()) { throw new SelendroidException("Error - Android emulator is already started " + this); }// w w w . ja va 2 s. c om Long timeout = null; String emulatorOptions = null; String display = null; if (options != null) { if (options.containsKey(TIMEOUT_OPTION)) { timeout = (Long) options.get(TIMEOUT_OPTION); } if (options.containsKey(DISPLAY_OPTION)) { display = (String) options.get(DISPLAY_OPTION); } if (options.containsKey(EMULATOR_OPTIONS)) { emulatorOptions = (String) options.get(EMULATOR_OPTIONS); } } if (display != null) { log.info("Using display " + display + " for running the emulator"); } if (timeout == null) { timeout = 120000L; } log.info("Using timeout of '" + timeout / 1000 + "' seconds to start the emulator."); this.locale = locale; CommandLine cmd = new CommandLine(AndroidSdk.emulator()); cmd.addArgument("-no-snapshot-save", false); cmd.addArgument("-avd", false); cmd.addArgument(avdName, false); cmd.addArgument("-port", false); cmd.addArgument(String.valueOf(emulatorPort), false); if (locale != null) { cmd.addArgument("-prop", false); cmd.addArgument("persist.sys.language=" + locale.getLanguage(), false); cmd.addArgument("-prop", false); cmd.addArgument("persist.sys.country=" + locale.getCountry(), false); } if (emulatorOptions != null && !emulatorOptions.isEmpty()) { cmd.addArguments(emulatorOptions.split(" "), false); } long start = System.currentTimeMillis(); long timeoutEnd = start + timeout; try { ShellCommand.execAsync(display, cmd); } catch (ShellCommandException e) { throw new SelendroidException("unable to start the emulator: " + this); } setSerial(emulatorPort); Boolean adbKillServerAttempted = false; // Without this one seconds, the call to "isDeviceReady" is // too quickly sent while the emulator is still starting and // not ready to receive any commands. Because of this the // while loops failed and sometimes hung in isDeviceReady function. try { Thread.sleep(1000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } while (!isDeviceReady()) { if (!adbKillServerAttempted && System.currentTimeMillis() - start > 10000) { CommandLine adbDevicesCmd = new CommandLine(AndroidSdk.adb()); adbDevicesCmd.addArgument("devices", false); String devices = ""; try { devices = ShellCommand.exec(adbDevicesCmd, 20000); } catch (ShellCommandException e) { // pass } if (!devices.contains(String.valueOf(emulatorPort))) { CommandLine resetAdb = new CommandLine(AndroidSdk.adb()); resetAdb.addArgument("kill-server", false); try { ShellCommand.exec(resetAdb, 20000); } catch (ShellCommandException e) { throw new SelendroidException("unable to kill the adb server"); } } adbKillServerAttempted = true; } if (timeoutEnd >= System.currentTimeMillis()) { try { Thread.sleep(2000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } else { throw new AndroidDeviceException("The emulator with avd '" + getAvdName() + "' was not started after " + (System.currentTimeMillis() - start) / 1000 + " seconds."); } } log.info("Emulator start took: " + (System.currentTimeMillis() - start) / 1000 + " seconds"); log.info("Please have in mind, starting an emulator takes usually about 45 seconds."); unlockScreen(); waitForLauncherToComplete(); // we observed that emulators can sometimes not be 'fully loaded' // if we click on the All Apps button and wait for it to load it is more likely to be in a // usable state. allAppsGridView(); waitForLauncherToComplete(); setWasStartedBySelendroid(true); }
From source file:org.olat.core.util.i18n.I18nManager.java
/** * Create a local that represents the overlay locale for the given locale * /* w ww . j a va2s.co 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; }
From source file:org.openmrs.Concept.java
/** * Returns concept name, the look up for the appropriate name is done in the following order; * <ul>/*from www .ja v a 2 s. co m*/ * <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 : LocaleUtility.getLocalesInOrder()) { 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.opencms.workplace.commons.CmsPreferences.java
/** * Builds the html for the language select box of the start settings.<p> * //from w w w.j a v a 2s . c o m * @param htmlAttributes optional html attributes for the &lgt;select> tag * @return the html for the language select box */ public String buildSelectLanguage(String htmlAttributes) { // get available locales from the workplace manager List locales = OpenCms.getWorkplaceManager().getLocales(); List options = new ArrayList(locales.size()); List values = new ArrayList(locales.size()); int checkedIndex = 0; int counter = 0; Iterator i = locales.iterator(); Locale setLocale = getSettings().getUserSettings().getLocale(); while (i.hasNext()) { Locale currentLocale = (Locale) i.next(); // add all locales to the select box String language = currentLocale.getDisplayLanguage(setLocale); if (CmsStringUtil.isNotEmpty(currentLocale.getCountry())) { language = language + " (" + currentLocale.getDisplayCountry(setLocale) + ")"; } if (CmsStringUtil.isNotEmpty(currentLocale.getVariant())) { language = language + " (" + currentLocale.getDisplayVariant(setLocale) + ")"; } options.add(language); values.add(currentLocale.toString()); if (getParamTabWpLanguage().equals(currentLocale.toString())) { // mark the currently active locale checkedIndex = counter; } counter++; } return buildSelect(htmlAttributes, options, values, checkedIndex); }
From source file:org.olat.core.util.i18n.I18nManager.java
/** * Calculate the locale key that identifies the given locale. Adds support for * the overlay mechanism./*from w w w. j a va 2 s. com*/ * * @param locale * @return */ public String getLocaleKey(Locale locale) { String key = localeToLocaleKey.get(locale); if (key == null) { String langKey = locale.getLanguage(); String country = locale.getCountry(); // Only add country when available - in case of an overlay country is // set to // an empty value if (StringHelper.containsNonWhitespace(country)) { langKey = langKey + "_" + country; } String variant = locale.getVariant(); // Only add the _ separator if the variant contains something in // addition to // the overlay, otherways use the __ only if (StringHelper.containsNonWhitespace(variant)) { if (variant.startsWith("__" + I18nModule.getOverlayName())) { langKey += variant; } else { langKey = langKey + "_" + variant; } } key = localeToLocaleKey.putIfAbsent(locale, langKey); if (key == null) { key = langKey; } } return key; }