Search in sources :

Example 1 with FileProvider

use of org.apache.commons.vfs2.provider.FileProvider in project agileway by fangjinuo.

the class VFSUtils method removeFileProvider.

public static void removeFileProvider(final DefaultFileSystemManager fileSystemManager, String uriSchema) {
    if (fileSystemManager.hasProvider(uriSchema)) {
        FileProvider provider = getAllProviders(fileSystemManager).remove(uriSchema);
        if (provider != null) {
            FileProvider defaultProvider = Reflects.getFieldValue(defaultFileSystemManager_defaultProvider, fileSystemManager, true, false);
            if (defaultProvider == provider) {
                Reflects.setFieldValue(defaultFileSystemManager_defaultProvider, fileSystemManager, null, true, false);
            }
            List<Object> components = Reflects.getFieldValue(defaultFileSystemManager_components, fileSystemManager, true, false);
            components.remove(provider);
        }
    }
}
Also used : FileProvider(org.apache.commons.vfs2.provider.FileProvider)

Example 2 with FileProvider

use of org.apache.commons.vfs2.provider.FileProvider in project commons-vfs by apache.

the class StandardFileSystemManager method addProvider.

/**
 * Adds a provider from a provider definition.
 *
 * @param providerDef the provider definition
 * @param isDefault true if the default should be used.
 * @throws FileSystemException if an error occurs.
 */
private void addProvider(final Element providerDef, final boolean isDefault) throws FileSystemException {
    final String classname = providerDef.getAttribute("class-name");
    // Make sure all required schemes are available
    final String[] requiredSchemes = getRequiredSchemes(providerDef);
    for (final String requiredScheme : requiredSchemes) {
        if (!hasProvider(requiredScheme)) {
            final String msg = Messages.getString("vfs.impl/skipping-provider-scheme.debug", classname, requiredScheme);
            VfsLog.debug(getLogger(), getLogger(), msg);
            return;
        }
    }
    // Make sure all required classes are in classpath
    final String[] requiredClasses = getRequiredClasses(providerDef);
    for (final String requiredClass : requiredClasses) {
        if (!findClass(requiredClass)) {
            final String msg = Messages.getString("vfs.impl/skipping-provider.debug", classname, requiredClass);
            VfsLog.debug(getLogger(), getLogger(), msg);
            return;
        }
    }
    // Create and register the provider
    final FileProvider provider = (FileProvider) createInstance(classname);
    final String[] schemas = getSchemas(providerDef);
    if (schemas.length > 0) {
        addProvider(schemas, provider);
    }
    // Set as default, if required
    if (isDefault) {
        setDefaultProvider(provider);
    }
}
Also used : FileProvider(org.apache.commons.vfs2.provider.FileProvider)

Example 3 with FileProvider

use of org.apache.commons.vfs2.provider.FileProvider in project commons-vfs by apache.

the class DefaultFileSystemManager method resolveURI.

/**
 * Resolve the uri to a file name.
 *
 * @param uri The URI to resolve.
 * @return The FileName of the file.
 * @throws FileSystemException if an error occurs.
 */
@Override
public FileName resolveURI(final String uri) throws FileSystemException {
    UriParser.checkUriEncoding(uri);
    if (uri == null) {
        throw new IllegalArgumentException();
    }
    // Extract the scheme
    final String scheme = UriParser.extractScheme(getSchemes(), uri);
    if (scheme != null) {
        // An absolute URI - locate the provider
        final FileProvider provider = providers.get(scheme);
        if (provider != null) {
            return provider.parseUri(null, uri);
        }
    // Otherwise, assume a local file
    }
    // Handle absolute file names
    if (localFileProvider != null && localFileProvider.isAbsoluteLocalName(uri)) {
        return localFileProvider.parseUri(null, uri);
    }
    if (scheme != null) {
        // An unknown scheme - hand it to the default provider
        FileSystemException.requireNonNull(defaultProvider, "vfs.impl/unknown-scheme.error", scheme, uri);
        return defaultProvider.parseUri(null, uri);
    }
    // Assume a relative name - use the supplied base file
    FileSystemException.requireNonNull(baseFile, "vfs.impl/find-rel-file.error", uri);
    return resolveName(baseFile.getName(), uri, NameScope.FILE_SYSTEM);
}
Also used : LocalFileProvider(org.apache.commons.vfs2.provider.LocalFileProvider) AbstractFileProvider(org.apache.commons.vfs2.provider.AbstractFileProvider) FileProvider(org.apache.commons.vfs2.provider.FileProvider)

Example 4 with FileProvider

use of org.apache.commons.vfs2.provider.FileProvider in project commons-vfs by apache.

the class DefaultFileSystemManager method getProviderCapabilities.

/**
 * Get the capabilities for a given scheme.
 *
 * @param scheme The scheme to located.
 * @return A Collection of capabilities.
 * @throws FileSystemException if the given scheme is not konwn
 */
@Override
public Collection<Capability> getProviderCapabilities(final String scheme) throws FileSystemException {
    final FileProvider provider = providers.get(scheme);
    FileSystemException.requireNonNull(provider, "vfs.impl/unknown-scheme.error", scheme);
    return provider.getCapabilities();
}
Also used : LocalFileProvider(org.apache.commons.vfs2.provider.LocalFileProvider) AbstractFileProvider(org.apache.commons.vfs2.provider.AbstractFileProvider) FileProvider(org.apache.commons.vfs2.provider.FileProvider)

Example 5 with FileProvider

use of org.apache.commons.vfs2.provider.FileProvider in project commons-vfs by apache.

the class DefaultFileSystemManager method createFileSystem.

/**
 * Creates a layered file system.
 *
 * @param scheme The scheme to use.
 * @param file The FileObject.
 * @return The layered FileObject.
 * @throws FileSystemException if an error occurs.
 */
@Override
public FileObject createFileSystem(final String scheme, final FileObject file) throws FileSystemException {
    final FileProvider provider = providers.get(scheme);
    FileSystemException.requireNonNull(provider, "vfs.impl/unknown-provider.error", scheme, file);
    return provider.createFileSystem(scheme, file, file.getFileSystem().getFileSystemOptions());
}
Also used : LocalFileProvider(org.apache.commons.vfs2.provider.LocalFileProvider) AbstractFileProvider(org.apache.commons.vfs2.provider.AbstractFileProvider) FileProvider(org.apache.commons.vfs2.provider.FileProvider)

Aggregations

FileProvider (org.apache.commons.vfs2.provider.FileProvider)10 AbstractFileProvider (org.apache.commons.vfs2.provider.AbstractFileProvider)6 LocalFileProvider (org.apache.commons.vfs2.provider.LocalFileProvider)6 FileName (org.apache.commons.vfs2.FileName)2 FileObject (org.apache.commons.vfs2.FileObject)1 FileSystemException (org.apache.commons.vfs2.FileSystemException)1 FileSystemOptions (org.apache.commons.vfs2.FileSystemOptions)1 FileType (org.apache.commons.vfs2.FileType)1 DefaultFileSystemManager (org.apache.commons.vfs2.impl.DefaultFileSystemManager)1 AbstractFileName (org.apache.commons.vfs2.provider.AbstractFileName)1 DefaultLocalFileProvider (org.apache.commons.vfs2.provider.local.DefaultLocalFileProvider)1 Test (org.junit.Test)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 VfsEmbeddedFileSystemCloser (org.pentaho.di.core.osgi.api.VfsEmbeddedFileSystemCloser)1 GoogleDriveFileProvider (org.pentaho.googledrive.vfs.GoogleDriveFileProvider)1