View Javadoc
1   /*
2    * Copyright (C) 2007-2012 Argeo GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *         http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.argeo.maintenance.backup.vfs;
17  
18  import org.apache.commons.vfs2.FileSystemException;
19  import org.apache.commons.vfs2.impl.DefaultFileSystemManager;
20  import org.apache.commons.vfs2.provider.bzip2.Bzip2FileProvider;
21  import org.apache.commons.vfs2.provider.ftp.FtpFileProvider;
22  import org.apache.commons.vfs2.provider.gzip.GzipFileProvider;
23  import org.apache.commons.vfs2.provider.local.DefaultLocalFileProvider;
24  import org.apache.commons.vfs2.provider.ram.RamFileProvider;
25  import org.apache.commons.vfs2.provider.sftp.SftpFileProvider;
26  import org.apache.commons.vfs2.provider.url.UrlFileProvider;
27  import org.argeo.maintenance.MaintenanceException;
28  
29  /**
30   * Programatically configured VFS file system manager which can be declared as a
31   * bean and associated with a life cycle (methods
32   * {@link DefaultFileSystemManager#init()} and
33   * {@link DefaultFileSystemManager#close()}). Supports bz2, file, ram, gzip,
34   * ftp, sftp
35   */
36  public class BackupFileSystemManager extends DefaultFileSystemManager {
37  
38  	public BackupFileSystemManager() {
39  		super();
40  		try {
41  			addProvider("file", new DefaultLocalFileProvider());
42  			addProvider("bz2", new Bzip2FileProvider());
43  			addProvider("ftp", new FtpFileProvider());
44  			addProvider("sftp", new SftpFileProvider());
45  			addProvider("gzip", new GzipFileProvider());
46  			addProvider("ram", new RamFileProvider());
47  			setDefaultProvider(new UrlFileProvider());
48  		} catch (FileSystemException e) {
49  			throw new MaintenanceException("Cannot configure backup file provider", e);
50  		}
51  	}
52  }