本文整理汇总了Java中org.thymeleaf.messageresolver.MessageResolution类的典型用法代码示例。如果您正苦于以下问题:Java MessageResolution类的具体用法?Java MessageResolution怎么用?Java MessageResolution使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MessageResolution类属于org.thymeleaf.messageresolver包,在下文中一共展示了MessageResolution类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolveMessage
import org.thymeleaf.messageresolver.MessageResolution; //导入依赖的package包/类
/**
* Resolve a translated value of an object's property.
*
* @param args
* @param key
* @param messageParams
* @return the resolved message
*/
public MessageResolution resolveMessage(final Arguments args, final String key, final Object[] messageParams) {
Validate.notNull(args, "args cannot be null");
Validate.notNull(args.getContext().getLocale(), "Locale in context cannot be null");
Validate.notNull(key, "Message key cannot be null");
if (I18N_VALUE_KEY.equals(key)) {
Object entity = messageParams[0];
String property = (String) messageParams[1];
Locale locale = args.getContext().getLocale();
if (LOG.isTraceEnabled()) {
LOG.trace(String.format("Attempting to resolve translated value for object %s, property %s, locale %s",
entity, property, locale));
}
String resolvedMessage = translationService.getTranslatedValue(entity, property, locale);
if (StringUtils.isNotBlank(resolvedMessage)) {
return new MessageResolution(resolvedMessage);
}
}
return null;
}
示例2: testMessageWhenNoI18N
import org.thymeleaf.messageresolver.MessageResolution; //导入依赖的package包/类
@Test
public void testMessageWhenNoI18N() {
WisdomMessageResolver resolver = new WisdomMessageResolver();
resolver.i18n = mock(InternationalizationService.class);
MessageResolution resolution = resolver.resolveMessage(null, "welcome", null);
assertThat(resolution).isNull();
}
示例3: testMessageWithAI18NButNoMessage
import org.thymeleaf.messageresolver.MessageResolution; //导入依赖的package包/类
@Test
public void testMessageWithAI18NButNoMessage() {
WisdomMessageResolver resolver = new WisdomMessageResolver();
resolver.i18n = mock(InternationalizationService.class);
when(resolver.i18n.get(locales, "welcome", NULL_ARRAY)).thenReturn("welcome");
MessageResolution resolution = resolver.resolveMessage(null, "welcome", null);
assertThat(resolution).isNotNull();
assertThat(resolution.getResolvedMessage()).isEqualTo("welcome");
resolution = resolver.resolveMessage(null, "missing", null);
assertThat(resolution).isNull();
}
示例4: testMessageWithParameters
import org.thymeleaf.messageresolver.MessageResolution; //导入依赖的package包/类
@Test
public void testMessageWithParameters() {
WisdomMessageResolver resolver = new WisdomMessageResolver();
resolver.i18n = mock(InternationalizationService.class);
when(resolver.i18n.get(locales, "welcome", "wisdom")).thenReturn("welcome wisdom");
when(resolver.i18n.get(locales, "welcome", NULL_ARRAY)).thenReturn("welcome");
MessageResolution resolution = resolver.resolveMessage(null, "welcome", null);
assertThat(resolution).isNotNull();
assertThat(resolution.getResolvedMessage()).isEqualTo("welcome");
resolution = resolver.resolveMessage(null, "welcome", new Object[] {"wisdom"});
assertThat(resolution).isNotNull();
assertThat(resolution.getResolvedMessage()).isEqualTo("welcome wisdom");
}
示例5: resolveMessage
import org.thymeleaf.messageresolver.MessageResolution; //导入依赖的package包/类
@Override
public MessageResolution resolveMessage(Arguments arguments, String key,
Object[] messageParameters) {
Validate.notNull(arguments, "Arguments cannot be null");
Locale locale = arguments.getContext().getLocale();
Validate.notNull(locale, "Locale in context cannot be null");
Validate.notNull(key, "Message key cannot be null");
String templateName = arguments.getTemplateName();
LOG.trace("[THYMELEAF][{}] Resolving message with key \"{}\" for template \"{}\" and locale \"{}\". Messages will be retrieved from Spring's MessageSource infrastructure.", TemplateEngine.threadIndex(), key, templateName, locale);
try {
Map<String, Object> params = new HashMap<>();
for (int i = 0; i < messageParameters.length; i++) {
if (messageParameters[i] instanceof Map) {
params.putAll((Map) messageParameters[i]);
} else {
params.put(String.valueOf(i), messageParameters[i]);
}
}
ResourceResolutionContext context = context(resolve(locale), params);
String resolvedMessage = resources.get(plain(key), context)
.notNull()
.asIs();
// TODO: why was it here?
// resolvedMessage = resolvedMessage.replace("'", "\\'");
return new MessageResolution(resolvedMessage);
} catch (MissingValueException e) {
// According to contract for message resolver
return null;
}
}
示例6: resolveMessage
import org.thymeleaf.messageresolver.MessageResolution; //导入依赖的package包/类
@Override
public MessageResolution resolveMessage(Arguments arguments, String key, Object[] messageParameters) {
String message = LocalizedTextUtil.findDefaultText(key, ActionContext.getContext().getLocale(), messageParameters);
return new MessageResolution(message);
}
示例7: resolveMessage
import org.thymeleaf.messageresolver.MessageResolution; //导入依赖的package包/类
/**
* <p>
* Resolve the message, returning a {@link MessageResolution} object.
* </p>
* <p>
* If the message cannot be resolved, this method should return null.
* </p>
*
* @param arguments the {@link Arguments} object being used for template processing
* @param key the message key
* @param messageParameters the (optional) message parameters
* @return a {@link MessageResolution} object containing the resolved message,
* {@literal null} is returned when the resolver cannot retrieve a message for the given key. This policy is
* compliant with the (Thymeleaf) standard message resolver.
*/
@Override
public MessageResolution resolveMessage(Arguments arguments, String key, Object[] messageParameters) {
Locale[] locales = getLocales();
String message = i18n.get(locales, key, messageParameters);
// Same policy as the Thymeleaf standard message resolver.
if (message == null) {
return null;
}
return new MessageResolution(message);
}