|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectch.elca.el4j.services.i18n.MessageRewriter
public class MessageRewriter
A rewriting ressource bundle provides localized strings, which are defined using rewrite rules. The bundle is backed by a list of such rules. When asked to look up a key, the bundle uses the last matching rule.
Every non-black, non-comment line in a rule file defines a rewrite rule:
rule: pattern = MessageFormatPattern pattern space = space MessageFormatPatternWhen asked to look up a key, the bundle finds the last rule whose pattern matches the key, and uses the rule's MessageFormatPattern to format the result.
pattern: qualifier pattern . qualifier qualifier: literal { variableName } variableName: StringA key is said to match a rule if it matches the rule's pattern. It matches the pattern if, after it is split up in its different qualifiers, every qualifier of the key matches the qualifier of the pattern. If the pattern's qualifier is a literal, the key's qualifier matches only if it is identical. If the pattern's qualifier is a variable name, this defines a variable and assigns the key's qualifier to it.
For instance, the key "ch.elca.el4j" matches the patterns "ch.elca.el4j" and "ch.{company}.el4j". In the latter case, the variable "company" contains "elca" after the matching. The key does not match "tv.elca.el4j" as the first qualifier does not match.
FormatElement: (in addition to inherited members) { variableName } { MessageFormatPattern }where the MessageFormatPattern must not start with a digit. The former addition asks the message format to insert the value of the variable, the latter asks to insert the value associated with the key obtained by evaluating the MessageFormatPattern.
For instance, if we look up "earth.poetic" in the rule source
{planet}.name = {planet} earth.name = home {planet}.poetic = A piece of rock called {{planet}.name}. *we get "A piece of rock called home.". If we look up "Mars.poetic" instead, we get "A piece of rock called Mars."
Nested Class Summary | |
---|---|
static class |
MessageRewriter.NoDefinitionException
thrown to indicate that there is no matching rule for the requested key. |
static interface |
MessageRewriter.Rule
Represents a rewriting rule. |
Constructor Summary | |
---|---|
MessageRewriter(List<Reader> readers)
Constructor. |
Method Summary | |
---|---|
void |
add(List<? extends MessageRewriter.Rule> rules)
Adds the provided rules to the list of rewriting rules used. |
void |
add(MessageRewriter.Rule... rules)
Adds the provided rules to the list of rewriting rules used. |
static String[] |
qualifiers(String s)
returns the qualifiers in s, i.e. the list of maximal substrings not containing '.'. |
String |
resolve(String key)
Like resolve(String, Object[]) with empty argument list. |
String |
resolve(String key,
Object[] arguments)
returns the value associated with the given key, using the supplied arguments, or throws a NoDefinitionException, if the key could not be resolved. |
StringBuffer |
resolveAndAppend(String key,
Object[] arguments,
StringBuffer target)
resolves the value of the provided key with the provided user arguments and appends the result to target, or throws a MessageRewriter.NoDefinitionException if no rule applies to the
key. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MessageRewriter(List<Reader> readers)
readers
- readers providing the rule lists to be used.
The lists are locically
concatenated in the order they were provided.Method Detail |
---|
public static String[] qualifiers(String s)
s
- the fully qualified name
public void add(MessageRewriter.Rule... rules)
public void add(List<? extends MessageRewriter.Rule> rules)
public StringBuffer resolveAndAppend(String key, Object[] arguments, StringBuffer target)
MessageRewriter.NoDefinitionException
if no rule applies to the
key.
key
- .arguments
- the user arguments. must not be null, but may be empty.target
- .
target
public String resolve(String key, Object[] arguments)
public String resolve(String key)
resolve(String, Object[])
with empty argument list.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |