| 1 | |
package org.webslinger.commons.vfs.virtual; |
| 2 | |
|
| 3 | |
import java.util.Collection; |
| 4 | |
|
| 5 | |
import org.apache.commons.vfs.Capability; |
| 6 | |
import org.apache.commons.vfs.FileName; |
| 7 | |
import org.apache.commons.vfs.FileObject; |
| 8 | |
import org.apache.commons.vfs.FileSystem; |
| 9 | |
import org.apache.commons.vfs.FileSystemConfigBuilder; |
| 10 | |
import org.apache.commons.vfs.FileSystemException; |
| 11 | |
import org.apache.commons.vfs.FileSystemOptions; |
| 12 | |
import org.apache.commons.vfs.FileType; |
| 13 | |
import org.apache.commons.vfs.impl.VirtualFileName; |
| 14 | |
import org.apache.commons.vfs.provider.AbstractLayeredFileProvider; |
| 15 | |
import org.apache.commons.vfs.provider.LayeredFileName; |
| 16 | |
|
| 17 | |
import org.webslinger.commons.vfs.FilteringFileProvider; |
| 18 | |
import org.webslinger.commons.vfs.VFSUtil; |
| 19 | |
import org.webslinger.commons.vfs.handlers.HandlerFactory; |
| 20 | |
import org.webslinger.commons.vfs.handlers.cow.COWStorageHandler; |
| 21 | |
|
| 22 | 47 | public class VirtualFileProvider extends AbstractLayeredFileProvider { |
| 23 | |
public VirtualConfigBuilder getConfigBuilder() { |
| 24 | 85 | return VirtualConfigBuilder.getInstance(); |
| 25 | |
} |
| 26 | |
|
| 27 | |
|
| 28 | |
public Collection getCapabilities() { |
| 29 | 0 | return FilteringFileProvider.capabilities; |
| 30 | |
} |
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
public FileObject createFileSystem(final FileObject rootFile) |
| 36 | |
throws FileSystemException |
| 37 | |
{ |
| 38 | 0 | final FileName rootName = |
| 39 | |
getContext().getFileSystemManager().resolveName(rootFile.getName(), FileName.ROOT_PATH); |
| 40 | 0 | final VirtualFileSystem fs = makeFileSystem(rootName, rootFile, null); |
| 41 | 0 | return fs.getRoot(); |
| 42 | |
} |
| 43 | |
|
| 44 | |
protected VirtualFileSystem makeFileSystem(FileName rootName, FileObject rootMount, FileSystemOptions properties) throws FileSystemException { |
| 45 | 53 | properties = VFSUtil.findFileSystemOptions(rootMount, properties, true); |
| 46 | 53 | VirtualFileSystem fs = new VirtualFileSystem(rootName, properties); |
| 47 | 53 | addComponent(fs); |
| 48 | 53 | HandlerFactory<COWStorageHandler, VirtualFileSystem> factory = getConfigBuilder().getStorageHandlerFactory(properties); |
| 49 | 53 | if (factory == null) getConfigBuilder().setStorageHandlerFactory(properties, new VirtualCOWStateXmlStorageHandlerFactory()); |
| 50 | 53 | fs.addJunction(FileName.ROOT_PATH, rootMount); |
| 51 | 53 | return fs; |
| 52 | |
} |
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
public FileObject createFileSystem(final String rootUri) throws FileSystemException |
| 58 | |
{ |
| 59 | 0 | final FileName rootName = |
| 60 | |
new VirtualFileName(rootUri, FileName.ROOT_PATH, FileType.FOLDER); |
| 61 | 0 | final VirtualFileSystem fs = new VirtualFileSystem(rootName, null); |
| 62 | 0 | addComponent(fs); |
| 63 | 0 | return fs.getRoot(); |
| 64 | |
} |
| 65 | |
|
| 66 | |
protected FileSystem doCreateFileSystem(String scheme, FileObject file, FileSystemOptions properties) throws FileSystemException { |
| 67 | 53 | final FileName rootName = new LayeredFileName(scheme, file.getName(), FileName.ROOT_PATH, file.getType()); |
| 68 | 53 | return makeFileSystem(rootName, file, properties); |
| 69 | |
} |
| 70 | |
} |