FTPClientConfig.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *      http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */

  17. package org.apache.commons.net.ftp;

  18. import java.text.DateFormatSymbols;
  19. import java.util.Collection;
  20. import java.util.Locale;
  21. import java.util.Map;
  22. import java.util.StringTokenizer;
  23. import java.util.TreeMap;

  24. /**
  25.  * <p>
  26.  * This class implements an alternate means of configuring the {@link org.apache.commons.net.ftp.FTPClient FTPClient} object and also subordinate objects which
  27.  * it uses. Any class implementing the {@link org.apache.commons.net.ftp.Configurable Configurable } interface can be configured by this object.
  28.  * </p>
  29.  * <p>
  30.  * In particular this class was designed primarily to support configuration of FTP servers which express file timestamps in formats and languages other than
  31.  * those for the US locale, which although it is the most common is not universal. Unfortunately, nothing in the FTP spec allows this to be determined in an
  32.  * automated way, so manual configuration such as this is necessary.
  33.  * </p>
  34.  * <p>
  35.  * This functionality was designed to allow existing clients to work exactly as before without requiring use of this component. This component should only need
  36.  * to be explicitly invoked by the user of this package for problem cases that previous implementations could not solve.
  37.  * </p>
  38.  * <h2>Examples of use of FTPClientConfig</h2> Use cases: You are trying to access a server that
  39.  * <ul>
  40.  * <li>lists files with timestamps that use month names in languages other than English</li>
  41.  * <li>lists files with timestamps that use date formats other than the American English "standard" <code>MM dd yyyy</code></li>
  42.  * <li>is in different time zone and you need accurate timestamps for dependency checking as in Ant</li>
  43.  * </ul>
  44.  * <p>
  45.  * Unpaged (whole list) access on a UNIX server that uses French month names but uses the "standard" <code>MMM d yyyy</code> date formatting
  46.  *
  47.  * <pre>
  48.  * FTPClient f = FTPClient();
  49.  * FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_UNIX);
  50.  * conf.setServerLanguageCode("fr");
  51.  * f.configure(conf);
  52.  * f.connect(server);
  53.  * f.login(user, password);
  54.  * FTPFile[] files = listFiles(directory);
  55.  * </pre>
  56.  * <p>
  57.  * Paged access on a UNIX server that uses Danish month names and "European" date formatting in Denmark's time zone, when you are in some other time zone.
  58.  *
  59.  * <pre>
  60.  * FTPClient f = FTPClient();
  61.  * FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_UNIX);
  62.  * conf.setServerLanguageCode("da");
  63.  * conf.setDefaultDateFormat("d MMM yyyy");
  64.  * conf.setRecentDateFormat("d MMM HH:mm");
  65.  * conf.setTimeZoneId("Europe/Copenhagen");
  66.  * f.configure(conf);
  67.  * f.connect(server);
  68.  * f.login(user, password);
  69.  * FTPListParseEngine engine = f.initiateListParsing("com.whatever.YourOwnParser", directory);
  70.  *
  71.  * while (engine.hasNext()) {
  72.  *     FTPFile[] files = engine.getNext(25); // "page size" you want
  73.  *     // do whatever you want with these files, display them, etc.
  74.  *     // expensive FTPFile objects not created until needed.
  75.  * }
  76.  * </pre>
  77.  * <p>
  78.  * Unpaged (whole list) access on a VMS server that uses month names in a language not {@link #getSupportedLanguageCodes() supported} by the system. but uses
  79.  * the "standard" <code>MMM d yyyy</code> date formatting
  80.  *
  81.  * <pre>
  82.  * FTPClient f = FTPClient();
  83.  * FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_VMS);
  84.  * conf.setShortMonthNames("jan|feb|mar|apr|ma\u00ED|j\u00FAn|j\u00FAl|\u00e1g\u00FA|sep|okt|n\u00F3v|des");
  85.  * f.configure(conf);
  86.  * f.connect(server);
  87.  * f.login(user, password);
  88.  * FTPFile[] files = listFiles(directory);
  89.  * </pre>
  90.  * <p>
  91.  * Unpaged (whole list) access on a Windows-NT server in a different time zone. (Note, since the NT Format uses numeric date formatting, language issues are
  92.  * irrelevant here).
  93.  *
  94.  * <pre>
  95.  * FTPClient f = FTPClient();
  96.  * FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_NT);
  97.  * conf.setTimeZoneId("America/Denver");
  98.  * f.configure(conf);
  99.  * f.connect(server);
  100.  * f.login(user, password);
  101.  * FTPFile[] files = listFiles(directory);
  102.  * </pre>
  103.  *
  104.  * Unpaged (whole list) access on a Windows-NT server in a different time zone but which has been configured to use a unix-style listing format.
  105.  *
  106.  * <pre>
  107.  * FTPClient f = FTPClient();
  108.  * FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_UNIX);
  109.  * conf.setTimeZoneId("America/Denver");
  110.  * f.configure(conf);
  111.  * f.connect(server);
  112.  * f.login(user, password);
  113.  * FTPFile[] files = listFiles(directory);
  114.  * </pre>
  115.  *
  116.  * @since 1.4
  117.  * @see org.apache.commons.net.ftp.Configurable
  118.  * @see org.apache.commons.net.ftp.FTPClient
  119.  * @see org.apache.commons.net.ftp.parser.FTPTimestampParserImpl#configure(FTPClientConfig)
  120.  * @see org.apache.commons.net.ftp.parser.ConfigurableFTPFileEntryParserImpl
  121.  */
  122. public class FTPClientConfig {

  123.     /**
  124.      * Identifier by which a Unix-based ftp server is known throughout the commons-net ftp system.
  125.      */
  126.     public static final String SYST_UNIX = "UNIX";

  127.     /**
  128.      * Identifier for alternate UNIX parser; same as {@link #SYST_UNIX} but leading spaces are trimmed from file names. This is to maintain backwards
  129.      * compatibility with the original behavior of the parser which ignored multiple spaces between the date and the start of the file name.
  130.      *
  131.      * @since 3.4
  132.      */
  133.     public static final String SYST_UNIX_TRIM_LEADING = "UNIX_LTRIM";

  134.     /**
  135.      * Identifier by which a vms-based ftp server is known throughout the commons-net ftp system.
  136.      */
  137.     public static final String SYST_VMS = "VMS";

  138.     /**
  139.      * Identifier by which a WindowsNT-based ftp server is known throughout the commons-net ftp system.
  140.      */
  141.     public static final String SYST_NT = "WINDOWS";

  142.     /**
  143.      * Identifier by which an OS/2-based ftp server is known throughout the commons-net ftp system.
  144.      */
  145.     public static final String SYST_OS2 = "OS/2";

  146.     /**
  147.      * Identifier by which an OS/400-based ftp server is known throughout the commons-net ftp system.
  148.      */
  149.     public static final String SYST_OS400 = "OS/400";

  150.     /**
  151.      * Identifier by which an AS/400-based ftp server is known throughout the commons-net ftp system.
  152.      */
  153.     public static final String SYST_AS400 = "AS/400";

  154.     /**
  155.      * Identifier by which an MVS-based ftp server is known throughout the commons-net ftp system.
  156.      */
  157.     public static final String SYST_MVS = "MVS";

  158.     /**
  159.      * Some servers return an "UNKNOWN Type: L8" message in response to the SYST command. We set these to be a Unix-type system. This may happen if the ftpd in
  160.      * question was compiled without system information.
  161.      *
  162.      * NET-230 - Updated to be UPPERCASE so that the check done in createFileEntryParser will succeed.
  163.      *
  164.      * @since 1.5
  165.      */
  166.     public static final String SYST_L8 = "TYPE: L8";

  167.     /**
  168.      * Identifier by which a Netware-based ftp server is known throughout the commons-net ftp system.
  169.      *
  170.      * @since 1.5
  171.      */
  172.     public static final String SYST_NETWARE = "NETWARE";

  173.     /**
  174.      * Identifier by which a Mac pre OS-X -based ftp server is known throughout the commons-net ftp system.
  175.      *
  176.      * @since 3.1
  177.      */
  178.     // Full string is "MACOS Peter's Server"; the substring below should be enough
  179.     public static final String SYST_MACOS_PETER = "MACOS PETER"; // NET-436

  180.     private static final Map<String, Object> LANGUAGE_CODE_MAP = new TreeMap<>();
  181.     static {

  182.         // if there are other commonly used month name encodings which
  183.         // correspond to particular locales, please add them here.

  184.         // many locales code short names for months as all three letters
  185.         // these we handle simply.
  186.         LANGUAGE_CODE_MAP.put("en", Locale.ENGLISH);
  187.         LANGUAGE_CODE_MAP.put("de", Locale.GERMAN);
  188.         LANGUAGE_CODE_MAP.put("it", Locale.ITALIAN);
  189.         LANGUAGE_CODE_MAP.put("es", new Locale("es", "", "")); // spanish
  190.         LANGUAGE_CODE_MAP.put("pt", new Locale("pt", "", "")); // portuguese
  191.         LANGUAGE_CODE_MAP.put("da", new Locale("da", "", "")); // danish
  192.         LANGUAGE_CODE_MAP.put("sv", new Locale("sv", "", "")); // swedish
  193.         LANGUAGE_CODE_MAP.put("no", new Locale("no", "", "")); // norwegian
  194.         LANGUAGE_CODE_MAP.put("nl", new Locale("nl", "", "")); // dutch
  195.         LANGUAGE_CODE_MAP.put("ro", new Locale("ro", "", "")); // romanian
  196.         LANGUAGE_CODE_MAP.put("sq", new Locale("sq", "", "")); // albanian
  197.         LANGUAGE_CODE_MAP.put("sh", new Locale("sh", "", "")); // serbo-croatian
  198.         LANGUAGE_CODE_MAP.put("sk", new Locale("sk", "", "")); // slovak
  199.         LANGUAGE_CODE_MAP.put("sl", new Locale("sl", "", "")); // slovenian

  200.         // some don't
  201.         LANGUAGE_CODE_MAP.put("fr", "jan|f\u00e9v|mar|avr|mai|jun|jui|ao\u00fb|sep|oct|nov|d\u00e9c"); // french

  202.     }

  203.     /**
  204.      * Returns a DateFormatSymbols object configured with short month names as in the supplied string
  205.      *
  206.      * @param shortmonths This should be as described in {@link #setShortMonthNames(String) shortMonthNames}
  207.      * @return a DateFormatSymbols object configured with short month names as in the supplied string
  208.      */
  209.     public static DateFormatSymbols getDateFormatSymbols(final String shortmonths) {
  210.         final String[] months = splitShortMonthString(shortmonths);
  211.         final DateFormatSymbols dfs = new DateFormatSymbols(Locale.US);
  212.         dfs.setShortMonths(months);
  213.         return dfs;
  214.     }

  215.     /**
  216.      * Returns a Collection of all the language codes currently supported by this class. See {@link #setServerLanguageCode(String) serverLanguageCode} for a
  217.      * functional description of language codes within this system.
  218.      *
  219.      * @return a Collection of all the language codes currently supported by this class
  220.      */
  221.     public static Collection<String> getSupportedLanguageCodes() {
  222.         return LANGUAGE_CODE_MAP.keySet();
  223.     }

  224.     /**
  225.      * Looks up the supplied language code in the internally maintained table of language codes. Returns a DateFormatSymbols object configured with short month
  226.      * names corresponding to the code. If there is no corresponding entry in the table, the object returned will be that for <code>Locale.US</code>
  227.      *
  228.      * @param languageCode See {@link #setServerLanguageCode(String) serverLanguageCode}
  229.      * @return a DateFormatSymbols object configured with short month names corresponding to the supplied code, or with month names for <code>Locale.US</code>
  230.      *         if there is no corresponding entry in the internal table.
  231.      */
  232.     public static DateFormatSymbols lookupDateFormatSymbols(final String languageCode) {
  233.         final Object lang = LANGUAGE_CODE_MAP.get(languageCode);
  234.         if (lang != null) {
  235.             if (lang instanceof Locale) {
  236.                 return new DateFormatSymbols((Locale) lang);
  237.             }
  238.             if (lang instanceof String) {
  239.                 return getDateFormatSymbols((String) lang);
  240.             }
  241.         }
  242.         return new DateFormatSymbols(Locale.US);
  243.     }

  244.     private static String[] splitShortMonthString(final String shortmonths) {
  245.         final StringTokenizer st = new StringTokenizer(shortmonths, "|");
  246.         final int monthcnt = st.countTokens();
  247.         if (12 != monthcnt) {
  248.             throw new IllegalArgumentException("expecting a pipe-delimited string containing 12 tokens");
  249.         }
  250.         final String[] months = new String[13];
  251.         int pos = 0;
  252.         while (st.hasMoreTokens()) {
  253.             months[pos++] = st.nextToken();
  254.         }
  255.         months[pos] = "";
  256.         return months;
  257.     }

  258.     private final String serverSystemKey;
  259.     private String defaultDateFormatStr;

  260.     private String recentDateFormatStr;

  261.     private boolean lenientFutureDates = true; // NET-407

  262.     private String serverLanguageCode;

  263.     private String shortMonthNames;

  264.     private String serverTimeZoneId;

  265.     private boolean saveUnparseableEntries;

  266.     /**
  267.      * Convenience constructor mainly for use in testing. Constructs a UNIX configuration.
  268.      */
  269.     public FTPClientConfig() {
  270.         this(SYST_UNIX);
  271.     }

  272.     /**
  273.      * Copy constructor
  274.      *
  275.      * @param config source
  276.      * @since 3.6
  277.      */
  278.     public FTPClientConfig(final FTPClientConfig config) {
  279.         this.serverSystemKey = config.serverSystemKey;
  280.         this.defaultDateFormatStr = config.defaultDateFormatStr;
  281.         this.lenientFutureDates = config.lenientFutureDates;
  282.         this.recentDateFormatStr = config.recentDateFormatStr;
  283.         this.saveUnparseableEntries = config.saveUnparseableEntries;
  284.         this.serverLanguageCode = config.serverLanguageCode;
  285.         this.serverTimeZoneId = config.serverTimeZoneId;
  286.         this.shortMonthNames = config.shortMonthNames;
  287.     }

  288.     /**
  289.      * The main constructor for an FTPClientConfig object
  290.      *
  291.      * @param systemKey key representing system type of the server being connected to. See {@link #getServerSystemKey() serverSystemKey} If set to the empty
  292.      *                  string, then FTPClient uses the system type returned by the server. However, this is not recommended for general use; the correct system
  293.      *                  type should be set if it is known.
  294.      */
  295.     public FTPClientConfig(final String systemKey) {
  296.         this.serverSystemKey = systemKey;
  297.     }

  298.     // Copy constructor, intended for use by FTPClient only
  299.     FTPClientConfig(final String systemKey, final FTPClientConfig config) {
  300.         this.serverSystemKey = systemKey;
  301.         this.defaultDateFormatStr = config.defaultDateFormatStr;
  302.         this.lenientFutureDates = config.lenientFutureDates;
  303.         this.recentDateFormatStr = config.recentDateFormatStr;
  304.         this.saveUnparseableEntries = config.saveUnparseableEntries;
  305.         this.serverLanguageCode = config.serverLanguageCode;
  306.         this.serverTimeZoneId = config.serverTimeZoneId;
  307.         this.shortMonthNames = config.shortMonthNames;
  308.     }

  309.     /**
  310.      * Constructor which allows setting of the format string member fields
  311.      *
  312.      * @param systemKey            key representing system type of the server being connected to. See {@link #getServerSystemKey() serverSystemKey}
  313.      * @param defaultDateFormatStr See {@link #setDefaultDateFormatStr(String) defaultDateFormatStr}
  314.      * @param recentDateFormatStr  See {@link #setRecentDateFormatStr(String) recentDateFormatStr}
  315.      * @since 3.6
  316.      */
  317.     public FTPClientConfig(final String systemKey, final String defaultDateFormatStr, final String recentDateFormatStr) {
  318.         this(systemKey);
  319.         this.defaultDateFormatStr = defaultDateFormatStr;
  320.         this.recentDateFormatStr = recentDateFormatStr;
  321.     }

  322.     /**
  323.      * Constructor which allows setting of most member fields
  324.      *
  325.      * @param systemKey            key representing system type of the server being connected to. See {@link #getServerSystemKey() serverSystemKey}
  326.      * @param defaultDateFormatStr See {@link #setDefaultDateFormatStr(String) defaultDateFormatStr}
  327.      * @param recentDateFormatStr  See {@link #setRecentDateFormatStr(String) recentDateFormatStr}
  328.      * @param serverLanguageCode   See {@link #setServerLanguageCode(String) serverLanguageCode}
  329.      * @param shortMonthNames      See {@link #setShortMonthNames(String) shortMonthNames}
  330.      * @param serverTimeZoneId     See {@link #setServerTimeZoneId(String) serverTimeZoneId}
  331.      */
  332.     public FTPClientConfig(final String systemKey, final String defaultDateFormatStr, final String recentDateFormatStr, final String serverLanguageCode,
  333.             final String shortMonthNames, final String serverTimeZoneId) {
  334.         this(systemKey);
  335.         this.defaultDateFormatStr = defaultDateFormatStr;
  336.         this.recentDateFormatStr = recentDateFormatStr;
  337.         this.serverLanguageCode = serverLanguageCode;
  338.         this.shortMonthNames = shortMonthNames;
  339.         this.serverTimeZoneId = serverTimeZoneId;
  340.     }

  341.     /**
  342.      * Constructor which allows setting of all member fields
  343.      *
  344.      * @param systemKey              key representing system type of the server being connected to. See {@link #getServerSystemKey() serverSystemKey}
  345.      * @param defaultDateFormatStr   See {@link #setDefaultDateFormatStr(String) defaultDateFormatStr}
  346.      * @param recentDateFormatStr    See {@link #setRecentDateFormatStr(String) recentDateFormatStr}
  347.      * @param serverLanguageCode     See {@link #setServerLanguageCode(String) serverLanguageCode}
  348.      * @param shortMonthNames        See {@link #setShortMonthNames(String) shortMonthNames}
  349.      * @param serverTimeZoneId       See {@link #setServerTimeZoneId(String) serverTimeZoneId}
  350.      * @param lenientFutureDates     See {@link #setLenientFutureDates(boolean) lenientFutureDates}
  351.      * @param saveUnparseableEntries See {@link #setUnparseableEntries(boolean) saveUnparseableEntries}
  352.      */
  353.     public FTPClientConfig(final String systemKey, final String defaultDateFormatStr, final String recentDateFormatStr, final String serverLanguageCode,
  354.             final String shortMonthNames, final String serverTimeZoneId, final boolean lenientFutureDates, final boolean saveUnparseableEntries) {
  355.         this(systemKey);
  356.         this.defaultDateFormatStr = defaultDateFormatStr;
  357.         this.lenientFutureDates = lenientFutureDates;
  358.         this.recentDateFormatStr = recentDateFormatStr;
  359.         this.saveUnparseableEntries = saveUnparseableEntries;
  360.         this.serverLanguageCode = serverLanguageCode;
  361.         this.shortMonthNames = shortMonthNames;
  362.         this.serverTimeZoneId = serverTimeZoneId;
  363.     }

  364.     /**
  365.      * getter for the {@link #setDefaultDateFormatStr(String) defaultDateFormatStr} property.
  366.      *
  367.      * @return Returns the defaultDateFormatStr property.
  368.      */
  369.     public String getDefaultDateFormatStr() {
  370.         return defaultDateFormatStr;
  371.     }

  372.     /**
  373.      * getter for the {@link #setRecentDateFormatStr(String) recentDateFormatStr} property.
  374.      *
  375.      * @return Returns the recentDateFormatStr property.
  376.      */

  377.     public String getRecentDateFormatStr() {
  378.         return recentDateFormatStr;
  379.     }

  380.     /**
  381.      * <p>
  382.      * getter for the {@link #setServerLanguageCode(String) serverLanguageCode} property.
  383.      * </p>
  384.      *
  385.      * @return Returns the serverLanguageCode property.
  386.      */
  387.     public String getServerLanguageCode() {
  388.         return serverLanguageCode;
  389.     }

  390.     /**
  391.      * Getter for the serverSystemKey property. This property specifies the general type of server to which the client connects. Should be either one of the
  392.      * <code>FTPClientConfig.SYST_*</code> codes or else the fully qualified class name of a parser implementing both the <code>FTPFileEntryParser</code> and
  393.      * <code>Configurable</code> interfaces.
  394.      *
  395.      * @return Returns the serverSystemKey property.
  396.      */
  397.     public String getServerSystemKey() {
  398.         return serverSystemKey;
  399.     }

  400.     /**
  401.      * getter for the {@link #setServerTimeZoneId(String) serverTimeZoneId} property.
  402.      *
  403.      * @return Returns the serverTimeZoneId property.
  404.      */
  405.     public String getServerTimeZoneId() {
  406.         return serverTimeZoneId;
  407.     }

  408.     /**
  409.      * <p>
  410.      * getter for the {@link #setShortMonthNames(String) shortMonthNames} property.
  411.      * </p>
  412.      *
  413.      * @return Returns the shortMonthNames.
  414.      */
  415.     public String getShortMonthNames() {
  416.         return shortMonthNames;
  417.     }

  418.     /**
  419.      * @return true if list parsing should return FTPFile entries even for unparseable response lines
  420.      *         <p>
  421.      *         If true, the FTPFile for any unparseable entries will contain only the unparsed entry {@link FTPFile#getRawListing()} and
  422.      *         {@link FTPFile#isValid()} will return {@code false}
  423.      * @since 3.4
  424.      */
  425.     public boolean getUnparseableEntries() {
  426.         return this.saveUnparseableEntries;
  427.     }

  428.     /**
  429.      * <p>
  430.      * getter for the {@link #setLenientFutureDates(boolean) lenientFutureDates} property.
  431.      * </p>
  432.      *
  433.      * @return Returns the lenientFutureDates (default true).
  434.      * @since 1.5
  435.      */
  436.     public boolean isLenientFutureDates() {
  437.         return lenientFutureDates;
  438.     }

  439.     /**
  440.      * <p>
  441.      * setter for the defaultDateFormatStr property. This property specifies the main date format that will be used by a parser configured by this configuration
  442.      * to parse file timestamps. If this is not specified, such a parser will use as a default value, the most commonly used format which will be in as used in
  443.      * <code>en_US</code> locales.
  444.      * </p>
  445.      * <p>
  446.      * This should be in the format described for <code>java.text.SimpleDateFormat</code>. property.
  447.      * </p>
  448.      *
  449.      * @param defaultDateFormatStr The defaultDateFormatStr to set.
  450.      */
  451.     public void setDefaultDateFormatStr(final String defaultDateFormatStr) {
  452.         this.defaultDateFormatStr = defaultDateFormatStr;
  453.     }

  454.     /**
  455.      * <p>
  456.      * setter for the lenientFutureDates property. This boolean property (default: true) only has meaning when a {@link #setRecentDateFormatStr(String)
  457.      * 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
  458.      * 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
  459.      * 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
  460.      * is highly recommended to use the {@link #setServerTimeZoneId(String) serverTimeZoneId} property instead) to resolve correctly.
  461.      * </p>
  462.      * <p>
  463.      * This is used primarily in unix-based systems.
  464.      * </p>
  465.      *
  466.      * @param lenientFutureDates set true to compensate for out-of-synch conditions.
  467.      */
  468.     public void setLenientFutureDates(final boolean lenientFutureDates) {
  469.         this.lenientFutureDates = lenientFutureDates;
  470.     }

  471.     /**
  472.      * <p>
  473.      * setter for the recentDateFormatStr property. This property specifies a secondary date format that will be used by a parser configured by this
  474.      * configuration to parse file timestamps, typically those less than a year old. If this is not specified, such a parser will not attempt to parse using an
  475.      * alternate format.
  476.      * </p>
  477.      * <p>
  478.      * This is used primarily in unix-based systems.
  479.      * </p>
  480.      * <p>
  481.      * This should be in the format described for <code>java.text.SimpleDateFormat</code>.
  482.      * </p>
  483.      *
  484.      * @param recentDateFormatStr The recentDateFormatStr to set.
  485.      */
  486.     public void setRecentDateFormatStr(final String recentDateFormatStr) {
  487.         this.recentDateFormatStr = recentDateFormatStr;
  488.     }

  489.     /**
  490.      * <p>
  491.      * setter for the serverLanguageCode property. This property allows user to specify a <a href="http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt">
  492.      * two-letter ISO-639 language code</a> that will be used to configure the set of month names used by the file timestamp parser. If neither this nor the
  493.      * {@link #setShortMonthNames(String) shortMonthNames} is specified, parsing will assume English month names, which may or may not be significant, depending
  494.      * on whether the date format(s) specified via {@link #setDefaultDateFormatStr(String) defaultDateFormatStr} and/or {@link #setRecentDateFormatStr(String)
  495.      * recentDateFormatStr} are using numeric or alphabetic month names.
  496.      * </p>
  497.      * <p>
  498.      * If the code supplied is not supported here, <code>en_US</code> month names will be used. We are supporting here those language codes which, when a
  499.      * <code>java.util.Locale</code> is constructed using it, and a <code>java.text.SimpleDateFormat</code> is constructed using that Locale, the array
  500.      * returned by the SimpleDateFormat's <code>getShortMonths()</code> method consists solely of three 8-bit ASCII character strings. Additionally, languages
  501.      * which do not meet this requirement are included if a common alternative set of short month names is known to be used. This means that users who can tell
  502.      * us of additional such encodings may get them added to the list of supported languages by contacting the Apache Commons Net team.
  503.      * </p>
  504.      * <p>
  505.      * <strong> Please note that this attribute will NOT be used to determine a locale-based date format for the language. </strong> Experience has shown that
  506.      * many if not most FTP servers outside the United States employ the standard <code>en_US</code> date format orderings of <code>MMM d yyyy</code> and
  507.      * <code>MMM d HH:mm</code> and attempting to deduce this automatically here would cause more problems than it would solve. The date format must be changed
  508.      * via the {@link #setDefaultDateFormatStr(String) defaultDateFormatStr} and/or {@link #setRecentDateFormatStr(String) recentDateFormatStr} parameters.
  509.      * </p>
  510.      *
  511.      * @param serverLanguageCode The value to set to the serverLanguageCode property.
  512.      */
  513.     public void setServerLanguageCode(final String serverLanguageCode) {
  514.         this.serverLanguageCode = serverLanguageCode;
  515.     }

  516.     /**
  517.      * <p>
  518.      * setter for the serverTimeZoneId property. This property allows a time zone to be specified corresponding to that known to be used by an FTP server in
  519.      * file listings. This might be particularly useful to clients such as Ant that try to use these timestamps for dependency checking.
  520.      * </p>
  521.      * <p>
  522.      * This should be one of the identifiers used by <code>java.util.TimeZone</code> to refer to time zones, for example, <code>America/Chicago</code> or
  523.      * <code>Asia/Rangoon</code>.
  524.      * </p>
  525.      *
  526.      * @param serverTimeZoneId The serverTimeZoneId to set.
  527.      */
  528.     public void setServerTimeZoneId(final String serverTimeZoneId) {
  529.         this.serverTimeZoneId = serverTimeZoneId;
  530.     }

  531.     /**
  532.      * <p>
  533.      * setter for the shortMonthNames property. This property allows the user to specify a set of month names used by the server that is different from those
  534.      * that may be specified using the {@link #setServerLanguageCode(String) serverLanguageCode} property.
  535.      * </p>
  536.      * <p>
  537.      * This should be a string containing twelve strings each composed of three characters, delimited by pipe (|) characters. Currently, only 8-bit ASCII
  538.      * characters are known to be supported. For example, a set of month names used by a hypothetical Icelandic FTP server might conceivably be specified as
  539.      * <code>"jan|feb|mar|apr|ma&#xED;|j&#xFA;n|j&#xFA;l|&#xE1;g&#xFA;|sep|okt|n&#xF3;v|des"</code>.
  540.      * </p>
  541.      *
  542.      * @param shortMonthNames The value to set to the shortMonthNames property.
  543.      */
  544.     public void setShortMonthNames(final String shortMonthNames) {
  545.         this.shortMonthNames = shortMonthNames;
  546.     }

  547.     /**
  548.      * Allow list parsing methods to create basic FTPFile entries if parsing fails.
  549.      * <p>
  550.      * In this case, the FTPFile will contain only the unparsed entry {@link FTPFile#getRawListing()} and {@link FTPFile#isValid()} will return {@code false}
  551.      *
  552.      * @param saveUnparseable if true, then create FTPFile entries if parsing fails
  553.      * @since 3.4
  554.      */
  555.     public void setUnparseableEntries(final boolean saveUnparseable) {
  556.         this.saveUnparseableEntries = saveUnparseable;
  557.     }

  558. }