1 16 package org.apache.commons.vfs.provider.local; 17 18 import org.apache.commons.vfs.Capability; 19 import org.apache.commons.vfs.FileName; 20 import org.apache.commons.vfs.FileObject; 21 import org.apache.commons.vfs.FileSystem; 22 import org.apache.commons.vfs.FileSystemException; 23 import org.apache.commons.vfs.FileSystemOptions; 24 import org.apache.commons.vfs.provider.AbstractOriginatingFileProvider; 25 import org.apache.commons.vfs.provider.LocalFileProvider; 26 import org.apache.commons.vfs.provider.UriParser; 27 import org.apache.commons.vfs.util.Os; 28 29 import java.io.File ; 30 import java.util.Arrays ; 31 import java.util.Collection ; 32 import java.util.Collections ; 33 34 39 public class DefaultLocalFileProvider 40 extends AbstractOriginatingFileProvider 41 implements LocalFileProvider 42 { 43 public final static Collection capabilities = Collections.unmodifiableCollection(Arrays.asList(new Capability[] 44 { 45 Capability.CREATE, 46 Capability.DELETE, 47 Capability.RENAME, 48 Capability.GET_TYPE, 49 Capability.GET_LAST_MODIFIED, 50 Capability.SET_LAST_MODIFIED_FILE, 51 Capability.SET_LAST_MODIFIED_FOLDER, 52 Capability.LIST_CHILDREN, 53 Capability.READ_CONTENT, 54 Capability.URI, 55 Capability.WRITE_CONTENT, 56 Capability.APPEND_CONTENT, 57 Capability.RANDOM_ACCESS_READ, 58 Capability.RANDOM_ACCESS_WRITE 59 })); 60 61 public DefaultLocalFileProvider() 62 { 63 super(); 64 65 if (Os.isFamily(Os.OS_FAMILY_WINDOWS)) 66 { 67 setFileNameParser(new WindowsFileNameParser()); 68 } 69 else 70 { 71 setFileNameParser(new GenericFileNameParser()); 72 } 73 } 74 75 78 public boolean isAbsoluteLocalName(final String name) 79 { 80 return ((LocalFileNameParser) getFileNameParser()).isAbsoluteName(name); 81 } 82 83 86 public FileObject findLocalFile(final String name) 87 throws FileSystemException 88 { 89 StringBuffer uri = new StringBuffer (name.length() + 5); 90 uri.append("file:"); 91 uri.append(name); 92 FileName filename = parseUri(null, uri.toString()); 93 return findFile(filename, null); 94 } 95 96 99 public FileObject findLocalFile(final File file) 100 throws FileSystemException 101 { 102 return findLocalFile(UriParser.encode(file.getAbsolutePath())); 103 } 105 106 109 protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions) 110 throws FileSystemException 111 { 112 final LocalFileName rootName = (LocalFileName) name; 114 return new LocalFileSystem(rootName, rootName.getRootFile(), fileSystemOptions); 115 } 116 117 public Collection getCapabilities() 118 { 119 return capabilities; 120 } 121 } 122 | Popular Tags |