com.icthh.xm.commons.lep.impl.utils.ClassPathLepRepository Maven / Gradle / Ivy
package com.icthh.xm.commons.lep.impl.utils;
import com.icthh.xm.commons.lep.api.XmLepConfigFile;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.reflections.Reflections;
import org.reflections.scanners.Scanners;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@RequiredArgsConstructor
public class ClassPathLepRepository {
private final ResourceLoader resourceLoader;
@SneakyThrows
public Map getLepFilesFromResources(String folderName) {
Set defaultLeps = getResourceFiles(folderName);
Map defauleLepsMap = new HashMap<>();
for (String fileName: defaultLeps) {
Resource resource = resourceLoader.getResource("classpath:" + fileName);
String relativePath = fileName.substring(folderName.length());
defauleLepsMap.put(relativePath, new XmLepConfigFile(relativePath, resource));
}
return defauleLepsMap;
}
private Set getResourceFiles(String folderName) {
Reflections reflections = new Reflections("lep", Scanners.Resources);
return reflections.getResources(Pattern.compile(".*")).stream()
.filter(it -> it.startsWith(folderName))
.collect(Collectors.toSet());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy