Author: ggregory
Date: Thu May 17 15:02:59 2012
New Revision: 1339627
URL: http://svn.apache.org/viewvc?rev=1339627&view=rev
Log:
Replace all magic string with constants (except error keys into the message
table). Order all members. Change some variable names (e.g. o -> obj). Add
missing @Override.
Modified:
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystemConfigBuilder.java
Modified:
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystemConfigBuilder.java
URL:
http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystemConfigBuilder.java?rev=1339627&r1=1339626&r2=1339627&view=diff
==============================================================================
---
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystemConfigBuilder.java
(original)
+++
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystemConfigBuilder.java
Thu May 17 15:02:59 2012
@@ -31,24 +31,6 @@ import com.jcraft.jsch.UserInfo;
*/
public final class SftpFileSystemConfigBuilder extends FileSystemConfigBuilder
{
- /** HTTP Proxy. */
- public static final ProxyType PROXY_HTTP = new ProxyType("http");
- /** SOCKS Proxy. */
- public static final ProxyType PROXY_SOCKS5 = new ProxyType("socks");
-
- private static final SftpFileSystemConfigBuilder BUILDER = new
SftpFileSystemConfigBuilder();
- private static final String USER_DIR_IS_ROOT =
SftpFileSystemConfigBuilder.class.getName() + ".USER_DIR_IS_ROOT";
- private static final String TIMEOUT =
SftpFileSystemConfigBuilder.class.getName() + ".TIMEOUT";
-
- private SftpFileSystemConfigBuilder()
- {
- super("sftp.");
- }
-
- public static SftpFileSystemConfigBuilder getInstance()
- {
- return BUILDER;
- }
/**
* Proxy type.
@@ -67,26 +49,27 @@ public final class SftpFileSystemConfigB
this.proxyType = proxyType;
}
- public int compareTo(ProxyType o)
+ @Override
+ public int compareTo(final ProxyType pType)
{
- return proxyType.compareTo(o.proxyType);
+ return this.proxyType.compareTo(pType.proxyType);
}
@Override
- public boolean equals(Object o)
+ public boolean equals(final Object obj)
{
- if (this == o)
+ if (this == obj)
{
return true;
}
- if (o == null || getClass() != o.getClass())
+ if (obj == null || this.getClass() != obj.getClass())
{
return false;
}
- ProxyType proxyType1 = (ProxyType) o;
+ final ProxyType pType = (ProxyType) obj;
- if (proxyType != null ? !proxyType.equals(proxyType1.proxyType) :
proxyType1.proxyType != null)
+ if (this.proxyType != null ?
!this.proxyType.equals(pType.proxyType) : pType.proxyType != null)
{
return false;
}
@@ -95,277 +78,360 @@ public final class SftpFileSystemConfigB
}
/**
- * @return a hash code value for this object.
+ * @return a hash code value for this object.
* @since 2.0
*/
@Override
public int hashCode()
{
- return proxyType.hashCode();
+ return this.proxyType.hashCode();
}
}
- /**
- * Set the userinfo class to use if e.g. a password or a not known host
- * will be contacted.
- *
- * @param opts The FileSystem options.
- * @param info User information.
- */
- public void setUserInfo(FileSystemOptions opts, UserInfo info)
+ private static final String _PREFIX =
SftpFileSystemConfigBuilder.class.getName();
+
+ private static final SftpFileSystemConfigBuilder BUILDER = new
SftpFileSystemConfigBuilder();
+
+ private static final String COMPRESSION = _PREFIX + "COMPRESSION";
+ private static final String HOST_KEY_CHECK_ASK = "ask";
+ private static final String HOST_KEY_CHECK_NO = "no";
+ private static final String HOST_KEY_CHECK_YES = "yes";
+ private static final String IDENTITIES = _PREFIX + ".IDENTITIES";
+ private static final String KNOWN_HOSTS = _PREFIX + ".KNOWN_HOSTS";
+ private static final String PREFERRED_AUTHENTICATIONS = _PREFIX +
".PREFERRED_AUTHENTICATIONS";
+ private static final String PROXY_HOST = _PREFIX + ".PROXY_HOST";
+
+ /** HTTP Proxy. */
+ public static final ProxyType PROXY_HTTP = new ProxyType("http");
+ private static final String PROXY_PORT = _PREFIX + ".PROXY_PORT";
+
+ /** SOCKS Proxy. */
+ public static final ProxyType PROXY_SOCKS5 = new ProxyType("socks");
+ private static final String PROXY_TYPE = _PREFIX + ".PROXY_TYPE";
+ private static final String STRICT_HOST_KEY_CHECKING = _PREFIX +
".STRICT_HOST_KEY_CHECKING";
+ private static final String TIMEOUT = _PREFIX + ".TIMEOUT";
+ private static final String USER_DIR_IS_ROOT = _PREFIX +
".USER_DIR_IS_ROOT";
+
+ public static SftpFileSystemConfigBuilder getInstance()
{
- setParam(opts, UserInfo.class.getName(), info);
+ return BUILDER;
}
- /**
- * @param opts The FileSystem options.
- * @return The UserInfo.
- * @see #setUserInfo
- */
- public UserInfo getUserInfo(FileSystemOptions opts)
+ private SftpFileSystemConfigBuilder()
{
- return (UserInfo) getParam(opts, UserInfo.class.getName());
+ super("sftp.");
}
/**
- * Set the known_hosts file. e.g. /home/user/.ssh/known_hosts2<br>
- * Need to use a java.io.File as JSch cant deal with vfs FileObjects ;-)
- *
- * @param opts The FileSystem options.
- * @param sshdir The known hosts directory.
- * @throws FileSystemException if an error occurs.
+ * @param opts
+ * The FileSystem options.
+ * @return The name of the compression algorithm.
+ * @see #setCompression
*/
- public void setKnownHosts(FileSystemOptions opts, File sshdir) throws
FileSystemException
+ public String getCompression(final FileSystemOptions opts)
+ {
+ return this.getString(opts, COMPRESSION);
+ }
+
+ @Override
+ protected Class<? extends FileSystem> getConfigClass()
{
- setParam(opts, "knownHosts", sshdir);
+ return SftpFileSystem.class;
}
/**
- * @param opts The FileSystem options.
- * @return the known hosts File.
- * @see #setKnownHosts
+ * Gets the identity files (your private key files).
+ * <p>
+ * We use java.io.File because JSch cannot deal with VFS FileObjects.
+ * </p>
+ *
+ * @param opts
+ * The FileSystem options.
+ * @return the array of identity Files.
+ * @see #setIdentities
*/
- public File getKnownHosts(FileSystemOptions opts)
+ public File[] getIdentities(final FileSystemOptions opts)
{
- return (File) getParam(opts, "knownHosts");
+ return (File[]) this.getParam(opts, IDENTITIES);
}
/**
- * Set the identity files (your private key files).<br>
- * Need to use a java.io.File as JSch cant deal with vfs FileObjects ;-)
- *
- * @param opts The FileSystem options.
- * @param identities An array of identity Files.
- * @throws FileSystemException if an error occurs.
+ * @param opts
+ * The FileSystem options.
+ * @return the known hosts File.
+ * @see #setKnownHosts
*/
- public void setIdentities(FileSystemOptions opts, File[] identities)
throws FileSystemException
+ public File getKnownHosts(final FileSystemOptions opts)
{
- setParam(opts, "identities", identities);
+ return (File) this.getParam(opts, KNOWN_HOSTS);
}
/**
- * configure the compression to use.<br>
- * e.g. pass "zlib,none" to enable the compression.<br>
- * See the jsch documentation for details.
- *
- * @param opts The FileSystem options.
- * @param compression The compression algorithm name.
- * @throws FileSystemException if an error occurs.
+ * Get authentication order.
+ *
+ * @param opts
+ * The FileSystem options.
+ * @return The authentication order.
+ * @since 2.0
*/
- public void setCompression(FileSystemOptions opts, String compression)
throws FileSystemException
+ public String getPreferredAuthentications(final FileSystemOptions opts)
{
- setParam(opts, "compression", compression);
+ return (String) this.getParam(opts, PREFERRED_AUTHENTICATIONS);
}
/**
- * @param opts The FileSystem options.
- * @return The name of the compression algorithm.
- * @see #setCompression
+ * Get the proxy to use for sftp connection. You have to set the ProxyPort
too if you would like to have the proxy
+ * relly used.
+ *
+ * @param opts
+ * The FileSystem options.
+ * @return proxyHost
+ * @see #setProxyPort
*/
- public String getCompression(FileSystemOptions opts)
+ public String getProxyHost(final FileSystemOptions opts)
{
- return getString(opts, "compression");
+ return this.getString(opts, PROXY_HOST);
}
/**
- * @param opts The FileSystem options.
- * @return the array of identity Files.
- * @see #setIdentities
+ * Get the proxy-port to use for sftp the connection You have to set the
ProxyHost too if you would like to have the
+ * proxy relly used.
+ *
+ * @param opts
+ * The FileSystem options.
+ * @return proxyPort: the port number or 0 if it is not set
+ * @see #setProxyHost
*/
- public File[] getIdentities(FileSystemOptions opts)
+ public int getProxyPort(final FileSystemOptions opts)
{
- return (File[]) getParam(opts, "identities");
+ return this.getInteger(opts, PROXY_PORT, 0);
}
/**
- * configure the host key checking to use.<br>
- * valid arguments are only yes, no and ask.<br>
- * See the jsch documentation for details.
- *
- * @param opts The FileSystem options.
- * @param hostKeyChecking The host key checking to use.
- * @throws FileSystemException if an error occurs.
+ * Get the proxy type to use for sftp connection.
+ *
+ * @param opts
+ * The FileSystem options.
+ * @return The ProxyType.
*/
- public void setStrictHostKeyChecking(FileSystemOptions opts, String
hostKeyChecking) throws FileSystemException
+ public ProxyType getProxyType(final FileSystemOptions opts)
{
- if (hostKeyChecking == null || (!hostKeyChecking.equals("ask") &&
!hostKeyChecking.equals("no") &&
- !hostKeyChecking.equals("yes")))
- {
- throw new
FileSystemException("vfs.provider.sftp/StrictHostKeyChecking-arg.error",
hostKeyChecking);
- }
-
- setParam(opts, "StrictHostKeyChecking", hostKeyChecking);
+ return (ProxyType) this.getParam(opts, PROXY_TYPE);
}
/**
- * @param opts The FileSystem options.
+ * @param opts
+ * The FileSystem options.
* @return the option value The host key checking.
* @see #setStrictHostKeyChecking(FileSystemOptions, String)
*/
- public String getStrictHostKeyChecking(FileSystemOptions opts)
+ public String getStrictHostKeyChecking(final FileSystemOptions opts)
{
- return getString(opts, "StrictHostKeyChecking", "no");
+ return this.getString(opts, STRICT_HOST_KEY_CHECKING,
HOST_KEY_CHECK_NO);
}
/**
- * use user directory as root (do not change to fs root).
- *
- * @param opts The FileSystem options.
- * @param userDirIsRoot true if the user dir is the root directory.
+ * @param opts
+ * The FileSystem options.
+ * @return The timeout value.
+ * @see #setTimeout
*/
- public void setUserDirIsRoot(FileSystemOptions opts, boolean userDirIsRoot)
+ public Integer getTimeout(final FileSystemOptions opts)
{
- setParam(opts, USER_DIR_IS_ROOT, userDirIsRoot ? Boolean.TRUE :
Boolean.FALSE);
+ return this.getInteger(opts, TIMEOUT);
}
/**
- * @param opts The FileSystemOptions.
+ * @param opts
+ * The FileSystemOptions.
* @return true if the user directory is the root.
* @see #setUserDirIsRoot
*/
- public Boolean getUserDirIsRoot(FileSystemOptions opts)
+ public Boolean getUserDirIsRoot(final FileSystemOptions opts)
{
- return getBoolean(opts, USER_DIR_IS_ROOT, Boolean.TRUE);
+ return this.getBoolean(opts, USER_DIR_IS_ROOT, Boolean.TRUE);
}
/**
- * set the timeout value on jsch session.
- *
- * @param opts The FileSystem options.
- * @param timeout The timeout.
+ * @param opts
+ * The FileSystem options.
+ * @return The UserInfo.
+ * @see #setUserInfo
*/
- public void setTimeout(FileSystemOptions opts, Integer timeout)
+ public UserInfo getUserInfo(final FileSystemOptions opts)
{
- setParam(opts, TIMEOUT, timeout);
+ return (UserInfo) this.getParam(opts, UserInfo.class.getName());
}
/**
- * @param opts The FileSystem options.
- * @return The timeout value.
- * @see #setTimeout
- */
- public Integer getTimeout(FileSystemOptions opts)
- {
- return getInteger(opts, TIMEOUT);
+ * configure the compression to use.<br>
+ * e.g. pass "zlib,none" to enable the compression.<br>
+ * See the jsch documentation for details.
+ *
+ * @param opts
+ * The FileSystem options.
+ * @param compression
+ * The compression algorithm name.
+ * @throws FileSystemException
+ * if an error occurs.
+ */
+ public void setCompression(final FileSystemOptions opts, final String
compression) throws FileSystemException
+ {
+ this.setParam(opts, COMPRESSION, compression);
}
- @Override
- protected Class<? extends FileSystem> getConfigClass()
+ /**
+ * Sets the identity files (your private key files).
+ * <p>
+ * We use java.io.File because JSch cannot deal with VFS FileObjects.
+ * </p>
+ *
+ * @param opts
+ * The FileSystem options.
+ * @param identityFiles
+ * An array of identity Files.
+ * @throws FileSystemException
+ * if an error occurs.
+ */
+ public void setIdentities(final FileSystemOptions opts, final File...
identityFiles) throws FileSystemException
{
- return SftpFileSystem.class;
+ this.setParam(opts, IDENTITIES, identityFiles);
}
/**
- * Set the proxy to use for sftp connection.<br>
- * You have to set the ProxyPort too if you would like to have the proxy
relly used.
- *
- * @param opts The FileSystem options.
- * @param proxyHost the host
- * @see #setProxyPort
+ * Set the known_hosts file. e.g. /home/user/.ssh/known_hosts2<br>
+ * Need to use a java.io.File as JSch cant deal with vfs FileObjects ;-)
+ *
+ * @param opts
+ * The FileSystem options.
+ * @param sshdir
+ * The known hosts directory.
+ * @throws FileSystemException
+ * if an error occurs.
*/
- public void setProxyHost(FileSystemOptions opts, String proxyHost)
+ public void setKnownHosts(final FileSystemOptions opts, final File sshdir)
throws FileSystemException
{
- setParam(opts, "proxyHost", proxyHost);
+ this.setParam(opts, KNOWN_HOSTS, sshdir);
}
/**
- * Set the proxy-port to use for sftp connection.
- * You have to set the ProxyHost too if you would like to have the proxy
relly used.
- *
- * @param opts The FileSystem options.
- * @param proxyPort the port
- * @see #setProxyHost
+ * Configure authentication order.
+ *
+ * @param opts
+ * The FileSystem options.
+ * @param preferredAuthentications
+ * The authentication order.
+ * @since 2.0
*/
- public void setProxyPort(FileSystemOptions opts, int proxyPort)
+ public void setPreferredAuthentications(final FileSystemOptions opts,
final String preferredAuthentications)
{
- setParam(opts, "proxyPort", Integer.valueOf(proxyPort));
+ this.setParam(opts, PREFERRED_AUTHENTICATIONS,
preferredAuthentications);
}
/**
- * Get the proxy to use for sftp connection.
+ * Set the proxy to use for sftp connection.<br>
* You have to set the ProxyPort too if you would like to have the proxy
relly used.
- *
- * @param opts The FileSystem options.
- * @return proxyHost
+ *
+ * @param opts
+ * The FileSystem options.
+ * @param proxyHost
+ * the host
* @see #setProxyPort
*/
- public String getProxyHost(FileSystemOptions opts)
+ public void setProxyHost(final FileSystemOptions opts, final String
proxyHost)
{
- return getString(opts, "proxyHost");
+ this.setParam(opts, PROXY_HOST, proxyHost);
}
/**
- * Get the proxy-port to use for sftp the connection
- * You have to set the ProxyHost too if you would like to have the proxy
relly used.
- *
- * @param opts The FileSystem options.
- * @return proxyPort: the port number or 0 if it is not set
+ * Set the proxy-port to use for sftp connection. You have to set the
ProxyHost too if you would like to have the
+ * proxy relly used.
+ *
+ * @param opts
+ * The FileSystem options.
+ * @param proxyPort
+ * the port
* @see #setProxyHost
*/
- public int getProxyPort(FileSystemOptions opts)
+ public void setProxyPort(final FileSystemOptions opts, final int proxyPort)
{
- return getInteger(opts, "proxyPort", 0);
+ this.setParam(opts, PROXY_PORT, Integer.valueOf(proxyPort));
}
/**
* Set the proxy type to use for sftp connection.
- * @param opts The FileSystem options.
- * @param proxyType the type of the proxy to use.
+ *
+ * @param opts
+ * The FileSystem options.
+ * @param proxyType
+ * the type of the proxy to use.
*/
- public void setProxyType(FileSystemOptions opts, ProxyType proxyType)
+ public void setProxyType(final FileSystemOptions opts, final ProxyType
proxyType)
{
- setParam(opts, "proxyType", proxyType);
+ this.setParam(opts, PROXY_TYPE, proxyType);
}
/**
- * Get the proxy type to use for sftp connection.
- * @param opts The FileSystem options.
- * @return The ProxyType.
+ * configure the host key checking to use.<br>
+ * valid arguments are only yes, no and ask.<br>
+ * See the jsch documentation for details.
+ *
+ * @param opts
+ * The FileSystem options.
+ * @param hostKeyChecking
+ * The host key checking to use.
+ * @throws FileSystemException
+ * if an error occurs.
+ */
+ public void setStrictHostKeyChecking(final FileSystemOptions opts, final
String hostKeyChecking)
+ throws FileSystemException
+ {
+ if (hostKeyChecking == null
+ || (!hostKeyChecking.equals(HOST_KEY_CHECK_ASK) &&
!hostKeyChecking.equals(HOST_KEY_CHECK_NO) && !hostKeyChecking
+ .equals(HOST_KEY_CHECK_YES)))
+ {
+ throw new
FileSystemException("vfs.provider.sftp/StrictHostKeyChecking-arg.error",
hostKeyChecking);
+ }
+
+ this.setParam(opts, STRICT_HOST_KEY_CHECKING, hostKeyChecking);
+ }
+
+ /**
+ * set the timeout value on jsch session.
+ *
+ * @param opts
+ * The FileSystem options.
+ * @param timeout
+ * The timeout.
*/
- public ProxyType getProxyType(FileSystemOptions opts)
+ public void setTimeout(final FileSystemOptions opts, final Integer timeout)
{
- return (ProxyType) getParam(opts, "proxyType");
+ this.setParam(opts, TIMEOUT, timeout);
}
/**
- * Configure authentication order.
- * @param opts The FileSystem options.
- * @param preferredAuthentications The authentication order.
- * @since 2.0
+ * use user directory as root (do not change to fs root).
+ *
+ * @param opts
+ * The FileSystem options.
+ * @param userDirIsRoot
+ * true if the user dir is the root directory.
*/
- public void setPreferredAuthentications(FileSystemOptions opts, String
preferredAuthentications)
+ public void setUserDirIsRoot(final FileSystemOptions opts, final boolean
userDirIsRoot)
{
- setParam(opts, "PreferredAuthentications", preferredAuthentications);
+ this.setParam(opts, USER_DIR_IS_ROOT, userDirIsRoot ? Boolean.TRUE :
Boolean.FALSE);
}
/**
- * Get authentication order.
- * @param opts The FileSystem options.
- * @return The authentication order.
- * @since 2.0
+ * Set the userinfo class to use if e.g. a password or a not known host
will be contacted.
+ *
+ * @param opts
+ * The FileSystem options.
+ * @param info
+ * User information.
*/
- public String getPreferredAuthentications(FileSystemOptions opts)
+ public void setUserInfo(final FileSystemOptions opts, final UserInfo info)
{
- return (String) getParam(opts, "PreferredAuthentications");
+ this.setParam(opts, UserInfo.class.getName(), info);
}
}