2 * Copyright (C) 2007-2012 Mathieu Baudier
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org
.argeo
.slc
.vfs
;
18 import java
.util
.HashMap
;
21 import org
.apache
.commons
.vfs
.FileObject
;
22 import org
.apache
.commons
.vfs
.FileSystemException
;
23 import org
.apache
.commons
.vfs
.FileSystemManager
;
24 import org
.apache
.commons
.vfs
.VFS
;
25 import org
.argeo
.slc
.SlcException
;
26 import org
.argeo
.slc
.core
.deploy
.ResourceSet
;
27 import org
.springframework
.core
.io
.Resource
;
29 public class VfsResourceSet
implements ResourceSet
{
32 public Map
<String
, Resource
> listResources() {
34 FileSystemManager fileSystemManager
= VFS
.getManager();
35 FileObject fileObject
= fileSystemManager
.resolveFile(base
);
36 Map
<String
, Resource
> map
= new HashMap
<String
, Resource
>();
37 addToMap(map
, "", fileObject
);
41 } catch (FileSystemException e
) {
42 throw new SlcException("Cannot list VFS resources from " + base
, e
);
47 protected void addToMap(Map
<String
, Resource
> map
, String parentPath
,
48 FileObject fileObject
) {
50 String newParentPath
= parentPath
51 + fileObject
.getName().getBaseName() + '/';
52 if (fileObject
.getType().hasChildren()) {
53 for (FileObject child
: fileObject
.getChildren()) {
54 addToMap(map
, newParentPath
, child
);
57 map
.put(parentPath
+ fileObject
.getName().getBaseName(),
58 new VfsResource(fileObject
));
60 } catch (FileSystemException e
) {
61 throw new SlcException("Cannot add children from " + parentPath
, e
);
65 public void setBase(String base
) {