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());
}
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) {
}
}
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;
}
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;
}
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);
}
}
Aggregations