@Component(value="cuba_MessageTools")
public class MessageTools
extends java.lang.Object
Messages.getTools()
method.Modifier and Type | Field and Description |
---|---|
protected ExtendedEntities |
extendedEntities |
protected GlobalConfig |
globalConfig |
static java.lang.String |
MAIN_MARK |
static java.lang.String |
MARK
Prefix defining that the string is actually a key in a localized messages pack.
|
protected Messages |
messages |
protected Metadata |
metadata |
static java.lang.String |
NAME |
protected java.lang.Boolean |
useLocaleLanguageOnly |
Constructor and Description |
---|
MessageTools(Configuration configuration) |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getDefaultDateFormat(javax.persistence.TemporalType temporalType) |
java.util.Locale |
getDefaultLocale() |
java.lang.String |
getDefaultRequiredMessage(com.haulmont.chile.core.model.MetaClass metaClass,
java.lang.String propertyName)
Get default required message for specified property of MetaClass.
|
java.lang.String |
getDefaultRequiredMessage(com.haulmont.chile.core.model.MetaProperty metaProperty)
Deprecated.
|
java.lang.String |
getDetailedEntityCaption(com.haulmont.chile.core.model.MetaClass metaClass) |
java.lang.String |
getDetailedEntityCaption(com.haulmont.chile.core.model.MetaClass metaClass,
java.util.Locale locale) |
java.lang.String |
getEntityCaption(com.haulmont.chile.core.model.MetaClass metaClass) |
java.lang.String |
getEntityCaption(com.haulmont.chile.core.model.MetaClass metaClass,
java.util.Locale locale) |
java.lang.String |
getLocValue(java.lang.String attribute,
com.haulmont.chile.core.model.Instance instance)
Get localized value of an attribute based on
LocalizedValue annotation. |
java.lang.String |
getMessageRef(com.haulmont.chile.core.model.MetaClass metaClass,
java.lang.String propertyName)
Get message reference of an entity property.
|
java.lang.String |
getMessageRef(com.haulmont.chile.core.model.MetaProperty property)
Get message reference of an entity property.
|
protected java.lang.String |
getNotNullMessage(com.haulmont.chile.core.model.MetaProperty metaProperty)
Get default required message for specified property of MetaClass if it has
NotNull annotation. |
java.lang.String |
getPropertyCaption(com.haulmont.chile.core.model.MetaClass metaClass,
java.lang.String propertyName)
Get localized name of an entity property.
|
java.lang.String |
getPropertyCaption(com.haulmont.chile.core.model.MetaClass metaClass,
java.lang.String propertyName,
java.util.Locale locale)
Get localized name of an entity property.
|
java.lang.String |
getPropertyCaption(com.haulmont.chile.core.model.MetaProperty property)
Get localized name of an entity property.
|
java.lang.String |
getPropertyCaption(com.haulmont.chile.core.model.MetaProperty property,
java.util.Locale locale)
Get localized name of an entity property.
|
boolean |
hasPropertyCaption(com.haulmont.chile.core.model.MetaProperty property)
Checks whether a localized name of the property exists.
|
java.lang.String |
inferMessagePack(java.lang.String attribute,
com.haulmont.chile.core.model.Instance instance)
Returns message pack inferred from
LocalizedValue annotation. |
java.lang.String |
loadString(java.lang.String ref)
Get localized message by reference provided in the full format.
|
java.lang.String |
loadString(java.lang.String ref,
java.util.Locale locale)
Get localized message by reference provided in the full format.
|
java.lang.String |
loadString(java.lang.String messagesPack,
java.lang.String ref)
Get localized message by reference provided in full or brief format.
|
java.lang.String |
loadString(java.lang.String messagesPack,
java.lang.String ref,
java.util.Locale locale)
Get localized message by reference provided in full or brief format.
|
java.lang.String |
localeToString(java.util.Locale locale)
Locale representation depending on
cuba.useLocaleLanguageOnly application property. |
java.util.Locale |
trimLocale(java.util.Locale locale)
Trims locale to language-only if
useLocaleLanguageOnly() is true. |
boolean |
useLocaleLanguageOnly() |
public static final java.lang.String MARK
public static final java.lang.String MAIN_MARK
public static final java.lang.String NAME
protected volatile java.lang.Boolean useLocaleLanguageOnly
@Inject protected Messages messages
@Inject protected Metadata metadata
@Inject protected ExtendedEntities extendedEntities
protected GlobalConfig globalConfig
@Inject public MessageTools(Configuration configuration)
public java.lang.String loadString(java.lang.String ref)
ref
- reference to message in the following format: msg://message_pack/message_id
msg://
public java.lang.String loadString(java.lang.String ref, java.util.Locale locale)
ref
- reference to message in the following format: msg://message_pack/message_id
msg://
@Nullable public java.lang.String loadString(@Nullable java.lang.String messagesPack, @Nullable java.lang.String ref)
messagesPack
- messages pack to use if the second parameter is in brief formatref
- reference to message in the following format:
msg://message_pack/message_id
msg://message_id
, in this case the first parameter is taken into account
mainMsg://message_id
msg://
or mainMsg://
@Nullable public java.lang.String loadString(@Nullable java.lang.String messagesPack, @Nullable java.lang.String ref, @Nullable java.util.Locale locale)
messagesPack
- messages pack to use if the second parameter is in brief formatref
- reference to message in the following format:locale
- locale
msg://message_pack/message_id
msg://message_id
, in this case the first parameter is taken into account
mainMsg://message_id
msg://
or mainMsg://
public java.lang.String getEntityCaption(com.haulmont.chile.core.model.MetaClass metaClass)
public java.lang.String getEntityCaption(com.haulmont.chile.core.model.MetaClass metaClass, @Nullable java.util.Locale locale)
public java.lang.String getDetailedEntityCaption(com.haulmont.chile.core.model.MetaClass metaClass)
public java.lang.String getDetailedEntityCaption(com.haulmont.chile.core.model.MetaClass metaClass, @Nullable java.util.Locale locale)
public java.lang.String getPropertyCaption(com.haulmont.chile.core.model.MetaClass metaClass, java.lang.String propertyName)
metaClass
- MetaClass containing the propertypropertyName
- property's namepublic java.lang.String getPropertyCaption(com.haulmont.chile.core.model.MetaClass metaClass, java.lang.String propertyName, @Nullable java.util.Locale locale)
metaClass
- MetaClass containing the propertypropertyName
- property's namelocale
- locale, if value is null locale of current user is usedpublic java.lang.String getPropertyCaption(com.haulmont.chile.core.model.MetaProperty property)
property
- MetaPropertypublic java.lang.String getPropertyCaption(com.haulmont.chile.core.model.MetaProperty property, @Nullable java.util.Locale locale)
property
- MetaPropertylocale
- locale, if value is null locale of current user is usedpublic boolean hasPropertyCaption(com.haulmont.chile.core.model.MetaProperty property)
property
- MetaPropertygetPropertyCaption(com.haulmont.chile.core.model.MetaProperty)
returns a
string which has no dots inside or the first part before a dot is not equal to the declaring class@Deprecated public java.lang.String getDefaultRequiredMessage(com.haulmont.chile.core.model.MetaProperty metaProperty)
getDefaultRequiredMessage(MetaClass, String)
public java.lang.String getDefaultRequiredMessage(com.haulmont.chile.core.model.MetaClass metaClass, java.lang.String propertyName)
metaClass
- MetaClass containing the propertypropertyName
- property's nameprotected java.lang.String getNotNullMessage(com.haulmont.chile.core.model.MetaProperty metaProperty)
NotNull
annotation.metaProperty
- MetaPropertypublic java.lang.String getMessageRef(com.haulmont.chile.core.model.MetaClass metaClass, java.lang.String propertyName)
metaClass
- MetaClass containing the propertypropertyName
- property's namemsg://message_pack/message_id
public java.lang.String getMessageRef(com.haulmont.chile.core.model.MetaProperty property)
property
- MetaPropertymsg://message_pack/message_id
@Nullable public java.lang.String getLocValue(java.lang.String attribute, com.haulmont.chile.core.model.Instance instance)
LocalizedValue
annotation.attribute
- attribute nameinstance
- entity instance@Nullable public java.lang.String inferMessagePack(java.lang.String attribute, com.haulmont.chile.core.model.Instance instance)
LocalizedValue
annotation.attribute
- attribute nameinstance
- entity instancepublic boolean useLocaleLanguageOnly()
cuba.availableLocales
app property are language only.public java.lang.String localeToString(java.util.Locale locale)
cuba.useLocaleLanguageOnly
application property.locale
- locale instancecuba.useLocaleLanguageOnly=true
, or full locale representation otherwisepublic java.util.Locale trimLocale(java.util.Locale locale)
useLocaleLanguageOnly()
is true.locale
- a localepublic java.util.Locale getDefaultLocale()
cuba.availableLocales
app property, taking into
account useLocaleLanguageOnly()
return value.public java.lang.String getDefaultDateFormat(javax.persistence.TemporalType temporalType)
temporalType
- a temporal type