You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by cr...@locus.apache.org on 2000/08/11 19:01:56 UTC

cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util Base64.java CookieTools.java DOMWriter.java DateTool.java Enumerator.java FastDateFormat.java InstanceSupport.java LifecycleSupport.java MD5Encoder.java MIME2Java.java Queue.java RequestUtil.java SimplePool.java StringManager.java StringParser.java XMLWriter.java

craigmcc    00/08/11 10:01:53

  Added:       catalina/src/share/org/apache/catalina/util Base64.java
                        CookieTools.java DOMWriter.java DateTool.java
                        Enumerator.java FastDateFormat.java
                        InstanceSupport.java LifecycleSupport.java
                        MD5Encoder.java MIME2Java.java Queue.java
                        RequestUtil.java SimplePool.java StringManager.java
                        StringParser.java XMLWriter.java
  Log:
  Migrate to Tomcat 4.0.
  
  Revision  Changes    Path
  1.1                  jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/Base64.java
  
  Index: Base64.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/Base64.java,v 1.1 2000/08/11 17:01:49 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2000/08/11 17:01:49 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  
  package org.apache.catalina.util;
  
  
  /**
   * This class provides encode/decode for RFC 2045 Base64 as
   * defined by RFC 2045, N. Freed and N. Borenstein.
   * RFC 2045: Multipurpose Internet Mail Extensions (MIME)
   * Part One: Format of Internet Message Bodies. Reference
   * 1996 Available at: http://www.ietf.org/rfc/rfc2045.txt
   * This class is used by XML Schema binary format validation
   *
   * @author Jeffrey Rodriguez
   * @version $Revision: 1.1 $ $Date: 2000/08/11 17:01:49 $
   */
  
  public final class Base64 {
  
  
      static private final int  BASELENGTH         = 255;
      static private final int  LOOKUPLENGTH       = 63;
      static private final int  TWENTYFOURBITGROUP = 24;
      static private final int  EIGHTBIT           = 8;
      static private final int  SIXTEENBIT         = 16;
      static private final int  SIXBIT             = 6;
      static private final int  FOURBYTE           = 4;
  
  
      static private final byte PAD               = ( byte ) '=';
      static private byte [] base64Alphabet       = new byte[BASELENGTH];
      static private byte [] lookUpBase64Alphabet = new byte[LOOKUPLENGTH];
  
      static {
  
          for (int i = 0; i<BASELENGTH; i++ ) {
              base64Alphabet[i] = -1;
          }
          for ( int i = 'Z'; i >= 'A'; i-- ) {
              base64Alphabet[i] = (byte) (i-'A');
          }
          for ( int i = 'z'; i>= 'a'; i--) {
              base64Alphabet[i] = (byte) ( i-'a' + 26);
          }
  
          for ( int i = '9'; i >= '0'; i--) {
              base64Alphabet[i] = (byte) (i-'0' + 52);
          }
  
          base64Alphabet['+']  = 62;
          base64Alphabet['/']  = 63;
  
         for (int i = 0; i<=25; i++ )
              lookUpBase64Alphabet[i] = (byte) ('A'+i );
  
          for (int i = 26,  j = 0; i<=51; i++, j++ )
              lookUpBase64Alphabet[i] = (byte) ('a'+ j );
  
          for (int i = 52,  j = 0; i<=61; i++, j++ )
              lookUpBase64Alphabet[i] = (byte) ('0' + j );
  
      }
  
  
      static boolean isBase64( byte octect ) {
          //shall we ignore white space? JEFF??
          return(octect == PAD || base64Alphabet[octect] != -1 );
      }
  
  
      static boolean isArrayByteBase64( byte[] arrayOctect ) {
          int length = arrayOctect.length;
          if ( length == 0 )
              return false;
          for ( int i=0; i < length; i++ ) {
              if ( Base64.isBase64( arrayOctect[i] ) == false)
                  return false;
          }
          return true;
      }
  
      /**
       * Encodes hex octects into Base64
       *
       * @param binaryData Array containing binaryData
       * @return Encoded Base64 array
       */
      public byte[] encode( byte[] binaryData ) {
          int      lengthDataBits    = binaryData.length*EIGHTBIT;
          int      fewerThan24bits   = lengthDataBits%TWENTYFOURBITGROUP;
          int      numberTriplets    = lengthDataBits/TWENTYFOURBITGROUP;
          byte     encodedData[]     = null;
  
  
          if ( fewerThan24bits != 0 ) //data not divisible by 24 bit
              encodedData = new byte[ (numberTriplets + 1 )*4  ];
          else // 16 or 8 bit
              encodedData = new byte[ numberTriplets*4 ];
  
          byte k=0, l=0, b1=0,b2=0,b3=0;
  
          int encodedIndex = 0;
          int dataIndex   = 0;
          int i           = 0;
          for ( i = 0; i<numberTriplets; i++ ) {
  
              dataIndex = i*3;
              b1 = binaryData[dataIndex];
              b2 = binaryData[dataIndex + 1];
              b3 = binaryData[dataIndex + 2];
  
              l  = (byte)(b2 & 0x0f);
              k  = (byte)(b1 & 0x03);
  
              encodedIndex = i*4;
              encodedData[encodedIndex]   = lookUpBase64Alphabet[ b1 >>2 ];
              encodedData[encodedIndex+1] = lookUpBase64Alphabet[(b2 >>4 ) |
  ( k<<4 )];
              encodedData[encodedIndex+2] = lookUpBase64Alphabet[ (l <<2 ) |
  ( b3>>6)];
              encodedData[encodedIndex+3] = lookUpBase64Alphabet[ b3 & 0x3f ];
          }
  
          // form integral number of 6-bit groups
          dataIndex    = i*3;
          encodedIndex = i*4;
          if (fewerThan24bits == EIGHTBIT ) {
              b1 = binaryData[dataIndex];
              k = (byte) ( b1 &0x03 );
              encodedData[encodedIndex]     = lookUpBase64Alphabet[ b1 >>2 ];
              encodedData[encodedIndex + 1] = lookUpBase64Alphabet[ k<<4 ];
              encodedData[encodedIndex + 2] = PAD;
              encodedData[encodedIndex + 3] = PAD;
          } else if ( fewerThan24bits == SIXTEENBIT ) {
  
              b1 = binaryData[dataIndex];
              b2 = binaryData[dataIndex +1 ];
              l = ( byte ) ( b2 &0x0f );
              k = ( byte ) ( b1 &0x03 );
              encodedData[encodedIndex]     = lookUpBase64Alphabet[ b1 >>2 ];
              encodedData[encodedIndex + 1] = lookUpBase64Alphabet[ (b2 >>4 )
  | ( k<<4 )];
              encodedData[encodedIndex + 2] = lookUpBase64Alphabet[ l<<2 ];
              encodedData[encodedIndex + 3] = PAD;
          }
          return encodedData;
      }
  
  
      /**
       * Decodes Base64 data into octects
       *
       * @param binaryData Byte array containing Base64 data
       * @return Array containind decoded data.
       */
      public byte[] decode( byte[] base64Data ) {
          int      numberQuadruple    = base64Data.length/FOURBYTE;
          byte     decodedData[]      = null;
          byte     b1=0,b2=0,b3=0, b4=0, marker0=0, marker1=0;
  
          // Throw away anything not in base64Data
          // Adjust size
  
          int encodedIndex = 0;
          int dataIndex    = 0;
          decodedData      = new byte[ numberQuadruple*3 + 1 ];
  
          for (int i = 0; i<numberQuadruple; i++ ) {
              dataIndex = i*4;
              marker0   = base64Data[dataIndex +2];
              marker1   = base64Data[dataIndex +3];
  
              b1 = base64Alphabet[base64Data[dataIndex]];
              b2 = base64Alphabet[base64Data[dataIndex +1]];
  
              if ( marker0 != PAD && marker1 != PAD ) {     //No PAD e.g 3cQl
                  b3 = base64Alphabet[ marker0 ];
                  b4 = base64Alphabet[ marker1 ];
  
                  decodedData[encodedIndex]   = (byte)(  b1 <<2 | b2>>4 ) ;
                  decodedData[encodedIndex+1] = (byte)(((b2 & 0xf)<<4 ) |(
  (b3>>2) & 0xf) );
                  decodedData[encodedIndex+2] = (byte)( b3<<6 | b4 );
              } else if ( marker0 == PAD ) {               //Two PAD e.g. 3c[Pad][Pad]
                  decodedData[encodedIndex]   = (byte)(  b1 <<2 | b2>>4 ) ;
                  decodedData[encodedIndex+1] = (byte)((b2 & 0xf)<<4 );
                  decodedData[encodedIndex+2] = (byte) 0;
              } else if ( marker1 == PAD ) {              //One PAD e.g. 3cQ[Pad]
                  b3 = base64Alphabet[ marker0 ];
  
                  decodedData[encodedIndex]   = (byte)(  b1 <<2 | b2>>4 );
                  decodedData[encodedIndex+1] = (byte)(((b2 & 0xf)<<4 ) |(
  (b3>>2) & 0xf) );
                  decodedData[encodedIndex+2] = (byte)( b3<<6);
              }
              encodedIndex += 3;
          }
          return decodedData;
  
      }
  }
  
  
  
  
  1.1                  jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/CookieTools.java
  
  Index: CookieTools.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/CookieTools.java,v 1.1 2000/08/11 17:01:50 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2000/08/11 17:01:50 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  
  package org.apache.catalina.util;
  import java.text.*;
  import java.util.*;
  
  import javax.servlet.http.Cookie;
  
  // XXX use only one Date instance/request, reuse it.
  
  /**
   * Cookie utils - generate cookie header, etc
   *
   * @author Original Author Unknown
   * @author duncan@eng.sun.com
   */
  public class CookieTools {
  
      /** Return the header name to set the cookie, based on cookie
       *  version
       */
      public static String getCookieHeaderName(Cookie cookie) {
          int version = cookie.getVersion();
  	
          if (version == 1) {
  	    return "Set-Cookie2";
          } else {
              return "Set-Cookie";
          }
      }
  
      /** Return the header value used to set this cookie
       *  @deprecated Use StringBuffer version
       */
      public static String getCookieHeaderValue(Cookie cookie) {
          StringBuffer buf = new StringBuffer();
  	getCookieHeaderValue( cookie, buf );
  	return buf.toString();
      }
      
      /** Return the header value used to set this cookie
       */
      public static void getCookieHeaderValue(Cookie cookie, StringBuffer buf) {
          int version = cookie.getVersion();
  
          // this part is the same for all cookies
          
          buf.append(cookie.getName());
          buf.append("=");
          maybeQuote(version, buf, cookie.getValue());
  
   	// add version 1 specific information 
  	if (version == 1) {
  	    // Version=1 ... required 
  	    buf.append (";Version=1");
  
  	    // Comment=comment
  	    if (cookie.getComment() != null) {
  		buf.append (";Comment=");
  		maybeQuote (version, buf, cookie.getComment());
  	    }
  	}
  
  	// add domain information, if present
  
  	if (cookie.getDomain() != null) {
  	    buf.append(";Domain=");
  	    maybeQuote (version, buf, cookie.getDomain());
  	}
  
  	// Max-Age=secs/Discard ... or use old "Expires" format
  	if (cookie.getMaxAge() >= 0) {
  	    if (version == 0) {
  		buf.append (";Expires=");
  		DateTool.oldCookieFormat.format(new Date( System.currentTimeMillis() + cookie.getMaxAge() *1000) ,buf,
  						new FieldPosition(0));
  
  	    } else {
  		buf.append (";Max-Age=");
  		buf.append (cookie.getMaxAge());
  	    }
  	} else if (version == 1)
  	  buf.append (";Discard");
  
  	// Path=path
  	if (cookie.getPath() != null) {
  	    buf.append (";Path=");
  	    maybeQuote (version, buf, cookie.getPath());
  	}
  
  	// Secure
  	if (cookie.getSecure()) {
  	  buf.append (";Secure");
  	}
      }
  
      static void maybeQuote (int version, StringBuffer buf,
                                      String value)
      {
  	if (version == 0 || isToken (value))
  	  buf.append (value);
  	else {
  	    buf.append ('"');
  	    buf.append (value);
  	    buf.append ('"');
  	}
      }
  
          //
      // from RFC 2068, token special case characters
      //
      private static final String tspecials = "()<>@,;:\\\"/[]?={} \t";
  
      /*
       * Return true iff the string counts as an HTTP/1.1 "token".
       */
      private static boolean isToken (String value) {
  	int len = value.length ();
  
  	for (int i = 0; i < len; i++) {
  	    char c = value.charAt (i);
  
  	    if (c < 0x20 || c >= 0x7f || tspecials.indexOf (c) != -1)
  	      return false;
  	}
  	return true;
      }    
  
  
  }
  
  
  
  1.1                  jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/DOMWriter.java
  
  Index: DOMWriter.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/DOMWriter.java,v 1.1 2000/08/11 17:01:50 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2000/08/11 17:01:50 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  package org.apache.catalina.util;
  
  import java.io.*;
  import org.w3c.dom.Attr;
  import org.w3c.dom.Document;
  import org.w3c.dom.NamedNodeMap;
  import org.w3c.dom.Node;
  import org.w3c.dom.NodeList;
  import org.xml.sax.InputSource;
  
  /**
   * A sample DOM writer. This sample program illustrates how to
   * traverse a DOM tree in order to print a document that is parsed.
   */
  public class DOMWriter {
  
     //
     // Data
     //
  
     /** Default Encoding */
     private static  String
     PRINTWRITER_ENCODING = "UTF8";
  
     private static String MIME2JAVA_ENCODINGS[] =
      { "Default", "UTF-8", "US-ASCII", "ISO-8859-1", "ISO-8859-2", "ISO-8859-3", "ISO-8859-4", 
        "ISO-8859-5", "ISO-8859-6", "ISO-8859-7", "ISO-8859-8", "ISO-8859-9", "ISO-2022-JP",
        "SHIFT_JIS", "EUC-JP","GB2312", "BIG5", "EUC-KR", "ISO-2022-KR", "KOI8-R", "EBCDIC-CP-US", 
        "EBCDIC-CP-CA", "EBCDIC-CP-NL", "EBCDIC-CP-DK", "EBCDIC-CP-NO", "EBCDIC-CP-FI", "EBCDIC-CP-SE",
        "EBCDIC-CP-IT", "EBCDIC-CP-ES", "EBCDIC-CP-GB", "EBCDIC-CP-FR", "EBCDIC-CP-AR1", 
        "EBCDIC-CP-HE", "EBCDIC-CP-CH", "EBCDIC-CP-ROECE","EBCDIC-CP-YU",  
        "EBCDIC-CP-IS", "EBCDIC-CP-AR2", "UTF-16"
      };
  
  
     /** Print writer. */
     protected PrintWriter out;
  
     /** Canonical output. */
     protected boolean canonical;
  
  
     public DOMWriter(String encoding, boolean canonical)              
     throws UnsupportedEncodingException {
        out = new PrintWriter(new OutputStreamWriter(System.out, encoding));
        this.canonical = canonical;
     } // <init>(String,boolean)
  
     //
     // Constructors
     //
  
     /** Default constructor. */
     public DOMWriter(boolean canonical) throws UnsupportedEncodingException {
        this( getWriterEncoding(), canonical);
     }
  
      public DOMWriter(Writer writer, boolean canonical) {
  	out = new PrintWriter(writer);
  	this.canonical = canonical;	
      }
  
     public static String getWriterEncoding( ) {
        return (PRINTWRITER_ENCODING);
     }// getWriterEncoding 
  
     public static void  setWriterEncoding( String encoding ) {
        if( encoding.equalsIgnoreCase( "DEFAULT" ) )
           PRINTWRITER_ENCODING  = "UTF8";
        else if( encoding.equalsIgnoreCase( "UTF-16" ) )
           PRINTWRITER_ENCODING  = "Unicode";
        else
           PRINTWRITER_ENCODING = MIME2Java.convert( encoding ); 
     }// setWriterEncoding 
  
  
     public static boolean isValidJavaEncoding( String encoding ) {
        for ( int i = 0; i < MIME2JAVA_ENCODINGS.length; i++ )
           if ( encoding.equals( MIME2JAVA_ENCODINGS[i] ) )
              return (true);
  
        return (false);
     }// isValidJavaEncoding 
  
  
     /** Prints the specified node, recursively. */
     public void print(Node node) {
  
        // is there anything to do?
        if ( node == null ) {
           return;
        }
  
        int type = node.getNodeType();
        switch ( type ) {
           // print document
           case Node.DOCUMENT_NODE: {
                 if ( !canonical ) {
                    String  Encoding = this.getWriterEncoding();
                    if( Encoding.equalsIgnoreCase( "DEFAULT" ) )
                       Encoding = "UTF-8";
                    else if( Encoding.equalsIgnoreCase( "Unicode" ) )
                       Encoding = "UTF-16";
                    else 
                       Encoding = MIME2Java.reverse( Encoding );
  
                    out.println("<?xml version=\"1.0\" encoding=\""+
                             Encoding + "\"?>");
                 }
                 print(((Document)node).getDocumentElement());
                 out.flush();
                 break;
              }
  
              // print element with attributes
           case Node.ELEMENT_NODE: {
                 out.print('<');
                 out.print(node.getNodeName());
                 Attr attrs[] = sortAttributes(node.getAttributes());
                 for ( int i = 0; i < attrs.length; i++ ) {
                    Attr attr = attrs[i];
                    out.print(' ');
                    out.print(attr.getNodeName());
                    out.print("=\"");
                    out.print(normalize(attr.getNodeValue()));
                    out.print('"');
                 }
                 out.print('>');
                 NodeList children = node.getChildNodes();
                 if ( children != null ) {
                    int len = children.getLength();
                    for ( int i = 0; i < len; i++ ) {
                       print(children.item(i));
                    }
                 }
                 break;
              }
  
              // handle entity reference nodes
           case Node.ENTITY_REFERENCE_NODE: {
                 if ( canonical ) {
                    NodeList children = node.getChildNodes();
                    if ( children != null ) {
                       int len = children.getLength();
                       for ( int i = 0; i < len; i++ ) {
                          print(children.item(i));
                       }
                    }
                 } else {
                    out.print('&');
                    out.print(node.getNodeName());
                    out.print(';');
                 }
                 break;
              }
  
              // print cdata sections
           case Node.CDATA_SECTION_NODE: {
                 if ( canonical ) {
                    out.print(normalize(node.getNodeValue()));
                 } else {
                    out.print("<![CDATA[");
                    out.print(node.getNodeValue());
                    out.print("]]>");
                 }
                 break;
              }
  
              // print text
           case Node.TEXT_NODE: {
                 out.print(normalize(node.getNodeValue()));
                 break;
              }
  
              // print processing instruction
           case Node.PROCESSING_INSTRUCTION_NODE: {
                 out.print("<?");
                 out.print(node.getNodeName());
                 String data = node.getNodeValue();
                 if ( data != null && data.length() > 0 ) {
                    out.print(' ');
                    out.print(data);
                 }
                 out.print("?>");
                 break;
              }
        }
  
        if ( type == Node.ELEMENT_NODE ) {
           out.print("</");
           out.print(node.getNodeName());
           out.print('>');
        }
  
        out.flush();
  
     } // print(Node)
  
     /** Returns a sorted list of attributes. */
     protected Attr[] sortAttributes(NamedNodeMap attrs) {
  
        int len = (attrs != null) ? attrs.getLength() : 0;
        Attr array[] = new Attr[len];
        for ( int i = 0; i < len; i++ ) {
           array[i] = (Attr)attrs.item(i);
        }
        for ( int i = 0; i < len - 1; i++ ) {
           String name  = array[i].getNodeName();
           int    index = i;
           for ( int j = i + 1; j < len; j++ ) {
              String curName = array[j].getNodeName();
              if ( curName.compareTo(name) < 0 ) {
                 name  = curName;
                 index = j;
              }
           }
           if ( index != i ) {
              Attr temp    = array[i];
              array[i]     = array[index];
              array[index] = temp;
           }
        }
  
        return (array);
  
     } // sortAttributes(NamedNodeMap):Attr[]
  
  
     /** Normalizes the given string. */
     protected String normalize(String s) {
        StringBuffer str = new StringBuffer();
  
        int len = (s != null) ? s.length() : 0;
        for ( int i = 0; i < len; i++ ) {
           char ch = s.charAt(i);
           switch ( ch ) {
              case '<': {
                    str.append("&lt;");
                    break;
                 }
              case '>': {
                    str.append("&gt;");
                    break;
                 }
              case '&': {
                    str.append("&amp;");
                    break;
                 }
              case '"': {
                    str.append("&quot;");
                    break;
                 }
              case '\r':
              case '\n': {
                    if ( canonical ) {
                       str.append("&#");
                       str.append(Integer.toString(ch));
                       str.append(';');
                       break;
                    }
                    // else, default append char
                 }
              default: {
                    str.append(ch);
                 }
           }
        }
  
        return (str.toString());
  
     } // normalize(String):String
  
     private static void printValidJavaEncoding() {
        System.err.println( "    ENCODINGS:" );
        System.err.print( "   " );
        for( int i = 0;
                       i < MIME2JAVA_ENCODINGS.length; i++) {
           System.err.print( MIME2JAVA_ENCODINGS[i] + " " );
        if( (i % 7 ) == 0 ){
           System.err.println();
           System.err.print( "   " );
           }
        }
  
     } // printJavaEncoding()            
  
  } 
  
  
  
  1.1                  jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/DateTool.java
  
  Index: DateTool.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/DateTool.java,v 1.1 2000/08/11 17:01:50 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2000/08/11 17:01:50 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  
  package org.apache.catalina.util;
  
  import java.io.IOException;
  import java.io.OutputStream;
  import java.util.*;
  import java.text.*;
  
  /**
   *  Common place for date utils.
   *
   * @author dac@eng.sun.com
   * @author Jason Hunter [jch@eng.sun.com]
   * @author James Todd [gonzo@eng.sun.com]
   * @author Costin Manolache
   */
  public class DateTool {
  
      private static StringManager sm =
          StringManager.getManager("org.apache.catalina.util");
  
      /** 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"
      private final static String rfc1036Pattern =
          "EEEEEEEEE, dd-MMM-yy HH:mm:ss z";
  
      // format for C asctime() date string -- "Sun Nov  6 08:49:37 1994"
      private final static String asctimePattern =
          "EEE MMM d HH:mm:ss yyyyy";
  
      /** 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 DateFormat rfc1123Format =
  	new SimpleDateFormat(RFC1123_PATTERN, LOCALE_US);
      
      /** DateFormat to be used to format old netscape cookies
       */
      public final static DateFormat oldCookieFormat =
  	new SimpleDateFormat(OLD_COOKIE_PATTERN, LOCALE_US);
      
      public final static DateFormat rfc1036Format =
  	new SimpleDateFormat(rfc1036Pattern, LOCALE_US);
      
      public final static DateFormat asctimeFormat =
  	new SimpleDateFormat(asctimePattern, LOCALE_US);
      
      static {
  	rfc1123Format.setTimeZone(GMT_ZONE);
  	oldCookieFormat.setTimeZone(GMT_ZONE);
  	rfc1036Format.setTimeZone(GMT_ZONE);
  	asctimeFormat.setTimeZone(GMT_ZONE);
      }
      
  }
  
  
  
  1.1                  jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/Enumerator.java
  
  Index: Enumerator.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/Enumerator.java,v 1.1 2000/08/11 17:01:50 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2000/08/11 17:01:50 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  
  package org.apache.catalina.util;
  
  
  import java.util.Collection;
  import java.util.Enumeration;
  import java.util.Iterator;
  import java.util.Map;
  import java.util.NoSuchElementException;
  
  
  /**
   * Adapter class that wraps an <code>Enumeration</code> around a Java2
   * collection classes object <code>Iterator</code> so that existing APIs
   * returning Enumerations can easily run on top of the new collections.
   * Constructors are provided to easliy create such wrappers.
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2000/08/11 17:01:50 $
   */
  
  public final class Enumerator implements Enumeration {
  
  
      // ----------------------------------------------------------- Constructors
  
  
      /**
       * Return an Enumeration over the values of the specified Collection.
       *
       * @param collection Collection whose values should be enumerated
       */
      public Enumerator(Collection collection) {
  
  	this(collection.iterator());
  
      }
  
  
      /**
       * Return an Enumeration over the values returned by the
       * specified Iterator.
       *
       * @param iterator Iterator to be wrapped
       */
      public Enumerator(Iterator iterator) {
  
  	super();
  	this.iterator = iterator;
  
      }
  
  
      /**
       * Return an Enumeration over the values of the specified Map.
       *
       * @param map Map whose values should be enumerated
       */
      public Enumerator(Map map) {
  
  	this(map.values().iterator());
  
      }
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      /**
       * The <code>Iterator</code> over which the <code>Enumeration</code>
       * represented by this class actually operates.
       */
      private Iterator iterator = null;
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Tests if this enumeration contains more elements.
       *
       * @return <code>true</code> if and only if this enumeration object
       *  contains at least one more element to provide, <code>false</code>
       *  otherwise
       */
      public boolean hasMoreElements() {
  
  	return (iterator.hasNext());
  
      }
  
  
      /**
       * Returns the next element of this enumeration if this enumeration
       * has at least one more element to provide.
       *
       * @return the next element of this enumeration
       *
       * @exception NoSuchElementException if no more elements exist
       */
      public Object nextElement() throws NoSuchElementException {
  
  	return (iterator.next());
  
      }
  
  
  }
  
  
  
  1.1                  jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/FastDateFormat.java
  
  Index: FastDateFormat.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Original code Copyright 2000 Quadcap Software: 
   * This software may be freely redistributed in source or binary form
   * for any purpose.
   *
   */
  
  package org.apache.catalina.util;
  
  import java.util.Date;
  
  import java.text.DateFormat;
  import java.text.FieldPosition;
  import java.text.ParsePosition;
  import java.text.SimpleDateFormat;
  
  /**
   * Fast date formatter that caches recently formatted date information
   * and uses it to avoid too-frequent calls to the underlying
   * formatter.  Note: breaks fieldPosition param of format(Date,
   * StringBuffer, FieldPosition).  If you care about the field
   * position, call the underlying DateFormat directly.
   *
   * @author Stan Bailes
   * @author Alex Chaffee
   **/
  public class FastDateFormat extends DateFormat {
      DateFormat    df;
      long          lastSec = -1;
      StringBuffer  sb      = new StringBuffer();
      FieldPosition fp      = new FieldPosition(DateFormat.MILLISECOND_FIELD);
      
      public FastDateFormat(DateFormat df) {
          this.df = df;
      }
  
      public Date parse(String text, ParsePosition pos) {
  	return df.parse(text, pos);
      }
  
      /**
       * Note: breaks functionality of fieldPosition param. Also:
       * there's a bug in SimpleDateFormat with "S" and "SS", use "SSS"
       * instead if you want a msec field.
       **/
      public StringBuffer format(Date date, StringBuffer toAppendTo,
  			       FieldPosition fieldPosition) {
          long dt = date.getTime();
          long ds = dt / 1000;
          if (ds != lastSec) {
              sb.setLength(0);
              df.format(date, sb, fp);
              lastSec = ds;
          } else {
  	    // munge current msec into existing string
              int ms = (int)(dt % 1000);
              int pos = fp.getEndIndex();
  	    int begin = fp.getBeginIndex();
  	    if (pos > 0) {
  		if (pos > begin)
  		    sb.setCharAt(--pos, Character.forDigit(ms % 10, 10));
  		ms /= 10;
  		if (pos > begin)
  		    sb.setCharAt(--pos, Character.forDigit(ms % 10, 10));
  		ms /= 10;
  		if (pos > begin)
  		    sb.setCharAt(--pos, Character.forDigit(ms % 10, 10));
  	    }
          }
  	toAppendTo.append(sb.toString());
  	return toAppendTo;
      }
  
      public static void main(String[] args) {
  	String format = "yyyy-MM-dd HH:mm:ss.SSS";
  	if (args.length > 0)
  	    format = args[0];
          SimpleDateFormat sdf = new SimpleDateFormat(format);
          FastDateFormat fdf = new FastDateFormat(sdf);
          Date d = new Date();
  
  	d.setTime(1); System.out.println(fdf.format(d) + "\t" + sdf.format(d));
  	d.setTime(20); System.out.println(fdf.format(d) + "\t" + sdf.format(d));
  	d.setTime(500); System.out.println(fdf.format(d) + "\t" + sdf.format(d));
  	d.setTime(543); System.out.println(fdf.format(d) + "\t" + sdf.format(d));
  	d.setTime(999); System.out.println(fdf.format(d) + "\t" + sdf.format(d));
  	d.setTime(1050); System.out.println(fdf.format(d) + "\t" + sdf.format(d));
  	d.setTime(2543); System.out.println(fdf.format(d) + "\t" + sdf.format(d));
  	d.setTime(12345); System.out.println(fdf.format(d) + "\t" + sdf.format(d));
  	d.setTime(12340); System.out.println(fdf.format(d) + "\t" + sdf.format(d));
  	
          final int reps = 100000;
          {
              long start = System.currentTimeMillis();
              for (int i = 0; i < reps; i++) {
                  d.setTime(System.currentTimeMillis());
                  fdf.format(d);
              }
              long elap = System.currentTimeMillis() - start;
              System.out.println("fast: " + elap + " elapsed");
  	    System.out.println(fdf.format(d));
          }
          {
              long start = System.currentTimeMillis();
              for (int i = 0; i < reps; i++) {
                  d.setTime(System.currentTimeMillis());
                  sdf.format(d);
              }
              long elap = System.currentTimeMillis() - start;	    
              System.out.println("slow: " + elap + " elapsed");
  	    System.out.println(sdf.format(d));
          }
      }
  }
  
  
  
  1.1                  jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/InstanceSupport.java
  
  Index: InstanceSupport.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/InstanceSupport.java,v 1.1 2000/08/11 17:01:50 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2000/08/11 17:01:50 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  
  package org.apache.catalina.util;
  
  
  import javax.servlet.Servlet;
  import org.apache.catalina.InstanceEvent;
  import org.apache.catalina.InstanceListener;
  import org.apache.catalina.Wrapper;
  
  
  /**
   * Support class to assist in firing InstanceEvent notifications to
   * registered InstanceListeners.
   *
   * @author Craig R. McClanahan
   * @version $Id: InstanceSupport.java,v 1.1 2000/08/11 17:01:50 craigmcc Exp $
   */
  
  public final class InstanceSupport {
  
  
      // ----------------------------------------------------------- Constructors
  
  
      /**
       * Construct a new InstanceSupport object associated with the specified
       * Instance component.
       *
       * @param lifecycle The Instance component that will be the source
       *  of events that we fire
       */
      public InstanceSupport(Wrapper wrapper) {
  
  	super();
  	this.wrapper = wrapper;
  
      }
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      /**
       * The set of registered InstanceListeners for event notifications.
       */
      private InstanceListener listeners[] = new InstanceListener[0];
  
  
      /**
       * The source component for instance events that we will fire.
       */
      private Wrapper wrapper = null;
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Add a lifecycle event listener to this component.
       *
       * @param listener The listener to add
       */
      public void addInstanceListener(InstanceListener listener) {
  
        synchronized (listeners) {
  	  InstanceListener results[] =
  	    new InstanceListener[listeners.length + 1];
  	  for (int i = 0; i < listeners.length; i++)
  	      results[i] = listeners[i];
  	  results[listeners.length] = listener;
  	  listeners = results;
        }
  
      }
  
  
      /**
       * Notify all lifecycle event listeners that a particular event has
       * occurred for this Container.  The default implementation performs
       * this notification synchronously using the calling thread.
       *
       * @param type Event type
       * @param data Event data
       */
      public void fireInstanceEvent(String type, Servlet servlet) {
  
  	InstanceEvent event = new InstanceEvent(wrapper, servlet, type);
  	InstanceListener interested[] = null;
  	synchronized (listeners) {
  	    interested = (InstanceListener[]) listeners.clone();
  	}
  	for (int i = 0; i < interested.length; i++)
  	    interested[i].instanceEvent(event);
  
      }
  
  
      /**
       * Remove a lifecycle event listener from this component.
       *
       * @param listener The listener to remove
       */
      public void removeInstanceListener(InstanceListener listener) {
  
          synchronized (listeners) {
  	    int n = -1;
  	    for (int i = 0; i < listeners.length; i++) {
  	        if (listeners[i] == listener) {
  		    n = i;
  		    break;
  		}
  	    }
  	    if (n < 0)
  	        return;
  	    InstanceListener results[] =
  	      new InstanceListener[listeners.length - 1];
  	    int j = 0;
  	    for (int i = 0; i < listeners.length; i++) {
  	        if (i != n)
  		    results[j++] = listeners[i];
  	    }
  	    listeners = results;
  	}
  
      }
  
  
  }
  
  
  
  1.1                  jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/LifecycleSupport.java
  
  Index: LifecycleSupport.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/LifecycleSupport.java,v 1.1 2000/08/11 17:01:50 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2000/08/11 17:01:50 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  
  package org.apache.catalina.util;
  
  
  import org.apache.catalina.Lifecycle;
  import org.apache.catalina.LifecycleEvent;
  import org.apache.catalina.LifecycleListener;
  
  
  /**
   * Support class to assist in firing LifecycleEvent notifications to
   * registered LifecycleListeners.
   *
   * @author Craig R. McClanahan
   * @version $Id: LifecycleSupport.java,v 1.1 2000/08/11 17:01:50 craigmcc Exp $
   */
  
  public final class LifecycleSupport {
  
  
      // ----------------------------------------------------------- Constructors
  
  
      /**
       * Construct a new LifecycleSupport object associated with the specified
       * Lifecycle component.
       *
       * @param lifecycle The Lifecycle component that will be the source
       *  of events that we fire
       */
      public LifecycleSupport(Lifecycle lifecycle) {
  
  	super();
  	this.lifecycle = lifecycle;
  
      }
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      /**
       * The source component for lifecycle events that we will fire.
       */
      private Lifecycle lifecycle = null;
  
  
      /**
       * The set of registered LifecycleListeners for event notifications.
       */
      private LifecycleListener listeners[] = new LifecycleListener[0];
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Add a lifecycle event listener to this component.
       *
       * @param listener The listener to add
       */
      public void addLifecycleListener(LifecycleListener listener) {
  
        synchronized (listeners) {
  	  LifecycleListener results[] =
  	    new LifecycleListener[listeners.length + 1];
  	  for (int i = 0; i < listeners.length; i++)
  	      results[i] = listeners[i];
  	  results[listeners.length] = listener;
  	  listeners = results;
        }
  
      }
  
  
      /**
       * Notify all lifecycle event listeners that a particular event has
       * occurred for this Container.  The default implementation performs
       * this notification synchronously using the calling thread.
       *
       * @param type Event type
       * @param data Event data
       */
      public void fireLifecycleEvent(String type, Object data) {
  
  	LifecycleEvent event = new LifecycleEvent(lifecycle, type, data);
  	LifecycleListener interested[] = null;
  	synchronized (listeners) {
  	    interested = (LifecycleListener[]) listeners.clone();
  	}
  	for (int i = 0; i < interested.length; i++)
  	    interested[i].lifecycleEvent(event);
  
      }
  
  
      /**
       * Remove a lifecycle event listener from this component.
       *
       * @param listener The listener to remove
       */
      public void removeLifecycleListener(LifecycleListener listener) {
  
          synchronized (listeners) {
  	    int n = -1;
  	    for (int i = 0; i < listeners.length; i++) {
  	        if (listeners[i] == listener) {
  		    n = i;
  		    break;
  		}
  	    }
  	    if (n < 0)
  	        return;
  	    LifecycleListener results[] =
  	      new LifecycleListener[listeners.length - 1];
  	    int j = 0;
  	    for (int i = 0; i < listeners.length; i++) {
  	        if (i != n)
  		    results[j++] = listeners[i];
  	    }
  	    listeners = results;
  	}
  
      }
  
  
  }
  
  
  
  1.1                  jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/MD5Encoder.java
  
  Index: MD5Encoder.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/MD5Encoder.java,v 1.1 2000/08/11 17:01:50 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2000/08/11 17:01:50 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  
  package org.apache.catalina.util;
  
  
  /**
   * Encode an MD5 digest into a String.
   * <p>
   * The 128 bit MD5 hash is converted into a 32 character long String.
   * Each character of the String is the hexadecimal representation of 4 bits
   * of the digest.
   *
   * @author Remy Maucherat
   * @version $Revision: 1.1 $ $Date: 2000/08/11 17:01:50 $
   */
  
  public final class MD5Encoder {
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      private static final char[] hexadecimal = 
      {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 
       'a', 'b', 'c', 'd', 'e', 'f'};
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Encodes the 128 bit (16 bytes) MD5 into a 32 character String.
       *
       * @param binaryData Array containing the digest
       * @return Encoded MD5, or null if encoding failed
       */
      public String encode( byte[] binaryData ) {
          
          if (binaryData.length != 16)
              return null;
  
          char[] buffer = new char[32];
          
          for (int i=0; i<16; i++) {
              int low = (int) (binaryData[i] & 0x0f);
              int high = (int) ((binaryData[i] & 0xf0) >> 4);
              buffer[i*2] = hexadecimal[high];
              buffer[i*2 + 1] = hexadecimal[low];
          }
  
          return new String(buffer);
  
      }
  
  
  }
  
  
  
  
  1.1                  jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/MIME2Java.java
  
  Index: MIME2Java.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xerces" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.apache.org.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.catalina.util;
  
  import java.util.*;
  
  /**
   * MIME2Java is a convenience class which handles conversions between MIME charset names
   * and Java encoding names.
   * <p>The supported XML encodings are the intersection of XML-supported code sets and those 
   * supported in JDK 1.1.
   * <p>MIME charset names are used on <var>xmlEncoding</var> parameters to methods such
   * as <code>TXDocument#setEncoding</code> and <code>DTD#setEncoding</code>.
   * <p>Java encoding names are used on <var>encoding</var> parameters to
   * methods such as <code>TXDocument#printWithFormat</code> and <code>DTD#printExternal</code>. 
   * <P>
   * <TABLE BORDER="0" WIDTH="100%">
   *  <TR>
   *      <TD WIDTH="33%">
   *          <P ALIGN="CENTER"><B>Common Name</B>
   *      </TD>
   *      <TD WIDTH="15%">
   *          <P ALIGN="CENTER"><B>Use this name in XML files</B>
   *      </TD>
   *      <TD WIDTH="12%">
   *          <P ALIGN="CENTER"><B>Name Type</B>
   *      </TD>
   *      <TD WIDTH="31%">
   *          <P ALIGN="CENTER"><B>Xerces converts to this Java Encoder Name</B>
   *      </TD>
   *  </TR>
   *  <TR>
   *      <TD WIDTH="33%">8 bit Unicode</TD>
   *      <TD WIDTH="15%">
   *          <P ALIGN="CENTER">UTF-8
   *      </TD>
   *      <TD WIDTH="12%">
   *          <P ALIGN="CENTER">IANA
   *      </TD>
   *      <TD WIDTH="31%">
   *          <P ALIGN="CENTER">UTF8
   *      </TD>
   *  </TR>
   *  <TR>
   *      <TD WIDTH="33%">ISO Latin 1</TD>
   *      <TD WIDTH="15%">
   *          <P ALIGN="CENTER">ISO-8859-1
   *      </TD>
   *      <TD WIDTH="12%">
   *          <P ALIGN="CENTER">MIME
   *      </TD>
   *      <TD WIDTH="31%">
   *          <P ALIGN="CENTER">ISO-8859-1
   *      </TD>
   *  </TR>
   *  <TR>
   *      <TD WIDTH="33%">ISO Latin 2</TD>
   *      <TD WIDTH="15%">
   *          <P ALIGN="CENTER">ISO-8859-2
   *      </TD>
   *      <TD WIDTH="12%">
   *          <P ALIGN="CENTER">MIME
   *      </TD>
   *      <TD WIDTH="31%">
   *          <P ALIGN="CENTER">ISO-8859-2
   *      </TD>
   *  </TR>
   *  <TR>
   *      <TD WIDTH="33%">ISO Latin 3</TD>
   *      <TD WIDTH="15%">
   *          <P ALIGN="CENTER">ISO-8859-3
   *      </TD>
   *      <TD WIDTH="12%">
   *          <P ALIGN="CENTER">MIME
   *      </TD>
   *      <TD WIDTH="31%">
   *          <P ALIGN="CENTER">ISO-8859-3
   *      </TD>
   *  </TR>
   *  <TR>
   *      <TD WIDTH="33%">ISO Latin 4</TD>
   *      <TD WIDTH="15%">
   *          <P ALIGN="CENTER">ISO-8859-4
   *      </TD>
   *      <TD WIDTH="12%">
   *          <P ALIGN="CENTER">MIME
   *      </TD>
   *      <TD WIDTH="31%">
   *          <P ALIGN="CENTER">ISO-8859-4
   *      </TD>
   *  </TR>
   *  <TR>
   *      <TD WIDTH="33%">ISO Latin Cyrillic</TD>
   *      <TD WIDTH="15%">
   *          <P ALIGN="CENTER">ISO-8859-5
   *      </TD>
   *      <TD WIDTH="12%">
   *          <P ALIGN="CENTER">MIME
   *      </TD>
   *      <TD WIDTH="31%">
   *          <P ALIGN="CENTER">ISO-8859-5
   *      </TD>
   *  </TR>
   *  <TR>
   *      <TD WIDTH="33%">ISO Latin Arabic</TD>
   *      <TD WIDTH="15%">
   *          <P ALIGN="CENTER">ISO-8859-6
   *      </TD>
   *      <TD WIDTH="12%">
   *          <P ALIGN="CENTER">MIME
   *      </TD>
   *      <TD WIDTH="31%">
   *          <P ALIGN="CENTER">ISO-8859-6
   *      </TD>
   *  </TR>
   *  <TR>
   *      <TD WIDTH="33%">ISO Latin Greek</TD>
   *      <TD WIDTH="15%">
   *          <P ALIGN="CENTER">ISO-8859-7
   *      </TD>
   *      <TD WIDTH="12%">
   *          <P ALIGN="CENTER">MIME
   *      </TD>
   *      <TD WIDTH="31%">
   *          <P ALIGN="CENTER">ISO-8859-7
   *      </TD>
   *  </TR>
   *  <TR>
   *      <TD WIDTH="33%">ISO Latin Hebrew</TD>
   *      <TD WIDTH="15%">
   *          <P ALIGN="CENTER">ISO-8859-8
   *      </TD>
   *      <TD WIDTH="12%">
   *          <P ALIGN="CENTER">MIME
   *      </TD>
   *      <TD WIDTH="31%">
   *          <P ALIGN="CENTER">ISO-8859-8
   *      </TD>
   *  </TR>
   *  <TR>
   *      <TD WIDTH="33%">ISO Latin 5</TD>
   *      <TD WIDTH="15%">
   *          <P ALIGN="CENTER">ISO-8859-9
   *      </TD>
   *      <TD WIDTH="12%">
   *          <P ALIGN="CENTER">MIME
   *      </TD>
   *      <TD WIDTH="31%">
   *          <P ALIGN="CENTER">ISO-8859-9
   *      </TD>
   *  </TR>
   *  <TR>
   *      <TD WIDTH="33%">EBCDIC: US</TD>
   *      <TD WIDTH="15%">
   *          <P ALIGN="CENTER">ebcdic-cp-us
   *      </TD>
   *      <TD WIDTH="12%">
   *          <P ALIGN="CENTER">IANA
   *      </TD>
   *      <TD WIDTH="31%">
   *          <P ALIGN="CENTER">cp037
   *      </TD>
   *  </TR>
   *  <TR>
   *      <TD WIDTH="33%">EBCDIC: Canada</TD>
   *      <TD WIDTH="15%">
   *          <P ALIGN="CENTER">ebcdic-cp-ca
   *      </TD>
   *      <TD WIDTH="12%">
   *          <P ALIGN="CENTER">IANA
   *      </TD>
   *      <TD WIDTH="31%">
   *          <P ALIGN="CENTER">cp037
   *      </TD>
   *  </TR>
   *  <TR>
   *      <TD WIDTH="33%">EBCDIC: Netherlands</TD>
   *      <TD WIDTH="15%">
   *          <P ALIGN="CENTER">ebcdic-cp-nl
   *      </TD>
   *      <TD WIDTH="12%">
   *          <P ALIGN="CENTER">IANA
   *      </TD>
   *      <TD WIDTH="31%">
   *          <P ALIGN="CENTER">cp037
   *      </TD>
   *  </TR>
   *  <TR>
   *      <TD WIDTH="33%">EBCDIC: Denmark</TD>
   *      <TD WIDTH="15%">
   *          <P ALIGN="CENTER">ebcdic-cp-dk
   *      </TD>
   *      <TD WIDTH="12%">
   *          <P ALIGN="CENTER">IANA
   *      </TD>
   *      <TD WIDTH="31%">
   *          <P ALIGN="CENTER">cp277
   *      </TD>
   *  </TR>
   *  <TR>
   *      <TD WIDTH="33%">EBCDIC: Norway</TD>
   *      <TD WIDTH="15%">
   *          <P ALIGN="CENTER">ebcdic-cp-no
   *      </TD>
   *      <TD WIDTH="12%">
   *          <P ALIGN="CENTER">IANA
   *      </TD>
   *      <TD WIDTH="31%">
   *          <P ALIGN="CENTER">cp277
   *      </TD>
   *  </TR>
   *  <TR>
   *      <TD WIDTH="33%">EBCDIC: Finland</TD>
   *      <TD WIDTH="15%">
   *          <P ALIGN="CENTER">ebcdic-cp-fi
   *      </TD>
   *      <TD WIDTH="12%">
   *          <P ALIGN="CENTER">IANA
   *      </TD>
   *      <TD WIDTH="31%">
   *          <P ALIGN="CENTER">cp278
   *      </TD>
   *  </TR>
   *  <TR>
   *      <TD WIDTH="33%">EBCDIC: Sweden</TD>
   *      <TD WIDTH="15%">
   *          <P ALIGN="CENTER">ebcdic-cp-se
   *      </TD>
   *      <TD WIDTH="12%">
   *          <P ALIGN="CENTER">IANA
   *      </TD>
   *      <TD WIDTH="31%">
   *          <P ALIGN="CENTER">cp278
   *      </TD>
   *  </TR>
   *  <TR>
   *      <TD WIDTH="33%">EBCDIC: Italy</TD>
   *      <TD WIDTH="15%">
   *          <P ALIGN="CENTER">ebcdic-cp-it
   *      </TD>
   *      <TD WIDTH="12%">
   *          <P ALIGN="CENTER">IANA
   *      </TD>
   *      <TD WIDTH="31%">
   *          <P ALIGN="CENTER">cp280
   *      </TD>
   *  </TR>
   *  <TR>
   *      <TD WIDTH="33%">EBCDIC: Spain, Latin America</TD>
   *      <TD WIDTH="15%">
   *          <P ALIGN="CENTER">ebcdic-cp-es
   *      </TD>
   *      <TD WIDTH="12%">
   *          <P ALIGN="CENTER">IANA
   *      </TD>
   *      <TD WIDTH="31%">
   *          <P ALIGN="CENTER">cp284
   *      </TD>
   *  </TR>
   *  <TR>
   *      <TD WIDTH="33%">EBCDIC: Great Britain</TD>
   *      <TD WIDTH="15%">
   *          <P ALIGN="CENTER">ebcdic-cp-gb
   *      </TD>
   *      <TD WIDTH="12%">
   *          <P ALIGN="CENTER">IANA
   *      </TD>
   *      <TD WIDTH="31%">
   *          <P ALIGN="CENTER">cp285
   *      </TD>
   *  </TR>
   *  <TR>
   *      <TD WIDTH="33%">EBCDIC: France</TD>
   *      <TD WIDTH="15%">
   *          <P ALIGN="CENTER">ebcdic-cp-fr
   *      </TD>
   *      <TD WIDTH="12%">
   *          <P ALIGN="CENTER">IANA
   *      </TD>
   *      <TD WIDTH="31%">
   *          <P ALIGN="CENTER">cp297
   *      </TD>
   *  </TR>
   *  <TR>
   *      <TD WIDTH="33%">EBCDIC: Arabic</TD>
   *      <TD WIDTH="15%">
   *          <P ALIGN="CENTER">ebcdic-cp-ar1
   *      </TD>
   *      <TD WIDTH="12%">
   *          <P ALIGN="CENTER">IANA
   *      </TD>
   *      <TD WIDTH="31%">
   *          <P ALIGN="CENTER">cp420
   *      </TD>
   *  </TR>
   *  <TR>
   *      <TD WIDTH="33%">EBCDIC: Hebrew</TD>
   *      <TD WIDTH="15%">
   *          <P ALIGN="CENTER">ebcdic-cp-he
   *      </TD>
   *      <TD WIDTH="12%">
   *          <P ALIGN="CENTER">IANA
   *      </TD>
   *      <TD WIDTH="31%">
   *          <P ALIGN="CENTER">cp424
   *      </TD>
   *  </TR>
   *  <TR>
   *      <TD WIDTH="33%">EBCDIC: Switzerland</TD>
   *      <TD WIDTH="15%">
   *          <P ALIGN="CENTER">ebcdic-cp-ch
   *      </TD>
   *      <TD WIDTH="12%">
   *          <P ALIGN="CENTER">IANA
   *      </TD>
   *      <TD WIDTH="31%">
   *          <P ALIGN="CENTER">cp500
   *      </TD>
   *  </TR>
   *  <TR>
   *      <TD WIDTH="33%">EBCDIC: Roece</TD>
   *      <TD WIDTH="15%">
   *          <P ALIGN="CENTER">ebcdic-cp-roece
   *      </TD>
   *      <TD WIDTH="12%">
   *          <P ALIGN="CENTER">IANA
   *      </TD>
   *      <TD WIDTH="31%">
   *          <P ALIGN="CENTER">cp870
   *      </TD>
   *  </TR>
   *  <TR>
   *      <TD WIDTH="33%">EBCDIC: Yogoslavia</TD>
   *      <TD WIDTH="15%">
   *          <P ALIGN="CENTER">ebcdic-cp-yu
   *      </TD>
   *      <TD WIDTH="12%">
   *          <P ALIGN="CENTER">IANA
   *      </TD>
   *      <TD WIDTH="31%">
   *          <P ALIGN="CENTER">cp870
   *      </TD>
   *  </TR>
   *  <TR>
   *      <TD WIDTH="33%">EBCDIC: Iceland</TD>
   *      <TD WIDTH="15%">
   *          <P ALIGN="CENTER">ebcdic-cp-is
   *      </TD>
   *      <TD WIDTH="12%">
   *          <P ALIGN="CENTER">IANA
   *      </TD>
   *      <TD WIDTH="31%">
   *          <P ALIGN="CENTER">cp871
   *      </TD>
   *  </TR>
   *  <TR>
   *      <TD WIDTH="33%">EBCDIC: Urdu</TD>
   *      <TD WIDTH="15%">
   *          <P ALIGN="CENTER">ebcdic-cp-ar2
   *      </TD>
   *      <TD WIDTH="12%">
   *          <P ALIGN="CENTER">IANA
   *      </TD>
   *      <TD WIDTH="31%">
   *          <P ALIGN="CENTER">cp918
   *      </TD>
   *  </TR>
   *  <TR>
   *      <TD WIDTH="33%">Chinese for PRC, mixed 1/2 byte</TD>
   *      <TD WIDTH="15%">
   *          <P ALIGN="CENTER">gb2312
   *      </TD>
   *      <TD WIDTH="12%">
   *          <P ALIGN="CENTER">MIME
   *      </TD>
   *      <TD WIDTH="31%">
   *          <P ALIGN="CENTER">GB2312
   *      </TD>
   *  </TR>
   *  <TR>
   *      <TD WIDTH="33%">Extended Unix Code, packed for Japanese</TD>
   *      <TD WIDTH="15%">
   *          <P ALIGN="CENTER">euc-jp
   *      </TD>
   *      <TD WIDTH="12%">
   *          <P ALIGN="CENTER">MIME
   *      </TD>
   *      <TD WIDTH="31%">
   *          <P ALIGN="CENTER">eucjis
   *      </TD>
   *  </TR>
   *  <TR>
   *      <TD WIDTH="33%">Japanese: iso-2022-jp</TD>
   *      <TD WIDTH="15%">
   *          <P ALIGN="CENTER">iso-2020-jp
   *      </TD>
   *      <TD WIDTH="12%">
   *          <P ALIGN="CENTER">MIME
   *      </TD>
   *      <TD WIDTH="31%">
   *          <P ALIGN="CENTER">JIS
   *      </TD>
   *  </TR>
   *  <TR>
   *      <TD WIDTH="33%">Japanese: Shift JIS</TD>
   *      <TD WIDTH="15%">
   *          <P ALIGN="CENTER">Shift_JIS
   *      </TD>
   *      <TD WIDTH="12%">
   *          <P ALIGN="CENTER">MIME
   *      </TD>
   *      <TD WIDTH="31%">
   *          <P ALIGN="CENTER">SJIS
   *      </TD>
   *  </TR>
   *  <TR>
   *      <TD WIDTH="33%">Chinese: Big5</TD>
   *      <TD WIDTH="15%">
   *          <P ALIGN="CENTER">Big5
   *      </TD>
   *      <TD WIDTH="12%">
   *          <P ALIGN="CENTER">MIME
   *      </TD>
   *      <TD WIDTH="31%">
   *          <P ALIGN="CENTER">Big5
   *      </TD>
   *  </TR>
   *  <TR>
   *      <TD WIDTH="33%">Extended Unix Code, packed for Korean</TD>
   *      <TD WIDTH="15%">
   *          <P ALIGN="CENTER">euc-kr
   *      </TD>
   *      <TD WIDTH="12%">
   *          <P ALIGN="CENTER">MIME
   *      </TD>
   *      <TD WIDTH="31%">
   *          <P ALIGN="CENTER">iso2022kr
   *      </TD>
   *  </TR>
   *  <TR>
   *      <TD WIDTH="33%">Cyrillic</TD>
   *      <TD WIDTH="15%">
   *          <P ALIGN="CENTER">koi8-r
   *      </TD>
   *      <TD WIDTH="12%">
   *          <P ALIGN="CENTER">MIME
   *      </TD>
   *      <TD WIDTH="31%">
   *          <P ALIGN="CENTER">koi8-r
   *      </TD>
   *  </TR>
   * </TABLE>
   * 
   * @version
   * @author TAMURA Kent &lt;kent@trl.ibm.co.jp&gt;
   */
  public class MIME2Java {
      
      static private Hashtable s_enchash;
      static private Hashtable s_revhash;
      
      static {
          s_enchash = new Hashtable();
          //    <preferred MIME name>, <Java encoding name>
          s_enchash.put("UTF-8", "UTF8");
          s_enchash.put("US-ASCII",        "8859_1");    // ?
          s_enchash.put("ISO-8859-1",      "8859_1");
          s_enchash.put("ISO-8859-2",      "8859_2");
          s_enchash.put("ISO-8859-3",      "8859_3");
          s_enchash.put("ISO-8859-4",      "8859_4");
          s_enchash.put("ISO-8859-5",      "8859_5");
          s_enchash.put("ISO-8859-6",      "8859_6");
          s_enchash.put("ISO-8859-7",      "8859_7");
          s_enchash.put("ISO-8859-8",      "8859_8");
          s_enchash.put("ISO-8859-9",      "8859_9");
          s_enchash.put("ISO-2022-JP",     "JIS");
          s_enchash.put("SHIFT_JIS",       "SJIS");
          s_enchash.put("EUC-JP",          "EUCJIS");
          s_enchash.put("GB2312",          "GB2312");
          s_enchash.put("BIG5",            "Big5");
          s_enchash.put("EUC-KR",          "KSC5601");
          s_enchash.put("ISO-2022-KR",     "ISO2022KR");
          s_enchash.put("KOI8-R",          "KOI8_R");
  
          s_enchash.put("EBCDIC-CP-US",    "CP037");
          s_enchash.put("EBCDIC-CP-CA",    "CP037");
          s_enchash.put("EBCDIC-CP-NL",    "CP037");
          s_enchash.put("EBCDIC-CP-DK",    "CP277");
          s_enchash.put("EBCDIC-CP-NO",    "CP277");
          s_enchash.put("EBCDIC-CP-FI",    "CP278");
          s_enchash.put("EBCDIC-CP-SE",    "CP278");
          s_enchash.put("EBCDIC-CP-IT",    "CP280");
          s_enchash.put("EBCDIC-CP-ES",    "CP284");
          s_enchash.put("EBCDIC-CP-GB",    "CP285");
          s_enchash.put("EBCDIC-CP-FR",    "CP297");
          s_enchash.put("EBCDIC-CP-AR1",   "CP420");
          s_enchash.put("EBCDIC-CP-HE",    "CP424");
          s_enchash.put("EBCDIC-CP-CH",    "CP500");
          s_enchash.put("EBCDIC-CP-ROECE", "CP870");
          s_enchash.put("EBCDIC-CP-YU",    "CP870");
          s_enchash.put("EBCDIC-CP-IS",    "CP871");
          s_enchash.put("EBCDIC-CP-AR2",   "CP918");
  
                                                  // j:CNS11643 -> EUC-TW?
                                                  // ISO-2022-CN? ISO-2022-CN-EXT?
                                                  
          s_revhash = new Hashtable();
          //    <Java encoding name>, <preferred MIME name>
          s_revhash.put("UTF8", "UTF-8");
          //s_revhash.put("8859_1", "US-ASCII");    // ?
          s_revhash.put("8859_1", "ISO-8859-1");
          s_revhash.put("8859_2", "ISO-8859-2");
          s_revhash.put("8859_3", "ISO-8859-3");
          s_revhash.put("8859_4", "ISO-8859-4");
          s_revhash.put("8859_5", "ISO-8859-5");
          s_revhash.put("8859_6", "ISO-8859-6");
          s_revhash.put("8859_7", "ISO-8859-7");
          s_revhash.put("8859_8", "ISO-8859-8");
          s_revhash.put("8859_9", "ISO-8859-9");
          s_revhash.put("JIS", "ISO-2022-JP");
          s_revhash.put("SJIS", "Shift_JIS");
          s_revhash.put("EUCJIS", "EUC-JP");
          s_revhash.put("GB2312", "GB2312");
          s_revhash.put("BIG5", "Big5");
          s_revhash.put("KSC5601", "EUC-KR");
          s_revhash.put("ISO2022KR", "ISO-2022-KR");
          s_revhash.put("KOI8_R", "KOI8-R");
  
          s_revhash.put("CP037", "EBCDIC-CP-US");
          s_revhash.put("CP037", "EBCDIC-CP-CA");
          s_revhash.put("CP037", "EBCDIC-CP-NL");
          s_revhash.put("CP277", "EBCDIC-CP-DK");
          s_revhash.put("CP277", "EBCDIC-CP-NO");
          s_revhash.put("CP278", "EBCDIC-CP-FI");
          s_revhash.put("CP278", "EBCDIC-CP-SE");
          s_revhash.put("CP280", "EBCDIC-CP-IT");
          s_revhash.put("CP284", "EBCDIC-CP-ES");
          s_revhash.put("CP285", "EBCDIC-CP-GB");
          s_revhash.put("CP297", "EBCDIC-CP-FR");
          s_revhash.put("CP420", "EBCDIC-CP-AR1");
          s_revhash.put("CP424", "EBCDIC-CP-HE");
          s_revhash.put("CP500", "EBCDIC-CP-CH");
          s_revhash.put("CP870", "EBCDIC-CP-ROECE");
          s_revhash.put("CP870", "EBCDIC-CP-YU");
          s_revhash.put("CP871", "EBCDIC-CP-IS");
          s_revhash.put("CP918", "EBCDIC-CP-AR2");
      }
  
      private MIME2Java() {
      }
  
      /**
       * Convert a MIME charset name, also known as an XML encoding name, to a Java encoding name.
       * @param   mimeCharsetName Case insensitive MIME charset name: <code>UTF-8, US-ASCII, ISO-8859-1,
       *                          ISO-8859-2, ISO-8859-3, ISO-8859-4, ISO-8859-5, ISO-8859-6,
       *                          ISO-8859-7, ISO-8859-8, ISO-8859-9, ISO-2022-JP, Shift_JIS, 
       *                          EUC-JP, GB2312, Big5, EUC-KR, ISO-2022-KR, KOI8-R,
       *                          EBCDIC-CP-US, EBCDIC-CP-CA, EBCDIC-CP-NL, EBCDIC-CP-DK,
       *                          EBCDIC-CP-NO, EBCDIC-CP-FI, EBCDIC-CP-SE, EBCDIC-CP-IT,
       *                          EBCDIC-CP-ES, EBCDIC-CP-GB, EBCDIC-CP-FR, EBCDIC-CP-AR1,
       *                          EBCDIC-CP-HE, EBCDIC-CP-CH, EBCDIC-CP-ROECE, EBCDIC-CP-YU,
       *                          EBCDIC-CP-IS and EBCDIC-CP-AR2</code>.
       * @return                  Java encoding name, or <var>null</var> if <var>mimeCharsetName</var>
       *                          is unknown.
       * @see #reverse
       */
      public static String convert(String mimeCharsetName) {
          return (String)s_enchash.get(mimeCharsetName.toUpperCase());
      }
  
      /**
       * Convert a Java encoding name to MIME charset name.
       * Available values of <i>encoding</i> are "UTF8", "8859_1", "8859_2", "8859_3", "8859_4",
       * "8859_5", "8859_6", "8859_7", "8859_8", "8859_9", "JIS", "SJIS", "EUCJIS",
       * "GB2312", "BIG5", "KSC5601", "ISO2022KR",  "KOI8_R", "CP037", "CP277", "CP278",
       * "CP280", "CP284", "CP285", "CP297", "CP420", "CP424", "CP500", "CP870", "CP871" and "CP918".
       * @param   encoding    Case insensitive Java encoding name: <code>UTF8, 8859_1, 8859_2, 8859_3,
       *                      8859_4, 8859_5, 8859_6, 8859_7, 8859_8, 8859_9, JIS, SJIS, EUCJIS,
       *                      GB2312, BIG5, KSC5601, ISO2022KR, KOI8_R, CP037, CP277, CP278,
       *                      CP280, CP284, CP285, CP297, CP420, CP424, CP500, CP870, CP871 
       *                      and CP918</code>.
       * @return              MIME charset name, or <var>null</var> if <var>encoding</var> is unknown.
       * @see #convert
       */
      public static String reverse(String encoding) {
          return (String)s_revhash.get(encoding.toUpperCase());
      }
  }
  
  
  
  1.1                  jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/Queue.java
  
  Index: Queue.java
  ===================================================================
  /*
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */ 
  package org.apache.catalina.util;
  
  import java.util.Vector;
  
  /**
   * A simple FIFO queue class which causes the calling thread to wait
   * if the queue is empty and notifies threads that are waiting when it
   * is not empty.
   *
   * @author Anil V (akv@eng.sun.com)
   */
  public class Queue {
      private Vector vector = new Vector();
  
      /** 
       * Put the object into the queue.
       * 
       * @param	object		the object to be appended to the
       * 				queue. 
       */
      public synchronized void put(Object object) {
  	vector.addElement(object);
  	notify();
      }
      
      /**
       * Pull the first object out of the queue. Wait if the queue is
       * empty.
       */
      public synchronized Object pull() {
  	while (isEmpty())
  	    try {
  		wait();
  	    } catch (InterruptedException ex) {
  	    }
  	return get();
      }
  
      /**
       * Get the first object out of the queue. Return null if the queue
       * is empty. 
       */
      public synchronized Object get() {
  	Object object = peek();
  	if (object != null)
  	    vector.removeElementAt(0);
  	return object;
      }
  
      /**
       * Peek to see if something is available.
       */
      public Object peek() {
  	if (isEmpty())
  	    return null;
  	return vector.elementAt(0);
      }
      
      /**
       * Is the queue empty?
       */
      public boolean isEmpty() {
  	return vector.isEmpty();
      }
  
      /**
       * How many elements are there in this queue?
       */
      public int size() {
  	return vector.size();
      }
  }
  
  
  
  1.1                  jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/RequestUtil.java
  
  Index: RequestUtil.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/RequestUtil.java,v 1.1 2000/08/11 17:01:50 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2000/08/11 17:01:50 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  
  package org.apache.catalina.util;
  
  
  import java.text.SimpleDateFormat;
  import java.util.Date;
  import java.util.StringTokenizer;
  import java.util.TimeZone;
  import java.util.Vector;
  import javax.servlet.http.Cookie;
  
  
  /**
   * General purpose request parsing and encoding utility methods.
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2000/08/11 17:01:50 $
   */
  
  public final class RequestUtil {
  
  
      /**
       * The DateFormat to use for generating readable dates in cookies.
       */
      private static SimpleDateFormat format =
          new SimpleDateFormat(" EEEE, dd-MMM-yy kk:mm:ss zz");
  
      static {
          format.setTimeZone(TimeZone.getTimeZone("GMT"));
      }
  
  
      /**
       * Encode a cookie as per RFC 2109.  The resulting string can be used
       * as the value for a <code>Set-Cookie</code> header.
       *
       * @param cookie The cookie to encode.
       * @return A string following RFC 2109.
       */
      public static String encodeCookie(Cookie cookie) {
  
          StringBuffer buf = new StringBuffer( cookie.getName() );
          buf.append("=");
          buf.append(cookie.getValue());
  
  	if (cookie.getComment() != null) {
  	    buf.append("; Comment=\"");
  	    buf.append(cookie.getComment());
  	    buf.append("\"");
  	}
  
          if (cookie.getDomain() != null) {
              buf.append("; Domain=\"");
              buf.append(cookie.getDomain());
  	    buf.append("\"");
          }
  
          long age = cookie.getMaxAge();
  	if (cookie.getMaxAge() >= 0) {
  	    buf.append("; Max-Age=\"");
  	    buf.append(cookie.getMaxAge());
  	    buf.append("\"");
  	}
  
          if (cookie.getPath() != null) {
              buf.append("; Path=\"");
              buf.append(cookie.getPath());
  	    buf.append("\"");
          }
  
          if (cookie.getSecure()) {
              buf.append("; Secure");
          }
  
  	if (cookie.getVersion() > 0) {
  	    buf.append("; Version=\"");
  	    buf.append(cookie.getVersion());
  	    buf.append("\"");
  	}
  
          return (buf.toString());
      }
  
  
      /**
       * Parse the character encoding from the specified content type header.
       * If the content type is null, or there is no explicit character encoding,
       * <code>null</code> is returned.
       *
       * @param contentType a content type header
       */
      public static String parseCharacterEncoding(String contentType) {
  
  	if (contentType == null)
  	    return (null);
  	int start = contentType.indexOf("charset=");
  	if (start < 0)
  	    return (null);
  	String encoding = contentType.substring(start + 8);
  	int end = encoding.indexOf(";");
  	if (end >= 0)
  	    encoding = encoding.substring(0, end);
  	return (encoding.trim());
  
      }
  
  
      /**
       * Parse a cookie header into an array of cookies according to RFC 2109.
       *
       * @param header Value of an HTTP "Cookie" header
       */
      public static Cookie[] parseCookieHeader(String header) {
  
  	if ((header == null) || (header.length() < 1))
  	    return (new Cookie[0]);
  
  	Vector cookieJar = new Vector();
  	StringTokenizer tokens = new StringTokenizer(header, ";");
  	while (tokens.hasMoreTokens()) {
  	    try {
  		String token = tokens.nextToken();
  		int equals = token.indexOf("=");
  		if (equals > 0) {
  		    String name = URLDecode(token.substring(0, equals).trim());
  		    String value = URLDecode(token.substring(equals+1).trim());
  		    cookieJar.addElement(new Cookie(name, value));
  		}
  	    } catch (Throwable e) {
  		;
  	    }
  	}
  
  	Cookie[] cookies = new Cookie[cookieJar.size()];
  	cookieJar.copyInto(cookies);
  	return (cookies);
  
      }
  
  
      /**
       * Decode and return the specified URL-encoded String.
       *
       * @param str The url-encoded string
       *
       * @exception IllegalArgumentException if a '%' character is not followed
       * by a valid 2-digit hexadecimal number
       */
      public static String URLDecode(String str)
  	throws IllegalArgumentException {
  
  	if (str == null)
  	    return (null);
  
  	StringBuffer dec = new StringBuffer();
  	int pos = 0;
  	int len = str.length();
  	dec.ensureCapacity(str.length());
  
  	while (pos < len) {
  	    int lookahead;	// Look-ahead position
  
  	    // Look ahead to the next URLencoded metacharacter, if any
  	    for (lookahead = pos; lookahead < len; lookahead++) {
  		char ch = str.charAt(lookahead);
  		if ((ch == '+') || (ch == '%'))
  		    break;
  	    }
  
  	    // If there were non-metacharacters, copy them as a block
  	    if (lookahead > pos) {
  		dec.append(str.substring(pos, lookahead));
  		pos = lookahead;
  	    }
  
  	    // Shortcut out if we are at the end of the string
  	    if (pos >= len)
  		break;
  
  	    // Process the next metacharacter
  	    char meta = str.charAt(pos);
  	    if (meta == '+') {
  		dec.append(' ');
  		pos++;
  	    } else if (meta == '%') {
  		try {
  		    dec.append((char) Integer.parseInt
  			       (str.substring(pos+1, pos+3), 16));
  		} catch (NumberFormatException e) {
  		    throw new IllegalArgumentException
  			("Invalid hexadecimal '" + str.substring(pos+1, pos+3)
  			 + " in URLencoded string");
  		} catch (StringIndexOutOfBoundsException e) {
  		    throw new IllegalArgumentException
  			("Invalid unescaped '%' in URLcoded string");
  		}
  		pos += 3;
  	    }
  	}
  	return (dec.toString());
  
      }
  
  }
  
  
  
  1.1                  jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/SimplePool.java
  
  Index: SimplePool.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/SimplePool.java,v 1.1 2000/08/11 17:01:51 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2000/08/11 17:01:51 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  
  package org.apache.catalina.util;
  
  import java.util.zip.*;
  import java.net.*;
  import java.util.*;
  import java.io.*;
  
  /**
   * Simple object pool. Based on ThreadPool and few other classes
   *
   * The pool will ignore overflow and return null if empty.
   *
   * @author Gal Shachor
   * @author Costin
   */
  public final class SimplePool  {
      /*
       * Where the threads are held.
       */
      private Object pool[];
  
      private int max;
      private int minSpare;
      private int maxSpare;
  
      private int current=-1;
  
      Object lock;
      
      public SimplePool(int max) {
  	this.max=max;
  	pool=new Object[max];
  	lock=new Object();
      }
  
      /**
       * Add the object to the pool, silent nothing if the pool is full
       */
      public  void put(Object o) {
  	int idx=-1;
  	synchronized( lock ) {
  	    if( current < max )
  		idx=++current;
  	}
  	if( idx > 0 ) 
  	    pool[idx]=o;
      }
  
      /**
       * Get an object from the pool, null if the pool is empty.
       */
      public  Object get() {
  	int idx=-1;
  	synchronized( lock ) {
  	    if( current >= 0 )
  		idx=current--;
  	}
  	if( idx >= 0  ) 
  	    return pool[idx];
  	return null;
      }
  
      /** Return the size of the pool
       */
      public int getMax() {
  	return max;
      }
  }
  
  
  
  1.1                  jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/StringManager.java
  
  Index: StringManager.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/StringManager.java,v 1.1 2000/08/11 17:01:51 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2000/08/11 17:01:51 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  
  package org.apache.catalina.util;
  
  import java.text.MessageFormat;
  import java.util.Hashtable;
  import java.util.Locale;
  import java.util.MissingResourceException;
  import java.util.ResourceBundle;
  
  /**
   * An internationalization / localization helper class which reduces
   * the bother of handling ResourceBundles and takes care of the
   * common cases of message formating which otherwise require the
   * creation of Object arrays and such.
   *
   * <p>The StringManager operates on a package basis. One StringManager
   * per package can be created and accessed via the getManager method
   * call.
   *
   * <p>The StringManager will look for a ResourceBundle named by
   * the package name given plus the suffix of "LocalStrings". In
   * practice, this means that the localized information will be contained
   * in a LocalStrings.properties file located in the package
   * directory of the classpath.
   *
   * <p>Please see the documentation for java.util.ResourceBundle for
   * more information.
   *
   * @author James Duncan Davidson [duncan@eng.sun.com]
   * @author James Todd [gonzo@eng.sun.com]
   */
  
  public class StringManager {
  
      /**
       * The ResourceBundle for this StringManager.
       */
      
      private ResourceBundle bundle;
  
      /**
       * Creates a new StringManager for a given package. This is a
       * private method and all access to it is arbitrated by the
       * static getManager method call so that only one StringManager
       * per package will be created.
       *
       * @param packageName Name of package to create StringManager for.
       */
  
      private StringManager(String packageName) {
  	String bundleName = packageName + ".LocalStrings";
  	bundle = ResourceBundle.getBundle(bundleName);
      }
  
      /**
       * Get a string from the underlying resource bundle.
       *
       * @param key 
       */
      
      public String getString(String key) {
          if (key == null) {
              String msg = "key is null";
  
              throw new NullPointerException(msg);
          }
  
          String str = null;
  
          try {
  	    str = bundle.getString(key);
          } catch (MissingResourceException mre) {
              str = "Cannot find message associated with key '" + key + "'";
          }
  
          return str;
      }
  
      /**
       * Get a string from the underlying resource bundle and format
       * it with the given set of arguments.
       *
       * @param key
       * @param args
       */
  
      public String getString(String key, Object[] args) {
  	String iString = null;
          String value = getString(key);
  
  	// this check for the runtime exception is some pre 1.1.6
  	// VM's don't do an automatic toString() on the passed in
  	// objects and barf out
  	
  	try {
              // ensure the arguments are not null so pre 1.2 VM's don't barf
              Object nonNullArgs[] = args;
              for (int i=0; i<args.length; i++) {
  		if (args[i] == null) {
  		    if (nonNullArgs==args) nonNullArgs=(Object[])args.clone();
  		    nonNullArgs[i] = "null";
  		}
  	    }
   
              iString = MessageFormat.format(value, nonNullArgs);
  	} catch (IllegalArgumentException iae) {
  	    StringBuffer buf = new StringBuffer();
  	    buf.append(value);
  	    for (int i = 0; i < args.length; i++) {
  		buf.append(" arg[" + i + "]=" + args[i]);
  	    }
  	    iString = buf.toString();
  	}
  	return iString;
      }
  
      /**
       * Get a string from the underlying resource bundle and format it
       * with the given object argument. This argument can of course be
       * a String object.
       *
       * @param key
       * @param arg
       */
  
      public String getString(String key, Object arg) {
  	Object[] args = new Object[] {arg};
  	return getString(key, args);
      }
  
      /**
       * Get a string from the underlying resource bundle and format it
       * with the given object arguments. These arguments can of course
       * be String objects.
       *
       * @param key
       * @param arg1
       * @param arg2
       */
  
      public String getString(String key, Object arg1, Object arg2) {
  	Object[] args = new Object[] {arg1, arg2};
  	return getString(key, args);
      }
      
      /**
       * Get a string from the underlying resource bundle and format it
       * with the given object arguments. These arguments can of course
       * be String objects.
       *
       * @param key
       * @param arg1
       * @param arg2
       * @param arg3
       */
  
      public String getString(String key, Object arg1, Object arg2,
  			    Object arg3) {
  	Object[] args = new Object[] {arg1, arg2, arg3};
  	return getString(key, args);
      }
      
      /**
       * Get a string from the underlying resource bundle and format it
       * with the given object arguments. These arguments can of course
       * be String objects.
       *
       * @param key
       * @param arg1
       * @param arg2
       * @param arg3
       * @param arg4
       */
  
      public String getString(String key, Object arg1, Object arg2,
  			    Object arg3, Object arg4) {
  	Object[] args = new Object[] {arg1, arg2, arg3, arg4};
  	return getString(key, args);
      }   
      // --------------------------------------------------------------
      // STATIC SUPPORT METHODS
      // --------------------------------------------------------------
  
      private static Hashtable managers = new Hashtable();
  
      /**
       * Get the StringManager for a particular package. If a manager for
       * a package already exists, it will be reused, else a new
       * StringManager will be created and returned.
       *
       * @param packageName
       */
  
      public synchronized static StringManager getManager(String packageName) {
  	StringManager mgr = (StringManager)managers.get(packageName);
  	if (mgr == null) {
  	    mgr = new StringManager(packageName);
  	    managers.put(packageName, mgr);
  	}
  	return mgr;
      }
  }
  
  
  
  1.1                  jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/StringParser.java
  
  Index: StringParser.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/StringParser.java,v 1.1 2000/08/11 17:01:51 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2000/08/11 17:01:51 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  
  package org.apache.catalina.util;
  
  
  /**
   * Utility class for string parsing that is higher performance than
   * StringParser for simple delimited text cases.  Parsing is performed
   * by setting the string, and then using the <code>findXxxx()</code> and
   * <code>skipXxxx()</code> families of methods to remember significant
   * offsets.  To retrieve the parsed substrings, call the <code>extract()</code>
   * method with the appropriate saved offset values.
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2000/08/11 17:01:51 $
   */
  
  public final class StringParser {
  
  
      // ----------------------------------------------------------- Constructors
  
  
      /**
       * Construct a string parser with no preset string to be parsed.
       */
      public StringParser() {
  
  	this(null);
  
      }
  
  
      /**
       * Construct a string parser that is initialized to parse the specified
       * string.
       *
       * @param string The string to be parsed
       */
      public StringParser(String string) {
  
  	super();
  	setString(string);
  
      }
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      /**
       * The characters of the current string, as a character array.  Stored
       * when the string is first specified to speed up access to characters
       * being compared during parsing.
       */
      private char chars[] = null;
  
  
      /**
       * The zero-relative index of the current point at which we are
       * positioned within the string being parsed.  <strong>NOTE</strong>:
       * the value of this index can be one larger than the index of the last
       * character of the string (i.e. equal to the string length) if you
       * parse off the end of the string.  This value is useful for extracting
       * substrings that include the end of the string.
       */
      private int index = 0;
  
  
      /**
       * The length of the String we are currently parsing.  Stored when the
       * string is first specified to avoid repeated recalculations.
       */
      private int length = 0;
  
  
      /**
       * The String we are currently parsing.
       */
      private String string = null;
  
  
      // ------------------------------------------------------------- Properties
  
  
      /**
       * Return the zero-relative index of our current parsing position
       * within the string being parsed.
       */
      public int getIndex() {
  
  	return (this.index);
  
      }
  
  
      /**
       * Return the length of the string we are parsing.
       */
      public int getLength() {
  
  	return (this.length);
  
      }
  
  
      /**
       * Return the String we are currently parsing.
       */
      public String getString() {
  
  	return (this.string);
  
      }
  
  
      /**
       * Set the String we are currently parsing.  The parser state is also reset
       * to begin at the start of this string.
       *
       * @param string The string to be parsed.
       */
      public void setString(String string) {
  
  	this.string = string;
  	if (string != null) {
  	    this.length = string.length();
  	    chars = this.string.toCharArray();
  	} else {
  	    this.length = 0;
  	    chars = new char[0];
  	}
  	reset();
  
      }
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Advance the current parsing position by one, if we are not already
       * past the end of the string.
       */
      public void advance() {
  
  	if (index < length)
  	    index++;
  
      }
  
  
      /**
       * Extract and return a substring that starts at the specified position,
       * and extends to the end of the string being parsed.  If this is not
       * possible, a zero-length string is returned.
       *
       * @param start Starting index, zero relative, inclusive
       */
      public String extract(int start) {
  
  	if ((start < 0) || (start >= length))
  	    return ("");
  	else
  	    return (string.substring(start));
  
      }
  
  
      /**
       * Extract and return a substring that starts at the specified position,
       * and ends at the character before the specified position.  If this is
       * not possible, a zero-length string is returned.
       *
       * @param start Starting index, zero relative, inclusive
       * @param end Ending index, zero relative, exclusive
       */
      public String extract(int start, int end) {
  
  	if ((start < 0) || (start >= end) || (end > length))
  	    return ("");
  	else
  	    return (string.substring(start, end));
  
      }
  
  
      /**
       * Return the index of the next occurrence of the specified character,
       * or the index of the character after the last position of the string
       * if no more occurrences of this character are found.  The current
       * parsing position is updated to the returned value.
       *
       * @param ch Character to be found
       */
      public int findChar(char ch) {
  
  	while ((index < length) && (ch != chars[index]))
  	    index++;
  	return (index);
  
      }
  
  
      /**
       * Return the index of the next occurrence of a non-whitespace character,
       * or the index of the character after the last position of the string
       * if no more non-whitespace characters are found.  The current
       * parsing position is updated to the returned value.
       */
      public int findText() {
  
  	while ((index < length) && isWhite(chars[index]))
  	    index++;
  	return (index);
  
      }
  
  
      /**
       * Return the index of the next occurrence of a whitespace character,
       * or the index of the character after the last position of the string
       * if no more whitespace characters are found.  The current parsing
       * position is updated to the returned value.
       */
      public int findWhite() {
  
  	while ((index < length) && !isWhite(chars[index]))
  	    index++;
  	return (index);
  
      }
  
  
      /**
       * Reset the current state of the parser to the beginning of the
       * current string being parsed.
       */
      public void reset() {
  
  	index = 0;
  
      }
  
  
      /**
       * Advance the current parsing position while it is pointing at the
       * specified character, or until it moves past the end of the string.
       * Return the final value.
       *
       * @param ch Character to be skipped
       */
      public int skipChar(char ch) {
  
  	while ((index < length) && (ch == chars[index]))
  	    index++;
  	return (index);
  
      }
  
  
      /**
       * Advance the current parsing position while it is pointing at a
       * non-whitespace character, or until it moves past the end of the string.
       * Return the final value.
       */
      public int skipText() {
  
  	while ((index < length) && !isWhite(chars[index]))
  	    index++;
  	return (index);
  
      }
  
  
      /**
       * Advance the current parsing position while it is pointing at a
       * whitespace character, or until it moves past the end of the string.
       * Return the final value.
       */
      public int skipWhite() {
  
  	while ((index < length) && isWhite(chars[index]))
  	    index++;
  	return (index);
  
      }
  
  
      // ------------------------------------------------------ Protected Methods
  
  
      /**
       * Is the specified character considered to be whitespace?
       *
       * @param ch Character to be checked
       */
      protected boolean isWhite(char ch) {
  
  	if ((ch == ' ') || (ch == '\t') || (ch == '\r') || (ch == '\n'))
  	    return (true);
  	else
  	    return (false);
  
      }
  
  
  }
  
  
  
  1.1                  jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/XMLWriter.java
  
  Index: XMLWriter.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/XMLWriter.java,v 1.1 2000/08/11 17:01:51 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2000/08/11 17:01:51 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  package org.apache.catalina.util;
  
  /**
   * XMLWriter helper class.
   * 
   * @author Remy Maucherat
   */
  public class XMLWriter {
      
      
      // -------------------------------------------------------------- Constants
      
      
      /**
       * Opening tag.
       */
      public static final int OPENING = 0;
      
      
      /**
       * Closing tag.
       */
      public static final int CLOSING = 1;
      
      
      /**
       * Element with no content.
       */
      public static final int NO_CONTENT = 2;
      
      
      // ----------------------------------------------------- Instance Variables
      
      
      /**
       * Buffer.
       */
      protected StringBuffer buffer;
      
      
      // ----------------------------------------------------------- Constructors
      
      
      /**
       * Constructor.
       */
      public XMLWriter() {
          buffer = new StringBuffer();
      }
      
      
      // --------------------------------------------------------- Public Methods
      
      
      /**
       * Retrieve generated XML.
       * 
       * @return String containing the generated XML
       */
      public String toString() {
          return buffer.toString();
      }
      
      
      /**
       * Write property to the XML.
       * 
       * @param namespace Namespace
       * @param namespaceInfo Namespace info
       * @param name Property name
       * @param value Property value
       */
      public void writeProperty(String namespace, String namespaceInfo, 
                                String name, String value) {
          writeElement(namespace, namespaceInfo, name, OPENING);
          buffer.append(value);
          writeElement(namespace, namespaceInfo, name, CLOSING);
      }
      
      
      /**
       * Write property to the XML.
       * 
       * @param namespace Namespace
       * @param name Property name
       * @param value Property value
       */
      public void writeProperty(String namespace, String name, String value) {
          writeElement(namespace, name, OPENING);
          buffer.append(value);
          writeElement(namespace, name, CLOSING);
      }
      
      
      /**
       * Write property to the XML.
       * 
       * @param namespace Namespace
       * @param name Property name
       */
      public void writeProperty(String namespace, String name) {
          writeElement(namespace, name, NO_CONTENT);
      }
      
      
      /**
       * Write an element.
       * 
       * @param name Element name
       * @param namespace Namespace abbreviation
       * @param type Element type
       */
      public void writeElement(String namespace, String name, int type) {
          writeElement(namespace, null, name, type);
      }
      
      
      /**
       * Write an element.
       * 
       * @param namespace Namespace abbreviation
       * @param namespaceInfo Namespace info
       * @param name Element name
       * @param type Element type
       */
      public void writeElement(String namespace, String namespaceInfo, 
                               String name, int type) {
          if ((namespace != null) && (namespace.length() > 0)) {
              switch (type) {
              case OPENING:
                  if (namespaceInfo != null) {
                      buffer.append("<" + namespace + ":" + name + " xmlns:" 
                                    + namespace + "=\"" 
                                    + namespaceInfo + ":\">");
                  } else {
                      buffer.append("<" + namespace + ":" + name + ">");
                  }
                  break;
              case CLOSING:
                  buffer.append("</" + namespace + ":" + name + ">\n");
                  break;
              case NO_CONTENT:
              default:
                  if (namespaceInfo != null) {
                      buffer.append("<" + namespace + ":" + name + " xmlns:" 
                                    + namespace + "=\"" 
                                    + namespaceInfo + ":\"/>");
                  } else {
                      buffer.append("<" + namespace + ":" + name + "/>");
                  }
                  break;
              }
          } else {
              switch (type) {
              case OPENING:
                  buffer.append("<" + name + ">");
                  break;
              case CLOSING:
                  buffer.append("</" + name + ">\n");
                  break;
              case NO_CONTENT:
              default:
                  buffer.append("<" + name + "/>");
                  break;
              }
          }
      }
      
      
      /**
       * Write text.
       * 
       * @param text Text to append
       */
      public void writeText(String text) {
          buffer.append(text);
      }
      
      
      /**
       * Write XML Header.
       */
      public void writeXMLHeader() {
          buffer.append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n");
      }
      
      
  }