org.apache.wookie.w3c.util
Class LocalizationUtils

java.lang.Object
  extended by org.apache.wookie.w3c.util.LocalizationUtils

public class LocalizationUtils
extends java.lang.Object

Utilities for localization

Author:
Scott Wilson

Constructor Summary
LocalizationUtils()
           
 
Method Summary
protected static ILocalized[] filter(ILocalized[] elements, java.util.List<com.ibm.icu.util.ULocale> locales)
          Filters a set of elements using the locales and returns a copy of the array containing only elements that match the locales, or that are not localized if there are no matches
protected static java.util.List<com.ibm.icu.util.ULocale> getDefaultLocaleList()
          Gets the default locales list
protected static ILocalized getLocalizedElement(ILocalized[] elements, java.lang.String[] locales)
          Returns the first (best) match for an element given the set of locales, or null if there are no suitable elements.
static ILocalized getLocalizedElement(ILocalized[] elements, java.lang.String[] locales, java.lang.String defaultLocale)
          Returns the first (best) match for an element given the set of locales, or will fall back to the match for defaultLocale if there are no suitable matches, and then to null if there are no elements at all.
static java.util.List<com.ibm.icu.util.ULocale> getProcessedLocaleList(java.lang.String[] locales)
          Converts an array of language tags to a list of ULocale instances ordered according to priority, availability and fallback rules.
static boolean isValidLanguageTag(java.lang.String tag)
          Validates a given language tag.
static ILocalized[] processElementsByDefaultLocales(ILocalized[] elements)
          Sorts an array of localized elements using default locales (*).
protected static ILocalized[] processElementsByLocales(ILocalized[] elements, java.lang.String[] locales)
          Filters and sorts a list of localized elements using the given locale list; only localized elements are returned unless no appropriate localized elements are found, in which case nonlocalized elements are returned
static ILocalized[] processElementsByLocales(ILocalized[] elements, java.lang.String[] locales, java.lang.String defaultLocale)
          Filters and sorts a list of localized elements using the given locale list; only localized elements are returned unless no appropriate localized elements are found, in which case nonlocalized elements are returned.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LocalizationUtils

public LocalizationUtils()
Method Detail

getLocalizedElement

public static ILocalized getLocalizedElement(ILocalized[] elements,
                                             java.lang.String[] locales,
                                             java.lang.String defaultLocale)
Returns the first (best) match for an element given the set of locales, or will fall back to the match for defaultLocale if there are no suitable matches, and then to null if there are no elements at all.

Parameters:
elements -
locales -
defaultLocale - the default locale in case none of the supplied locales provide a match
Returns:
an ILocalizedElement, or null if there are no valid entries

getLocalizedElement

protected static ILocalized getLocalizedElement(ILocalized[] elements,
                                                java.lang.String[] locales)
Returns the first (best) match for an element given the set of locales, or null if there are no suitable elements.

Parameters:
elements -
locales -
Returns:
an ILocalizedElement, or null if there are no valid entries

processElementsByLocales

public static ILocalized[] processElementsByLocales(ILocalized[] elements,
                                                    java.lang.String[] locales,
                                                    java.lang.String defaultLocale)
Filters and sorts a list of localized elements using the given locale list; only localized elements are returned unless no appropriate localized elements are found, in which case nonlocalized elements are returned. If there are no nonlocalized elements, the defaultLocale attribute is used to try to find a suitable match

Parameters:
elements -
locales -
defaultLocale - the default locale in case none of the supplied locales provide a match
Returns:
the sorted and filtered set of elements

processElementsByLocales

protected static ILocalized[] processElementsByLocales(ILocalized[] elements,
                                                       java.lang.String[] locales)
Filters and sorts a list of localized elements using the given locale list; only localized elements are returned unless no appropriate localized elements are found, in which case nonlocalized elements are returned

Parameters:
elements -
locales -
Returns:
the sorted and filtered set of elements

processElementsByDefaultLocales

public static ILocalized[] processElementsByDefaultLocales(ILocalized[] elements)
Sorts an array of localized elements using default locales (*). This places any localized elements first, then any unlocalized elements

Returns:
the sorted list of elements

filter

protected static ILocalized[] filter(ILocalized[] elements,
                                     java.util.List<com.ibm.icu.util.ULocale> locales)
Filters a set of elements using the locales and returns a copy of the array containing only elements that match the locales, or that are not localized if there are no matches

Parameters:
elements -
locales -
Returns:
a copy of the array of elements only containing the filtered elements

getProcessedLocaleList

public static java.util.List<com.ibm.icu.util.ULocale> getProcessedLocaleList(java.lang.String[] locales)
Converts an array of language tags to a list of ULocale instances ordered according to priority, availability and fallback rules. For example "en-us-posix" will be returned as a List containing the ULocales for "en-us-posix", "en-us", and "en".

Parameters:
locales -
Returns:
the sorted list of ULocale instances

getDefaultLocaleList

protected static java.util.List<com.ibm.icu.util.ULocale> getDefaultLocaleList()
Gets the default locales list

Returns:
a list of ULocale instances for the default locale

isValidLanguageTag

public static boolean isValidLanguageTag(java.lang.String tag)
Validates a given language tag. Empty and null values are considered false.

Parameters:
tag -
Returns:
true if a valid language tag, otherwise false


2012 Apache Software Foundation.