use of org.springframework.core.io.Resource in project head by mifos.
the class PPISurveyLocatorImpl method getPPIUploadFileForCountry.
@Override
public String getPPIUploadFileForCountry(String country) {
try {
String fileName = getPPIXmlFileName(country);
Resource resource = this.resourceLoader.getResource(resolvePath());
return getPPIFilePath(fileName, resource.getFile());
} catch (IOException e) {
throw new SystemException(FETCH_PPI_COUNTRY_XML_FAILED, e);
}
}
use of org.springframework.core.io.Resource in project head by mifos.
the class MifosResourceUtilTest method testGetResources.
@Test
public void testGetResources() throws IOException {
Resource[] found = MifosResourceUtil.getClassPathResourcesAsResources("org/mifos/core/resources/included/**/*.xml");
assertEquals(2, found.length);
for (Resource resource : found) {
String f = resource.getFilename();
if (!"y.xml".equals(f) && !"z.xml".equals(f)) {
fail(resource + " should not have been returned");
}
}
}
use of org.springframework.core.io.Resource in project head by mifos.
the class ConfigurationLocator method getCustomFilePath.
/**
* Will not throw an exception if the file is not found. This method may be
* used to find files in cases where we don't care if the file cannot be
* found.
* @throws IOException
*/
@SuppressWarnings("PMD")
public // TODO It may be clearer if this returned an URI or URL instead of a String?
String getCustomFilePath(String filename) throws IOException {
String returnValue = filename;
LOGGER.info("Checking existance of : " + filename);
Resource configFile = getResource(filename);
if (configFile != null && configFile.exists()) {
returnValue = configFile.getURL().toExternalForm();
LOGGER.info("Custom configuration file exists : " + returnValue);
}
return returnValue;
}
use of org.springframework.core.io.Resource in project spring-boot by spring-projects.
the class ResourceUtils method getChildFiles.
private static List<String> getChildFiles(Resource resource) throws IOException {
Resource[] children = new PathMatchingResourcePatternResolver().getResources(resource.getURL() + "/**");
List<String> childFiles = new ArrayList<>();
for (Resource child : children) {
if (!child.getFile().isDirectory()) {
childFiles.add(absolutePath(child));
}
}
return childFiles;
}
use of org.springframework.core.io.Resource in project spring-boot by spring-projects.
the class ResourceUtils method getUrlsFromPrefixedWildcardPath.
private static List<String> getUrlsFromPrefixedWildcardPath(String path, ClassLoader classLoader) throws IOException {
Resource[] resources = new PathMatchingResourcePatternResolver(new FileSearchResourceLoader(classLoader)).getResources(path);
List<String> result = new ArrayList<>();
for (Resource resource : resources) {
if (resource.exists()) {
if (resource.getURI().getScheme().equals("file")) {
if (resource.getFile().isDirectory()) {
result.addAll(getChildFiles(resource));
continue;
}
}
result.add(absolutePath(resource));
}
}
return result;
}
Aggregations