]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - cms/org.argeo.slc.support/src/org/argeo/slc/vfs/VfsResourceFactory.java
Clarify SLC project structure.
[gpl/argeo-slc.git] / cms / org.argeo.slc.support / src / org / argeo / slc / vfs / VfsResourceFactory.java
diff --git a/cms/org.argeo.slc.support/src/org/argeo/slc/vfs/VfsResourceFactory.java b/cms/org.argeo.slc.support/src/org/argeo/slc/vfs/VfsResourceFactory.java
new file mode 100644 (file)
index 0000000..ac92adf
--- /dev/null
@@ -0,0 +1,36 @@
+package org.argeo.slc.vfs;
+
+import org.apache.commons.vfs2.CacheStrategy;
+import org.apache.commons.vfs2.FileSystemManager;
+import org.apache.commons.vfs2.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();
+               }
+
+       }
+
+}