Spring Framework StaticMessageSource - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework StaticMessageSource class.

This code example shows how to use the following methods:addMessage
		MockExternalContext externalContext = (MockExternalContext) requestContext.getExternalContext();
		externalContext.setLocale(Locale.ENGLISH);
 
		StaticApplicationContext applicationContext = new StaticApplicationContext();
		StaticMessageSource messageSource = applicationContext.getStaticMessageSource();
		messageSource.addMessage("myCode", externalContext.getLocale(), "myCode message");
		messageSource.addMessage("myCode.myCode", externalContext.getLocale(), "myCode myCode message");
		applicationContext.refresh();
 
		Flow flow = (Flow) requestContext.getActiveFlow();
		flow.setApplicationContext(applicationContext);
 
		String expressionString = "#{resourceBundle.myCode}";
		Expression exp = parser.parseExpression(expressionString, new FluentParserContext().template());
		assertEquals("myCode message", exp.getValue(requestContext));
 
		expressionString = "#{resourceBundle['myCode']}";
		exp = parser.parseExpression(expressionString, new FluentParserContext().template());
		assertEquals("myCode message", exp.getValue(requestContext));
 

7
CodeRank
This code example shows how to use the following methods:addMessage
 
	private MessageCodesResolver resolver;
 
	@Override 
	protected void setUp() throws Exception {
		StaticMessageSource messageSource = new StaticMessageSource();
		messageSource.addMessage(errorCode, Locale.getDefault(), "doesntmatter");
		context = new DefaultMessageContext(messageSource);
 
		resolver = EasyMock.createMock(MessageCodesResolver.class);
	} 
 
	public void testRejectUsesObjectName() throws Exception {
		EasyMock.expect(resolver.resolveMessageCodes(errorCode, objectName)).andReturn(new String[] {});
		EasyMock.replay(resolver);
 
		Object object = new Object();
		MessageContextErrors errors = new MessageContextErrors(context, objectName, object, null, resolver, null);
		errors.reject(errorCode, "doesntmatter");
 
6
CodeRank
This code example shows how to use the following methods:addMessage
	private StaticMessageSource messageSource = new StaticMessageSource();
	private Locale locale = Locale.getDefault();
	private MessageBuilder builder = new MessageBuilder();
 
	public void setUp() { 
		messageSource.addMessage("foo", locale, "bar");
		messageSource.addMessage("bar", locale, "{0}");
		messageSource.addMessage("baz", locale, "boop");
	} 
 
	public void testBuildDefaultText() { 
		MessageResolver resolver = builder.defaultText("foo").build();
		Message message = resolver.resolveMessage(messageSource, locale);
		assertEquals("foo", message.getText());
		assertEquals(Severity.INFO, message.getSeverity());
		assertNull(message.getSource());
	} 
 
	public void testBuildFatal() { 
		MessageResolver resolver = builder.fatal().defaultText("foo").build();
6
CodeRank
This code example shows how to use the following methods:addMessage
@Configuration 
public class CustomMessageSourceConfiguration { 
 
	@Bean 
	public MessageSource exampleMessageSource() {
		StaticMessageSource source = new StaticMessageSource();
		source.addMessage("pages.message.definedsource.hello", Locale.getDefault(), "Defined Source Hello");
		return source;
	} 
} 
5
CodeRank
This code example shows how to use the following methods:setUseCodeAsDefaultMessage
    private boolean useTabGroups = true;
     
    private MessageSource messageSource;
     
    public SitemapTest() { 
        StaticMessageSource staticMessageSource = new StaticMessageSource();
        staticMessageSource.setUseCodeAsDefaultMessage(true);
        this.messageSource = staticMessageSource;
    } 
     
    @Before 
    public void setup() { 
        new XalanLayoutElementTitleHelper().setMessageSource(messageSource);
        XalanMessageHelperBean messageHelper = new XalanMessageHelperBean();
        messageHelper.setMessageSource(messageSource);
        new XalanMessageHelper().setMessageHelper(messageHelper);
    } 
     
    @Test
    public void testStylesheetCompilation() throws IOException {
5
CodeRank
See Code Examples for Spring Framework StaticMessageSource Methods: