org.springframework.context.support.MessageSourceAccessor Java Examples

The following examples show how to use org.springframework.context.support.MessageSourceAccessor. 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 File: DefaultValuesControllerTest.java    From n2o-framework with 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 File: CopyValuesControllerTest.java    From n2o-framework with 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 File: DataControllerTestBase.java    From n2o-framework with 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 File: N2oEnvironment.java    From n2o-framework with 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 File: N2oTestBase.java    From n2o-framework with 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 #6
Source File: AppConfigServlet.java    From n2o-framework with 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 #7
Source File: AbstractDelegateMessageBundle.java    From super-cloudops with Apache License 2.0 5 votes vote down vote up
/**
 * Get actual message source
 * 
 * @return
 */
public MessageSourceAccessor getSource() {
	if (accessor != null) {
		return accessor;
	}
	return (accessor = new MessageSourceAccessor(this));
}
 
Example #8
Source File: N2oEnvironmentConfiguration.java    From n2o-framework with 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 #9
Source File: N2oEnvironmentConfiguration.java    From n2o-framework with 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 #10
Source File: ErrorMessageBuilderTest.java    From n2o-framework with 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 #11
Source File: ErrorMessageBuilderTest.java    From n2o-framework with 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 #12
Source File: FederationAuthenticationProvider.java    From cxf-fediz with Apache License 2.0 4 votes vote down vote up
public void setMessageSource(final MessageSource messageSource) {
    this.messages = new MessageSourceAccessor(messageSource);
}
 
Example #13
Source File: IOProcessorImpl.java    From n2o-framework with Apache License 2.0 4 votes vote down vote up
public void setMessageSourceAccessor(MessageSourceAccessor messageSourceAccessor) {
    this.messageSourceAccessor = messageSourceAccessor;
}
 
Example #14
Source File: AbstractUserDetailsAuthenticationProvider.java    From Taroco with Apache License 2.0 4 votes vote down vote up
@Override
public void setMessageSource(MessageSource messageSource) {
    this.messages = new MessageSourceAccessor(messageSource);
}
 
Example #15
Source File: FirebaseAuthenticationProvider.java    From zhcet-web with 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 #16
Source File: MessageSourceBridge.java    From joinfaces with Apache License 2.0 4 votes vote down vote up
public MessageSourceBridge(MessageSource messageSource) {
	this.messageSourceAccessor = new MessageSourceAccessor(messageSource);
}
 
Example #17
Source File: MessageSourceBridgeTest.java    From joinfaces with Apache License 2.0 4 votes vote down vote up
@BeforeEach
void setUp() {
	this.messageSourceAccessor = mock(MessageSourceAccessor.class);
	this.messageSourceBridge = new MessageSourceBridge(this.messageSourceAccessor);
}
 
Example #18
Source File: GenericExceptionHandler.java    From SMSC with Apache License 2.0 4 votes vote down vote up
public GenericExceptionHandler(MessageSource messageSource) {

        Assert.notNull(messageSource, "MessageSource must not be null!");
        this.messageSourceAccessor = new MessageSourceAccessor(messageSource);
    }
 
Example #19
Source File: SpringFedizMessageSource.java    From cxf-fediz with Apache License 2.0 4 votes vote down vote up
public static MessageSourceAccessor getAccessor() {
    return new MessageSourceAccessor(new SpringFedizMessageSource());
}
 
Example #20
Source File: N2oEnvironment.java    From n2o-framework with Apache License 2.0 4 votes vote down vote up
@Override
public MessageSourceAccessor getMessageSource() {
    return messageSource;
}
 
Example #21
Source File: LogAspect.java    From openregistry with Apache License 2.0 4 votes vote down vote up
public void setMessageSource(final MessageSource messageSource) {
    this.messageSourceAccessor = new MessageSourceAccessor(messageSource);
}
 
Example #22
Source File: UserStatusChecker.java    From lemon with Apache License 2.0 4 votes vote down vote up
public void setMessageSource(MessageSource messageSource) {
    this.messages = new MessageSourceAccessor(messageSource);
}
 
Example #23
Source File: RoleChecker.java    From lemon with Apache License 2.0 4 votes vote down vote up
public void setMessageSource(MessageSource messageSource) {
    this.messages = new MessageSourceAccessor(messageSource);
}
 
Example #24
Source File: RoleDefChecker.java    From lemon with Apache License 2.0 4 votes vote down vote up
public void setMessageSource(MessageSource messageSource) {
    this.messages = new MessageSourceAccessor(messageSource);
}
 
Example #25
Source File: MessageHelper.java    From lemon with Apache License 2.0 4 votes vote down vote up
@Resource
public void setMessageSource(MessageSource messageSource) {
    this.messages = new MessageSourceAccessor(messageSource);
}
 
Example #26
Source File: IntegrationAuthenticationFilter.java    From nextreports-server with Apache License 2.0 4 votes vote down vote up
@Override
public void setMessageSource(MessageSource messageSource) {
    this.messages = new MessageSourceAccessor(messageSource);
}
 
Example #27
Source File: ErrorMessageBuilder.java    From n2o-framework with Apache License 2.0 4 votes vote down vote up
public ErrorMessageBuilder(MessageSourceAccessor messageSourceAccessor) {
    this.messageSourceAccessor = messageSourceAccessor;
}
 
Example #28
Source File: DefaultPasswordStrategy.java    From cola with 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 #29
Source File: SpringSecurityWebAuthnMessageSource.java    From webauthn4j-spring-security with Apache License 2.0 4 votes vote down vote up
public static MessageSourceAccessor getAccessor() {
    return new MessageSourceAccessor(new SpringSecurityWebAuthnMessageSource());
}
 
Example #30
Source File: SpringSecurityWebAuthnMessageSourceTest.java    From webauthn4j-spring-security with Apache License 2.0 4 votes vote down vote up
@Test
public void getAccessor_test() {
    MessageSourceAccessor accessor = SpringSecurityWebAuthnMessageSource.getAccessor();
    assertThat(accessor).isNotNull();
}