]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/vfs/VfsResourceSet.java
be00ef84873222cd3215ba7d8150b5f03c9970a1
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.simple / src / main / java / org / argeo / slc / vfs / VfsResourceSet.java
1 package org.argeo.slc.vfs;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6 import org.apache.commons.vfs.FileObject;
7 import org.apache.commons.vfs.FileSystemException;
8 import org.apache.commons.vfs.FileSystemManager;
9 import org.apache.commons.vfs.VFS;
10 import org.argeo.slc.SlcException;
11 import org.argeo.slc.core.deploy.ResourceSet;
12 import org.springframework.core.io.Resource;
13
14 public class VfsResourceSet implements ResourceSet {
15 private String base;
16
17 public Map<String, Resource> listResources() {
18 try {
19 FileSystemManager fileSystemManager = VFS.getManager();
20 FileObject fileObject = fileSystemManager.resolveFile(base);
21 Map<String, Resource> map = new HashMap<String, Resource>();
22 addToMap(map, "", fileObject);
23
24 // TODO: add filters
25 return map;
26 } catch (FileSystemException e) {
27 throw new SlcException("Cannot list VFS resources from " + base, e);
28 }
29 }
30
31 /** recursive */
32 protected void addToMap(Map<String, Resource> map, String parentPath,
33 FileObject fileObject) {
34 try {
35 String newParentPath = parentPath
36 + fileObject.getName().getBaseName() + '/';
37 if (fileObject.getType().hasChildren()) {
38 for (FileObject child : fileObject.getChildren()) {
39 addToMap(map, newParentPath, child);
40 }
41 } else {
42 map.put(parentPath + fileObject.getName().getBaseName(),
43 new VfsResource(fileObject));
44 }
45 } catch (FileSystemException e) {
46 throw new SlcException("Cannot add children from " + parentPath, e);
47 }
48 }
49
50 public void setBase(String base) {
51 this.base = base;
52 }
53
54 }