Search in sources :

Example 66 with ResourcePatternResolver

use of org.springframework.core.io.support.ResourcePatternResolver in project OsmAnd-tools by osmandapp.

the class OsmAndMapsService method validateAndInitConfig.

public boolean validateAndInitConfig() throws IOException {
    if (nativelib == null && config.initErrorMessage == null) {
        synchronized (this) {
            if (!(nativelib == null && config.initErrorMessage == null)) {
                return config.initErrorMessage == null;
            }
            if (config.obfLocation == null || config.obfLocation.isEmpty()) {
                config.initErrorMessage = "Files location is not specified";
            } else {
                File obfLocationF = new File(config.obfLocation);
                if (!obfLocationF.exists()) {
                    config.initErrorMessage = "Files location is not specified";
                }
            }
            tempDir = Files.createTempDirectory("osmandserver").toFile();
            LOGGER.info("Init temp rendering directory for libs / fonts: " + tempDir.getAbsolutePath());
            tempDir.deleteOnExit();
            ClassLoader cl = NativeJavaRendering.class.getClassLoader();
            ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(cl);
            Resource[] resources = resolver.getResources("classpath:/map/fonts/*.ttf");
            File fontsFolder = new File(tempDir, "fonts");
            fontsFolder.mkdirs();
            fontsFolder.deleteOnExit();
            for (Resource resource : resources) {
                InputStream ios = resource.getInputStream();
                File file = new File(fontsFolder, resource.getFilename());
                file.deleteOnExit();
                FileOutputStream fous = new FileOutputStream(file);
                Algorithms.streamCopy(ios, fous);
                fous.close();
                ios.close();
            }
            nativelib = NativeJavaRendering.getDefault(null, config.obfLocation, fontsFolder.getAbsolutePath());
            if (nativelib == null) {
                config.initErrorMessage = "Tile rendering engine is not initialized";
            }
        }
    }
    return config.initErrorMessage == null;
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) Resource(org.springframework.core.io.Resource) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) RandomAccessFile(java.io.RandomAccessFile) GPXFile(net.osmand.GPXUtilities.GPXFile) File(java.io.File)

Example 67 with ResourcePatternResolver

use of org.springframework.core.io.support.ResourcePatternResolver in project alfresco-repository by Alfresco.

the class SystemTemplateLocationsConstraint method loadClasspathTemplates.

private List<String> loadClasspathTemplates(String templatesParentClasspath, String... extensions) throws IOException {
    List<String> result = new ArrayList<String>(5);
    List<String> files = new ArrayList<String>(5);
    ClassLoader cl = this.getClass().getClassLoader();
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(cl);
    Resource[] resources = resolver.getResources("classpath*:" + templatesParentClasspath + "/*");
    for (Resource resource : resources) {
        files.add(resource.getFilename());
    }
    if (extensions != null && extensions.length > 0) {
        String extensionStr = "";
        for (int i = 0; i < extensions.length; i++) {
            if (i == extensions.length - 1) {
                extensionStr += extensions[i];
            } else {
                extensionStr += extensions[i] + "|";
            }
        }
        String fileExtensions = "(?i).*\\.(" + extensionStr + ")$";
        Pattern pattern = Pattern.compile(fileExtensions);
        for (String file : files) {
            if (pattern.matcher(file).matches()) {
                result.add("C" + templatesParentClasspath + "/" + file);
            }
        }
    }
    return result;
}
Also used : Pattern(java.util.regex.Pattern) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) ArrayList(java.util.ArrayList) Resource(org.springframework.core.io.Resource) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ListOfValuesConstraint(org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint)

Example 68 with ResourcePatternResolver

use of org.springframework.core.io.support.ResourcePatternResolver in project alfresco-repository by Alfresco.

the class AlfrescoEnviroment method exists.

@Override
public boolean exists(String classpath) {
    ClassLoader cl = this.getClass().getClassLoader();
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(cl);
    Resource resource = resolver.getResource("classpath:" + classpath);
    return resource.exists();
}
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