Package biz.aQute.bnd.reporter.helpers
Class LocaleHelper
- java.lang.Object
-
- biz.aQute.bnd.reporter.helpers.LocaleHelper
-
public class LocaleHelper extends java.lang.Object
An helper to extract localization data from a Jar.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Locale
_locale
private java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>>
_localizations
-
Constructor Summary
Constructors Modifier Constructor Description private
LocaleHelper()
private
LocaleHelper(Jar jar, java.util.Locale locale, java.lang.String basePath)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.util.Locale
computeNextLocale(java.util.Locale nextLocale)
static LocaleHelper
createIfPresent(Jar jar, java.util.Locale locale, java.lang.String basePath)
Create aLocaleHelper
if localization data are found at the specified path, otherwise returnnull
.static LocaleHelper
empty()
private java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>>
extractLocalizations(Jar jar, java.lang.String path)
java.lang.String
get(java.lang.String variableOrValue)
If the argument is a variable, its corresponding value will be returned for the default locale of this helper instance.java.lang.String
get(java.lang.String variableOrValue, java.util.Locale locale)
If the argument is a variable, its corresponding value will be returned for the specified locale.private static boolean
hasLocalization(Jar jar, java.lang.String path)
-
-
-
Constructor Detail
-
LocaleHelper
private LocaleHelper(Jar jar, java.util.Locale locale, java.lang.String basePath)
-
LocaleHelper
private LocaleHelper()
-
-
Method Detail
-
createIfPresent
public static LocaleHelper createIfPresent(Jar jar, java.util.Locale locale, java.lang.String basePath)
Create aLocaleHelper
if localization data are found at the specified path, otherwise returnnull
.- Parameters:
jar
- the jar containing the localization file, must not benull
locale
- the default locale for this helper, must not benull
basePath
- a base path in the Jar to the localization property files without its extension and its locale suffix, must not benull
- Returns:
- a
LocaleHelper
which contains localization data ornull
if there is no localization data at the specified path.
-
empty
public static LocaleHelper empty()
- Returns:
- a
LocaleHelper
without localization data, nevernull
-
get
public java.lang.String get(java.lang.String variableOrValue)
If the argument is a variable, its corresponding value will be returned for the default locale of this helper instance. Otherwise, the argument is returned.Values will be search from the most specific to the less specific locale including unlocalized (empty locale) value.
- Parameters:
variableOrValue
- a variable (starting with '%') or a value, can benull
- Returns:
- the localized value, can be
null
-
get
public java.lang.String get(java.lang.String variableOrValue, java.util.Locale locale)
If the argument is a variable, its corresponding value will be returned for the specified locale. Otherwise, the argument is returned.Values will be search from the most specific to the less specific locale including unlocalized (empty locale) value.
- Parameters:
variableOrValue
- a variable (starting with '%') or a value, can benull
locale
- the locale, must not benull
- Returns:
- the localized value, can be
null
-
computeNextLocale
private java.util.Locale computeNextLocale(java.util.Locale nextLocale)
-
hasLocalization
private static boolean hasLocalization(Jar jar, java.lang.String path)
-
extractLocalizations
private java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> extractLocalizations(Jar jar, java.lang.String path)
-
-