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