use of org.springframework.core.io.DefaultResourceLoader 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.DefaultResourceLoader 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.DefaultResourceLoader in project OpenClinica by OpenClinica.
the class LoggerStartupListener method start.
@Override
public void start() {
if (started)
return;
Context context = getContext();
if (resourceLoader == null)
resourceLoader = new DefaultResourceLoader();
try {
webapp = getWebAppName(resourceLoader.getResource("/").getURI().getPath());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
DATAINFO = loadProperties("datainfo.properties");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
getPropertiesSource();
context.putProperty("log.dir", getField("log.dir"));
context.putProperty("logLocation", getField("logLocation"));
context.putProperty("logLevel", getField("logLevel"));
context.putProperty("syslog.host", getField("syslog.host"));
context.putProperty("syslog.port", getField("syslog.port"));
context.putProperty("collectStats", getField("collectStats"));
context.putProperty("usage.stats.host", getField("usage.stats.host"));
context.putProperty("usage.stats.port", getField("usage.stats.port"));
context.putProperty("OpenClinica.version", getField("OpenClinica.version"));
started = true;
}
use of org.springframework.core.io.DefaultResourceLoader in project cas by apereo.
the class ResourceUtilsTests method verifyResourceExists.
@Test
public void verifyResourceExists() {
assertThrows(IllegalArgumentException.class, () -> ResourceUtils.getRawResourceFrom(null));
assertFalse(ResourceUtils.doesResourceExist(new FileSystemResource("invalid.json")));
val resourceLoader = mock(ResourceLoader.class);
when(resourceLoader.getResource(anyString())).thenThrow(new RuntimeException());
assertFalse(ResourceUtils.doesResourceExist("bad-resource", resourceLoader));
assertFalse(ResourceUtils.doesResourceExist(null, resourceLoader));
assertFalse(ResourceUtils.doesResourceExist("invalid.json"));
assertTrue(ResourceUtils.doesResourceExist("classpath:valid.json", new DefaultResourceLoader(ResourceUtilsTests.class.getClassLoader())));
}
use of org.springframework.core.io.DefaultResourceLoader in project cas by apereo.
the class CoreAuthenticationUtils method newCredentialSelectionPredicate.
/**
* Gets credential selection predicate.
*
* @param selectionCriteria the selection criteria
* @return the credential selection predicate
*/
public static Predicate<Credential> newCredentialSelectionPredicate(final String selectionCriteria) {
try {
if (StringUtils.isBlank(selectionCriteria)) {
return credential -> true;
}
if (selectionCriteria.endsWith(".groovy")) {
val loader = new DefaultResourceLoader();
val resource = loader.getResource(selectionCriteria);
val script = IOUtils.toString(resource.getInputStream(), StandardCharsets.UTF_8);
val classLoader = new GroovyClassLoader(Beans.class.getClassLoader(), new CompilerConfiguration(), true);
val clz = classLoader.parseClass(script);
return (Predicate<Credential>) clz.getDeclaredConstructor().newInstance();
}
val predicateClazz = ClassUtils.getClass(selectionCriteria);
return (Predicate<Credential>) predicateClazz.getDeclaredConstructor().newInstance();
} catch (final Exception e) {
val predicate = Pattern.compile(selectionCriteria).asPredicate();
return credential -> predicate.test(credential.getId());
}
}
Aggregations