Search in sources :

Example 36 with ResourcePatternResolver

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

the class MifosViewerServletContextListener method copyFromClassPathToDirectory.

private void copyFromClassPathToDirectory(String directoryToScan, File rootDirectory) throws IOException {
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    Resource[] resources = resolver.getResources(LOCATION_PATTERN);
    LOGGER.info("Found " + resources.length + " Resources on " + LOCATION_PATTERN);
    for (Resource resource : resources) {
        if (resource.exists() & resource.isReadable() && resource.contentLength() > 0) {
            URL url = resource.getURL();
            String urlString = url.toExternalForm();
            String targetName = urlString.substring(urlString.indexOf(directoryToScan));
            File destination = new File(rootDirectory, targetName);
            FileUtils.copyURLToFile(url, destination);
            LOGGER.info("Copied " + url + " to " + destination.getAbsolutePath());
        } else {
            LOGGER.debug("Did not copy, seems to be directory: " + resource.getDescription());
        }
    }
}
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) URL(java.net.URL)

Example 37 with ResourcePatternResolver

use of org.springframework.core.io.support.ResourcePatternResolver in project spring-boot by spring-projects.

the class SpringPackageScanClassResolver method scan.

private Resource[] scan(ClassLoader loader, String packageName) throws IOException {
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(loader);
    String pattern = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + ClassUtils.convertClassNameToResourcePath(packageName) + "/**/*.class";
    Resource[] resources = resolver.getResources(pattern);
    return resources;
}
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 38 with ResourcePatternResolver

use of org.springframework.core.io.support.ResourcePatternResolver in project jaffa-framework by jaffa-projects.

the class ConfigApiHelper method registerResources.

/**
 * Register configuration files in IManager implementationss, based on the source of the method call
 * @param file  The configuration file to be registered or unregistered
 * @return  Success or failure of the operation
 */
public static boolean registerResources(File file, FileContentsHelper fileContents) {
    boolean isSuccess = true;
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    for (IManager manager : ManagerRepositoryService.getInstance().getManagerMap().values()) {
        Resource resource = getMetaInfResource(file, resolver, manager);
        try {
            if (resource.getFile().exists()) {
                if (manager instanceof RoleManager) {
                    PolicyManager.clearCache();
                }
                manager.registerResource(resource, fileContents.getContextSalience(), fileContents.getVariationSalience());
                ManagerRepositoryService.getInstance().add(manager.getClass().getSimpleName(), manager);
                log.debug(resource.getFilename() + " was successfully registered to " + manager);
            }
        } catch (Exception e) {
            isSuccess = false;
            log.error("The resource " + resource.getFilename() + " failed to register", e);
        }
    }
    return isSuccess;
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) IManager(org.jaffa.loader.IManager) RoleManager(org.jaffa.loader.policy.RoleManager) Resource(org.springframework.core.io.Resource) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver)

Example 39 with ResourcePatternResolver

use of org.springframework.core.io.support.ResourcePatternResolver in project commons-dao by reportportal.

the class CriteriaMapFactory method findNeededTypes.

/**
 * Find Classes into specified package
 */
private List<Class<?>> findNeededTypes(String basePackage) {
    ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
    MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resourcePatternResolver);
    List<Class<?>> candidates = new LinkedList<>();
    try {
        String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + resolveBasePackage(basePackage) + "/" + "**/*.class";
        Resource[] resources = resourcePatternResolver.getResources(packageSearchPath);
        for (Resource resource : resources) {
            if (resource.isReadable()) {
                MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource);
                if (isCandidate(metadataReader)) {
                    candidates.add(Class.forName(metadataReader.getClassMetadata().getClassName()));
                }
            }
        }
        return candidates;
    } catch (Exception e) {
        throw new IllegalArgumentException("Unable to scan base package '" + basePackage + "'", e);
    }
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) CachingMetadataReaderFactory(org.springframework.core.type.classreading.CachingMetadataReaderFactory) MetadataReaderFactory(org.springframework.core.type.classreading.MetadataReaderFactory) Resource(org.springframework.core.io.Resource) MetadataReader(org.springframework.core.type.classreading.MetadataReader) CachingMetadataReaderFactory(org.springframework.core.type.classreading.CachingMetadataReaderFactory) LinkedList(java.util.LinkedList) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver)

Example 40 with ResourcePatternResolver

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

the class SchemaLoader method getSchema.

private Resource getSchema(String schemaName) throws IOException {
    if (schemaName.contains("/")) {
        schemaName = schemaName.substring(schemaName.lastIndexOf('/'));
    }
    ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
    String searchPattern = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + "/**/" + schemaName;
    Resource[] resources = resourcePatternResolver.getResources(searchPattern);
    if ((resources == null) || (resources.length == 0)) {
        throw new RuntimeException("Could not find schema [" + schemaName + "]");
    }
    return resources[0];
}
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)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