Search in sources :

Example 71 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project entando-core by entando.

the class ComponentLoader method loadComponent.

private void loadComponent(String locationPattern, Map<String, String> postProcessClasses) throws Throwable {
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    Resource[] resources = resolver.getResources(locationPattern);
    ComponentDefDOM dom = null;
    Set<String> codes = new HashSet<String>();
    for (int i = 0; i < resources.length; i++) {
        Resource resource = resources[i];
        InputStream is = null;
        String path = resource.getURL().getPath();
        try {
            is = resource.getInputStream();
            String xml = FileTextReader.getText(is);
            dom = new ComponentDefDOM(xml, path);
            Component component = dom.getComponent(postProcessClasses);
            if (null != component) {
                if (codes.add(component.getCode())) {
                    _logger.debug("Component '{}' loaded", component.getCode());
                    this.getComponents().put(component.getCode(), component);
                } else {
                    _logger.debug("Component '{}' already loaded", component.getCode());
                }
            }
        } catch (Throwable t) {
            _logger.error("Error loading Component definition by location Pattern '{}'", path, t);
        } finally {
            if (null != is) {
                is.close();
            }
        }
    }
}
Also used : InputStream(java.io.InputStream) Resource(org.springframework.core.io.Resource) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) Component(org.entando.entando.aps.system.init.model.Component) HashSet(java.util.HashSet)

Example 72 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project entando-core by entando.

the class TestLabelsProperties method testLabelsTranslations.

protected void testLabelsTranslations(String propertiesFolder, String properties1, String properties2) throws Throwable {
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    Resource[] resources1 = resolver.getResources(propertiesFolder + properties1);
    Resource[] resources2 = resolver.getResources(propertiesFolder + properties2);
    Properties props1 = new Properties();
    Properties props2 = new Properties();
    props1.load(resources1[0].getInputStream());
    props2.load(resources2[0].getInputStream());
    Set<String> stringPropertyNames1 = props1.stringPropertyNames();
    Set<String> stringPropertyNames2 = props2.stringPropertyNames();
    stringPropertyNames1.removeAll(stringPropertyNames2);
    stringPropertyNames1.forEach((v) -> {
        logger.error("{}{} -> found error for the key {} check this or {} file to fix this error", propertiesFolder, properties1, v, properties2);
    });
    assertEquals(0, stringPropertyNames1.size());
    stringPropertyNames1 = props1.stringPropertyNames();
    stringPropertyNames2 = props2.stringPropertyNames();
    stringPropertyNames2.removeAll(stringPropertyNames1);
    stringPropertyNames2.forEach((v) -> {
        logger.error("{}{} found error for the key {} check this or {} file to fix this error", propertiesFolder, properties2, v, properties1);
    });
    assertEquals(0, stringPropertyNames2.size());
}
Also used : Resource(org.springframework.core.io.Resource) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) Properties(java.util.Properties)

Example 73 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project webofneeds by researchstudio-sat.

the class TensorEntryAllGenerator method generateTensorEntries.

@Override
public Collection<TensorEntry> generateTensorEntries() throws IOException {
    Collection<TensorEntry> tensorEntries = new LinkedList<>();
    Collection<TensorEntrySparqlGenerator> queryGenerators = new LinkedList<>();
    // read all sparql queries from target directory and configure them with
    // variable bindings
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    Resource[] resources = resolver.getResources("classpath:" + queryDirectory + "/*.rq");
    for (Resource resource : resources) {
        String query = readFromInputStream(resource.getInputStream());
        TensorEntrySparqlGenerator queryGen = new TensorEntrySparqlGenerator(sparqlEndpoint, query);
        queryGen.addVariableBinding("from", Long.valueOf(from));
        queryGen.addVariableBinding("to", Long.valueOf(to));
        queryGenerators.add(queryGen);
    }
    // execute all sparql query generators
    for (TensorEntrySparqlGenerator queryGen : queryGenerators) {
        tensorEntries.addAll(queryGen.generateTensorEntries());
    }
    return tensorEntries;
}
Also used : Resource(org.springframework.core.io.Resource) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) LinkedList(java.util.LinkedList)

Example 74 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project webofneeds by researchstudio-sat.

the class BaseValidator method loadSparqlValidatorsFromDirectories.

protected void loadSparqlValidatorsFromDirectories(String[] dirs) {
    Map<String, List<WonSparqlValidator>> validatorsPerDir = new HashMap<>();
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    for (String dir : dirs) {
        try {
            List validators = ValidationUtils.loadResources(resolver, dir);
            validatorsPerDir.put(dir, Collections.unmodifiableList(validators));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    this.dirToValidator = Collections.unmodifiableMap(validatorsPerDir);
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) List(java.util.List) IOException(java.io.IOException) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver)

Example 75 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver 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)

Aggregations

PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)135 Resource (org.springframework.core.io.Resource)86 ResourcePatternResolver (org.springframework.core.io.support.ResourcePatternResolver)53 IOException (java.io.IOException)37 Bean (org.springframework.context.annotation.Bean)30 SqlSessionFactoryBean (org.mybatis.spring.SqlSessionFactoryBean)29 ArrayList (java.util.ArrayList)16 Properties (java.util.Properties)14 ClassPathResource (org.springframework.core.io.ClassPathResource)14 File (java.io.File)13 InputStream (java.io.InputStream)12 Test (org.junit.jupiter.api.Test)12 JndiDataSourceLookup (org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup)11 PageHelper (com.github.pagehelper.PageHelper)10 PersistenceUnitInfo (jakarta.persistence.spi.PersistenceUnitInfo)10 Primary (org.springframework.context.annotation.Primary)9 CachingMetadataReaderFactory (org.springframework.core.type.classreading.CachingMetadataReaderFactory)9 MetadataReader (org.springframework.core.type.classreading.MetadataReader)9 MetadataReaderFactory (org.springframework.core.type.classreading.MetadataReaderFactory)7 URL (java.net.URL)6