Changeset 12938


Ignore:
Timestamp:
10/02/10 19:00:52 (13 years ago)
Author:
ehuelsmann
Message:

Fix partial date format support while parsing Last-Modified
in ZipCache?. While at it, fix a locale issue too; the dates
sent are required to be US locale, not NL or any other.

Note: My system tried to parse the dates with an NL locale,

failing to understand the names of the days and months.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/ZipCache.java

    r12643 r12938  
    4242import java.net.URL;
    4343import java.net.URLConnection;
    44 import java.text.ParseException;
     44import java.text.ParsePosition;
    4545import java.text.SimpleDateFormat;
    4646import java.util.Date;
    4747import java.util.HashMap;
     48import java.util.Locale;
    4849import java.util.zip.ZipException;
    4950import java.util.zip.ZipFile;
     
    102103    }
    103104
     105    static final SimpleDateFormat ASCTIME
     106        = new SimpleDateFormat("EEE MMM d HH:mm:ss yyyy", Locale.US);
     107    static final SimpleDateFormat RFC_1036
     108        = new SimpleDateFormat("EEEE, dd-MMM-yy HH:mm:ss zzz", Locale.US);
    104109    static final SimpleDateFormat RFC_1123
    105         = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");
     110        = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
     111
    106112
    107113    synchronized public static ZipFile get(final URL url) {
     
    161167                String dateString = HttpHead.get(url, "Last-Modified");
    162168                Date date = null;
    163                 try {
    164                     if (dateString == null) {
    165                         throw new ParseException("Failed to get HEAD for " + url, 0);
     169                ParsePosition pos = new ParsePosition(0);
     170
     171                if (dateString != null) {
     172                    date = RFC_1123.parse(dateString, pos);
     173                    if (date == null) {
     174                        date = RFC_1036.parse(dateString, pos);
     175                        if (date == null)
     176                            date = ASCTIME.parse(dateString, pos);
    166177                    }
    167                     date = RFC_1123.parse(dateString);
    168                     long current = date.getTime();
    169                     if (current > entry.lastModified) {
    170                         entry = fetchURL(url, false);
    171                         zipCache.put(url, entry);
    172                     }
    173                 } catch (ParseException e) {
    174                    Debug.trace("Failed to parse HTTP Last-Modified field: " + e);
    175                    entry = fetchURL(url, false);
    176                    zipCache.put(url, entry);
    177                 }
    178            } else {
     178                }
     179
     180                if (date == null || date.getTime() > entry.lastModified) {
     181                    entry = fetchURL(url, false);
     182                    zipCache.put(url, entry);
     183                }
     184                if (date == null) {
     185                    if (dateString == null)
     186                        Debug.trace("Failed to retrieve request header: "
     187                                    + url.toString());
     188                    else
     189                        Debug.trace("Failed to parse Last-Modified date: " +
     190                                    dateString);
     191                }
     192
     193           } else {
    179194                entry = fetchURL(url, false);
    180195                zipCache.put(url, entry);
Note: See TracChangeset for help on using the changeset viewer.