Java Code Examples for org.springframework.context.support.MessageSourceAccessor

The following examples show how to use org.springframework.context.support.MessageSourceAccessor. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: n2o-framework   Source File: DefaultValuesControllerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
    N2oEnvironment environment = new N2oEnvironment();
    environment.setNamespacePersisterFactory(new PersisterFactoryByMap());
    environment.setNamespaceReaderFactory(new ReaderFactoryByMap());
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasenames("n2o_messages", "messages");
    messageSource.setDefaultEncoding("UTF-8");
    environment.setMessageSource(new MessageSourceAccessor(messageSource));
    OverrideProperties properties = PropertiesReader.getPropertiesFromClasspath("META-INF/n2o.properties");
    properties.put("n2o.engine.mapper", "spel");
    environment.setSystemProperties(new SimplePropertyResolver(properties));
    builder = new N2oApplicationBuilder(environment);
    configure(builder);
    CompileInfo.setSourceTypes(builder.getEnvironment().getSourceTypeRegister());
}
 
Example 2
Source Project: n2o-framework   Source File: CopyValuesControllerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
    N2oEnvironment environment = new N2oEnvironment();
    environment.setNamespacePersisterFactory(new PersisterFactoryByMap());
    environment.setNamespaceReaderFactory(new ReaderFactoryByMap());
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasenames("n2o_messages", "messages");
    messageSource.setDefaultEncoding("UTF-8");
    environment.setMessageSource(new MessageSourceAccessor(messageSource));
    OverrideProperties properties = PropertiesReader.getPropertiesFromClasspath("META-INF/n2o.properties");
    properties.put("n2o.engine.mapper", "spel");
    environment.setSystemProperties(new SimplePropertyResolver(properties));
    builder = new N2oApplicationBuilder(environment);
    configure(builder);
    CompileInfo.setSourceTypes(builder.getEnvironment().getSourceTypeRegister());
}
 
Example 3
Source Project: n2o-framework   Source File: DataControllerTestBase.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
    N2oEnvironment environment = new N2oEnvironment();
    environment.setNamespacePersisterFactory(new PersisterFactoryByMap());
    environment.setNamespaceReaderFactory(new ReaderFactoryByMap());
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasenames("n2o_messages", "messages");
    messageSource.setDefaultEncoding("UTF-8");
    environment.setMessageSource(new MessageSourceAccessor(messageSource));
    OverrideProperties properties = PropertiesReader.getPropertiesFromClasspath("META-INF/n2o.properties");
    properties.put("n2o.engine.mapper", "spel");
    SimplePropertyResolver propertyResolver = new SimplePropertyResolver(properties);
    setUpStaticProperties(propertyResolver);
    environment.setSystemProperties(propertyResolver);
    builder = new N2oApplicationBuilder(environment);
    configure(builder);
    CompileInfo.setSourceTypes(builder.getEnvironment().getSourceTypeRegister());
}
 
Example 4
Source Project: n2o-framework   Source File: N2oEnvironment.java    License: Apache License 2.0 6 votes vote down vote up
public N2oEnvironment() {
    this.metadataRegister = new N2oMetadataRegister();
    this.routeRegister = new N2oRouteRegister();
    this.sourceTypeRegister = new N2oSourceTypeRegister();

    this.messageSource = new MessageSourceAccessor(new ResourceBundleMessageSource());
    this.systemProperties = new N2oWebAppEnvironment();
    this.domainProcessor = new DomainProcessor(new ObjectMapper());
    this.contextProcessor = new ContextProcessor(new TestContextEngine());

    this.namespaceReaderFactory = new ReaderFactoryByMap();
    this.namespacePersisterFactory = new PersisterFactoryByMap();
    this.dynamicMetadataProviderFactory = new N2oDynamicMetadataProviderFactory();
    this.metadataScannerFactory = new N2oMetadataScannerFactory();
    this.sourceLoaderFactory = new N2oSourceLoaderFactory();
    this.sourceValidatorFactory = new N2oSourceValidatorFactory();
    this.sourceCompilerFactory = new N2oSourceCompilerFactory();
    this.compileTransformerFactory = new N2oCompileTransformerFactory();
    this.sourceTransformerFactory = new N2oSourceTransformerFactory();
    this.extensionAttributeMapperFactory = new N2oExtensionAttributeMapperFactory();
    this.sourceMergerFactory = new N2oSourceMergerFactory();
    this.metadataBinderFactory = new N2oMetadataBinderFactory();
    this.pipelineOperationFactory = new N2oPipelineOperationFactory();
    this.buttonGeneratorFactory = new N2oButtonGeneratorFactory();
}
 
Example 5
Source Project: n2o-framework   Source File: AppConfigServlet.java    License: Apache License 2.0 5 votes vote down vote up
private Map<String, String> getMessages() {
    MessageSourceAccessor accessor = new MessageSourceAccessor(messageSource);
    Locale locale = LocaleContextHolder.getLocale();
    Set<String> messagesBaseNames = messageSource.getBasenameSet();
    Map<String, String> map = new TreeMap<>();
    for (String baseName : messagesBaseNames) {
        Set<String> keys = messageSource.getKeys(baseName, locale);
        for (String key : keys) {
            map.put(key, accessor.getMessage(key, locale));
        }
    }
    return map;
}
 
Example 6
Source Project: n2o-framework   Source File: N2oEnvironmentConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
IOProcessor readerProcessor(@Qualifier("n2oMessageSourceAccessor") MessageSourceAccessor messageSourceAccessor,
                            NamespaceReaderFactory readerFactory,
                            ConfigurableEnvironment environment) {
    IOProcessorImpl ioProcessor = new IOProcessorImpl(readerFactory);
    ioProcessor.setMessageSourceAccessor(messageSourceAccessor);
    ioProcessor.setSystemProperties(environment);
    return ioProcessor;
}
 
Example 7
Source Project: n2o-framework   Source File: N2oEnvironmentConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
IOProcessor persisterProcessor(@Qualifier("n2oMessageSourceAccessor") MessageSourceAccessor messageSourceAccessor,
                               NamespacePersisterFactory persisterFactory,
                               ConfigurableEnvironment environment) {
    IOProcessorImpl ioProcessor = new IOProcessorImpl(persisterFactory);
    ioProcessor.setMessageSourceAccessor(messageSourceAccessor);
    ioProcessor.setSystemProperties(environment);
    return ioProcessor;
}
 
Example 8
Source Project: n2o-framework   Source File: ErrorMessageBuilderTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testAnyException() {
    MessageSourceAccessor messageSource = mock(MessageSourceAccessor.class);
    when(messageSource.getMessage("n2o.exceptions.error.message", "n2o.exceptions.error.message")).thenReturn("Internal error");
    ErrorMessageBuilder builder = new ErrorMessageBuilder(messageSource);
    Exception e = new IllegalStateException();
    ResponseMessage message = builder.build(e);
    assertThat(message.getText(), is("Internal error"));
    assertThat(message.getSeverity(), is("danger"));
    assertThat(message.getStacktrace(), hasItem(containsString("ErrorMessageBuilderTest")));
    builder = new ErrorMessageBuilder(messageSource, false);
    message = builder.build(e);
    assertThat(message.getStacktrace(), nullValue());
}
 
Example 9
Source Project: n2o-framework   Source File: ErrorMessageBuilderTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testUserException() {
    MessageSourceAccessor messageSource = mock(MessageSourceAccessor.class);
    when(messageSource.getMessage("user.code", "user.code")).thenReturn("User message {0}");
    ErrorMessageBuilder builder = new ErrorMessageBuilder(messageSource);
    N2oException e = new N2oUserException("user.code").addData("test");
    ResponseMessage message = builder.build(e);
    assertThat(message.getText(), is("User message test"));
}
 
Example 10
Source Project: n2o-framework   Source File: N2oTestBase.java    License: Apache License 2.0 5 votes vote down vote up
public void setUp() throws Exception {
    N2oEnvironment environment = new N2oEnvironment();
    environment.setNamespacePersisterFactory(new PersisterFactoryByMap());
    environment.setNamespaceReaderFactory(new ReaderFactoryByMap());
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasenames("n2o_messages", "messages");
    messageSource.setDefaultEncoding("UTF-8");
    environment.setMessageSource(new MessageSourceAccessor(messageSource));
    OverrideProperties properties = PropertiesReader.getPropertiesFromClasspath("META-INF/n2o.properties");
    environment.setSystemProperties(new SimplePropertyResolver(properties));

    builder = new N2oApplicationBuilder(environment);
    configure(builder);
    CompileInfo.setSourceTypes(builder.getEnvironment().getSourceTypeRegister());
}
 
Example 11
/**
 * Get actual message source
 * 
 * @return
 */
public MessageSourceAccessor getSource() {
	if (accessor != null) {
		return accessor;
	}
	return (accessor = new MessageSourceAccessor(this));
}
 
Example 12
@Override
public void setMessageSource(MessageSource messageSource) {
    this.messages = new MessageSourceAccessor(messageSource);
}
 
Example 13
Source Project: cola   Source File: DefaultPasswordStrategy.java    License: MIT License 4 votes vote down vote up
public DefaultPasswordStrategy(PasswordProperties properties) {
	this.properties = properties;
	ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
	messageSource.setBasename("messages");
	messages = new MessageSourceAccessor(messageSource);
}
 
Example 14
public static MessageSourceAccessor getAccessor() {
    return new MessageSourceAccessor(new SpringSecurityWebAuthnMessageSource());
}
 
Example 15
@Test
public void getAccessor_test() {
    MessageSourceAccessor accessor = SpringSecurityWebAuthnMessageSource.getAccessor();
    assertThat(accessor).isNotNull();
}
 
Example 16
Source Project: n2o-framework   Source File: N2oMessagesConfiguration.java    License: Apache License 2.0 4 votes vote down vote up
@Bean("n2oMessageSourceAccessor")
@ConditionalOnMissingBean(name = "n2oMessageSourceAccessor")
public MessageSourceAccessor messageSourceAccessor(@Qualifier("n2oMessageSource") MessageSource messageSource) {
    return new MessageSourceAccessor(messageSource);
}
 
Example 17
Source Project: n2o-framework   Source File: N2oEnvironmentConfiguration.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public MetadataEnvironment n2oEnvironment(Map<String, ButtonGenerator> generators,
                                          @Qualifier("n2oMessageSourceAccessor") MessageSourceAccessor messageSourceAccessor,
                                          ConfigurableEnvironment properties,
                                          DomainProcessor domainProcessor,
                                          ContextProcessor contextProcessor,
                                          SourceTypeRegister sourceTypeRegister,
                                          MetadataRegister metadataRegister,
                                          RouteRegister routeRegister,
                                          MetadataScannerFactory metadataScannerFactory,
                                          SourceLoaderFactory sourceReaderFactory,
                                          SourceValidatorFactory sourceValidatorFactory,
                                          NamespacePersisterFactory persisterFactory,
                                          NamespaceReaderFactory readerFactory,
                                          SourceCompilerFactory sourceCompilerFactory,
                                          CompileTransformerFactory compileTransformerFactory,
                                          SourceTransformerFactory sourceTransformerFactory,
                                          SourceMergerFactory sourceMergerFactory,
                                          MetadataBinderFactory metadataBinderFactory,
                                          PipelineOperationFactory pipelineOperationFactory,
                                          DynamicMetadataProviderFactory dynamicMetadataProviderFactory,
                                          ExtensionAttributeMapperFactory extensionAttributeMapperFactory,
                                          ButtonGeneratorFactory buttonGeneratorFactory) {
    ((CrudGenerator) generators.get("crudGenerator")).setButtonGeneratorFactory(buttonGeneratorFactory);
    N2oEnvironment environment = new N2oEnvironment();
    environment.setSystemProperties(properties);
    environment.setMessageSource(messageSourceAccessor);
    environment.setSourceTypeRegister(sourceTypeRegister);
    environment.setMetadataRegister(metadataRegister);
    environment.setRouteRegister(routeRegister);
    environment.setNamespaceReaderFactory(new N2oNamespaceReaderFactory());
    environment.setNamespacePersisterFactory(new N2oMetadataPersisterFactory());
    environment.setMetadataScannerFactory(metadataScannerFactory);
    environment.setDynamicMetadataProviderFactory(dynamicMetadataProviderFactory);
    environment.setSourceLoaderFactory(sourceReaderFactory);
    environment.setNamespacePersisterFactory(persisterFactory);
    environment.setNamespaceReaderFactory(readerFactory);
    environment.setSourceValidatorFactory(sourceValidatorFactory);
    environment.setSourceCompilerFactory(sourceCompilerFactory);
    environment.setCompileTransformerFactory(compileTransformerFactory);
    environment.setSourceTransformerFactory(sourceTransformerFactory);
    environment.setSourceMergerFactory(sourceMergerFactory);
    environment.setPipelineOperationFactory(pipelineOperationFactory);
    environment.setMetadataBinderFactory(metadataBinderFactory);
    environment.setDomainProcessor(domainProcessor);
    environment.setContextProcessor(contextProcessor);
    environment.setExtensionAttributeMapperFactory(extensionAttributeMapperFactory);
    environment.setButtonGeneratorFactory(buttonGeneratorFactory);
    return environment;
}
 
Example 18
Source Project: n2o-framework   Source File: N2oMetadataConfiguration.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public N2oJdomTextProcessing n2oJdomTextProcessing(@Qualifier("n2oMessageSourceAccessor") MessageSourceAccessor n2oMessageSourceAccessor,
                                                   ConfigurableEnvironment environment) {
    return new N2oJdomTextProcessing(n2oMessageSourceAccessor, environment);
}
 
Example 19
Source Project: n2o-framework   Source File: ErrorMessageBuilder.java    License: Apache License 2.0 4 votes vote down vote up
public ErrorMessageBuilder(MessageSourceAccessor messageSourceAccessor) {
    this.messageSourceAccessor = messageSourceAccessor;
}
 
Example 20
Source Project: n2o-framework   Source File: ErrorMessageBuilder.java    License: Apache License 2.0 4 votes vote down vote up
public ErrorMessageBuilder(MessageSourceAccessor messageSourceAccessor, Boolean showStacktrace) {
    this.messageSourceAccessor = messageSourceAccessor;
    this.showStacktrace = showStacktrace;
}
 
Example 21
Source Project: n2o-framework   Source File: N2oServlet.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void init() throws ServletException {
    super.init();
    if (errorMessageBuilder == null)
        errorMessageBuilder = new ErrorMessageBuilder(new MessageSourceAccessor(new ResourceBundleMessageSource()));
}
 
Example 22
Source Project: n2o-framework   Source File: AutoTestApplication.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
ErrorMessageBuilder errorMessageBuilder(@Qualifier("n2oMessageSourceAccessor") MessageSourceAccessor messageSourceAccessor) {
    return new ErrorMessageBuilder(messageSourceAccessor);
}
 
Example 23
Source Project: n2o-framework   Source File: N2oEnvironment.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public MessageSourceAccessor getMessageSource() {
    return messageSource;
}
 
Example 24
Source Project: n2o-framework   Source File: N2oEnvironment.java    License: Apache License 2.0 4 votes vote down vote up
public void setMessageSource(MessageSourceAccessor messageSource) {
    this.messageSource = messageSource;
}
 
Example 25
Source Project: n2o-framework   Source File: N2oJdomTextProcessing.java    License: Apache License 2.0 4 votes vote down vote up
public N2oJdomTextProcessing(MessageSourceAccessor messageSourceAccessor,
                             PropertyResolver systemProperties) {
    this.messageSourceAccessor = messageSourceAccessor;
    this.systemProperties = systemProperties;
}
 
Example 26
Source Project: n2o-framework   Source File: IOProcessorImpl.java    License: Apache License 2.0 4 votes vote down vote up
public void setMessageSourceAccessor(MessageSourceAccessor messageSourceAccessor) {
    this.messageSourceAccessor = messageSourceAccessor;
}
 
Example 27
@Override
public void setMessageSource(MessageSource messageSource) {
    this.messages = new MessageSourceAccessor(messageSource);
}
 
Example 28
Source Project: zhcet-web   Source File: FirebaseAuthenticationProvider.java    License: Apache License 2.0 4 votes vote down vote up
@Override
@Autowired(required = false)
public void setMessageSource(@NonNull MessageSource messageSource) {
    this.messages = new MessageSourceAccessor(messageSource);
}
 
Example 29
Source Project: joinfaces   Source File: MessageSourceBridge.java    License: Apache License 2.0 4 votes vote down vote up
public MessageSourceBridge(MessageSource messageSource) {
	this.messageSourceAccessor = new MessageSourceAccessor(messageSource);
}
 
Example 30
Source Project: joinfaces   Source File: MessageSourceBridgeTest.java    License: Apache License 2.0 4 votes vote down vote up
@BeforeEach
void setUp() {
	this.messageSourceAccessor = mock(MessageSourceAccessor.class);
	this.messageSourceBridge = new MessageSourceBridge(this.messageSourceAccessor);
}