Project

General

Profile

1
package eu.dnetlib.functionality.modular.ui.workflows.values;
2

    
3
import java.io.File;
4
import java.util.List;
5
import java.util.Map;
6

    
7
import org.springframework.core.io.Resource;
8
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
9
import org.springframework.core.io.support.ResourcePatternResolver;
10

    
11
import com.google.common.collect.Lists;
12

    
13
import eu.dnetlib.msro.workflows.util.ValidNodeValuesFetcher;
14

    
15
public class ListFilesValues extends ValidNodeValuesFetcher {
16

    
17
	private final ResourcePatternResolver pathResolver = new PathMatchingResourcePatternResolver();
18

    
19
	@Override
20
	protected List<DnetParamValue> obtainValues(final Map<String, String> params) throws Exception {
21
		verifyParams(params, "path", "ext");
22

    
23
		final String pathTmp = params.get("path");
24

    
25
		final String path = pathTmp.startsWith("/") ? pathTmp : "/" + pathTmp;
26

    
27
		final List<DnetParamValue> values = Lists.newArrayList();
28
		for (Resource r : pathResolver.getResources("classpath*:" + path + "/*." + params.get("ext"))) {
29
			values.add(new DnetParamValue(path + File.separator + r.getFilename(), r.getFilename()));
30
		}
31

    
32
		return values;
33
	}
34

    
35
}
(5-5/10)