001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.commons.vfs2.provider.local; 018 019import java.io.File; 020import java.io.FilePermission; 021import java.util.Collection; 022 023import org.apache.commons.vfs2.Capability; 024import org.apache.commons.vfs2.FileName; 025import org.apache.commons.vfs2.FileObject; 026import org.apache.commons.vfs2.FileSelector; 027import org.apache.commons.vfs2.FileSystemException; 028import org.apache.commons.vfs2.FileSystemOptions; 029import org.apache.commons.vfs2.provider.AbstractFileName; 030import org.apache.commons.vfs2.provider.AbstractFileSystem; 031import org.apache.commons.vfs2.util.FileObjectUtils; 032 033/** 034 * A local file system. 035 */ 036public class LocalFileSystem extends AbstractFileSystem { 037 private final String rootFile; 038 039 public LocalFileSystem(final FileName rootName, final String rootFile, final FileSystemOptions opts) { 040 super(rootName, null, opts); 041 this.rootFile = rootFile; 042 } 043 044 /** 045 * Creates a file object. 046 */ 047 @Override 048 protected FileObject createFile(final AbstractFileName name) throws FileSystemException { 049 // Create the file 050 return new LocalFile(this, rootFile, name); 051 } 052 053 /** 054 * Returns the capabilities of this file system. 055 */ 056 @Override 057 protected void addCapabilities(final Collection<Capability> caps) { 058 caps.addAll(DefaultLocalFileProvider.capabilities); 059 } 060 061 /** 062 * Creates a temporary local copy of a file and its descendants. 063 */ 064 @Override 065 protected File doReplicateFile(final FileObject fileObject, final FileSelector selector) throws Exception { 066 final LocalFile localFile = (LocalFile) FileObjectUtils.getAbstractFileObject(fileObject); 067 final File file = localFile.getLocalFile(); 068 final SecurityManager sm = System.getSecurityManager(); 069 if (sm != null) { 070 final FilePermission requiredPerm = new FilePermission(file.getAbsolutePath(), "read"); 071 sm.checkPermission(requiredPerm); 072 } 073 return file; 074 } 075 076}