|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectnet.sf.freecol.common.model.FreeColObject
net.sf.freecol.common.model.StringTemplate
public class StringTemplate
The StringTemplate represents a non-localized string
that can be localized by looking up its value in a message bundle
or similar Map. The StringTemplate may contain variables (keys)
delimited by the '%' character, such as "%amount%" that will be
replaced with a string or a StringTemplate. If the StringTemplate
contains replacement values but no keys, then it is considered a
"label" StringTemplate, and its value will be used to join the
replacement values.
| Nested Class Summary | |
|---|---|
static class |
StringTemplate.TemplateType
The type of this StringTemplate, either NAME, a proper name that must not be localized (e.g. |
| Field Summary | |
|---|---|
private java.lang.String |
defaultId
An alternative key to use if the Id is not contained in the message bundle. |
private java.util.List<java.lang.String> |
keys
The keys to replace within the string template. |
private java.util.List<StringTemplate> |
replacements
The values with which to replace the keys in the string template. |
private StringTemplate.TemplateType |
templateType
The TemplateType of this StringTemplate. |
| Fields inherited from class net.sf.freecol.common.model.FreeColObject |
|---|
ARRAY_SIZE, ID_ATTRIBUTE, ID_ATTRIBUTE_TAG, INFINITY, logger, NO_ID, PARTIAL_ATTRIBUTE, UNDEFINED, VALUE_TAG |
| Constructor Summary | |
|---|---|
protected |
StringTemplate()
|
protected |
StringTemplate(java.lang.String template,
StringTemplate.TemplateType templateType)
Creates a new Template instance. |
|
StringTemplate(java.lang.String id,
StringTemplate template)
|
| Method Summary | |
|---|---|
StringTemplate |
add(java.lang.String value)
Add a replacement value without a key to the StringTemplate. |
StringTemplate |
add(java.lang.String key,
java.lang.String value)
Add a new key and replacement to the StringTemplate. |
StringTemplate |
addAmount(java.lang.String key,
java.lang.Number amount)
Add a key and an integer value to replace it to this StringTemplate. |
StringTemplate |
addName(java.lang.String value)
Add a replacement value without a key to the StringTemplate. |
StringTemplate |
addName(java.lang.String key,
FreeColObject object)
Add a new key and replacement to the StringTemplate. |
StringTemplate |
addName(java.lang.String key,
java.lang.String value)
Add a new key and replacement to the StringTemplate. |
StringTemplate |
addStringTemplate(java.lang.String key,
StringTemplate template)
Add a key and a StringTemplate to replace it to this StringTemplate. |
StringTemplate |
addStringTemplate(StringTemplate template)
Add a StringTemplate to this LABEL StringTemplate. |
boolean |
equals(java.lang.Object o)
|
java.lang.String |
getDefaultId()
Get the DefaultId value. |
java.util.List<java.lang.String> |
getKeys()
Get the Keys value. |
StringTemplate |
getReplacement(java.lang.String key)
Return the replacement value for a given key, or null if there is none. |
java.util.List<StringTemplate> |
getReplacements()
Get the Replacements value. |
StringTemplate.TemplateType |
getTemplateType()
Get the TemplateType value. |
static java.lang.String |
getXMLElementTagName()
Returns the tag name of the root element representing this object. |
int |
hashCode()
|
static StringTemplate |
key(java.lang.String value)
|
static StringTemplate |
label(java.lang.String value)
|
static StringTemplate |
name(java.lang.String value)
|
protected void |
readAttributes(javax.xml.stream.XMLStreamReader in)
Reads the attributes of this object from an XML stream. |
protected void |
readChildren(javax.xml.stream.XMLStreamReader in)
Reads the children of this object from an XML stream. |
private void |
readOldFormat(java.lang.String[] data)
|
StringTemplate |
setDefaultId(java.lang.String newDefaultId)
Set the DefaultId value. |
static StringTemplate |
template(java.lang.String value)
|
java.lang.String |
toString()
|
protected void |
toXMLImpl(javax.xml.stream.XMLStreamWriter out)
This method writes an XML-representation of this object to the given stream. |
protected void |
writeAttributes(javax.xml.stream.XMLStreamWriter out)
Write the attributes of this object to a stream. |
protected void |
writeChildren(javax.xml.stream.XMLStreamWriter out)
Write the children of this object to a stream. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
private StringTemplate.TemplateType templateType
private java.lang.String defaultId
private java.util.List<java.lang.String> keys
private java.util.List<StringTemplate> replacements
| Constructor Detail |
|---|
protected StringTemplate()
public StringTemplate(java.lang.String id,
StringTemplate template)
protected StringTemplate(java.lang.String template,
StringTemplate.TemplateType templateType)
Template instance.
template - a String valuetemplateType - a TemplateType value| Method Detail |
|---|
public final java.lang.String getDefaultId()
DefaultId value.
String valuepublic StringTemplate setDefaultId(java.lang.String newDefaultId)
DefaultId value.
newDefaultId - The new DefaultId value.
StringTemplate valuepublic static StringTemplate name(java.lang.String value)
public static StringTemplate key(java.lang.String value)
public static StringTemplate template(java.lang.String value)
public static StringTemplate label(java.lang.String value)
public final StringTemplate.TemplateType getTemplateType()
TemplateType value.
TemplateType valuepublic final java.util.List<java.lang.String> getKeys()
Keys value.
List valuepublic final java.util.List<StringTemplate> getReplacements()
Replacements value.
List valuepublic final StringTemplate getReplacement(java.lang.String key)
key - a String value
String value
public StringTemplate add(java.lang.String key,
java.lang.String value)
key - a String valuevalue - a String value
StringTemplate valuepublic StringTemplate add(java.lang.String value)
value - a String value
StringTemplate value
public StringTemplate addName(java.lang.String key,
java.lang.String value)
key - a String valuevalue - a String value
StringTemplate value
public StringTemplate addName(java.lang.String key,
FreeColObject object)
key - a String valueobject - a FreeColObject value
StringTemplate valuepublic StringTemplate addName(java.lang.String value)
value - a String value
StringTemplate value
public StringTemplate addAmount(java.lang.String key,
java.lang.Number amount)
key - a String valueamount - a Number value
StringTemplate value
public StringTemplate addStringTemplate(java.lang.String key,
StringTemplate template)
key - a String valuetemplate - a StringTemplate value
StringTemplate valuepublic StringTemplate addStringTemplate(StringTemplate template)
template - a StringTemplate value
StringTemplate valuepublic java.lang.String toString()
toString in class java.lang.Objectpublic boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Object
protected void toXMLImpl(javax.xml.stream.XMLStreamWriter out)
throws javax.xml.stream.XMLStreamException
toXMLImpl in class FreeColObjectout - The target stream.
javax.xml.stream.XMLStreamException - if there are any problems writing
to the stream.
protected void writeAttributes(javax.xml.stream.XMLStreamWriter out)
throws javax.xml.stream.XMLStreamException
writeAttributes in class FreeColObjectout - The target stream.
javax.xml.stream.XMLStreamException - if there are any problems writing to
the stream.
protected void writeChildren(javax.xml.stream.XMLStreamWriter out)
throws javax.xml.stream.XMLStreamException
writeChildren in class FreeColObjectout - The target stream.
javax.xml.stream.XMLStreamException - if there are any problems writing to
the stream.
protected void readAttributes(javax.xml.stream.XMLStreamReader in)
throws javax.xml.stream.XMLStreamException
readAttributes in class FreeColObjectin - The XML input stream.
javax.xml.stream.XMLStreamException - if a problem was encountered
during parsing.
protected void readChildren(javax.xml.stream.XMLStreamReader in)
throws javax.xml.stream.XMLStreamException
readChildren in class FreeColObjectin - The XML input stream.
javax.xml.stream.XMLStreamException - if a problem was encountered
during parsing.private void readOldFormat(java.lang.String[] data)
public static java.lang.String getXMLElementTagName()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||