Search in sources :

Example 61 with ResourcePatternResolver

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;
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) ArrayList(java.util.ArrayList) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) URL(java.net.URL)

Example 62 with ResourcePatternResolver

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);
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) Resource(org.springframework.core.io.Resource) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) File(java.io.File) Test(org.junit.Test)

Example 63 with ResourcePatternResolver

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();
}
Also used : DefaultModuleDefinition(org.apache.cloudstack.spring.module.model.impl.DefaultModuleDefinition) ModuleDefinition(org.apache.cloudstack.spring.module.model.ModuleDefinition) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver)

Example 64 with ResourcePatternResolver

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()]));
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) CachingPathMatchingResourcePatternResolver(org.grails.core.io.CachingPathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) ClassRelativeResourcePatternResolver(org.grails.core.support.internal.tools.ClassRelativeResourcePatternResolver) GrailsApplicationClass(grails.core.GrailsApplicationClass) Resource(org.springframework.core.io.Resource) FileSystemResource(org.springframework.core.io.FileSystemResource) ArrayList(java.util.ArrayList) FileSystemResource(org.springframework.core.io.FileSystemResource) DefaultGrailsApplication(grails.core.DefaultGrailsApplication) FilenameFilter(java.io.FilenameFilter) ClassRelativeResourcePatternResolver(org.grails.core.support.internal.tools.ClassRelativeResourcePatternResolver) File(java.io.File)

Example 65 with ResourcePatternResolver

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;
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) Resource(org.springframework.core.io.Resource) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver)

Aggregations

ResourcePatternResolver (org.springframework.core.io.support.ResourcePatternResolver)68 PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)65 Resource (org.springframework.core.io.Resource)52 IOException (java.io.IOException)15 ArrayList (java.util.ArrayList)11 Bean (org.springframework.context.annotation.Bean)11 PageHelper (com.github.pagehelper.PageHelper)9 File (java.io.File)9 SqlSessionFactoryBean (org.mybatis.spring.SqlSessionFactoryBean)9 CachingMetadataReaderFactory (org.springframework.core.type.classreading.CachingMetadataReaderFactory)9 MetadataReader (org.springframework.core.type.classreading.MetadataReader)9 MetadataReaderFactory (org.springframework.core.type.classreading.MetadataReaderFactory)9 Properties (java.util.Properties)8 InputStream (java.io.InputStream)6 FileOutputStream (java.io.FileOutputStream)5 URL (java.net.URL)5 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)3 EventLoopGroup (io.netty.channel.EventLoopGroup)2 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)2 SocketChannel (io.netty.channel.socket.SocketChannel)2