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);
}
}
}
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);
}
}
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);
}
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();
}
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());
}
Aggregations