org.openmrs.util
Class LocaleUtility

java.lang.Object
  extended by org.openmrs.util.LocaleUtility

public class LocaleUtility
extends java.lang.Object

A utility class for working with Locales.


Field Summary
static java.util.Locale DEFAULT_LOCALE
          Deprecated. use getDefaultLocale() now
 
Constructor Summary
LocaleUtility()
           
 
Method Summary
static boolean areCompatible(java.util.Locale lhs, java.util.Locale rhs)
          Compatible is a looser matching than that provided by Locale.equals().
static java.util.Locale fromSpecification(java.lang.String localeSpecification)
          Creates a locale based on a string specification.
static java.util.Locale getDefaultLocale()
          Gets the default locale specified as a global property.
static java.util.Set<java.util.Locale> getLocalesInOrder()
          Utility method that returns a collection of all openmrs system locales, the set includes the current logged in user's preferred locale if any is set, the default locale, allowed locales in the order they are specified in the 'allowed.locale.list' global property and 'en' at the very end of the set if it isn't yet among them.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_LOCALE

@Deprecated
public static final java.util.Locale DEFAULT_LOCALE
Deprecated. use getDefaultLocale() now
Default internal locale.

Constructor Detail

LocaleUtility

public LocaleUtility()
Method Detail

getDefaultLocale

public static java.util.Locale getDefaultLocale()
Gets the default locale specified as a global property.

Returns:
default locale object.
Since:
1.5
Expected behavior:
not return null if global property does not exist, not fail with empty global property value, not fail with bogus global property value, return locale object for global property

areCompatible

public static boolean areCompatible(java.util.Locale lhs,
                                    java.util.Locale rhs)
Compatible is a looser matching than that provided by Locale.equals(). Two locales are considered equal if they are equal, or if either does not have a country specified and the languages match.

Parameters:
lhs - left hand side Locale
rhs - right hand side Locale
Returns:
true if the two locales are compatible, false otherwise
Expected behavior:
confirm different language missing country as compatible, confirm same language missing country as compatible, not confirm different country as compatible, confirm matching country as compatible, not confirm different language as compatible, confirm matching language as compatible

fromSpecification

public static java.util.Locale fromSpecification(java.lang.String localeSpecification)
Creates a locale based on a string specification. The specification must be conform with the following format: ll_CC_vv
For example: en_US_Traditional_WIN ...represents English language in the United States with the traditional collation for windows.

Parameters:
localeSpecification - encoded locale specification
Returns:
the representative Locale, or null if the specification is invalid
Expected behavior:
get locale from two character language code, get locale from language code and country code, get locale from language code country code and variant

getLocalesInOrder

public static java.util.Set<java.util.Locale> getLocalesInOrder()
Utility method that returns a collection of all openmrs system locales, the set includes the current logged in user's preferred locale if any is set, the default locale, allowed locales in the order they are specified in the 'allowed.locale.list' global property and 'en' at the very end of the set if it isn't yet among them.

Since:
1.7
Expected behavior:
return a set of locales with a predictable order, return a set of locales with no duplicates, have default locale as the first element if user has no preferred locale, have default locale as the second element if user has a preferred locale, always have english included in the returned collection

OpenMRS-1.7.x

Generated Apr 27 2012 10:06 PM. NOTE - these libraries are in active development and subject to change