KickJava   Java API By Example, From Geeks To Geeks.

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


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.FileName;
19 import org.apache.commons.vfs.FileObject;
20 import org.apache.commons.vfs.FileSelector;
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.AbstractFileSystem;
25
26 import java.io.File JavaDoc;
27 import java.io.FilePermission JavaDoc;
28 import java.util.Collection JavaDoc;
29
30 /**
31  * A local file system.
32  *
33  * @author <a HREF="mailto:adammurdoch@apache.org">Adam Murdoch</a>
34  */

35 public class LocalFileSystem
36     extends AbstractFileSystem
37     implements FileSystem
38 {
39     private final String JavaDoc rootFile;
40
41     public LocalFileSystem(final FileName rootName,
42                            final String JavaDoc rootFile,
43                            final FileSystemOptions opts)
44     {
45         super(rootName, null, opts);
46         this.rootFile = rootFile;
47     }
48
49     /**
50      * Creates a file object.
51      */

52     protected FileObject createFile(final FileName name) throws FileSystemException
53     {
54         // Create the file
55
String JavaDoc fileName = rootFile + name.getPath();
56         return new LocalFile(this, fileName, name);
57     }
58
59     /**
60      * Returns the capabilities of this file system.
61      */

62     protected void addCapabilities(final Collection JavaDoc caps)
63     {
64         caps.addAll(DefaultLocalFileProvider.capabilities);
65     }
66
67     /**
68      * Creates a temporary local copy of a file and its descendents.
69      */

70     protected File JavaDoc doReplicateFile(final FileObject fileObject,
71                                    final FileSelector selector)
72         throws Exception JavaDoc
73     {
74         final LocalFile localFile = (LocalFile) fileObject;
75         final File JavaDoc file = localFile.getLocalFile();
76         final SecurityManager JavaDoc sm = System.getSecurityManager();
77         if (sm != null)
78         {
79             final FilePermission JavaDoc requiredPerm = new FilePermission JavaDoc(file.getAbsolutePath(), "read");
80             sm.checkPermission(requiredPerm);
81         }
82         return file;
83     }
84
85 }
86
Popular Tags