Example usage for org.apache.commons.vfs FileSystemException getCode

List of usage examples for org.apache.commons.vfs FileSystemException getCode

Introduction

In this page you can find the example usage for org.apache.commons.vfs FileSystemException getCode.

Prototype

public String getCode() 

Source Link

Document

Retrieve error code of the exception.

Usage

From source file:com.adito.networkplaces.store.webdav.WebDAVMount.java

public FileObject createVFSFileObject(String path, PasswordCredentials credentials) throws IOException {
    try {// w  ww  . ja  v a 2s. c o  m
        URI uri = getRootVFSURI();
        if (credentials != null) {
            uri.setUserinfo(DAVUtilities.encodeURIUserInfo(credentials.getUsername()
                    + (credentials.getPassword() != null ? ":" + new String(credentials.getPassword()) : "")));
        }
        uri.setPath(uri.getPath() + (uri.getPath().endsWith("/") ? "" : "/") + DAVUtilities.encodePath(path));

        FileObject fileObject = this.getStore().getRepository().getFileSystemManager()
                .resolveFile(uri.toString());
        return fileObject;
    } catch (FileSystemException fse) {
        if (fse.getCode().equals("vfs.provider.ftp/connect.error")) {
            throw new DAVAuthenticationRequiredException(getMountString());
        }
        throw fse;
    }
}

From source file:com.adito.networkplaces.store.http.HTTPMount.java

public FileObject createVFSFileObject(String path, PasswordCredentials credentials) throws IOException {
    try {/* www  . jav a2  s .  c o m*/
        URI uri = getRootVFSURI();
        if (credentials != null) {
            uri.setUserinfo(DAVUtilities.encodeURIUserInfo(credentials.getUsername()
                    + (credentials.getPassword() != null ? ":" + new String(credentials.getPassword()) : "")));
        }
        uri.setPath(uri.getPath() + (uri.getPath().endsWith("/") ? "" : "/") + DAVUtilities.encodePath(path));
        FileObject fileObject = this.getStore().getRepository().getFileSystemManager()
                .resolveFile(uri.toString(), getOptions(uri));
        return fileObject;
    } catch (FileSystemException fse) {
        if (fse.getCode().equals("vfs.provider.http/connect.error")) {
            throw new DAVAuthenticationRequiredException(getMountString());
        }
        throw fse;
    }
}

From source file:com.adito.networkplaces.store.ftp.FTPMount.java

public FileObject createVFSFileObject(String path, PasswordCredentials credentials) throws IOException {
    try {/*from   w  w  w.  j  ava2  s  .  co m*/
        URI uri = getRootVFSURI();
        if (credentials != null) {
            uri.setUserinfo(DAVUtilities.encodeURIUserInfo(credentials.getUsername()
                    + (credentials.getPassword() != null ? ":" + new String(credentials.getPassword()) : "")));
        }
        uri.setPath(uri.getPath() + (uri.getPath().endsWith("/") ? "" : "/") + DAVUtilities.encodePath(path));
        FileObject fileObject = this.getStore().getRepository().getFileSystemManager()
                .resolveFile(uri.toString(), getOptions(uri));
        return fileObject;
    } catch (FileSystemException fse) {
        if (fse.getCode().equals("vfs.provider.ftp/connect.error")) {
            throw new DAVAuthenticationRequiredException(getMountString());
        }
        throw fse;
    }
}

From source file:org.pentaho.di.core.vfs.configuration.KettleGenericFileSystemConfigBuilder.java

@Override
public void setParameter(FileSystemOptions opts, String name, String value, String fullParameterName,
        String vfsUrl) throws IOException {
    // Use the DelgatingFileSystemOptionsBuilder to insert generic parameters
    // This must be done to assure the correct VFS FileSystem drivers will process the parameters
    String scheme = extractScheme(fullParameterName);
    try {//  www  .j a v a  2 s.  c  o m
        DelegatingFileSystemOptionsBuilder delegateFSOptionsBuilder = new DelegatingFileSystemOptionsBuilder(
                KettleVFS.getInstance().getFileSystemManager());
        if (scheme != null) {
            delegateFSOptionsBuilder.setConfigString(opts, scheme, name, value);
        } else {
            log.logMinimal("Warning: Cannot process VFS parameters if no scheme is specified: " + vfsUrl);
        }
    } catch (FileSystemException e) {
        if (e.getCode().equalsIgnoreCase("vfs.provider/config-key-invalid.error")) {
            // This key is not supported by the default scheme config builder. This may be a custom key of another config
            // builder
            log.logMinimal("Warning: The configuration parameter [" + name
                    + "] is not supported by the default configuration builder for scheme: " + scheme);
        } else {
            // An unexpected error has occurred loading in parameters
            throw new IOException(e.getLocalizedMessage());
        }
    }
}