2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
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.
17 package org
.argeo
.slc
.vfs
;
19 import java
.util
.HashMap
;
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
;
30 public class VfsResourceSet
implements ResourceSet
{
33 public Map
<String
, Resource
> listResources() {
35 FileSystemManager fileSystemManager
= VFS
.getManager();
36 FileObject fileObject
= fileSystemManager
.resolveFile(base
);
37 Map
<String
, Resource
> map
= new HashMap
<String
, Resource
>();
38 addToMap(map
, "", fileObject
);
42 } catch (FileSystemException e
) {
43 throw new SlcException("Cannot list VFS resources from " + base
, e
);
48 protected void addToMap(Map
<String
, Resource
> map
, String parentPath
,
49 FileObject fileObject
) {
51 String newParentPath
= parentPath
52 + fileObject
.getName().getBaseName() + '/';
53 if (fileObject
.getType().hasChildren()) {
54 for (FileObject child
: fileObject
.getChildren()) {
55 addToMap(map
, newParentPath
, child
);
58 map
.put(parentPath
+ fileObject
.getName().getBaseName(),
59 new VfsResource(fileObject
));
61 } catch (FileSystemException e
) {
62 throw new SlcException("Cannot add children from " + parentPath
, e
);
66 public void setBase(String base
) {