All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.icthh.xm.commons.lep.impl.utils.ClassPathLepRepository Maven / Gradle / Ivy

There is a newer version: 4.0.21
Show newest version
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