use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project OpenClinica by OpenClinica.
the class CoreResources method copyConfig.
private void copyConfig() throws IOException {
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(resourceLoader);
Resource[] resources = null;
FileOutputStream out = null;
Resource resource1 = null;
Resource resource2 = null;
resource1 = resolver.getResource("classpath:datainfo.properties");
resource2 = resolver.getResource("classpath:extract.properties");
String filePath = "$catalina.home/$WEBAPP.lower.config";
filePath = replaceWebapp(filePath);
filePath = replaceCatHome(filePath);
File dest = new File(filePath);
if (!dest.exists()) {
if (!dest.mkdirs()) {
throw new OpenClinicaSystemException("Copying files, Could not create directory: " + dest.getAbsolutePath() + ".");
}
}
File f1 = new File(dest, resource1.getFilename());
File f2 = new File(dest, resource2.getFilename());
if (!f1.exists()) {
out = new FileOutputStream(f1);
IOUtils.copy(resource1.getInputStream(), out);
out.close();
}
if (!f2.exists()) {
out = new FileOutputStream(f2);
IOUtils.copy(resource2.getInputStream(), out);
out.close();
}
/*
*
* for (Resource r: resources) { File f = new File(dest, r.getFilename()); if(!f.exists()){ out = new
* FileOutputStream(f); IOUtils.copy(r.getInputStream(), out); out.close(); } }
*/
}
use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project OpenClinica by OpenClinica.
the class CoreResources method copyImportRulesFiles.
private void copyImportRulesFiles() throws IOException {
ByteArrayInputStream[] listSrcFiles = new ByteArrayInputStream[3];
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(resourceLoader);
String[] fileNames = { "rules.xsd", "rules_template.xml", "rules_template_with_notes.xml" };
Resource[] resources = null;
FileOutputStream out = null;
resources = resolver.getResources("classpath*:properties/rules_template*.xml");
File dest = new File(getField("filePath") + "rules");
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());
out = new FileOutputStream(f);
IOUtils.copy(r.getInputStream(), out);
out.close();
}
Resource[] r1 = resolver.getResources("classpath*:properties/" + fileNames[0]);
File f1 = new File(dest, r1[0].getFilename());
out = new FileOutputStream(f1);
IOUtils.copy(r1[0].getInputStream(), out);
out.close();
}
use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project OpenClinica by OpenClinica.
the class CoreResources method copyODMMappingXMLtoResources.
private void copyODMMappingXMLtoResources(ResourceLoader resourceLoader) {
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(resourceLoader);
String[] fileNames = { "cd_odm_mapping.xml" };
Resource[] resources;
try {
resources = resolver.getResources("classpath*:properties/cd_odm_mapping.xml");
} catch (IOException ioe) {
OpenClinicaSystemException oe = new OpenClinicaSystemException("Unable to read source files");
oe.initCause(ioe);
oe.setStackTrace(ioe.getStackTrace());
logger.debug(ioe.getMessage());
throw oe;
}
File dest = null;
try {
dest = new File(getField("filePath"));
if (!dest.exists()) {
if (!dest.mkdirs()) {
throw new OpenClinicaSystemException("Copying files, Could not create direcotry: " + dest.getAbsolutePath() + ".");
}
}
File f = new File(dest, resources[0].getFilename());
FileOutputStream out = new FileOutputStream(f);
IOUtils.copy(resources[0].getInputStream(), out);
out.close();
} catch (IOException ioe) {
OpenClinicaSystemException oe = new OpenClinicaSystemException("Unable to get web app base path");
oe.initCause(ioe);
oe.setStackTrace(ioe.getStackTrace());
throw oe;
}
}
use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project midpoint by Evolveum.
the class ActivitiEngine method autoDeploy.
private void autoDeploy() {
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
String[] autoDeploymentFrom = wfConfiguration.getAutoDeploymentFrom();
for (String adf : autoDeploymentFrom) {
Resource[] resources;
try {
resources = resolver.getResources(adf);
} catch (IOException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't get resources to be automatically deployed from " + adf, e);
continue;
}
LOGGER.info("Auto deployment from " + adf + " yields " + resources.length + " resource(s)");
for (Resource resource : resources) {
try {
autoDeployResource(resource);
} catch (IOException | XPathExpressionException | RuntimeException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't deploy the resource " + resource, e);
}
}
}
}
use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project grails-core by grails.
the class ClosureClassIgnoringComponentScanBeanDefinitionParser method configureScanner.
@Override
protected ClassPathBeanDefinitionScanner configureScanner(ParserContext parserContext, Element element) {
final ClassPathBeanDefinitionScanner scanner = super.configureScanner(parserContext, element);
final ResourceLoader originalResourceLoader = parserContext.getReaderContext().getResourceLoader();
if (LOG.isDebugEnabled()) {
LOG.debug("Scanning only this classloader:" + originalResourceLoader.getClassLoader());
}
ResourceLoader parentOnlyResourceLoader;
try {
parentOnlyResourceLoader = new ResourceLoader() {
ClassLoader parentOnlyGetResourcesClassLoader = new ParentOnlyGetResourcesClassLoader(originalResourceLoader.getClassLoader());
public Resource getResource(String location) {
return originalResourceLoader.getResource(location);
}
public ClassLoader getClassLoader() {
return parentOnlyGetResourcesClassLoader;
}
};
} catch (Throwable t) {
// restrictive classloading environment, use the original
parentOnlyResourceLoader = originalResourceLoader;
}
final PathMatchingResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver(parentOnlyResourceLoader) {
@Override
protected Resource[] findAllClassPathResources(String location) throws IOException {
Set<Resource> result = new LinkedHashSet<Resource>(16);
if (BuildSettings.CLASSES_DIR != null) {
@SuppressWarnings("unused") URL classesDir = BuildSettings.CLASSES_DIR.toURI().toURL();
// only scan classes from project classes directory
String path = location;
if (path.startsWith("/")) {
path = path.substring(1);
}
Enumeration<URL> resourceUrls = getClassLoader().getResources(path);
while (resourceUrls.hasMoreElements()) {
URL url = resourceUrls.nextElement();
if (LOG.isDebugEnabled()) {
LOG.debug("Scanning URL " + url.toExternalForm() + " while searching for '" + location + "'");
}
/*
if (!warDeployed && classesDir!= null && url.equals(classesDir)) {
result.add(convertClassLoaderURL(url));
}
else if (warDeployed) {
result.add(convertClassLoaderURL(url));
}
*/
result.add(convertClassLoaderURL(url));
}
}
return result.toArray(new Resource[result.size()]);
}
};
resourceResolver.setPathMatcher(new AntPathMatcher() {
@Override
public boolean match(String pattern, String path) {
if (path.endsWith(".class")) {
String filename = GrailsStringUtils.getFileBasename(path);
if (filename.contains("$"))
return false;
}
return super.match(pattern, path);
}
});
scanner.setResourceLoader(resourceResolver);
return scanner;
}
Aggregations