Search in sources :

Example 1 with IVfs

use of org.apache.hop.core.vfs.plugin.IVfs in project hop by apache.

the class HopVfs method createFileSystemManager.

/**
 * Make sure to close when done using!
 *
 * @return A new standard file system manager
 * @throws HopException
 */
private static DefaultFileSystemManager createFileSystemManager() throws HopException {
    try {
        DefaultFileSystemManager fsm = new DefaultFileSystemManager();
        fsm.addProvider("ram", new org.apache.commons.vfs2.provider.ram.RamFileProvider());
        fsm.addProvider("file", new org.apache.commons.vfs2.provider.local.DefaultLocalFileProvider());
        fsm.addProvider("res", new org.apache.commons.vfs2.provider.res.ResourceFileProvider());
        fsm.addProvider("zip", new org.apache.commons.vfs2.provider.zip.ZipFileProvider());
        fsm.addProvider("gz", new org.apache.commons.vfs2.provider.gzip.GzipFileProvider());
        fsm.addProvider("jar", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
        fsm.addProvider("http", new org.apache.commons.vfs2.provider.http.HttpFileProvider());
        fsm.addProvider("https", new org.apache.commons.vfs2.provider.https.HttpsFileProvider());
        fsm.addProvider("ftp", new org.apache.commons.vfs2.provider.ftp.FtpFileProvider());
        fsm.addProvider("ftps", new org.apache.commons.vfs2.provider.ftps.FtpsFileProvider());
        fsm.addProvider("war", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
        fsm.addProvider("par", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
        fsm.addProvider("ear", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
        fsm.addProvider("sar", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
        fsm.addProvider("ejb3", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
        fsm.addProvider("tmp", new org.apache.commons.vfs2.provider.temp.TemporaryFileProvider());
        fsm.addProvider("tar", new org.apache.commons.vfs2.provider.tar.TarFileProvider());
        fsm.addProvider("tbz2", new org.apache.commons.vfs2.provider.tar.TarFileProvider());
        fsm.addProvider("tgz", new org.apache.commons.vfs2.provider.tar.TarFileProvider());
        fsm.addProvider("bz2", new org.apache.commons.vfs2.provider.bzip2.Bzip2FileProvider());
        fsm.addProvider("files-cache", new org.apache.commons.vfs2.provider.temp.TemporaryFileProvider());
        fsm.addExtensionMap("jar", "jar");
        fsm.addExtensionMap("zip", "zip");
        fsm.addExtensionMap("gz", "gz");
        fsm.addExtensionMap("tar", "tar");
        fsm.addExtensionMap("tbz2", "tar");
        fsm.addExtensionMap("tgz", "tar");
        fsm.addExtensionMap("bz2", "bz2");
        fsm.addMimeTypeMap("application/x-tar", "tar");
        fsm.addMimeTypeMap("application/x-gzip", "gz");
        fsm.addMimeTypeMap("application/zip", "zip");
        fsm.setFileContentInfoFactory(new FileContentInfoFilenameFactory());
        fsm.setReplicator(new DefaultFileReplicator());
        fsm.setFilesCache(new SoftRefFilesCache());
        fsm.setCacheStrategy(CacheStrategy.ON_RESOLVE);
        // Here are extra VFS plugins to register
        // 
        PluginRegistry registry = PluginRegistry.getInstance();
        List<IPlugin> plugins = registry.getPlugins(VfsPluginType.class);
        for (IPlugin plugin : plugins) {
            IVfs iVfs = registry.loadClass(plugin, IVfs.class);
            try {
                fsm.addProvider(iVfs.getUrlSchemes(), iVfs.getProvider());
            } catch (Exception e) {
                throw new HopException("Error registering provider for VFS plugin " + plugin.getIds()[0] + " : " + plugin.getName() + " : ", e);
            }
        }
        fsm.init();
        return fsm;
    } catch (Exception e) {
        throw new HopException("Error creating file system manager", e);
    }
}
Also used : IPlugin(org.apache.hop.core.plugins.IPlugin) FileContentInfoFilenameFactory(org.apache.commons.vfs2.impl.FileContentInfoFilenameFactory) SoftRefFilesCache(org.apache.commons.vfs2.cache.SoftRefFilesCache) IVfs(org.apache.hop.core.vfs.plugin.IVfs) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) HopException(org.apache.hop.core.exception.HopException) HopException(org.apache.hop.core.exception.HopException) HopFileException(org.apache.hop.core.exception.HopFileException) PluginRegistry(org.apache.hop.core.plugins.PluginRegistry) org.apache.commons.vfs2(org.apache.commons.vfs2) DefaultFileReplicator(org.apache.commons.vfs2.impl.DefaultFileReplicator)

Aggregations

org.apache.commons.vfs2 (org.apache.commons.vfs2)1 SoftRefFilesCache (org.apache.commons.vfs2.cache.SoftRefFilesCache)1 DefaultFileReplicator (org.apache.commons.vfs2.impl.DefaultFileReplicator)1 DefaultFileSystemManager (org.apache.commons.vfs2.impl.DefaultFileSystemManager)1 FileContentInfoFilenameFactory (org.apache.commons.vfs2.impl.FileContentInfoFilenameFactory)1 HopException (org.apache.hop.core.exception.HopException)1 HopFileException (org.apache.hop.core.exception.HopFileException)1 IPlugin (org.apache.hop.core.plugins.IPlugin)1 PluginRegistry (org.apache.hop.core.plugins.PluginRegistry)1 IVfs (org.apache.hop.core.vfs.plugin.IVfs)1