Search in sources :

Example 16 with ResourcePatternResolver

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

the class BlueprintSegmentReader method getFiles.

private List<Resource> getFiles(String configDir) throws IOException {
    ResourcePatternResolver patternResolver = new PathMatchingResourcePatternResolver();
    List<Resource> handleBarFiles = Arrays.stream(patternResolver.getResources("classpath:" + configDir + "/*/*.handlebars")).collect(toList());
    List<Resource> jsonFiles = Arrays.stream(patternResolver.getResources("classpath:" + configDir + "/*/*.json")).collect(toList());
    List<Resource> resources = new ArrayList<>();
    resources.addAll(handleBarFiles);
    resources.addAll(jsonFiles);
    return resources;
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) Resource(org.springframework.core.io.Resource) ArrayList(java.util.ArrayList) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver)

Example 17 with ResourcePatternResolver

use of org.springframework.core.io.support.ResourcePatternResolver in project onebusaway-application-modules by camsys.

the class ResourceServiceImpl method getCollectionResourceAsSourceUrl.

private URL getCollectionResourceAsSourceUrl(String resourceName, LocaleProvider localeProvider) {
    int index = resourceName.indexOf('=');
    if (index == -1)
        throw new IllegalStateException("invalid resource collection specifier: " + resourceName);
    String collectionPrefix = resourceName.substring(0, index);
    String collectionResourcePath = resourceName.substring(index + 1);
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    Map<String, String> resourceMapping = new HashMap<String, String>();
    try {
        org.springframework.core.io.Resource[] resources = resolver.getResources(collectionResourcePath);
        for (org.springframework.core.io.Resource resource : resources) {
            URL url = resource.getURL();
            String name = getLocalUrlAsResourceName(url);
            Resource r = getResourceForPath(name, localeProvider, url);
            if (r != null) {
                String path = url.getPath();
                int sepIndex = path.lastIndexOf(File.separator);
                if (sepIndex != -1)
                    path = path.substring(sepIndex + 1);
                resourceMapping.put(path, r.getExternalUrl());
                String alternateId = PREFIX_COLLECTION_ENTRY + collectionPrefix + ":" + path;
                _resourceEntriesByResourcePath.put(alternateId, r);
            }
        }
        File file = getOutputFile(PREFIX_COLLECTION + collectionPrefix + ".js");
        PrintWriter out = new PrintWriter(file);
        JSONObject obj = new JSONObject(resourceMapping);
        out.println("var OBA = window.OBA || {};");
        out.println("if(!OBA.Resources) { OBA.Resources = {}; }");
        out.println("OBA.Resources." + collectionPrefix + " = " + obj.toString() + ";");
        out.close();
        return getFileAsUrl(file);
    } catch (IOException ex) {
        throw new IllegalStateException("error loading resources", ex);
    }
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Resource(org.onebusaway.presentation.services.resources.Resource) IOException(java.io.IOException) URL(java.net.URL) JSONObject(org.json.JSONObject) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 18 with ResourcePatternResolver

use of org.springframework.core.io.support.ResourcePatternResolver in project jim-framework by jiangmin168168.

the class MyBatisConfig method sqlSessionFactoryBean.

@Bean(name = "sqlSessionFactory")
public SqlSessionFactory sqlSessionFactoryBean() {
    SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
    bean.setDataSource(dataSource);
    bean.setTypeAliasesPackage("com.jim.dao.generated.entity");
    // 分页插件
    PageHelper pageHelper = new PageHelper();
    Properties properties = new Properties();
    properties.setProperty("dialect", "postgresql");
    properties.setProperty("reasonable", "true");
    properties.setProperty("supportMethodsArguments", "true");
    properties.setProperty("returnPageInfo", "check");
    properties.setProperty("params", "count=countSql");
    pageHelper.setProperties(properties);
    // 添加插件
    bean.setPlugins(new Interceptor[] { pageHelper });
    // 添加XML目录
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    try {
        bean.setMapperLocations(resolver.getResources("classpath:mapper/*.xml"));
        return bean.getObject();
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
Also used : PageHelper(com.github.pagehelper.PageHelper) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) Properties(java.util.Properties) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 19 with ResourcePatternResolver

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

the class AppConfig method init.

@PostConstruct
public void init() throws IOException {
    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
    ResourcePatternResolver patternResolver = new PathMatchingResourcePatternResolver();
    PropertySourceLoader load = new YamlPropertySourceLoader();
    for (Resource resource : patternResolver.getResources("classpath*:*-images.yml")) {
        environment.getPropertySources().addLast(load.load(resource.getFilename(), resource, null));
    }
    for (Resource resource : loadEtcResources()) {
        environment.getPropertySources().addFirst(load.load(resource.getFilename(), resource, null));
    }
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) PropertySourceLoader(org.springframework.boot.env.PropertySourceLoader) YamlPropertySourceLoader(org.springframework.boot.env.YamlPropertySourceLoader) Resource(org.springframework.core.io.Resource) YamlPropertySourceLoader(org.springframework.boot.env.YamlPropertySourceLoader) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) PostConstruct(javax.annotation.PostConstruct)

Example 20 with ResourcePatternResolver

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

the class SaltOrchestrator method getStateConfigZip.

@Override
public byte[] getStateConfigZip() throws IOException {
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
        try (ZipOutputStream zout = new ZipOutputStream(baos)) {
            ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
            Map<String, List<Resource>> structure = new TreeMap<>();
            for (Resource resource : resolver.getResources("classpath*:salt/**")) {
                String path = resource.getURL().getPath();
                String dir = path.substring(path.indexOf("/salt") + "/salt".length(), path.lastIndexOf('/') + 1);
                List<Resource> list = structure.get(dir);
                if (list == null) {
                    list = new ArrayList<>();
                }
                structure.put(dir, list);
                if (!path.endsWith("/")) {
                    list.add(resource);
                }
            }
            for (Entry<String, List<Resource>> entry : structure.entrySet()) {
                zout.putNextEntry(new ZipEntry(entry.getKey()));
                for (Resource resource : entry.getValue()) {
                    LOGGER.debug("Zip salt entry: {}", resource.getFilename());
                    zout.putNextEntry(new ZipEntry(entry.getKey() + resource.getFilename()));
                    InputStream inputStream = resource.getInputStream();
                    byte[] bytes = IOUtils.toByteArray(inputStream);
                    zout.write(bytes);
                    zout.closeEntry();
                }
            }
        } catch (IOException e) {
            LOGGER.error("Failed to zip salt configurations", e);
            throw new IOException("Failed to zip salt configurations", e);
        }
        return baos.toByteArray();
    }
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) Resource(org.springframework.core.io.Resource) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) TreeMap(java.util.TreeMap) ZipOutputStream(java.util.zip.ZipOutputStream) List(java.util.List) ArrayList(java.util.ArrayList) 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