01: // CookieDate.java
02: // $Id: CookieDate.java,v 1.3 2002/07/17 14:22:09 ylafon Exp $
03: // (c) COPYRIGHT MIT and INRIA, 1998.
04: // Please first read the full copyright statement in file COPYRIGHT.html
05: package org.w3c.www.http;
06:
07: import java.util.Date;
08: import java.util.Calendar;
09: import java.util.TimeZone;
10:
11: /**
12: * @version $Revision: 1.3 $
13: * @author Benoît Mahé (bmahe@w3.org)
14: */
15: public class CookieDate extends HttpDate {
16: protected static String days[] = { "Pad", "Sun", "Mon", "Tue",
17: "Wed", "Thu", "Fri", "Sat" };
18: protected static String months[] = { "Jan", "Feb", "Mar", "Apr",
19: "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
20:
21: protected void updateByteValue() {
22: if (cal == null) {
23: TimeZone tz = TimeZone.getTimeZone("UTC");
24: cal = Calendar.getInstance(tz);
25: }
26: // Dump the date, according to Cookie prefered format
27: Date now = new Date(date.longValue());
28: cal.setTime(now);
29: // Dump the date, according to HTTP/1.1 prefered format
30: HttpBuffer buf = new HttpBuffer(32);
31: buf.append(days[cal.get(Calendar.DAY_OF_WEEK)]);
32: buf.append(',');
33: buf.append(' ');
34: buf.appendInt(cal.get(Calendar.DAY_OF_MONTH), 2, (byte) '0');
35: buf.append('-');
36: buf.append(months[cal.get(Calendar.MONTH)]);
37: buf.append('-');
38: buf.appendInt(cal.get(Calendar.YEAR), 2, (byte) '0');
39: buf.append(' ');
40: buf.appendInt(cal.get(Calendar.HOUR_OF_DAY), 2, (byte) '0');
41: buf.append(':');
42: buf.appendInt(cal.get(Calendar.MINUTE), 2, (byte) '0');
43: buf.append(':');
44: buf.appendInt(cal.get(Calendar.SECOND), 2, (byte) '0');
45: buf.append(" GMT");
46: raw = buf.getByteCopy();
47: roff = 0;
48: rlen = raw.length;
49: }
50:
51: public CookieDate(boolean isValid, long date) {
52: super(isValid, date);
53: }
54:
55: }
|