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: */
017: package org.apache.commons.vfs.provider.local;
018:
019: import org.apache.commons.vfs.Capability;
020: import org.apache.commons.vfs.FileName;
021: import org.apache.commons.vfs.FileObject;
022: import org.apache.commons.vfs.FileSystem;
023: import org.apache.commons.vfs.FileSystemException;
024: import org.apache.commons.vfs.FileSystemOptions;
025: import org.apache.commons.vfs.provider.AbstractOriginatingFileProvider;
026: import org.apache.commons.vfs.provider.LocalFileProvider;
027: import org.apache.commons.vfs.provider.UriParser;
028: import org.apache.commons.vfs.util.Os;
029:
030: import java.io.File;
031: import java.util.Arrays;
032: import java.util.Collection;
033: import java.util.Collections;
034:
035: /**
036: * A file system provider, which uses direct file access.
037: *
038: * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
039: * @version $Revision: 480428 $ $Date: 2006-11-28 22:15:24 -0800 (Tue, 28 Nov 2006) $
040: */
041: public class DefaultLocalFileProvider extends
042: AbstractOriginatingFileProvider implements LocalFileProvider {
043: public final static Collection capabilities = Collections
044: .unmodifiableCollection(Arrays.asList(new Capability[] {
045: Capability.CREATE, Capability.DELETE,
046: Capability.RENAME, Capability.GET_TYPE,
047: Capability.GET_LAST_MODIFIED,
048: Capability.SET_LAST_MODIFIED_FILE,
049: Capability.SET_LAST_MODIFIED_FOLDER,
050: Capability.LIST_CHILDREN, Capability.READ_CONTENT,
051: Capability.URI, Capability.WRITE_CONTENT,
052: Capability.APPEND_CONTENT,
053: Capability.RANDOM_ACCESS_READ,
054: Capability.RANDOM_ACCESS_WRITE }));
055:
056: public DefaultLocalFileProvider() {
057: super ();
058:
059: if (Os.isFamily(Os.OS_FAMILY_WINDOWS)) {
060: setFileNameParser(new WindowsFileNameParser());
061: } else {
062: setFileNameParser(new GenericFileNameParser());
063: }
064: }
065:
066: /**
067: * Determines if a name is an absolute file name.
068: */
069: public boolean isAbsoluteLocalName(final String name) {
070: return ((LocalFileNameParser) getFileNameParser())
071: .isAbsoluteName(name);
072: }
073:
074: /**
075: * Finds a local file, from its local name.
076: */
077: public FileObject findLocalFile(final String name)
078: throws FileSystemException {
079: StringBuffer uri = new StringBuffer(name.length() + 5);
080: uri.append("file:");
081: uri.append(name);
082: FileName filename = parseUri(null, uri.toString());
083: return findFile(filename, null);
084: }
085:
086: /**
087: * Finds a local file.
088: */
089: public FileObject findLocalFile(final File file)
090: throws FileSystemException {
091: return findLocalFile(UriParser.encode(file.getAbsolutePath()));
092: // return findLocalFile(file.getAbsolutePath());
093: }
094:
095: /**
096: * Creates the filesystem.
097: */
098: protected FileSystem doCreateFileSystem(final FileName name,
099: final FileSystemOptions fileSystemOptions)
100: throws FileSystemException {
101: // Create the file system
102: final LocalFileName rootName = (LocalFileName) name;
103: return new LocalFileSystem(rootName, rootName.getRootFile(),
104: fileSystemOptions);
105: }
106:
107: public Collection getCapabilities() {
108: return capabilities;
109: }
110: }
|