use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project OpenClinica by OpenClinica.
the class QueryStore method init.
public void init() {
String dbFolder = resolveDbFolder();
PathMatchingResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver(resourceLoader);
try {
Resource[] resources = resourceResolver.getResources("classpath:queries/" + dbFolder + "/**/*.properties");
for (Resource r : resources) {
Properties p = new Properties();
p.load(r.getInputStream());
fileByName.put(StringUtils.substringBeforeLast(r.getFilename(), "."), p);
}
} catch (IOException e) {
throw new BeanInitializationException("Unable to read files from directory 'classpath:queries/" + dbFolder + "'", e);
}
}
use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project ORCID-Source by ORCID.
the class TestXmlValidity method testAllOrcidMessages.
@Test
public void testAllOrcidMessages() throws IOException {
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource[] resources = resolver.getResources("classpath*:**/*message-latest.xml");
for (Resource resource : resources) {
LOG.info("Found resource: {}", resource);
InputStream is = null;
try {
is = resource.getInputStream();
OrcidMessage message = (OrcidMessage) unmarshaller.unmarshal(is);
validationManager = getValidationManager(message.getMessageVersion());
validationManager.validateMessage(message);
} catch (IOException e) {
Assert.fail("Unable to read resource: " + resource + "\n" + e);
} catch (JAXBException e) {
Assert.fail("ORCID message is not well formed: " + resource + "\n" + e);
} catch (OrcidValidationException e) {
Assert.fail("Validation failed: " + resource + "\n" + e.getCause());
} finally {
IOUtils.closeQuietly(is);
}
}
}
use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project OpenClinica by OpenClinica.
the class CoreResources method copyBaseToDest.
private void copyBaseToDest(ResourceLoader resourceLoader) {
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(resourceLoader);
Resource[] resources;
try {
/*
* Use classpath* to search for resources that match this pattern in ALL of the jars in the application
* class path. See:
* http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/resources
* .html#resources-classpath-wildcards
*/
resources = resolver.getResources("classpath*:properties/xslt/*.xsl");
} catch (IOException ioe) {
logger.debug(ioe.getMessage(), ioe);
throw new OpenClinicaSystemException("Unable to read source files", ioe);
}
File dest = new File(getField("filePath") + "xslt");
if (!dest.exists()) {
if (!dest.mkdirs()) {
throw new OpenClinicaSystemException("Copying files, Could not create direcotry: " + dest.getAbsolutePath() + ".");
}
}
for (Resource r : resources) {
File f = new File(dest, r.getFilename());
try {
FileOutputStream out = new FileOutputStream(f);
IOUtils.copy(r.getInputStream(), out);
out.close();
} catch (IOException ioe) {
logger.debug(ioe.getMessage(), ioe);
throw new OpenClinicaSystemException("Unable to copy file: " + r.getFilename() + " to " + f.getAbsolutePath(), ioe);
}
}
}
use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project Asqatasun by Asqatasun.
the class LanguageDetector method initProfiles.
/**
* Initialise the language profiles needed by the detector. This
* initialisation has to be performed only once.
*/
private void initProfiles() {
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
List<String> profiles = new ArrayList<>();
DetectorFactory.setSeed(0L);
try {
for (Resource rs : resolver.getResources(profilePath)) {
StringWriter writer = new StringWriter();
IOUtils.copy(rs.getInputStream(), writer);
profiles.add(writer.toString());
}
DetectorFactory.loadProfile(profiles);
} catch (IOException | LangDetectException ex) {
LOGGER.warn(ex);
}
}
Aggregations