use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project disconf by knightliao.
the class ReloadablePropertiesFactoryBean method setLocations.
/**
*/
public void setLocations(List<String> fileNames) {
List<Resource> resources = new ArrayList<Resource>();
for (String filename : fileNames) {
// trim
filename = filename.trim();
String realFileName = getFileName(filename);
//
// register to disconf
//
DisconfMgr.getInstance().reloadableScan(realFileName);
//
// only properties will reload
//
String ext = FilenameUtils.getExtension(filename);
if (ext.equals("properties")) {
PathMatchingResourcePatternResolver pathMatchingResourcePatternResolver = new PathMatchingResourcePatternResolver();
try {
Resource[] resourceList = pathMatchingResourcePatternResolver.getResources(filename);
for (Resource resource : resourceList) {
resources.add(resource);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
this.locations = resources.toArray(new Resource[resources.size()]);
lastModified = new long[locations.length];
super.setLocations(locations);
}
use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project disconf by knightliao.
the class TestAntPathMatcher method ResourceLoaderTest.
@Test
public void ResourceLoaderTest() throws Exception {
/* 资源地址表达式
* classpath:相对于类的根路径,可访问jar或zip中的资源哦
* classpath*:和上面类似,只不过上面是加载找到的第一个资源,这个是全部加载
* file:文件系统目录中加载,可以是绝对,也可以是相对
* http:// 不用多说了吧
* ftp:// 不用多说了吧
*
* ant风格:可以使用通配符
* ?:匹配一个字符
* *:匹配多个字符
* **:匹配多层路径
* */
ResourcePatternResolver rpr = new PathMatchingResourcePatternResolver();
Resource[] rs = rpr.getResources("classpath:testXml.xml");
for (Resource one : rs) {
showResourceInfo(one, true);
}
System.out.println("=============================");
//file:访问文件系统(绝对 和 相对路径方式)
//绝对路径 类似于FileSystemResource
rs = rpr.getResources("file:src/test/resources/res/testXml.xml");
//rs=rpr.getResources("file:src/aop.xml");
for (Resource one : rs) {
showResourceInfo(one, true);
}
System.out.println("=============================");
//http:方式
rs = rpr.getResources("http://www.baidu.com/img/bdlogo.gif");
//为了测试的简便,这里直接取第一个资源
byte[] gifByte = IOUtils.toByteArray(rs[0].getInputStream());
FileUtils.writeByteArrayToFile(new File("tmp/bdlogo1.gif"), gifByte);
}
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());
}
}
}
use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project spring-security by spring-projects.
the class ApacheDSContainer method importLdifs.
private void importLdifs() throws Exception {
// Import any ldif files
Resource[] ldifs;
if (ctxt == null) {
// Not running within an app context
ldifs = new PathMatchingResourcePatternResolver().getResources(ldifResources);
} else {
ldifs = ctxt.getResources(ldifResources);
}
if (ldifs == null || ldifs.length == 0) {
return;
}
if (ldifs.length == 1) {
String ldifFile;
try {
ldifFile = ldifs[0].getFile().getAbsolutePath();
} catch (IOException e) {
ldifFile = ldifs[0].getURI().toString();
}
logger.info("Loading LDIF file: " + ldifFile);
LdifFileLoader loader = new LdifFileLoader(service.getAdminSession(), new File(ldifFile), null, getClass().getClassLoader());
loader.execute();
} else {
throw new IllegalArgumentException("More than one LDIF resource found with the supplied pattern:" + ldifResources + " Got " + Arrays.toString(ldifs));
}
}
use of org.springframework.core.io.support.PathMatchingResourcePatternResolver in project spring-security by spring-projects.
the class PythonInterpreterPreInvocationAdvice method before.
public boolean before(Authentication authentication, MethodInvocation mi, PreInvocationAttribute preAttr) {
PythonInterpreterPreInvocationAttribute pythonAttr = (PythonInterpreterPreInvocationAttribute) preAttr;
String script = pythonAttr.getScript();
PythonInterpreter python = new PythonInterpreter();
python.set("authentication", authentication);
python.set("args", createArgumentMap(mi));
python.set("method", mi.getMethod().getName());
Resource scriptResource = new PathMatchingResourcePatternResolver().getResource(script);
try {
python.execfile(scriptResource.getInputStream());
} catch (IOException e) {
throw new IllegalArgumentException("Couldn't run python script, " + script, e);
}
PyObject allowed = python.get("allow");
if (allowed == null) {
throw new IllegalStateException("Python script did not set the permit flag");
}
return (Boolean) Py.tojava(allowed, Boolean.class);
}
Aggregations