public class LocalizedString extends Object implements Serializable, PublicCloneable<LocalizedString>
A String which is localized. There are two mechanisms to find and provide translations: They can
explicitely be set with set(java.lang.String, java.util.Locale) (e.g. during parsing an XML), or a resource-bundle can be
associated with setBundle(java.lang.String), which will be used to find translations based on the key of
this object.
The 'set' mechanism can also be driven by fillFromXml(java.lang.String, org.w3c.dom.Element), which provides a sensible way to fill the LocalizedString with
setting from a sub element of XMLs.
The idea is that objects of this type can be used in stead of normal String objects, for error messages, descriptions and other texts which need localization (e.g. because they are exposed to end-users).
| Constructor and Description |
|---|
LocalizedString(String k) |
| Modifier and Type | Method and Description |
|---|---|
Map<Locale,String> |
asMap()
Returns a Map representation of the localisation setting represented by this
LocalizedString.
|
LocalizedString |
clone() |
static List<Locale> |
degrade(Locale locale) |
static Locale |
degrade(Locale locale,
Locale originalLocale)
Degrades a Locale object to a more general Locale.
|
boolean |
equals(Object o) |
void |
fillFromXml(String tagName,
Element element)
Given a certain tagname, and a DOM parent element, it configures this LocalizedString, using
subtags with this tagname with 'xml:lang' attributes.
|
String |
get(Locale locale)
Gets the value for a certain locale.
|
protected String |
getBundle() |
String |
getDebugString() |
static Locale |
getDefault()
Returns the default locale if set, or otherwise the system default (
Locale.getDefault()). |
String |
getKey()
Gets the key to use as a default and/or for obtaining a value from the bundle
|
static Locale |
getLocale(Element element)
This utility takes care of reading the xml:lang attribute from an element
|
static Locale |
getLocale(String xmlLang) |
ReadonlyLocalizedString |
getReadonlyLocalizedString() |
protected Map<Locale,String> |
getValues() |
static String |
getXmlLang(Locale locale)
This utility determines the value of an xml:lang attribute.
|
int |
hashCode() |
void |
set(String value,
Locale locale)
Sets the value for a certain locale.
|
void |
setBundle(String b)
A resource-bundle with given name can be associated to this LocalizedString.
|
static Locale |
setDefault(Locale locale)
Sets a default locale for this JVM or web-app.
|
void |
setKey(String key)
Sets the key to use as a default and/or for obtaining a value from the bundle
|
static void |
setXmlLang(Element element,
Locale locale)
This utility takes care of setting the xml:lang attribute on an element.
|
String |
toString()
For LocalizedString this returns the String for the default Locale (see
getDefault()). |
static Collection<String> |
toStrings(Collection<LocalizedString> col,
Locale locale)
Converts a collection of localized strings to a collection of normal strings.
|
void |
toXml(String tagName,
String ns,
Element element,
String path)
Writes this LocalizedString object back to an XML, i.e.
|
public LocalizedString(String k)
k - The key of this String, if k == null then the first set will define it.public static Locale setDefault(Locale locale)
null since it is
odd to call this more than once.public static Locale getDefault()
Locale.getDefault()).public static Collection<String> toStrings(Collection<LocalizedString> col, Locale locale)
col - Collection of LocalizedString objectslocale - Locale to be used for the call to get(Locale) which obviously is neededpublic String getKey()
public void setKey(String key)
public String get(Locale locale)
public void set(String value, Locale locale)
public Map<Locale,String> asMap()
protected String getBundle()
public void setBundle(String b)
public String toString()
getDefault()).public String getDebugString()
public static Locale getLocale(Element element)
element - a DOM elementLocale object, or null if the element did not have,
or had an empty, xml:lang attributepublic static Locale degrade(Locale locale, Locale originalLocale)
locale - The locale to be degradedoriginalLocale - The original locale (used to find back the original variant after
dropping the country)null if the locale could not be degraded any further.public static String getXmlLang(Locale locale)
Locale
it produces a String.locale - A java localepublic static void setXmlLang(Element element, Locale locale)
element - Element on which the xml:lang attribute is going to be setlocale - Java's Locale objectpublic void fillFromXml(String tagName, Element element)
set(String, Locale).public void toXml(String tagName, String ns, Element element, String path)
tagName - Tag-name of the to be used sub-elementsns - Namespace of the to be created sub-elements, or nullelement - The parent element which must contain the localized elements.path - A comma separated list of names of tags which must skipped, before appending
childs. See DocumentReader.appendChild(Element, Element, String).public LocalizedString clone()
clone in interface PublicCloneable<LocalizedString>clone in class Objectpublic ReadonlyLocalizedString getReadonlyLocalizedString()
MMBase 1.9-SNAPSHOT - ${javadoctimestamp}