Search in sources :

Example 31 with ResourcePatternResolver

use of org.springframework.core.io.support.ResourcePatternResolver in project OpenClinica by OpenClinica.

the class CoreResources method copyConfig.

private void copyConfig() throws IOException {
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(resourceLoader);
    Resource[] resources = null;
    FileOutputStream out = null;
    Resource resource1 = null;
    Resource resource2 = null;
    resource1 = resolver.getResource("classpath:datainfo.properties");
    resource2 = resolver.getResource("classpath:extract.properties");
    String filePath = "$catalina.home/$WEBAPP.lower.config";
    filePath = replaceWebapp(filePath);
    filePath = replaceCatHome(filePath);
    File dest = new File(filePath);
    if (!dest.exists()) {
        if (!dest.mkdirs()) {
            throw new OpenClinicaSystemException("Copying files, Could not create directory: " + dest.getAbsolutePath() + ".");
        }
    }
    File f1 = new File(dest, resource1.getFilename());
    File f2 = new File(dest, resource2.getFilename());
    if (!f1.exists()) {
        out = new FileOutputStream(f1);
        IOUtils.copy(resource1.getInputStream(), out);
        out.close();
    }
    if (!f2.exists()) {
        out = new FileOutputStream(f2);
        IOUtils.copy(resource2.getInputStream(), out);
        out.close();
    }
/*
         * 
         * for (Resource r: resources) { File f = new File(dest, r.getFilename()); if(!f.exists()){ out = new
         * FileOutputStream(f); IOUtils.copy(r.getInputStream(), out); out.close(); } }
         */
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) FileOutputStream(java.io.FileOutputStream) Resource(org.springframework.core.io.Resource) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) File(java.io.File)

Example 32 with ResourcePatternResolver

use of org.springframework.core.io.support.ResourcePatternResolver in project cxf by apache.

the class SpringClasspathScanner method findResourcesInternal.

@Override
protected List<URL> findResourcesInternal(Collection<String> basePackages, String extension, ClassLoader loader) throws IOException {
    final List<URL> resourceURLs = new ArrayList<>();
    if (basePackages == null || basePackages.isEmpty()) {
        return resourceURLs;
    }
    ResourcePatternResolver resolver = getResolver(loader);
    for (final String basePackage : basePackages) {
        final boolean scanAllPackages = basePackage.equals(WILDCARD);
        String theBasePackage = basePackage;
        if (theBasePackage.startsWith(CLASSPATH_URL_SCHEME)) {
            theBasePackage = theBasePackage.substring(CLASSPATH_URL_SCHEME.length());
        }
        final String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + (scanAllPackages ? "" : basePackage.contains(WILDCARD) ? basePackage : ClassUtils.convertClassNameToResourcePath(theBasePackage)) + ALL_FILES + "." + extension;
        final Resource[] resources = resolver.getResources(packageSearchPath);
        for (final Resource resource : resources) {
            resourceURLs.add(resource.getURL());
        }
    }
    return resourceURLs;
}
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) URL(java.net.URL)

Example 33 with ResourcePatternResolver

use of org.springframework.core.io.support.ResourcePatternResolver in project web3sdk by FISCO-BCOS.

the class PEMManager method load.

public void load() throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException, NoSuchProviderException, InvalidKeySpecException {
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    Resource pemResources = resolver.getResource(pemFile);
    load(pemResources.getInputStream());
}
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)

Example 34 with ResourcePatternResolver

use of org.springframework.core.io.support.ResourcePatternResolver in project dq-easy-cloud by dq-open-cloud.

the class EcDataSourceConfig method sqlSessionFactory.

@Bean
public SqlSessionFactory sqlSessionFactory(DataSource dataSourece) throws Exception {
    // 添加XML目录
    SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
    sessionFactory.setDataSource(dataSourece);
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    try {
        sessionFactory.setMapperLocations(resolver.getResources(mapperLocations));
        return sessionFactory.getObject();
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 35 with ResourcePatternResolver

use of org.springframework.core.io.support.ResourcePatternResolver in project littlefisher-system by littlefishercoder.

the class PackageUtil method scanTypePackage.

/**
 * 扫描获取指定包路径所有类
 *
 * @param typePackage 扫描类包路径
 * @return Set<Class>
 */
public static Set<Class> scanTypePackage(String typePackage) {
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resolver);
    String pkg = ClassUtils.convertClassNameToResourcePath(typePackage) + ".class";
    /*
         * 将加载多个绝对匹配的所有Resource
         * 将首先通过ClassLoader.getResource("META-INF")加载非模式路径部分,然后进行遍历模式匹配,排除重复包路径
         */
    try {
        Set<Class> set = Sets.newHashSet();
        Resource[] resources = resolver.getResources(pkg);
        if (ArrayUtils.isNotEmpty(resources)) {
            MetadataReader metadataReader;
            for (Resource resource : resources) {
                if (resource.isReadable()) {
                    metadataReader = metadataReaderFactory.getMetadataReader(resource);
                    set.add(Class.forName(metadataReader.getClassMetadata().getClassName()));
                }
            }
        }
        return set;
    } catch (Exception e) {
        throw new BaseAppException("CORE-000007", null, e);
    }
}
Also used : BaseAppException(com.littlefisher.core.common.exception.BaseAppException) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) MetadataReaderFactory(org.springframework.core.type.classreading.MetadataReaderFactory) CachingMetadataReaderFactory(org.springframework.core.type.classreading.CachingMetadataReaderFactory) Resource(org.springframework.core.io.Resource) MetadataReader(org.springframework.core.type.classreading.MetadataReader) CachingMetadataReaderFactory(org.springframework.core.type.classreading.CachingMetadataReaderFactory) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) BaseAppException(com.littlefisher.core.common.exception.BaseAppException)

Aggregations

ResourcePatternResolver (org.springframework.core.io.support.ResourcePatternResolver)65 PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)62 Resource (org.springframework.core.io.Resource)49 IOException (java.io.IOException)15 Bean (org.springframework.context.annotation.Bean)11 ArrayList (java.util.ArrayList)10 PageHelper (com.github.pagehelper.PageHelper)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 File (java.io.File)8 Properties (java.util.Properties)8 InputStream (java.io.InputStream)5 URL (java.net.URL)5 FileOutputStream (java.io.FileOutputStream)3 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