use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project entando-core by entando.
the class ComponentLoader method loadComponent.
private void loadComponent(String locationPattern, Map<String, String> postProcessClasses) throws Throwable {
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource[] resources = resolver.getResources(locationPattern);
ComponentDefDOM dom = null;
Set<String> codes = new HashSet<String>();
for (int i = 0; i < resources.length; i++) {
Resource resource = resources[i];
InputStream is = null;
String path = resource.getURL().getPath();
try {
is = resource.getInputStream();
String xml = FileTextReader.getText(is);
dom = new ComponentDefDOM(xml, path);
Component component = dom.getComponent(postProcessClasses);
if (null != component) {
if (codes.add(component.getCode())) {
_logger.debug("Component '{}' loaded", component.getCode());
this.getComponents().put(component.getCode(), component);
} else {
_logger.debug("Component '{}' already loaded", component.getCode());
}
}
} catch (Throwable t) {
_logger.error("Error loading Component definition by location Pattern '{}'", path, t);
} finally {
if (null != is) {
is.close();
}
}
}
}
use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project entando-core by entando.
the class TestLabelsProperties method testLabelsTranslations.
protected void testLabelsTranslations(String propertiesFolder, String properties1, String properties2) throws Throwable {
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource[] resources1 = resolver.getResources(propertiesFolder + properties1);
Resource[] resources2 = resolver.getResources(propertiesFolder + properties2);
Properties props1 = new Properties();
Properties props2 = new Properties();
props1.load(resources1[0].getInputStream());
props2.load(resources2[0].getInputStream());
Set<String> stringPropertyNames1 = props1.stringPropertyNames();
Set<String> stringPropertyNames2 = props2.stringPropertyNames();
stringPropertyNames1.removeAll(stringPropertyNames2);
stringPropertyNames1.forEach((v) -> {
logger.error("{}{} -> found error for the key {} check this or {} file to fix this error", propertiesFolder, properties1, v, properties2);
});
assertEquals(0, stringPropertyNames1.size());
stringPropertyNames1 = props1.stringPropertyNames();
stringPropertyNames2 = props2.stringPropertyNames();
stringPropertyNames2.removeAll(stringPropertyNames1);
stringPropertyNames2.forEach((v) -> {
logger.error("{}{} found error for the key {} check this or {} file to fix this error", propertiesFolder, properties2, v, properties1);
});
assertEquals(0, stringPropertyNames2.size());
}
use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project webofneeds by researchstudio-sat.
the class TensorEntryAllGenerator method generateTensorEntries.
@Override
public Collection<TensorEntry> generateTensorEntries() throws IOException {
Collection<TensorEntry> tensorEntries = new LinkedList<>();
Collection<TensorEntrySparqlGenerator> queryGenerators = new LinkedList<>();
// read all sparql queries from target directory and configure them with
// variable bindings
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource[] resources = resolver.getResources("classpath:" + queryDirectory + "/*.rq");
for (Resource resource : resources) {
String query = readFromInputStream(resource.getInputStream());
TensorEntrySparqlGenerator queryGen = new TensorEntrySparqlGenerator(sparqlEndpoint, query);
queryGen.addVariableBinding("from", Long.valueOf(from));
queryGen.addVariableBinding("to", Long.valueOf(to));
queryGenerators.add(queryGen);
}
// execute all sparql query generators
for (TensorEntrySparqlGenerator queryGen : queryGenerators) {
tensorEntries.addAll(queryGen.generateTensorEntries());
}
return tensorEntries;
}
use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project webofneeds by researchstudio-sat.
the class BaseValidator method loadSparqlValidatorsFromDirectories.
protected void loadSparqlValidatorsFromDirectories(String[] dirs) {
Map<String, List<WonSparqlValidator>> validatorsPerDir = new HashMap<>();
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
for (String dir : dirs) {
try {
List validators = ValidationUtils.loadResources(resolver, dir);
validatorsPerDir.put(dir, Collections.unmodifiableList(validators));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
this.dirToValidator = Collections.unmodifiableMap(validatorsPerDir);
}
use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project head by mifos.
the class MifosViewerServletContextListener method copyFromClassPathToDirectory.
private void copyFromClassPathToDirectory(String directoryToScan, File rootDirectory) throws IOException {
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource[] resources = resolver.getResources(LOCATION_PATTERN);
LOGGER.info("Found " + resources.length + " Resources on " + LOCATION_PATTERN);
for (Resource resource : resources) {
if (resource.exists() & resource.isReadable() && resource.contentLength() > 0) {
URL url = resource.getURL();
String urlString = url.toExternalForm();
String targetName = urlString.substring(urlString.indexOf(directoryToScan));
File destination = new File(rootDirectory, targetName);
FileUtils.copyURLToFile(url, destination);
LOGGER.info("Copied " + url + " to " + destination.getAbsolutePath());
} else {
LOGGER.debug("Did not copy, seems to be directory: " + resource.getDescription());
}
}
}
Aggregations