log4j.logger.org.springframework=WARN
#log4j.logger.org.springframework.web=DEBUG
#log4j.logger.org.springframework.jms=WARN
-#log4j.logger.org.springframework.security=WARN
+#log4j.logger.org.springframework.security=TRACE
+#log4j.logger.org.springframework.ldap=TRACE
#log4j.logger.org.springframework.osgi.web=TRACE
log4j.logger.org.apache.activemq=WARN
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.argeo.slc</groupId>
org.dbunit.dataset.xml;resolution:="optional",
org.dbunit.operation;resolution:="optional",
junit.framework;resolution:="optional",
+ org.apache.commons.vfs.*
</Import-Package>
</instructions>
</configuration>
<artifactId>com.springsource.org.tmatesoft.svn</artifactId>
</dependency>
+ <!-- Commons VFS -->
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>com.springsource.org.apache.commons.vfs</artifactId>
+ </dependency>
+
<!-- TODO: check if necessary here -->
<dependency>
<groupId>org.springframework</groupId>
--- /dev/null
+package org.argeo.slc.vfs;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import org.apache.commons.io.IOExceptionWithCause;
+import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.FileSystemException;
+import org.apache.commons.vfs.NameScope;
+import org.argeo.slc.SlcException;
+import org.springframework.core.io.Resource;
+
+public class VfsResource implements Resource {
+ private FileObject fileObject;
+
+ public VfsResource(FileObject fileObject) {
+ this.fileObject = fileObject;
+ }
+
+ public Resource createRelative(String relativePath) throws IOException {
+ return new VfsResource(fileObject.resolveFile(relativePath,
+ NameScope.DESCENDENT_OR_SELF));
+ }
+
+ public boolean exists() {
+ try {
+ return fileObject.exists();
+ } catch (FileSystemException e) {
+ throw new SlcException("Cannot find out whether " + fileObject
+ + " exists", e);
+ }
+ }
+
+ public String getDescription() {
+ return "VFS resource " + fileObject;
+ }
+
+ public File getFile() throws IOException {
+ throw new IOException("Cannot access " + getDescription()
+ + " as a local file");
+ // TODO: access local files
+ // if(fileObject instanceof LocalFile){
+ // ((LocalFile)fileObject).
+ // }
+ // return null;
+ }
+
+ public String getFilename() {
+ return fileObject.getName().getBaseName();
+ }
+
+ public URI getURI() throws IOException {
+ try {
+ return new URI(fileObject.getName().getURI());
+ } catch (URISyntaxException e) {
+ throw new IOExceptionWithCause(e);
+ }
+ }
+
+ public URL getURL() throws IOException {
+ return fileObject.getURL();
+ }
+
+ public boolean isOpen() {
+ return fileObject.isContentOpen();
+ }
+
+ public boolean isReadable() {
+ try {
+ return fileObject.isReadable();
+ } catch (FileSystemException e) {
+ throw new SlcException("Cannot find out whether " + fileObject
+ + " is readable", e);
+ }
+ }
+
+ public long lastModified() throws IOException {
+ return fileObject.getContent().getLastModifiedTime();
+ }
+
+ public InputStream getInputStream() throws IOException {
+ return fileObject.getContent().getInputStream();
+ }
+
+ public FileObject getFileObject() {
+ return fileObject;
+ }
+
+}
--- /dev/null
+package org.argeo.slc.vfs;
+
+import org.apache.commons.vfs.CacheStrategy;
+import org.apache.commons.vfs.FileSystemManager;
+import org.apache.commons.vfs.impl.StandardFileSystemManager;
+import org.springframework.beans.factory.FactoryBean;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.core.io.Resource;
+
+public class VfsResourceFactory implements FactoryBean, InitializingBean {
+ private String url;
+ private FileSystemManager fileSystemManager;
+
+ public Object getObject() throws Exception {
+ return new VfsResource(fileSystemManager.resolveFile(url));
+ }
+
+ public Class<?> getObjectType() {
+ return Resource.class;
+ }
+
+ public boolean isSingleton() {
+ return false;
+ }
+
+ public void afterPropertiesSet() throws Exception {
+ if (fileSystemManager == null) {
+ fileSystemManager = new StandardFileSystemManager();
+ ((StandardFileSystemManager) fileSystemManager)
+ .setCacheStrategy(CacheStrategy.ON_RESOLVE);
+ ((StandardFileSystemManager) fileSystemManager).init();
+ }
+
+ }
+
+}
--- /dev/null
+package org.argeo.slc.vfs;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.FileSystemException;
+import org.apache.commons.vfs.FileSystemManager;
+import org.apache.commons.vfs.VFS;
+import org.argeo.slc.SlcException;
+import org.argeo.slc.core.deploy.ResourceSet;
+import org.springframework.core.io.Resource;
+
+public class VfsResourceSet implements ResourceSet {
+ private String base;
+
+ public Map<String, Resource> listResources() {
+ try {
+ FileSystemManager fileSystemManager = VFS.getManager();
+ FileObject fileObject = fileSystemManager.resolveFile(base);
+ Map<String, Resource> map = new HashMap<String, Resource>();
+ addToMap(map, "", fileObject);
+
+ // TODO: add filters
+ return map;
+ } catch (FileSystemException e) {
+ throw new SlcException("Cannot list VFS resources from " + base, e);
+ }
+ }
+
+ /** recursive */
+ protected void addToMap(Map<String, Resource> map, String parentPath,
+ FileObject fileObject) {
+ try {
+ String newParentPath = parentPath
+ + fileObject.getName().getBaseName() + '/';
+ if (fileObject.getType().hasChildren()) {
+ for (FileObject child : fileObject.getChildren()) {
+ addToMap(map, newParentPath, child);
+ }
+ } else {
+ map.put(parentPath + fileObject.getName().getBaseName(),
+ new VfsResource(fileObject));
+ }
+ } catch (FileSystemException e) {
+ throw new SlcException("Cannot add children from " + parentPath, e);
+ }
+ }
+
+ public void setBase(String base) {
+ this.base = base;
+ }
+
+}