T
- the type of Object this I18nKeyGenerator
generates keys for.public abstract class AbstractI18nKeyGenerator<T> extends Object implements I18nKeyGenerator<T>
I18nKeyGenerator
which provides a number of helper methods to generate keys.
By casting objects to I18nParentable
(see getParentViaCast(Object)
), implementations are
able to generate context-dependent keys for any given object.Constructor and Description |
---|
AbstractI18nKeyGenerator() |
Modifier and Type | Method and Description |
---|---|
protected void |
addKey(List<String> keys,
boolean stripLabelSuffix,
String... parts)
Adds a key to the given list; if the last part is "label", adds another key without it.
|
protected void |
addKey(List<String> keys,
String... parts) |
protected String |
fieldOrGetterName(AnnotatedElement el)
Returns the name of the field or method passed to
I18nKeyGenerator#keysFor(String, T, java.lang.reflect.AnnotatedElement) . |
protected <C> List<I18nKeyGenerator> |
getAncestorKeyGenerators(C obj)
Returns the
I18nKeyGenerator s corresponding to the parent objects of the given object. |
protected <C> List<Object> |
getAncestors(C obj)
Returns the list of parent objects as set via the
I18nParentable interface
when the object was decorated by I18nizer . |
protected String |
getIdOrNameForUnknownRoot(Object obj) |
protected String |
getIdOrNameForUnknownRoot(Object obj,
boolean keyify)
Will try to call either
getId() or getName() on a root object of unknown type. |
protected String |
getIdWithoutModuleName(String id) |
protected <P> I18nKeyGenerator<P> |
getKeyGenerator(P obj)
Returns the
I18nKeyGenerator s corresponding to the given object. |
protected String |
getModuleName(String id) |
protected <P,C> P |
getParentViaCast(C obj)
Returns the parent object that was set via the
I18nParentable interface
when the object was decorated by I18nizer . |
protected <C> Object |
getRoot(C obj)
Returns the root object that of the
I18nParentable hierarchy. |
protected <C> I18nKeyGenerator |
getRootKeyGenerator(C obj)
Returns the
I18nKeyGenerator s corresponding to the root object of the given object. |
protected String |
keyify(String... parts)
Makes up a key from the given parts.
|
protected String |
keyify(String id)
Replaces the characters like ':' or '/' with dots to create i18n key.
|
protected abstract void |
keysFor(List<String> keys,
T object,
AnnotatedElement el) |
String[] |
keysFor(String undecoratedResult,
T object,
AnnotatedElement el)
Default implementation for
I18nKeyGenerator.keysFor(String, Object, java.lang.reflect.AnnotatedElement) , which sets
the undecoratedResult value if it is not null, and delegates to keysFor(java.util.List, Object, java.lang.reflect.AnnotatedElement) . |
String |
messageBundleNameFor(T object)
Deprecated.
since 5.4.5. Will be removed in a future version.
|
protected String |
replaceColons(String e) |
protected String |
resolveMessageBundleNameUpwards(Object object)
Deprecated.
since 5.4.5. Will be removed in a future version.
|
protected static final String FIELDS
public String[] keysFor(String undecoratedResult, T object, AnnotatedElement el)
I18nKeyGenerator.keysFor(String, Object, java.lang.reflect.AnnotatedElement)
, which sets
the undecoratedResult value if it is not null, and delegates to keysFor(java.util.List, Object, java.lang.reflect.AnnotatedElement)
.keysFor
in interface I18nKeyGenerator<T>
undecoratedResult
- the value returned by the undecorated underlying method call. It is generally expected
that this value will be part of the returned keys, such that an object with an explicitly configured key or label
will be translated using that value rather than derived keys.el
- the element being translated - typically a Method
instance.@Deprecated public String messageBundleNameFor(T object)
I18nKeyGenerator
messageBundleNameFor
in interface I18nKeyGenerator<T>
@Deprecated protected String resolveMessageBundleNameUpwards(Object object)
protected abstract void keysFor(List<String> keys, T object, AnnotatedElement el)
protected String fieldOrGetterName(AnnotatedElement el)
I18nKeyGenerator#keysFor(String, T, java.lang.reflect.AnnotatedElement)
.protected <P,C> P getParentViaCast(C obj)
I18nParentable
interface
when the object was decorated by I18nizer
.protected <C> List<Object> getAncestors(C obj)
I18nParentable
interface
when the object was decorated by I18nizer
.getParentViaCast(Object)
protected <C> Object getRoot(C obj)
I18nParentable
hierarchy.getParentViaCast(Object)
protected <C> List<I18nKeyGenerator> getAncestorKeyGenerators(C obj)
I18nKeyGenerator
s corresponding to the parent objects of the given object.getAncestors(Object)
protected <C> I18nKeyGenerator getRootKeyGenerator(C obj)
I18nKeyGenerator
s corresponding to the root object of the given object.getRoot(Object)
protected <P> I18nKeyGenerator<P> getKeyGenerator(P obj)
I18nKeyGenerator
s corresponding to the given object.protected void addKey(List<String> keys, boolean stripLabelSuffix, String... parts)
keyify(String...)
protected String keyify(String id)
protected String getIdOrNameForUnknownRoot(Object obj, boolean keyify)
getId()
or getName()
on a root object of unknown type. The result is normalized by replacing colon [:] and slash [/] characters with dots [.].
Should the object not have the above methods, null
is returned. Should the methods both return null
or an empty string, null
is returned.
Copyright © 2003–2020 Magnolia International Ltd.. All rights reserved.