Class FTPTimestampParserImpl
- java.lang.Object
-
- org.apache.commons.net.ftp.parser.FTPTimestampParserImpl
-
- All Implemented Interfaces:
Configurable,FTPTimestampParser
public class FTPTimestampParserImpl extends java.lang.Object implements FTPTimestampParser, Configurable
Default implementation of theFTPTimestampParserinterface also implements theConfigurableinterface to allow the parsing to be configured from the outside.- Since:
- 1.4
- See Also:
ConfigurableFTPFileEntryParserImpl
-
-
Field Summary
Fields Modifier and Type Field Description private static int[]CALENDAR_UNITSprivate java.text.SimpleDateFormatdefaultDateFormatThe date format for all dates, except possibly recent dates.private intdefaultDateSmallestUnitIndexprivate booleanlenientFutureDatesprivate java.text.SimpleDateFormatrecentDateFormatThe format used for recent dates (which don't have the year).private intrecentDateSmallestUnitIndex-
Fields inherited from interface org.apache.commons.net.ftp.parser.FTPTimestampParser
DEFAULT_RECENT_SDF, DEFAULT_SDF
-
-
Constructor Summary
Constructors Constructor Description FTPTimestampParserImpl()The only constructor for this class.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidconfigure(FTPClientConfig config)Implements theConfigurableinterface.java.text.SimpleDateFormatgetDefaultDateFormat()Gets the defaultDateFormat.java.lang.StringgetDefaultDateFormatString()Gets the defaultDateFormat pattern string.private static intgetEntry(java.text.SimpleDateFormat dateFormat)java.text.SimpleDateFormatgetRecentDateFormat()Gets the recentDateFormat.java.lang.StringgetRecentDateFormatString()Gets the recentDateFormat.java.util.TimeZonegetServerTimeZone()Gets the serverTimeZone used by this parser.java.lang.String[]getShortMonths()Gets an array of 12 strings representing the short month names used by this parse.private static intindexOf(int calendarUnit)(package private) booleanisLenientFutureDates()java.util.CalendarparseTimestamp(java.lang.String timestampStr)Implements the onemethodin theFTPTimestampParserinterface according to this algorithm: If the recentDateFormat member has been defined, try to parse the supplied string with that.java.util.CalendarparseTimestamp(java.lang.String timestampStr, java.util.Calendar serverTime)If the recentDateFormat member has been defined, try to parse the supplied string with that.private voidsetDefaultDateFormat(java.lang.String format, java.text.DateFormatSymbols dfs)(package private) voidsetLenientFutureDates(boolean lenientFutureDates)private static voidsetPrecision(int index, java.util.Calendar working)private voidsetRecentDateFormat(java.lang.String format, java.text.DateFormatSymbols dfs)private voidsetServerTimeZone(java.lang.String serverTimeZoneId)sets a TimeZone represented by the supplied ID string into all the parsers used by this server.
-
-
-
Field Detail
-
CALENDAR_UNITS
private static final int[] CALENDAR_UNITS
-
defaultDateFormat
private java.text.SimpleDateFormat defaultDateFormat
The date format for all dates, except possibly recent dates. Assumed to include the year.
-
defaultDateSmallestUnitIndex
private int defaultDateSmallestUnitIndex
-
recentDateFormat
private java.text.SimpleDateFormat recentDateFormat
The format used for recent dates (which don't have the year). May be null.
-
recentDateSmallestUnitIndex
private int recentDateSmallestUnitIndex
-
lenientFutureDates
private boolean lenientFutureDates
-
-
Method Detail
-
getEntry
private static int getEntry(java.text.SimpleDateFormat dateFormat)
-
indexOf
private static int indexOf(int calendarUnit)
-
setPrecision
private static void setPrecision(int index, java.util.Calendar working)
-
configure
public void configure(FTPClientConfig config)
Implements theConfigurableinterface. Configures thisFTPTimestampParseraccording to the following logic:Sets up the
defaultDateFormatand optionally therecentDateFormatto values supplied in the config based on month names configured as follows:- If a
shortMonthStringhas been supplied in theconfig, use that to parse parse timestamps. - Otherwise, if a
serverLanguageCodehas been supplied in theconfig, use the month names represented by thatlanguageto parse timestamps. - otherwise use default English month names
Finally if a
serverTimeZoneIdhas been supplied via the config, set that into all date formats that have been configured.- Specified by:
configurein interfaceConfigurable- Parameters:
config- the object containing the configuration data.
- If a
-
getDefaultDateFormat
public java.text.SimpleDateFormat getDefaultDateFormat()
Gets the defaultDateFormat.- Returns:
- the defaultDateFormat.
-
getDefaultDateFormatString
public java.lang.String getDefaultDateFormatString()
Gets the defaultDateFormat pattern string.- Returns:
- the defaultDateFormat pattern string.
-
getRecentDateFormat
public java.text.SimpleDateFormat getRecentDateFormat()
Gets the recentDateFormat.- Returns:
- the recentDateFormat.
-
getRecentDateFormatString
public java.lang.String getRecentDateFormatString()
Gets the recentDateFormat.- Returns:
- the recentDateFormat.
-
getServerTimeZone
public java.util.TimeZone getServerTimeZone()
Gets the serverTimeZone used by this parser.- Returns:
- the serverTimeZone used by this parser.
-
getShortMonths
public java.lang.String[] getShortMonths()
Gets an array of 12 strings representing the short month names used by this parse.- Returns:
- an array of 12 strings representing the short month names used by this parse.
-
isLenientFutureDates
boolean isLenientFutureDates()
- Returns:
- the lenientFutureDates.
-
parseTimestamp
public java.util.Calendar parseTimestamp(java.lang.String timestampStr) throws java.text.ParseExceptionImplements the onemethodin theFTPTimestampParserinterface 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:
parseTimestampin interfaceFTPTimestampParser- Parameters:
timestampStr- The timestamp to be parsed- Returns:
- a Calendar with the parsed timestamp
- Throws:
java.text.ParseException- if none of the parser mechanisms belonging to the implementor can parse the input.- See Also:
parseTimestamp(String, Calendar)
-
parseTimestamp
public java.util.Calendar parseTimestamp(java.lang.String timestampStr, java.util.Calendar serverTime) throws java.text.ParseExceptionIf 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 aCalendarinstance 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:
java.text.ParseException- if timestamp cannot be parsed- Since:
- 1.5
- See Also:
FTPTimestampParser.parseTimestamp(String)
-
setDefaultDateFormat
private void setDefaultDateFormat(java.lang.String format, java.text.DateFormatSymbols dfs)- 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
private void setRecentDateFormat(java.lang.String format, java.text.DateFormatSymbols dfs)- Parameters:
format- The recentDateFormat to set.dfs- the symbols to use (may be null)
-
setServerTimeZone
private void setServerTimeZone(java.lang.String serverTimeZoneId)
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.
-
-