Search in sources :

Example 1 with URLFileName

use of org.apache.commons.vfs2.provider.URLFileName in project pentaho-kettle by pentaho.

the class KettleSftpFileSystemConfigBuilder method setParameter.

/**
 * Publicly expose a generic way to set parameters
 */
@Override
public void setParameter(FileSystemOptions opts, String name, String value, String fullParameterName, String vfsUrl) throws IOException {
    if (!fullParameterName.startsWith("vfs.sftp")) {
        // This is not an SFTP parameter. Delegate to the generic handler
        super.setParameter(opts, name, value, fullParameterName, vfsUrl);
    } else {
        // Check for the presence of a host in the full variable name
        try {
            // Parse server name from vfsFilename
            FileNameParser sftpFilenameParser = SftpFileNameParser.getInstance();
            URLFileName file = (URLFileName) sftpFilenameParser.parseUri(null, null, vfsUrl);
            if (!parameterContainsHost(fullParameterName) || fullParameterName.endsWith(file.getHostName())) {
                // Match special cases for parameter names
                if (name.equalsIgnoreCase("AuthKeyPassphrase")) {
                    setParam(opts, UserInfo.class.getName(), new PentahoUserInfo(value));
                } else if (name.equals("identity")) {
                    IdentityInfo[] identities = (IdentityInfo[]) this.getParam(opts, IDENTITY_KEY);
                    if (identities == null) {
                        identities = new IdentityInfo[] { new IdentityInfo(new File(value)) };
                    } else {
                        // Copy, in a Java 5 friendly manner, identities into a larger array
                        IdentityInfo[] temp = new IdentityInfo[identities.length + 1];
                        System.arraycopy(identities, 0, temp, 0, identities.length);
                        identities = temp;
                        identities[identities.length - 1] = new IdentityInfo(new File(value));
                    }
                    setParam(opts, IDENTITY_KEY, identities);
                } else {
                    super.setParameter(opts, name, value, fullParameterName, vfsUrl);
                }
            } else {
                // No host match found
                log.logDebug("No host match found for: " + fullParameterName);
            }
        } catch (IOException e) {
            log.logError("Failed to set VFS parameter: [" + fullParameterName + "] " + value, e);
        }
    }
}
Also used : URLFileName(org.apache.commons.vfs2.provider.URLFileName) FileNameParser(org.apache.commons.vfs2.provider.FileNameParser) SftpFileNameParser(org.apache.commons.vfs2.provider.sftp.SftpFileNameParser) IdentityInfo(org.apache.commons.vfs2.provider.sftp.IdentityInfo) UserInfo(com.jcraft.jsch.UserInfo) IOException(java.io.IOException) File(java.io.File)

Aggregations

UserInfo (com.jcraft.jsch.UserInfo)1 File (java.io.File)1 IOException (java.io.IOException)1 FileNameParser (org.apache.commons.vfs2.provider.FileNameParser)1 URLFileName (org.apache.commons.vfs2.provider.URLFileName)1 IdentityInfo (org.apache.commons.vfs2.provider.sftp.IdentityInfo)1 SftpFileNameParser (org.apache.commons.vfs2.provider.sftp.SftpFileNameParser)1