You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2011/02/26 03:15:03 UTC
svn commit: r1074779 - in /commons/proper/net/trunk/src: changes/changes.xml
main/java/org/apache/commons/net/ftp/FTPClient.java
Author: sebb
Date: Sat Feb 26 02:15:02 2011
New Revision: 1074779
URL: http://svn.apache.org/viewvc?rev=1074779&view=rev
Log:
NET-229 Use properties file to handle new OS-type auto-detection.
Modified:
commons/proper/net/trunk/src/changes/changes.xml
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java
Modified: commons/proper/net/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/changes/changes.xml?rev=1074779&r1=1074778&r2=1074779&view=diff
==============================================================================
--- commons/proper/net/trunk/src/changes/changes.xml (original)
+++ commons/proper/net/trunk/src/changes/changes.xml Sat Feb 26 02:15:02 2011
@@ -52,6 +52,9 @@ The <action> type attribute can be add,u
<body>
<release version="2.3" date="TBA" description="TBA">
+ <action issue="NET-229" dev="sebb" type="add">
+ Use properties file to handle new OS-type auto-detection.
+ </action>
<action issue="NET-332" dev="sebb" type="add">
Commons net ftp cannot handle unknown type parser and should allow override of parser through vm argument.
The system property "org.apache.commons.net.ftp.systemType" can be used to provide the system type.
Modified: commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java?rev=1074779&r1=1074778&r2=1074779&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java (original)
+++ commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java Sat Feb 26 02:15:02 2011
@@ -28,6 +28,7 @@ import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.ArrayList;
+import java.util.Properties;
import java.util.Random;
import org.apache.commons.net.MalformedServerReplyException;
@@ -242,6 +243,11 @@ implements Configurable
*/
public static final String FTP_SYSTEM_TYPE = "org.apache.commons.net.ftp.systemType";
+ /**
+ * The name of the systemType properties file ({@value}).
+ */
+ private static final String SYSTEM_TYPE_PROPERTIES = "/systemType.properties";
+
/***
* A constant indicating the FTP session is expecting all transfers
* to occur between the client (local) and server and that the server
@@ -312,6 +318,28 @@ implements Configurable
__parms_pat = java.util.regex.Pattern.compile(__parms);
}
+ private static class PropertiesSingleton {
+
+ static final Properties PROPERTIES;
+
+ static {
+ InputStream resourceAsStream = FTPClient.class.getResourceAsStream(SYSTEM_TYPE_PROPERTIES);
+ Properties p = null;
+ if (resourceAsStream != null) {
+ p = new Properties();
+ try {
+ p.load(resourceAsStream);
+ } catch (IOException e) {
+ }
+ }
+ PROPERTIES = p;
+ }
+
+ }
+ private static Properties getOverrideProperties(){
+ return PropertiesSingleton.PROPERTIES;
+ }
+
/***
* Default FTPClient constructor. Creates a new FTPClient instance
* with the data connection mode set to
@@ -2546,6 +2574,9 @@ implements Configurable
* May be {@code null}, in which case the code checks first
* the system property {@link #FTP_SYSTEM_TYPE}, and if that is
* not defined the SYST command is used to provide the value.
+ * To allow for arbitrary system types, the return from the
+ * SYST command is used to look up an alias for the type in the
+ * {@link #SYSTEM_TYPE_PROPERTIES} properties file if it is available.
*
* @return A FTPListParseEngine object that holds the raw information and
* is capable of providing parsed FTPFile objects, one for each file
@@ -2604,9 +2635,15 @@ implements Configurable
String systemType = System.getProperty(FTP_SYSTEM_TYPE);
if (systemType == null) {
systemType = getSystemType(); // cannot be null
+ Properties override = getOverrideProperties();
+ if (override != null) {
+ String newType = override.getProperty(systemType);
+ if (newType != null) {
+ systemType = newType;
+ }
+ }
}
- __entryParser =
- __parserFactory.createFileEntryParser(systemType);
+ __entryParser = __parserFactory.createFileEntryParser(systemType);
__entryParserKey = systemType;
}
}
@@ -2616,7 +2653,6 @@ implements Configurable
}
-
/**
* private method through which all listFiles() and
* initiateListParsing methods pass once a parser is determined.