Search in sources :

Example 11 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project spring-framework by spring-projects.

the class PersistenceXmlParsingTests method testExample1.

@Test
public void testExample1() throws Exception {
    PersistenceUnitReader reader = new PersistenceUnitReader(new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup());
    String resource = "/org/springframework/orm/jpa/persistence-example1.xml";
    PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource);
    assertNotNull(info);
    assertEquals(1, info.length);
    assertEquals("OrderManagement", info[0].getPersistenceUnitName());
    assertFalse("Exclude unlisted should default false in 1.0.", info[0].excludeUnlistedClasses());
}
Also used : JndiDataSourceLookup(org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) PersistenceUnitInfo(javax.persistence.spi.PersistenceUnitInfo) Test(org.junit.Test)

Example 12 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project spring-framework by spring-projects.

the class PersistenceXmlParsingTests method testNoSchemaPersistence.

// not doing schema parsing anymore for JPA 2.0 compatibility
@Ignore
@Test
public void testNoSchemaPersistence() throws Exception {
    PersistenceUnitReader reader = new PersistenceUnitReader(new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup());
    String resource = "/org/springframework/orm/jpa/persistence-no-schema.xml";
    try {
        reader.readPersistenceUnitInfos(resource);
        fail("expected invalid document exception");
    } catch (RuntimeException expected) {
    }
}
Also used : JndiDataSourceLookup(org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 13 with PathMatchingResourcePatternResolver

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

the class ResourceMatcher method findInFolder.

private List<MatchedResource> findInFolder(File folder) throws IOException {
    List<MatchedResource> matchedResources = new ArrayList<>();
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(new FolderResourceLoader(folder));
    for (String include : this.includes) {
        for (Resource candidate : resolver.getResources(include)) {
            File file = candidate.getFile();
            if (file.isFile()) {
                MatchedResource matchedResource = new MatchedResource(folder, file);
                if (!isExcluded(matchedResource)) {
                    matchedResources.add(matchedResource);
                }
            }
        }
    }
    return matchedResources;
}
Also used : ArrayList(java.util.ArrayList) FileSystemResource(org.springframework.core.io.FileSystemResource) Resource(org.springframework.core.io.Resource) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) File(java.io.File)

Example 14 with PathMatchingResourcePatternResolver

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

the class BinaryGrailsPlugin method getProperties.

/**
     * Obtains all properties for this binary plugin for the given locale.
     *
     * Note this method does not cache so clients should in general cache the results of this method.
     *
     * @param locale The locale
     * @return The properties or null if non exist
     */
public Properties getProperties(final Locale locale) {
    Resource url = this.baseResourcesResource;
    Properties properties = null;
    if (url != null) {
        StaticResourceLoader resourceLoader = new StaticResourceLoader();
        resourceLoader.setBaseResource(url);
        ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(resourceLoader);
        try {
            // first load all properties
            Resource[] resources = resolver.getResources('*' + PROPERTIES_EXTENSION);
            resources = resources.length > 0 ? filterResources(resources, locale) : resources;
            if (resources.length > 0) {
                properties = new Properties();
                // message bundles are locale specific. The more underscores the locale has the more specific the locale
                // so we order by the number of underscores present so that the most specific appears
                Arrays.sort(resources, new Comparator<Resource>() {

                    @Override
                    public int compare(Resource o1, Resource o2) {
                        String f1 = o1.getFilename();
                        String f2 = o2.getFilename();
                        int firstUnderscoreCount = StringUtils.countOccurrencesOf(f1, "_");
                        int secondUnderscoreCount = StringUtils.countOccurrencesOf(f2, "_");
                        if (firstUnderscoreCount == secondUnderscoreCount) {
                            return 0;
                        } else {
                            return firstUnderscoreCount > secondUnderscoreCount ? 1 : -1;
                        }
                    }
                });
                loadFromResources(properties, resources);
            }
        } catch (IOException e) {
            return null;
        }
    }
    return properties;
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) StaticResourceLoader(org.grails.core.io.StaticResourceLoader) UrlResource(org.springframework.core.io.UrlResource) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver)

Example 15 with PathMatchingResourcePatternResolver

use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project midpoint by Evolveum.

the class MidPointApplication method mountFiles.

private void mountFiles(String path, Class<?> clazz) {
    try {
        List<Resource> list = new ArrayList<>();
        String packagePath = clazz.getPackage().getName().replace('.', '/');
        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        Resource[] res = resolver.getResources("classpath:" + packagePath + "/*.png");
        if (res != null) {
            list.addAll(Arrays.asList(res));
        }
        res = resolver.getResources("classpath:" + packagePath + "/*.gif");
        if (res != null) {
            list.addAll(Arrays.asList(res));
        }
        for (Resource resource : list) {
            URI uri = resource.getURI();
            File file = new File(uri.toString());
            mountResource(path + "/" + file.getName(), new SharedResourceReference(clazz, file.getName()));
        }
    } catch (Exception ex) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't mount files", ex);
    }
}
Also used : SharedResourceReference(org.apache.wicket.request.resource.SharedResourceReference) ArrayList(java.util.ArrayList) Resource(org.springframework.core.io.Resource) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) URI(java.net.URI) File(java.io.File) SchemaException(com.evolveum.midpoint.util.exception.SchemaException)

Aggregations

PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)34 Resource (org.springframework.core.io.Resource)22 Test (org.junit.Test)15 IOException (java.io.IOException)11 JndiDataSourceLookup (org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup)11 PersistenceUnitInfo (javax.persistence.spi.PersistenceUnitInfo)10 File (java.io.File)9 ResourcePatternResolver (org.springframework.core.io.support.ResourcePatternResolver)9 ClassPathResource (org.springframework.core.io.ClassPathResource)7 ArrayList (java.util.ArrayList)6 FileOutputStream (java.io.FileOutputStream)4 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)4 UrlResource (org.springframework.core.io.UrlResource)3 URL (java.net.URL)2 Properties (java.util.Properties)2 DataSource (javax.sql.DataSource)2 Ignore (org.junit.Ignore)2 DriverManagerDataSource (org.springframework.jdbc.datasource.DriverManagerDataSource)2 LangDetectException (com.cybozu.labs.langdetect.LangDetectException)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1