public class FTPTimestampParserImpl extends java.lang.Object implements FTPTimestampParser, Configurable
FTPTimestampParser
interface also implements the Configurable
interface to allow the parsing to be configured from the outside.ConfigurableFTPFileEntryParserImpl
Modifier and Type | Field and Description |
---|---|
private static int[] |
CALENDAR_UNITS |
private java.text.SimpleDateFormat |
defaultDateFormat
The date format for all dates, except possibly recent dates.
|
private int |
defaultDateSmallestUnitIndex |
private boolean |
lenientFutureDates |
private java.text.SimpleDateFormat |
recentDateFormat
The format used for recent dates (which don't have the year).
|
private int |
recentDateSmallestUnitIndex |
DEFAULT_RECENT_SDF, DEFAULT_SDF
Constructor and Description |
---|
FTPTimestampParserImpl()
The only constructor for this class.
|
Modifier and Type | Method and Description |
---|---|
void |
configure(FTPClientConfig config)
Implementation of the
Configurable
interface. |
java.text.SimpleDateFormat |
getDefaultDateFormat() |
java.lang.String |
getDefaultDateFormatString() |
private static int |
getEntry(java.text.SimpleDateFormat dateFormat) |
java.text.SimpleDateFormat |
getRecentDateFormat() |
java.lang.String |
getRecentDateFormatString() |
java.util.TimeZone |
getServerTimeZone() |
java.lang.String[] |
getShortMonths() |
private static int |
indexOf(int calendarUnit) |
(package private) boolean |
isLenientFutureDates() |
java.util.Calendar |
parseTimestamp(java.lang.String timestampStr)
Implements the one
method
in the FTPTimestampParser interface
according to this algorithm:
If the recentDateFormat member has been defined, try to parse the
supplied string with that. |
java.util.Calendar |
parseTimestamp(java.lang.String timestampStr,
java.util.Calendar serverTime)
If the recentDateFormat member has been defined, try to parse the
supplied string with that.
|
private void |
setDefaultDateFormat(java.lang.String format,
java.text.DateFormatSymbols dfs) |
(package private) void |
setLenientFutureDates(boolean lenientFutureDates) |
private static void |
setPrecision(int index,
java.util.Calendar working) |
private void |
setRecentDateFormat(java.lang.String format,
java.text.DateFormatSymbols dfs) |
private void |
setServerTimeZone(java.lang.String serverTimeZoneId)
sets a TimeZone represented by the supplied ID string into all
of the parsers used by this server.
|
private java.text.SimpleDateFormat defaultDateFormat
private int defaultDateSmallestUnitIndex
private java.text.SimpleDateFormat recentDateFormat
private int recentDateSmallestUnitIndex
private boolean lenientFutureDates
private static final int[] CALENDAR_UNITS
public FTPTimestampParserImpl()
private static int getEntry(java.text.SimpleDateFormat dateFormat)
private static int indexOf(int calendarUnit)
private static void setPrecision(int index, java.util.Calendar working)
public java.util.Calendar parseTimestamp(java.lang.String timestampStr) throws java.text.ParseException
method
in the FTPTimestampParser
interface
according to this algorithm:
If the recentDateFormat member has been defined, try to parse the
supplied string with that. If that parse fails, or if the recentDateFormat
member has not been defined, attempt to parse with the defaultDateFormat
member. If that fails, throw a ParseException.
This method assumes that the server time is the same as the local time.parseTimestamp
in interface FTPTimestampParser
timestampStr
- The timestamp to be parsedjava.text.ParseException
- if none of the parser mechanisms belonging to
the implementor can parse the input.parseTimestamp(String, Calendar)
public java.util.Calendar parseTimestamp(java.lang.String timestampStr, java.util.Calendar serverTime) throws java.text.ParseException
Calendar
instance to be passed in which represents the
current (system) time.timestampStr
- The timestamp to be parsedserverTime
- The current time for the serverjava.text.ParseException
- if timestamp cannot be parsedFTPTimestampParser.parseTimestamp(String)
public java.text.SimpleDateFormat getDefaultDateFormat()
public java.lang.String getDefaultDateFormatString()
private void setDefaultDateFormat(java.lang.String format, java.text.DateFormatSymbols dfs)
format
- The defaultDateFormat to be set.dfs
- the symbols to use (may be null)public java.text.SimpleDateFormat getRecentDateFormat()
public java.lang.String getRecentDateFormatString()
private void setRecentDateFormat(java.lang.String format, java.text.DateFormatSymbols dfs)
format
- The recentDateFormat to set.dfs
- the symbols to use (may be null)public java.lang.String[] getShortMonths()
public java.util.TimeZone getServerTimeZone()
private void setServerTimeZone(java.lang.String serverTimeZoneId)
serverTimeZone
- Time Id java.util.TimeZone id used by
the ftp server. If null the client's local time zone is assumed.public void configure(FTPClientConfig config)
Configurable
interface. Configures this FTPTimestampParser
according
to the following logic:
Set up the defaultDateFormat
and optionally the recentDateFormat
to values supplied in the config based on month names configured as follows:
shortMonthString
has been supplied in the config
, use that to parse parse timestamps.serverLanguageCode
has been supplied in the config
, use the month names represented
by that language
to parse timestamps.
Finally if a serverTimeZoneId
has been supplied via the config, set that into all date formats that have
been configured.
configure
in interface Configurable
config
- the object containing the configuration databoolean isLenientFutureDates()
void setLenientFutureDates(boolean lenientFutureDates)
lenientFutureDates
- The lenientFutureDates to set.