当前位置: 首页>>代码示例>>Java>>正文


Java MessageResolution类代码示例

本文整理汇总了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;
}
 
开发者ID:passion1014,项目名称:metaworks_framework,代码行数:33,代码来源:BroadleafThymeleafMessageResolver.java

示例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();
}
 
开发者ID:wisdom-framework,项目名称:wisdom,代码行数:8,代码来源:WisdomMessageResolverTest.java

示例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();
}
 
开发者ID:wisdom-framework,项目名称:wisdom,代码行数:14,代码来源:WisdomMessageResolverTest.java

示例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");
}
 
开发者ID:wisdom-framework,项目名称:wisdom,代码行数:16,代码来源:WisdomMessageResolverTest.java

示例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;
        }
	}
 
开发者ID:resource4j,项目名称:resource4j,代码行数:31,代码来源:Resource4jMessageResolver.java

示例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);
}
 
开发者ID:codework,项目名称:struts2-thymeleaf-plugin,代码行数:6,代码来源:StrutsMessageResolver.java

示例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);

}
 
开发者ID:wisdom-framework,项目名称:wisdom,代码行数:30,代码来源:WisdomMessageResolver.java


注:本文中的org.thymeleaf.messageresolver.MessageResolution类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。