Class FTPTimestampParserImpl
java.lang.Object
org.apache.commons.net.ftp.parser.FTPTimestampParserImpl
- All Implemented Interfaces:
Configurable
,FTPTimestampParser
Default implementation of the
FTPTimestampParser
interface also implements the Configurable
interface to allow the parsing to be configured from the outside.- Since:
- 1.4
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int[]
private SimpleDateFormat
The date format for all dates, except possibly recent dates.private int
private boolean
private SimpleDateFormat
The format used for recent dates (which don't have the year).private int
Fields inherited from interface org.apache.commons.net.ftp.parser.FTPTimestampParser
DEFAULT_RECENT_SDF, DEFAULT_SDF
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
configure
(FTPClientConfig config) Implementation of theConfigurable
interface.private static int
getEntry
(SimpleDateFormat dateFormat) String[]
private static int
indexOf
(int calendarUnit) (package private) boolean
parseTimestamp
(String timestampStr) Implements the onemethod
in theFTPTimestampParser
interface according to this algorithm: If the recentDateFormat member has been defined, try to parse the supplied string with that.parseTimestamp
(String timestampStr, Calendar serverTime) If the recentDateFormat member has been defined, try to parse the supplied string with that.private void
setDefaultDateFormat
(String format, DateFormatSymbols dfs) (package private) void
setLenientFutureDates
(boolean lenientFutureDates) private static void
setPrecision
(int index, Calendar working) private void
setRecentDateFormat
(String format, DateFormatSymbols dfs) private void
setServerTimeZone
(String serverTimeZoneId) sets a TimeZone represented by the supplied ID string into all the parsers used by this server.
-
Field Details
-
CALENDAR_UNITS
private static final int[] CALENDAR_UNITS -
defaultDateFormat
The date format for all dates, except possibly recent dates. Assumed to include the year. -
defaultDateSmallestUnitIndex
private int defaultDateSmallestUnitIndex -
recentDateFormat
The format used for recent dates (which don't have the year). May be null. -
recentDateSmallestUnitIndex
private int recentDateSmallestUnitIndex -
lenientFutureDates
private boolean lenientFutureDates
-
-
Constructor Details
-
FTPTimestampParserImpl
public FTPTimestampParserImpl()The only constructor for this class.
-
-
Method Details
-
getEntry
-
indexOf
private static int indexOf(int calendarUnit) -
setPrecision
-
configure
Implementation of theConfigurable
interface. Configures thisFTPTimestampParser
according to the following logic:Set up the
defaultDateFormat
and optionally therecentDateFormat
to values supplied in the config based on month names configured as follows:- If a
shortMonthString
has been supplied in theconfig
, use that to parse parse timestamps. - Otherwise, if a
serverLanguageCode
has been supplied in theconfig
, use the month names represented by thatlanguage
to parse timestamps. - otherwise use default English month names
Finally if a
serverTimeZoneId
has been supplied via the config, set that into all date formats that have been configured.- Specified by:
configure
in interfaceConfigurable
- Parameters:
config
- the object containing the configuration data
- If a
-
getDefaultDateFormat
- Returns:
- Returns the defaultDateFormat.
-
getDefaultDateFormatString
- Returns:
- Returns the defaultDateFormat pattern string.
-
getRecentDateFormat
- Returns:
- Returns the recentDateFormat.
-
getRecentDateFormatString
- Returns:
- Returns the recentDateFormat.
-
getServerTimeZone
- Returns:
- Returns the serverTimeZone used by this parser.
-
getShortMonths
- Returns:
- returns an array of 12 strings representing the short month names used by this parse.
-
isLenientFutureDates
boolean isLenientFutureDates()- Returns:
- Returns the lenientFutureDates.
-
parseTimestamp
Implements the onemethod
in theFTPTimestampParser
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.- Specified by:
parseTimestamp
in interfaceFTPTimestampParser
- Parameters:
timestampStr
- The timestamp to be parsed- Returns:
- a Calendar with the parsed timestamp
- Throws:
ParseException
- if none of the parser mechanisms belonging to the implementor can parse the input.- See Also:
-
parseTimestamp
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 allows aCalendar
instance to be passed in which represents the current (system) time.- Parameters:
timestampStr
- The timestamp to be parsedserverTime
- The current time for the server- Returns:
- the calendar
- Throws:
ParseException
- if timestamp cannot be parsed- Since:
- 1.5
- See Also:
-
setDefaultDateFormat
- Parameters:
format
- The defaultDateFormat to be set.dfs
- the symbols to use (may be null)
-
setLenientFutureDates
void setLenientFutureDates(boolean lenientFutureDates) - Parameters:
lenientFutureDates
- The lenientFutureDates to set.
-
setRecentDateFormat
- Parameters:
format
- The recentDateFormat to set.dfs
- the symbols to use (may be null)
-
setServerTimeZone
sets a TimeZone represented by the supplied ID string into all the parsers used by this server.- Parameters:
serverTimeZoneId
- Time Id java.util.TimeZone id used by the ftp server. If null the client's local time zone is assumed.
-