use of org.springframework.core.io.support.ResourcePatternResolver in project pinpoint by naver.
the class ServerTraceMetadataLoaderService method getTypeProviderUrls.
private List<URL> getTypeProviderUrls(ClassLoader classLoader, Collection<String> typeProviderPaths) {
ResourcePatternResolver resourceLoader = new PathMatchingResourcePatternResolver(classLoader);
List<URL> typeProviderUrls = new ArrayList<>();
for (String typeProviderPath : typeProviderPaths) {
try {
Resource[] resources = resourceLoader.getResources(typeProviderPath);
if (ArrayUtils.isEmpty(resources)) {
logger.info("{} did not match any resources.", typeProviderPath);
} else {
Arrays.stream(resources).map(this::toUrl).forEach(typeProviderUrls::add);
}
} catch (IOException e) {
logger.error("Error getting resources using " + typeProviderPath + ", skipping.", e);
}
}
return typeProviderUrls;
}
use of org.springframework.core.io.support.ResourcePatternResolver in project disconf by knightliao.
the class TestAntPathMatcher method ResourceLoaderTest.
@Test
public void ResourceLoaderTest() throws Exception {
/* 资源地址表达式
* classpath:相对于类的根路径,可访问jar或zip中的资源哦
* classpath*:和上面类似,只不过上面是加载找到的第一个资源,这个是全部加载
* file:文件系统目录中加载,可以是绝对,也可以是相对
* http:// 不用多说了吧
* ftp:// 不用多说了吧
*
* ant风格:可以使用通配符
* ?:匹配一个字符
* *:匹配多个字符
* **:匹配多层路径
* */
ResourcePatternResolver rpr = new PathMatchingResourcePatternResolver();
Resource[] rs = rpr.getResources("classpath:testXml.xml");
for (Resource one : rs) {
showResourceInfo(one, true);
}
System.out.println("=============================");
// file:访问文件系统(绝对 和 相对路径方式)
// 绝对路径 类似于FileSystemResource
rs = rpr.getResources("file:src/test/resources/res/testXml.xml");
// rs=rpr.getResources("file:src/aop.xml");
for (Resource one : rs) {
showResourceInfo(one, true);
}
System.out.println("=============================");
// http:方式
rs = rpr.getResources("http://www.baidu.com/img/bdlogo.gif");
// 为了测试的简便,这里直接取第一个资源
byte[] gifByte = IOUtils.toByteArray(rs[0].getInputStream());
FileUtils.writeByteArrayToFile(new File("tmp/bdlogo1.gif"), gifByte);
}
use of org.springframework.core.io.support.ResourcePatternResolver in project cloudstack by apache.
the class ClasspathModuleDefinitionLocator method locateModules.
@Override
public Collection<ModuleDefinition> locateModules(String context) throws IOException {
ResourcePatternResolver resolver = getResolver();
Map<String, ModuleDefinition> allModules = discoverModules(context, resolver);
return allModules.values();
}
use of org.springframework.core.io.support.ResourcePatternResolver in project grails-core by grails.
the class PluginAwareResourceBundleMessageSource method afterPropertiesSet.
public void afterPropertiesSet() throws Exception {
if (pluginCacheMillis == Long.MIN_VALUE) {
pluginCacheMillis = cacheMillis;
}
if (localResourceLoader == null) {
return;
}
Resource[] resources;
if (Environment.isDevelopmentEnvironmentAvailable()) {
File[] propertiesFiles = new File(BuildSettings.BASE_DIR, GRAILS_APP_I18N_PATH_COMPONENT).listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.endsWith(".properties");
}
});
if (propertiesFiles != null && propertiesFiles.length > 0) {
List<Resource> resourceList = new ArrayList<Resource>(propertiesFiles.length);
for (File propertiesFile : propertiesFiles) {
resourceList.add(new FileSystemResource(propertiesFile));
}
resources = resourceList.toArray(new Resource[resourceList.size()]);
} else {
resources = new Resource[0];
}
} else {
if (searchClasspath) {
resources = resourceResolver.getResources(messageBundleLocationPattern);
} else {
DefaultGrailsApplication defaultGrailsApplication = (DefaultGrailsApplication) application;
if (defaultGrailsApplication != null) {
GrailsApplicationClass applicationClass = defaultGrailsApplication.getApplicationClass();
if (applicationClass != null) {
ResourcePatternResolver resourcePatternResolver = new ClassRelativeResourcePatternResolver(applicationClass.getClass());
resources = resourcePatternResolver.getResources(messageBundleLocationPattern);
} else {
resources = resourceResolver.getResources(messageBundleLocationPattern);
}
} else {
resources = resourceResolver.getResources(messageBundleLocationPattern);
}
}
}
List<String> basenames = new ArrayList<String>();
for (Resource resource : resources) {
String filename = resource.getFilename();
String baseName = GrailsStringUtils.getFileBasename(filename);
int i = baseName.indexOf('_');
if (i > -1) {
baseName = baseName.substring(0, i);
}
if (!basenames.contains(baseName) && !baseName.equals(""))
basenames.add(baseName);
}
setBasenames(basenames.toArray(new String[basenames.size()]));
}
use of org.springframework.core.io.support.ResourcePatternResolver in project pigatron-web by pigatron-industries.
the class AdminResourceConfig method findWebResources.
public WebResources findWebResources(String path) throws IOException {
WebResources webResources = new WebResources();
ClassLoader cl = this.getClass().getClassLoader();
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(cl);
Resource[] resources = resolver.getResources("classpath*:/static/" + path + "/*.js");
for (Resource resource : resources) {
webResources.addResource(resource.getFilename(), WebResourceType.JS);
}
resources = resolver.getResources("classpath*:/static/" + path + "/*.css");
for (Resource resource : resources) {
webResources.addResource(resource.getFilename(), WebResourceType.CSS);
}
webResources.sort();
return webResources;
}
Aggregations