org.apache.commons.net.ftp.parser

## Class FTPTimestampParserImpl

- java.lang.Object
- - org.apache.commons.net.ftp.parser.FTPTimestampParserImpl

- All Implemented Interfaces:
    Configurable, FTPTimestampParser

      public class FTPTimestampParserImpl
      extends Object
      implements FTPTimestampParser, Configurable

  Default implementation of the `FTPTimestampParser` interface also implements the `Configurable` interface to allow the parsing to be configured from the outside.
  See Also:
    `ConfigurableFTPFileEntryParserImpl`

- - ### Field Summary

    - ### Fields inherited from interface org.apache.commons.net.ftp.parser.FTPTimestampParser

      `DEFAULT_RECENT_SDF, DEFAULT_SDF`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `FTPTimestampParserImpl()` The only constructor for this class.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `configure(FTPClientConfig config)` Implements the `Configurable` interface.
    `SimpleDateFormat` | `getDefaultDateFormat()` Gets the defaultDateFormat.
    `String` | `getDefaultDateFormatString()` Gets the defaultDateFormat pattern string.
    `SimpleDateFormat` | `getRecentDateFormat()` Gets the recentDateFormat.
    `String` | `getRecentDateFormatString()` Gets the recentDateFormat.
    `TimeZone` | `getServerTimeZone()` Gets the serverTimeZone used by this parser.
    `String[]` | `getShortMonths()` Gets an array of 12 strings representing the short month names used by this parse.
    `(package private) boolean` | `isLenientFutureDates()`
    `Calendar` | `parseTimestamp(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.
    `Calendar` | `parseTimestamp(String timestampStr, Calendar serverTime)` If the recentDateFormat member has been defined, try to parse the supplied string with that.
    `(package private) void` | `setLenientFutureDates(boolean lenientFutureDates)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### FTPTimestampParserImpl

          public FTPTimestampParserImpl()

      The only constructor for this class.

  - ### Method Detail

    - #### configure

          public void configure(FTPClientConfig config)

      Implements the `Configurable` interface. Configures this `FTPTimestampParser` according to the following logic:

      Sets up the `defaultDateFormat` and optionally the `recentDateFormat` to values supplied in the config based on month names configured as follows:

      - If a `shortMonthString` has been supplied in the `config`, use that to parse parse timestamps.
      - Otherwise, if a `serverLanguageCode` has been supplied in the `config`, use the month names represented by that `language` 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 interface `Configurable`
      Parameters:
        `config` - the object containing the configuration data.

    - #### getDefaultDateFormat

          public SimpleDateFormat getDefaultDateFormat()

      Gets the defaultDateFormat.
      Returns:
        the defaultDateFormat.

    - #### getDefaultDateFormatString

          public String getDefaultDateFormatString()

      Gets the defaultDateFormat pattern string.
      Returns:
        the defaultDateFormat pattern string.

    - #### getRecentDateFormat

          public SimpleDateFormat getRecentDateFormat()

      Gets the recentDateFormat.
      Returns:
        the recentDateFormat.

    - #### getRecentDateFormatString

          public String getRecentDateFormatString()

      Gets the recentDateFormat.
      Returns:
        the recentDateFormat.

    - #### getServerTimeZone

          public TimeZone getServerTimeZone()

      Gets the serverTimeZone used by this parser.
      Returns:
        the serverTimeZone used by this parser.

    - #### getShortMonths

          public 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 Calendar parseTimestamp(String timestampStr)
                                  throws ParseException

      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. 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 interface `FTPTimestampParser`
      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(String, Calendar)`

    - #### parseTimestamp

          public Calendar parseTimestamp(String timestampStr,
                                         Calendar serverTime)
                                  throws ParseException

      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 a `Calendar` instance to be passed in which represents the current (system) time.
      Parameters:
        `timestampStr` - The timestamp to be parsed
        `serverTime` - The current time for the server
      Returns:
        the calendar
      Throws:
        `ParseException` - if timestamp cannot be parsed
      See Also:
        `FTPTimestampParser.parseTimestamp(String)`

    - #### setLenientFutureDates

          void setLenientFutureDates(boolean lenientFutureDates)

      Parameters:
        `lenientFutureDates` - The lenientFutureDates to set.