Example usage for org.apache.commons.vfs2.impl DefaultFileSystemConfigBuilder getInstance

List of usage examples for org.apache.commons.vfs2.impl DefaultFileSystemConfigBuilder getInstance

Introduction

In this page you can find the example usage for org.apache.commons.vfs2.impl DefaultFileSystemConfigBuilder getInstance.

Prototype

public static DefaultFileSystemConfigBuilder getInstance() 

Source Link

Document

Gets the singleton builder.

Usage

From source file:com.sludev.commons.vfs2.provider.s3.SS3TestUtils.java

public static void uploadFile(String accntName, String acctHost, String accntKey, String containerName,
        Path localFile, Path remotePath) throws FileSystemException {
    DefaultFileSystemManager currMan = new DefaultFileSystemManager();
    currMan.addProvider(SS3Constants.S3SCHEME, new SS3FileProvider());
    currMan.addProvider("file", new DefaultLocalFileProvider());
    currMan.init();//w  w w  .  ja v  a  2  s .com

    StaticUserAuthenticator auth = new StaticUserAuthenticator("", accntName, accntKey);
    FileSystemOptions opts = new FileSystemOptions();
    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);

    String currUriStr = String.format("%s://%s/%s/%s", SS3Constants.S3SCHEME, acctHost, containerName,
            remotePath);
    FileObject currFile = currMan.resolveFile(currUriStr, opts);
    FileObject currFile2 = currMan.resolveFile(String.format("file://%s", localFile));

    currFile.copyFrom(currFile2, Selectors.SELECT_SELF);

    currFile.close();
    currMan.close();
}

From source file:com.sludev.commons.vfs2.provider.azure.AzTestUtils.java

public static void uploadFile(String accntName, String accntHost, String accntKey, String containerName,
        Path localFile, Path remotePath) throws FileSystemException {
    DefaultFileSystemManager currMan = new DefaultFileSystemManager();
    currMan.addProvider(AzConstants.AZSBSCHEME, new AzFileProvider());
    currMan.addProvider("file", new DefaultLocalFileProvider());
    currMan.init();//from w w  w .j av  a2s. com

    StaticUserAuthenticator auth = new StaticUserAuthenticator("", accntName, accntKey);
    FileSystemOptions opts = new FileSystemOptions();
    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);

    String currUriStr = String.format("%s://%s/%s/%s", AzConstants.AZSBSCHEME, accntHost, containerName,
            remotePath);
    FileObject currFile = currMan.resolveFile(currUriStr, opts);
    FileObject currFile2 = currMan.resolveFile(String.format("file://%s", localFile));

    currFile.copyFrom(currFile2, Selectors.SELECT_SELF);

    currFile.close();
    currMan.close();
}

From source file:net.sourceforge.fullsync.fs.filesystems.SmbAuthProvider.java

@Override
public final void authSetup(final ConnectionDescription description, final FileSystemOptions options)
        throws FileSystemException {
    String username = description.getUsername().orElse(""); //$NON-NLS-1$
    String password = description.getPassword().orElse(""); //$NON-NLS-1$
    StaticUserAuthenticator auth = new StaticUserAuthenticator(null, username, password);
    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(options, auth);
}

From source file:com.ewcms.publication.deploy.provider.DeployOperatorBaseTest.java

@Test
public void testSetAuthenticator() throws Exception {
    DeployOperatorable operator = new DeployOperatorBaseImpl.Builder().build();

    FileSystemOptions opts = new FileSystemOptions();
    DeployOperatorBase operatorBase = (DeployOperatorBase) operator;
    operatorBase.setAuthenticator(opts, "user", "password");
    UserAuthenticator auth = DefaultFileSystemConfigBuilder.getInstance().getUserAuthenticator(opts);
    Assert.assertNotNull(auth);/*www  .  j a va2 s.  c  om*/
}

From source file:net.sourceforge.fullsync.fs.filesystems.FTPAuthenticationProvider.java

@Override
public final void authSetup(final ConnectionDescription description, final FileSystemOptions options)
        throws FileSystemException {
    String username = description.getUsername().orElse(""); //$NON-NLS-1$
    String password = description.getPassword().orElse(""); //$NON-NLS-1$
    StaticUserAuthenticator auth = new StaticUserAuthenticator(null, username, password);
    FtpFileSystemConfigBuilder cfg = FtpFileSystemConfigBuilder.getInstance();
    cfg.setPassiveMode(options, true);/*from  www.  jav  a2  s  . c  om*/
    cfg.setUserDirIsRoot(options, description.isUserDirIsRoot());
    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(options, auth);
}

From source file:net.sourceforge.fullsync.fs.filesystems.FTPFileSystem.java

@Override
public final void authSetup(final ConnectionDescription description, final FileSystemOptions options)
        throws FileSystemException {
    StaticUserAuthenticator auth = new StaticUserAuthenticator(null,
            description.getParameter(ConnectionDescription.PARAMETER_USERNAME),
            description.getSecretParameter(ConnectionDescription.PARAMETER_PASSWORD));
    FtpFileSystemConfigBuilder.getInstance().setPassiveMode(options, true);
    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(options, auth);
}

From source file:com.sludev.commons.vfs2.provider.s3.SS3TestUtils.java

public static void deleteFile(String accntName, String accntHost, String accntKey, String containerName,
        Path remotePath) throws FileSystemException {
    DefaultFileSystemManager currMan = new DefaultFileSystemManager();
    currMan.addProvider(SS3Constants.S3SCHEME, new SS3FileProvider());
    currMan.init();/*  w w w  .  ja va2s. co  m*/

    StaticUserAuthenticator auth = new StaticUserAuthenticator("", accntName, accntKey);
    FileSystemOptions opts = new FileSystemOptions();
    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);

    String currUriStr = String.format("%s://%s/%s/%s", SS3Constants.S3SCHEME, accntHost, containerName,
            remotePath);
    FileObject currFile = currMan.resolveFile(currUriStr, opts);

    Boolean delRes = currFile.delete();
    Assert.assertTrue(delRes);
}

From source file:com.sludev.commons.vfs2.provider.azure.AzTestUtils.java

public static void deleteFile(String accntName, String accntHost, String accntKey, String containerName,
        Path remotePath) throws FileSystemException {
    DefaultFileSystemManager currMan = new DefaultFileSystemManager();
    currMan.addProvider(AzConstants.AZSBSCHEME, new AzFileProvider());
    currMan.init();/*from  www  .j  a  va 2  s  . c  om*/

    StaticUserAuthenticator auth = new StaticUserAuthenticator("", accntName, accntKey);
    FileSystemOptions opts = new FileSystemOptions();
    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);

    String currUriStr = String.format("%s://%s/%s/%s", AzConstants.AZSBSCHEME, accntHost, containerName,
            remotePath);
    FileObject currFile = currMan.resolveFile(currUriStr, opts);

    Boolean delRes = currFile.delete();
    Assert.assertTrue(delRes);
}

From source file:com.ewcms.publication.deploy.provider.DeployOperatorBaseTest.java

@Test
public void testUsernameIsNullSetAuthenticator() throws Exception {
    DeployOperatorable operator = new DeployOperatorBaseImpl.Builder().build();

    FileSystemOptions opts = new FileSystemOptions();
    DeployOperatorBase operatorBase = (DeployOperatorBase) operator;
    operatorBase.setAuthenticator(opts, null, null);
    UserAuthenticator auth = DefaultFileSystemConfigBuilder.getInstance().getUserAuthenticator(opts);
    Assert.assertNull(auth);//from ww w.  j a va2  s  . co m
}

From source file:com.codehaus.mojo.vfs.FileSystemOptionsFactory.java

public FileSystemOptions getFileSystemOptions(String url, String username, String password)
        throws FileSystemException {

    FileSystemOptions opts = new FileSystemOptions();

    String[] tokens = StringUtils.split(url, ":");

    String protocol = tokens[0];//from   ww w .  jav  a 2s.  com

    if ("ftp".equals(protocol)) {
        FtpFileSystemConfigBuilder builder = FtpFileSystemConfigBuilder.getInstance();
        builder.setPassiveMode(opts, ftpSettings.isPassiveMode());
        builder.setUserDirIsRoot(opts, ftpSettings.isUserDirIsRoot());
    }
    if ("sftp".equals(protocol)) {
        SftpFileSystemConfigBuilder builder = SftpFileSystemConfigBuilder.getInstance();
        builder.setUserDirIsRoot(opts, sftpSettings.isUserDirIsRoot());
    }

    String domain = null;
    tokens = StringUtils.split("\\");
    if (tokens.length == 2) {
        domain = tokens[0];
        username = tokens[1];
    }

    StaticUserAuthenticator auth = new StaticUserAuthenticator(domain, username, password);

    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);

    return opts;
}