Author: scohen
Date: Mon Jun 6 16:15:51 2005
New Revision: 185093
URL: http://svn.apache.org/viewcvs?rev=185093&view=rev
Log:
Fix bug 35181 - add an option to specify leniency when needed because
client and server systems cannot be synchronized.
Modified:
jakarta/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/FTPClientConfig.java
jakarta/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImpl.java
jakarta/commons/proper/net/trunk/src/test/org/apache/commons/net/ftp/parser/FTPTimestampParserImplTest.java
Modified:
jakarta/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/FTPClientConfig.java
URL:
http://svn.apache.org/viewcvs/jakarta/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/FTPClientConfig.java?rev=185093&r1=185092&r2=185093&view=diff
==============================================================================
---
jakarta/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/FTPClientConfig.java
(original)
+++
jakarta/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/FTPClientConfig.java
Mon Jun 6 16:15:51 2005
@@ -179,6 +179,7 @@
private final String serverSystemKey;
private String defaultDateFormatStr = null;
private String recentDateFormatStr = null;
+ private boolean lenientFutureDates = false;
private String serverLanguageCode = null;
private String shortMonthNames = null;
private String serverTimeZoneId = null;
@@ -324,6 +325,15 @@
return serverLanguageCode;
}
+ /**
+ * <p>
+ * getter for the [EMAIL PROTECTED] #setLenientFutureDates(boolean)
lenientFutureDates} property.
+ * </p>
+ * @return Returns the lenientFutureDates.
+ */
+ public boolean isLenientFutureDates() {
+ return lenientFutureDates;
+ }
/**
* <p>
* setter for the defaultDateFormatStr property. This property
@@ -361,6 +371,29 @@
this.recentDateFormatStr = recentDateFormatStr;
}
+ /**
+ * <p>
+ * setter for the lenientFutureDates property. This boolean property
+ * (default: false) only has meaning when a
+ * [EMAIL PROTECTED] #setRecentDateFormatStr(String)
recentDateFormatStr} property
+ * has been set. In that case, if this property is set true, then the
+ * parser, when it encounters a listing parseable with the recent date
+ * format, will only consider a date to belong to the previous year if
+ * it is more than one day in the future. This will allow all
+ * out-of-synch situations (whether based on "slop" - i.e. servers
simply
+ * out of synch with one another or because of time zone differences -
+ * but in the latter case it is highly recommended to use the
+ * [EMAIL PROTECTED] #setServerTimeZoneId(String) serverTimeZoneId}
property
+ * instead) to resolve correctly.
+ * </p><p>
+ * This is used primarily in unix-based systems.
+ * </p>
+ * @param lenientFutureDates set true to compensate for out-of-synch
+ * conditions.
+ */
+ public void setLenientFutureDates(boolean lenientFutureDates) {
+ this.lenientFutureDates = lenientFutureDates;
+ }
/**
* <p>
* setter for the serverTimeZoneId property. This property
Modified:
jakarta/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImpl.java
URL:
http://svn.apache.org/viewcvs/jakarta/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImpl.java?rev=185093&r1=185092&r2=185093&view=diff
==============================================================================
---
jakarta/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImpl.java
(original)
+++
jakarta/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImpl.java
Mon Jun 6 16:15:51 2005
@@ -41,6 +41,7 @@
private SimpleDateFormat defaultDateFormat;
private SimpleDateFormat recentDateFormat;
+ private boolean lenientFutureDates = false;
/**
@@ -82,6 +83,12 @@
{
working.setTime(parsed);
working.set(Calendar.YEAR, now.get(Calendar.YEAR));
+
+ if (this.lenientFutureDates) {
+ // add a day to "now" so that "slop" doesn't cause
a date
+ // slightly in the future to roll back a full year.
(Bug 35181)
+ now.add(Calendar.DATE, 1);
+ }
if (working.after(now)) {
working.add(Calendar.YEAR, -1);
}
@@ -233,5 +240,19 @@
this.defaultDateFormat.setLenient(false);
setServerTimeZone(config.getServerTimeZoneId());
+
+ this.lenientFutureDates = config.isLenientFutureDates();
}
+ /**
+ * @return Returns the lenientFutureDates.
+ */
+ boolean isLenientFutureDates() {
+ return lenientFutureDates;
+ }
+ /**
+ * @param lenientFutureDates The lenientFutureDates to set.
+ */
+ void setLenientFutureDates(boolean lenientFutureDates) {
+ this.lenientFutureDates = lenientFutureDates;
+ }
}
Modified:
jakarta/commons/proper/net/trunk/src/test/org/apache/commons/net/ftp/parser/FTPTimestampParserImplTest.java
URL:
http://svn.apache.org/viewcvs/jakarta/commons/proper/net/trunk/src/test/org/apache/commons/net/ftp/parser/FTPTimestampParserImplTest.java?rev=185093&r1=185092&r2=185093&view=diff
==============================================================================
---
jakarta/commons/proper/net/trunk/src/test/org/apache/commons/net/ftp/parser/FTPTimestampParserImplTest.java
(original)
+++
jakarta/commons/proper/net/trunk/src/test/org/apache/commons/net/ftp/parser/FTPTimestampParserImplTest.java
Mon Jun 6 16:15:51 2005
@@ -57,6 +57,43 @@
}
}
+ public void testParseTimestampWithSlop() {
+ Calendar cal = Calendar.getInstance();
+ int timeZoneOffset = cal.getTimeZone().getRawOffset();
+ cal.add(Calendar.HOUR_OF_DAY, 1);
+ cal.set(Calendar.SECOND,0);
+ cal.set(Calendar.MILLISECOND,0);
+ Date anHourFromNow = cal.getTime();
+ cal.add(Calendar.DATE, 1);
+ Date anHourFromNowTomorrow = cal.getTime();
+ cal.add(Calendar.DATE, -1);
+
+ FTPTimestampParserImpl parser = new FTPTimestampParserImpl();
+
+ // set the "slop" factor on
+ parser.setLenientFutureDates(true);
+
+ SimpleDateFormat sdf =
+ new
SimpleDateFormat(parser.getRecentDateFormatString());
+ try {
+ String fmtTime = sdf.format(anHourFromNow);
+ Calendar parsed = parser.parseTimestamp(fmtTime);
+ // the timestamp is ahead of now (by one hour), but
+ // that's within range of the "slop" factor.
+ // so the date is still considered this year.
+ assertEquals("test.slop.no.roll.back.year", 0,
cal.get(Calendar.YEAR) - parsed.get(Calendar.YEAR));
+
+ // add a day to get beyond the range of the slop
factor.
+ // this must mean the file's date refers to a year ago.
+ fmtTime = sdf.format(anHourFromNowTomorrow);
+ parsed = parser.parseTimestamp(fmtTime);
+ assertEquals("test.slop.roll.back.year", 1,
cal.get(Calendar.YEAR) - parsed.get(Calendar.YEAR));
+
+ } catch (ParseException e) {
+ fail("Unable to parse");
+ }
+ }
+
public void testParseTimestampAcrossTimeZones() {
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]