]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/vfs/VfsResourceSet.java
add some private constructors with no arg, some getters & setters and some ids to...
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.simple / src / main / java / org / argeo / slc / vfs / VfsResourceSet.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.argeo.slc.vfs;
18
19 import java.util.HashMap;
20 import java.util.Map;
21
22 import org.apache.commons.vfs.FileObject;
23 import org.apache.commons.vfs.FileSystemException;
24 import org.apache.commons.vfs.FileSystemManager;
25 import org.apache.commons.vfs.VFS;
26 import org.argeo.slc.SlcException;
27 import org.argeo.slc.core.deploy.ResourceSet;
28 import org.springframework.core.io.Resource;
29
30 public class VfsResourceSet implements ResourceSet {
31 private String base;
32
33 public Map<String, Resource> listResources() {
34 try {
35 FileSystemManager fileSystemManager = VFS.getManager();
36 FileObject fileObject = fileSystemManager.resolveFile(base);
37 Map<String, Resource> map = new HashMap<String, Resource>();
38 addToMap(map, "", fileObject);
39
40 // TODO: add filters
41 return map;
42 } catch (FileSystemException e) {
43 throw new SlcException("Cannot list VFS resources from " + base, e);
44 }
45 }
46
47 /** recursive */
48 protected void addToMap(Map<String, Resource> map, String parentPath,
49 FileObject fileObject) {
50 try {
51 String newParentPath = parentPath
52 + fileObject.getName().getBaseName() + '/';
53 if (fileObject.getType().hasChildren()) {
54 for (FileObject child : fileObject.getChildren()) {
55 addToMap(map, newParentPath, child);
56 }
57 } else {
58 map.put(parentPath + fileObject.getName().getBaseName(),
59 new VfsResource(fileObject));
60 }
61 } catch (FileSystemException e) {
62 throw new SlcException("Cannot add children from " + parentPath, e);
63 }
64 }
65
66 public void setBase(String base) {
67 this.base = base;
68 }
69
70 }