/** * constructor for this abstract class. * @param regex Regular expression used main parsing of the * file listing. */ public ConfigurableFTPFileEntryParserImpl(String regex) { super(regex); this.timestampParser = new FTPTimestampParserImpl(); }
/** * The only constructor for this class. */ public FTPTimestampParserImpl() { setDefaultDateFormat(DEFAULT_SDF, null); setRecentDateFormat(DEFAULT_RECENT_SDF, null); }
/** * Implements the one {@link FTPTimestampParser#parseTimestamp(String) method} * in the {@link FTPTimestampParser 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. * * @see FTPTimestampParserImpl#parseTimestamp(String, Calendar) * * @param timestampStr The timestamp to be parsed * @return a Calendar with the parsed timestamp */ @Override public Calendar parseTimestamp(String timestampStr) throws ParseException { Calendar now = Calendar.getInstance(); return parseTimestamp(timestampStr, now); }
setRecentDateFormat(recentFormatString, dfs); throw new IllegalArgumentException("defaultFormatString cannot be null"); setDefaultDateFormat(defaultFormatString, dfs); setServerTimeZone(config.getServerTimeZoneId());
FTPTimestampParserImpl jaParser = new FTPTimestampParserImpl(); jaParser.configure(new FTPClientConfig( FTPClientConfig.SYST_UNIX, DEFAULT_DATE_FORMAT_JA, DEFAULT_RECENT_DATE_FORMAT_JA)); file.setTimestamp(jaParser.parseTimestamp(datestr)); } else { file.setTimestamp(super.parseTimestamp(datestr));
working.setTimeZone(getServerTimeZone()); // is this needed? now.setTimeZone(this.getServerTimeZone()); if (lenientFutureDates) { working.add(Calendar.YEAR, -1); setPrecision(recentDateSmallestUnitIndex, working); return working; pp.getErrorIndex()); setPrecision(defaultDateSmallestUnitIndex, working); return working;
this.defaultDateFormat.setLenient(false); setServerTimeZone(config.getServerTimeZoneId());
now.setTimeZone(this.getServerTimeZone()); working.setTimeZone(this.getServerTimeZone()); ParsePosition pp = new ParsePosition(0);
/** * @param format The defaultDateFormat to be set. * @param dfs the symbols to use (may be null) */ private void setDefaultDateFormat(String format, DateFormatSymbols dfs) { if (format != null) { if (dfs != null) { this.defaultDateFormat = new SimpleDateFormat(format, dfs); } else { this.defaultDateFormat = new SimpleDateFormat(format); } this.defaultDateFormat.setLenient(false); } else { this.defaultDateFormat = null; } this.defaultDateSmallestUnitIndex = getEntry(this.defaultDateFormat); } /**
private static int getEntry(SimpleDateFormat dateFormat) { if (dateFormat == null) { return 0; } final String FORMAT_CHARS="SsmHdM"; final String pattern = dateFormat.toPattern(); for(char ch : FORMAT_CHARS.toCharArray()) { if (pattern.indexOf(ch) != -1){ // found the character switch(ch) { case 'S': return indexOf(Calendar.MILLISECOND); case 's': return indexOf(Calendar.SECOND); case 'm': return indexOf(Calendar.MINUTE); case 'H': return indexOf(Calendar.HOUR_OF_DAY); case 'd': return indexOf(Calendar.DAY_OF_MONTH); case 'M': return indexOf(Calendar.MONTH); } } } return 0; }
this.defaultDateFormat.setLenient(false); setServerTimeZone(config.getServerTimeZoneId());
now.setTimeZone(this.getServerTimeZone()); Calendar working = (Calendar) now.clone(); working.setTimeZone(getServerTimeZone()); ParsePosition pp = new ParsePosition(0);
/** * @param format The recentDateFormat to set. * @param dfs the symbols to use (may be null) */ private void setRecentDateFormat(String format, DateFormatSymbols dfs) { if (format != null) { if (dfs != null) { this.recentDateFormat = new SimpleDateFormat(format, dfs); } else { this.recentDateFormat = new SimpleDateFormat(format); } this.recentDateFormat.setLenient(false); } else { this.recentDateFormat = null; } this.recentDateSmallestUnitIndex = getEntry(this.recentDateFormat); }
/** * The only constructor for this class. */ public FTPTimestampParserImpl() { setDefaultDateFormat(DEFAULT_SDF); setRecentDateFormat(DEFAULT_RECENT_SDF); }
/** * constructor for this abstract class. * @param regex Regular expression used main parsing of the * file listing. * @param flags the flags to apply, see * {@link java.util.regex.Pattern#compile(String, int) Pattern#compile(String, int)}. Use 0 for none. * @since 3.4 */ public ConfigurableFTPFileEntryParserImpl(String regex, int flags) { super(regex, flags); this.timestampParser = new FTPTimestampParserImpl(); }
/** * Implements the one {@link FTPTimestampParser#parseTimestamp(String) method} * in the {@link FTPTimestampParser 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 allows a {@link Calendar} instance to be passed in which represents the * current (system) time. * * @see org.apache.commons.net.ftp.parser.FTPTimestampParser#parseTimestamp(java.lang.String) * * @param timestampStr The timestamp to be parsed */ public Calendar parseTimestamp(String timestampStr) throws ParseException { Calendar now = Calendar.getInstance(); return parseTimestamp(timestampStr, now); }
/** * The only constructor for this class. */ public FTPTimestampParserImpl() { setDefaultDateFormat(DEFAULT_SDF); setRecentDateFormat(DEFAULT_RECENT_SDF); }
/** * This constructor allows the creation of an NTFTPEntryParser object * with something other than the default configuration. * * @param config The {@link FTPClientConfig configuration} object used to * configure this parser. * @throws IllegalArgumentException * Thrown if the regular expression is unparseable. Should not be seen * under normal conditions. It it is seen, this is a sign that * <code>REGEX</code> is not a valid regular expression. * @since 1.4 */ public NTFTPEntryParser(FTPClientConfig config) { super(REGEX, Pattern.DOTALL); configure(config); FTPClientConfig config2 = new FTPClientConfig( FTPClientConfig.SYST_NT, DEFAULT_DATE_FORMAT2, null); config2.setDefaultDateFormatStr(DEFAULT_DATE_FORMAT2); this.timestampParser = new FTPTimestampParserImpl(); ((Configurable)this.timestampParser).configure(config2); }
/** * Only constructor for this absract class. * @param regex Regular expression used main parsing of the * file listing. */ public ConfigurableFTPFileEntryParserImpl(String regex) { super(regex); this.timestampParser = new FTPTimestampParserImpl(); }
/** * Only constructor for this absract class. * @param regex Regular expression used main parsing of the * file listing. */ public ConfigurableFTPFileEntryParserImpl(String regex) { super(regex); this.timestampParser = new FTPTimestampParserImpl(); }