KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > vfs > provider > local > DefaultLocalFileProvider


1 /*
2  * Copyright 2002-2005 The Apache Software Foundation.
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 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 JavaDoc;
30 import java.util.Arrays JavaDoc;
31 import java.util.Collection JavaDoc;
32 import java.util.Collections JavaDoc;
33
34 /**
35  * A file system provider, which uses direct file access.
36  *
37  * @author <a HREF="mailto:adammurdoch@apache.org">Adam Murdoch</a>
38  */

39 public class DefaultLocalFileProvider
40     extends AbstractOriginatingFileProvider
41     implements LocalFileProvider
42 {
43     public final static Collection JavaDoc 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     /**
76      * Determines if a name is an absolute file name.
77      */

78     public boolean isAbsoluteLocalName(final String JavaDoc name)
79     {
80         return ((LocalFileNameParser) getFileNameParser()).isAbsoluteName(name);
81     }
82
83     /**
84      * Finds a local file, from its local name.
85      */

86     public FileObject findLocalFile(final String JavaDoc name)
87         throws FileSystemException
88     {
89         StringBuffer JavaDoc uri = new StringBuffer JavaDoc(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     /**
97      * Finds a local file.
98      */

99     public FileObject findLocalFile(final File JavaDoc file)
100         throws FileSystemException
101     {
102         return findLocalFile(UriParser.encode(file.getAbsolutePath()));
103         // return findLocalFile(file.getAbsolutePath());
104
}
105
106     /**
107      * Creates the filesystem.
108      */

109     protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions)
110         throws FileSystemException
111     {
112         // Create the file system
113
final LocalFileName rootName = (LocalFileName) name;
114         return new LocalFileSystem(rootName, rootName.getRootFile(), fileSystemOptions);
115     }
116
117     public Collection JavaDoc getCapabilities()
118     {
119         return capabilities;
120     }
121 }
122
Popular Tags