use of org.springframework.core.io.ResourceLoader in project spring-framework by spring-projects.
the class FreeMarkerConfigurerTests method freeMarkerConfigurerWithNonFileResourceLoaderPath.
@Test
@SuppressWarnings("rawtypes")
public void freeMarkerConfigurerWithNonFileResourceLoaderPath() throws Exception {
freeMarkerConfigurer.setTemplateLoaderPath("file:/mydir");
Properties settings = new Properties();
settings.setProperty("localized_lookup", "false");
freeMarkerConfigurer.setFreemarkerSettings(settings);
freeMarkerConfigurer.setResourceLoader(new ResourceLoader() {
@Override
public Resource getResource(String location) {
if (!("file:/mydir".equals(location) || "file:/mydir/test".equals(location))) {
throw new IllegalArgumentException(location);
}
return new ByteArrayResource("test".getBytes(), "test");
}
@Override
public ClassLoader getClassLoader() {
return getClass().getClassLoader();
}
});
freeMarkerConfigurer.afterPropertiesSet();
assertThat(freeMarkerConfigurer.getConfiguration()).isInstanceOf(Configuration.class);
Configuration fc = freeMarkerConfigurer.getConfiguration();
Template ft = fc.getTemplate("test");
assertThat(FreeMarkerTemplateUtils.processTemplateIntoString(ft, new HashMap())).isEqualTo("test");
}
use of org.springframework.core.io.ResourceLoader in project spring-framework by spring-projects.
the class FreeMarkerConfigurerTests method freeMarkerConfigurerWithNonFileResourceLoaderPath.
@Test
@SuppressWarnings("rawtypes")
public void freeMarkerConfigurerWithNonFileResourceLoaderPath() throws Exception {
freeMarkerConfigurer.setTemplateLoaderPath("file:/mydir");
Properties settings = new Properties();
settings.setProperty("localized_lookup", "false");
freeMarkerConfigurer.setFreemarkerSettings(settings);
freeMarkerConfigurer.setResourceLoader(new ResourceLoader() {
@Override
public Resource getResource(String location) {
if (!("file:/mydir".equals(location) || "file:/mydir/test".equals(location))) {
throw new IllegalArgumentException(location);
}
return new ByteArrayResource("test".getBytes(), "test");
}
@Override
public ClassLoader getClassLoader() {
return getClass().getClassLoader();
}
});
freeMarkerConfigurer.afterPropertiesSet();
assertThat(freeMarkerConfigurer.getConfiguration()).isInstanceOf(Configuration.class);
Configuration fc = freeMarkerConfigurer.getConfiguration();
Template ft = fc.getTemplate("test");
assertThat(FreeMarkerTemplateUtils.processTemplateIntoString(ft, new HashMap())).isEqualTo("test");
}
use of org.springframework.core.io.ResourceLoader in project spring-framework by spring-projects.
the class WebFluxConfigurationSupport method resourceHandlerMapping.
/**
* Return a handler mapping ordered at Integer.MAX_VALUE-1 with mapped
* resource handlers. To configure resource handling, override
* {@link #addResourceHandlers}.
*/
@Bean
public HandlerMapping resourceHandlerMapping(ResourceUrlProvider resourceUrlProvider) {
ResourceLoader resourceLoader = this.applicationContext;
if (resourceLoader == null) {
resourceLoader = new DefaultResourceLoader();
}
ResourceHandlerRegistry registry = new ResourceHandlerRegistry(resourceLoader);
registry.setResourceUrlProvider(resourceUrlProvider);
addResourceHandlers(registry);
AbstractHandlerMapping handlerMapping = registry.getHandlerMapping();
if (handlerMapping != null) {
configureAbstractHandlerMapping(handlerMapping, getPathMatchConfigurer());
} else {
handlerMapping = new EmptyHandlerMapping();
}
return handlerMapping;
}
use of org.springframework.core.io.ResourceLoader in project dhis2-core by dhis2.
the class HelpAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
List<Locale> locales = localeManager.getLocalesOrderedByPriority();
ResourceLoader resourceLoader = new DefaultResourceLoader();
for (Locale locale : locales) {
String helpPage = helpPagePreLocale + locale.toString() + helpPagePostLocale;
if (resourceLoader.getResource(helpPage) != null) {
this.helpPage = helpPage;
return SUCCESS;
}
}
return SUCCESS;
}
use of org.springframework.core.io.ResourceLoader in project spring-security by spring-projects.
the class WebXmlJ2eeDefinedRolesRetrieverTests method testGetZeroJ2eeRoles.
@Test
public void testGetZeroJ2eeRoles() throws Exception {
final Resource webXml = new ClassPathResource("webxml/NoRoles.web.xml");
WebXmlMappableAttributesRetriever rolesRetriever = new WebXmlMappableAttributesRetriever();
rolesRetriever.setResourceLoader(new ResourceLoader() {
@Override
public ClassLoader getClassLoader() {
return Thread.currentThread().getContextClassLoader();
}
@Override
public Resource getResource(String location) {
return webXml;
}
});
rolesRetriever.afterPropertiesSet();
Set<String> j2eeRoles = rolesRetriever.getMappableAttributes();
assertThat(j2eeRoles).isEmpty();
}
Aggregations