tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cos...@locus.apache.org
Subject cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/util CookieTools.java HttpDate.java MimeHeaderField.java
Date Tue, 02 May 2000 19:58:42 GMT
costin      00/05/02 12:58:42

  Modified:    src/share/org/apache/tomcat/util CookieTools.java
                        HttpDate.java MimeHeaderField.java
  Log:
  - Moved the date format from CookieTool to HttpDate, it's better to have
  all of them in one place
  - moved getBytes from HttpDate to MimeHeaderField, it's easier to understand
  it.
  
  I found HttpDate a bit difficult to read - I would prefer to keep static
  helper methods for date formating separated from the actual date storage.
  JDK1.1+ is using the same aproach - the format/parse code is separated
  from the actual date representation.
  
  The date code seems to be very expensive, according to perf. tests - another
  argument to do the change when some time will be available.
  
  Revision  Changes    Path
  1.6       +5 -11     jakarta-tomcat/src/share/org/apache/tomcat/util/CookieTools.java
  
  Index: CookieTools.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/CookieTools.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- CookieTools.java	2000/05/02 19:19:22	1.5
  +++ CookieTools.java	2000/05/02 19:58:41	1.6
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/CookieTools.java,v
1.5 2000/05/02 19:19:22 costin Exp $
  - * $Revision: 1.5 $
  - * $Date: 2000/05/02 19:19:22 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/CookieTools.java,v
1.6 2000/05/02 19:58:41 costin Exp $
  + * $Revision: 1.6 $
  + * $Date: 2000/05/02 19:58:41 $
    *
    * ====================================================================
    *
  @@ -77,14 +77,8 @@
    * @author duncan@eng.sun.com
    */
   public class CookieTools {
  -    static String pattern = "EEE, dd-MMM-yyyy HH:mm:ss z";
  -    static Locale loc = Locale.US;
  -    static TimeZone zone = TimeZone.getTimeZone("GMT");
  -    static SimpleDateFormat df = new SimpleDateFormat(pattern, loc);
  +
       static FieldPosition FieldPosition0=new FieldPosition(0);
  -    static {
  -	df.setTimeZone(zone);
  -    }
   
       /** Return the header name to set the cookie, based on cookie
        *  version
  @@ -142,7 +136,7 @@
   	if (cookie.getMaxAge() >= 0) {
   	    if (version == 0) {
   		buf.append (";Expires=");
  -		df.format(new Date( System.currentTimeMillis() + cookie.getMaxAge() *1000) ,buf, FieldPosition0
);
  +		HttpDate.oldCookieFormat.format(new Date( System.currentTimeMillis() + cookie.getMaxAge()
*1000) ,buf, FieldPosition0 );
   	    } else {
   		buf.append (";Max-Age=");
   		buf.append (cookie.getMaxAge());
  
  
  
  1.4       +42 -43    jakarta-tomcat/src/share/org/apache/tomcat/util/HttpDate.java
  
  Index: HttpDate.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/HttpDate.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- HttpDate.java	2000/02/14 04:59:42	1.3
  +++ HttpDate.java	2000/05/02 19:58:41	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/HttpDate.java,v 1.3
2000/02/14 04:59:42 costin Exp $
  - * $Revision: 1.3 $
  - * $Date: 2000/02/14 04:59:42 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/HttpDate.java,v 1.4
2000/05/02 19:58:41 costin Exp $
  + * $Revision: 1.4 $
  + * $Date: 2000/05/02 19:58:41 $
    *
    * ====================================================================
    *
  @@ -80,26 +80,22 @@
    * @author Jason Hunter [jch@eng.sun.com]
    * @author James Todd [gonzo@eng.sun.com]
    */
  -
   public class HttpDate extends Ascii {
   
  -    private StringManager sm =
  +    private static StringManager sm =
           StringManager.getManager("org.apache.tomcat.util");
  -
  -    // ONLY FOR COMPAT -- KILL ASAP -- just make sure that dependant
  -    // classes know what's up. ref. MimeHeaderField
  -    private static final String DATESTR = "Sun, 06 Nov 1994 08:49:37 GMT";
  -    public static final int DATELEN = DATESTR.length();
  -    // END COMPAT -- DON'T FORGET TO KILL
  -    
  -    // we force our locale here as all http dates are in english
  -    private final static Locale loc = Locale.US;
  -
  -    // all http dates are expressed as time at GMT
  -    private final static TimeZone zone = TimeZone.getTimeZone("GMT");
   
  -    // format for RFC 1123 date string -- "Sun, 06 Nov 1994 08:49:37 GMT"
  -    private final static String rfc1123Pattern =
  +    /** US locale - all HTTP dates are in english
  +     */
  +    public final static Locale LOCALE_US = Locale.US;
  +
  +    /** GMT timezone - all HTTP dates are on GMT
  +     */
  +    public final static TimeZone GMT_ZONE = TimeZone.getTimeZone("GMT");
  +
  +    /** format for RFC 1123 date string -- "Sun, 06 Nov 1994 08:49:37 GMT"
  +     */
  +    public final static String RFC1123_PATTERN =
           "EEE, dd MMM yyyyy HH:mm:ss z";
   
       // format for RFC 1036 date string -- "Sunday, 06-Nov-94 08:49:37 GMT"
  @@ -110,24 +106,37 @@
       private final static String asctimePattern =
           "EEE MMM d HH:mm:ss yyyyy";
   
  -    private final static SimpleDateFormat rfc1123Format =
  -	new SimpleDateFormat(rfc1123Pattern, loc);
  +    /** Pattern used for old cookies
  +     */
  +    public final static String OLD_COOKIE_PATTERN = "EEE, dd-MMM-yyyy HH:mm:ss z";
  +    
  +    
  +    /** DateFormat to be used to format dates
  +     */
  +    public final static SimpleDateFormat rfc1123Format =
  +	new SimpleDateFormat(RFC1123_PATTERN, LOCALE_US);
  +    
  +    /** DateFormat to be used to format old netscape cookies
  +     */
  +    public final static SimpleDateFormat oldCookieFormat =
  +	new SimpleDateFormat(OLD_COOKIE_PATTERN, LOCALE_US);
       
  -    private final static SimpleDateFormat rfc1036Format =
  -	new SimpleDateFormat(rfc1036Pattern, loc);
  +    public final static SimpleDateFormat rfc1036Format =
  +	new SimpleDateFormat(rfc1036Pattern, LOCALE_US);
       
  -    private final static SimpleDateFormat asctimeFormat =
  -	new SimpleDateFormat(asctimePattern, loc);
  +    public final static SimpleDateFormat asctimeFormat =
  +	new SimpleDateFormat(asctimePattern, LOCALE_US);
       
       static {
  -	rfc1123Format.setTimeZone(zone);
  -	rfc1036Format.setTimeZone(zone);
  -	asctimeFormat.setTimeZone(zone);
  +	rfc1123Format.setTimeZone(GMT_ZONE);
  +	oldCookieFormat.setTimeZone(GMT_ZONE);
  +	rfc1036Format.setTimeZone(GMT_ZONE);
  +	asctimeFormat.setTimeZone(GMT_ZONE);
       }
       
       // protected so that oldcookieexpiry in cookieutils can use
       // yes, this is sloppy as crap and could stand to be done better.
  -    protected Calendar calendar = new GregorianCalendar(zone, loc);
  +    protected Calendar calendar = new GregorianCalendar(GMT_ZONE, LOCALE_US);
   
       public HttpDate() {
           calendar.setTime(new Date(System.currentTimeMillis()));
  @@ -198,21 +207,11 @@
           return calendar.getTime().getTime();
       }
   
  +    public  Calendar getCalendar() {
  +        return calendar;
  +    }
  +
       public static long getCurrentTime() {
           return System.currentTimeMillis();
       }
  -
  -    // KILL, THIS IS ONLY HERE FOR TEMP COMPAT as MimeHeaderField uses it.
  -    public int getBytes(byte[] buf, int off, int len) {
  -	if (len < DATELEN) {
  -            String msg = sm.getString("httpDate.iae", new Integer(len));
  -
  -	    throw new IllegalArgumentException(msg);
  -	}
  -
  -	String dateString = rfc1123Format.format(calendar.getTime());
  -	byte[] b = dateString.getBytes();
  -	System.arraycopy(b, 0, buf, off, DATELEN);
  -	return DATELEN;
  -    }    
   }
  
  
  
  1.4       +18 -6     jakarta-tomcat/src/share/org/apache/tomcat/util/MimeHeaderField.java
  
  Index: MimeHeaderField.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/MimeHeaderField.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MimeHeaderField.java	2000/02/16 17:46:58	1.3
  +++ MimeHeaderField.java	2000/05/02 19:58:41	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/MimeHeaderField.java,v
1.3 2000/02/16 17:46:58 costin Exp $
  - * $Revision: 1.3 $
  - * $Date: 2000/02/16 17:46:58 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/MimeHeaderField.java,v
1.4 2000/05/02 19:58:41 costin Exp $
  + * $Revision: 1.4 $
  + * $Date: 2000/05/02 19:58:41 $
    *
    * ====================================================================
    *
  @@ -100,7 +100,7 @@
       /**
        * The header field Date value.
        */
  -
  +    
       protected final HttpDate dateValue = new HttpDate(0);
   
       /**
  @@ -326,8 +326,8 @@
   	    buf_offset += intGetBytes(intValue, buf, buf_offset);
   	    break;
   	case T_DATE:
  -	    buf_offset += dateValue.getBytes(buf, buf_offset,
  -	        HttpDate.DATELEN);
  +	    buf_offset += getBytes(dateValue, buf, buf_offset,
  +					     DATELEN);
   	    break;
   	}
   
  @@ -337,6 +337,18 @@
   	return buf_offset - start_pt;
       }
   
  +    
  +    private static final String DATESTR = "Sun, 06 Nov 1994 08:49:37 GMT";
  +    private static final int DATELEN = DATESTR.length();
  +    
  +    private int getBytes(HttpDate dateValue, byte[] buf, int off, int len) {
  +	String dateString = HttpDate.rfc1123Format.format(dateValue.getCalendar().getTime());
  +	byte[] b = dateString.getBytes();
  +	System.arraycopy(b, 0, buf, off, DATELEN);
  +	return DATELEN;
  +    }    
  +
  +    
       /**
        * Parses a header field from a subarray of bytes.
        * @param b the bytes to parse
  
  
  

Mime
View raw message