commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jsde...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/java/org/apache/commons/httpclient HttpStatus.java
Date Sat, 03 May 2003 05:40:31 GMT
jsdever     2003/05/02 22:40:31

  Modified:    httpclient/src/java/org/apache/commons/httpclient
                        HttpStatus.java
  Log:
  Optimization of the HttpStatus lookups.
  
  Revision  Changes    Path
  1.13      +44 -29    jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpStatus.java
  
  Index: HttpStatus.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpStatus.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- HttpStatus.java	28 Jan 2003 22:25:21 -0000	1.12
  +++ HttpStatus.java	3 May 2003 05:40:31 -0000	1.13
  @@ -65,15 +65,18 @@
   
   import java.util.Hashtable;
   
  -import org.apache.commons.logging.LogFactory;
  -import org.apache.commons.logging.Log;
   
   /**
  - * <p>Constants enumerating the HTTP status codes.</p>
  + * Constants enumerating the HTTP status codes.
  + * All status codes defined in RFC1945 (HTTP/1.0, RFC2616 (HTTP/1.1), and
  + * RFC2518 (WebDAV) are supported.
    * 
    * @see StatusLine
    * @author Unascribed
    * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
  + * @author <a href="mailto:jsdever@apache.org">Jeff Dever</a>
  + * 
  + * TODO: Internationalization of reason phrases 
    * 
    * @version $Id$
    */
  @@ -82,44 +85,56 @@
   
       // -------------------------------------------------------- Class Variables
   
  -    /** Reason phrases (as Strings), by status code (as Integer). */
  -    private static final Hashtable MAP_STATUS_CODES = new Hashtable();
  +    /** Reason phrases lookup table. */
  +    private static final String[][] ReasonPhrases = new String[][]{
  +    	new String[0],
  +    	new String[3],
  +    	new String[8],
  +    	new String[8],
  +    	new String[25],
  +    	new String[8]
  +    };
  +
   
  -    /** Log object for this class. */
  -    private static final Log LOG = LogFactory.getLog(HttpStatus.class);
   
   
       // --------------------------------------------------------- Public Methods
   
       /**
  -     * Get the "reason phrase" associated with the given
  -     * HTTP status code, or <tt>null</tt> if no
  -     * such reason phrase can be found.
  -     * @param nHttpStatusCode the numeric status code
  +     * Get the reason phrase for a particular status code.
  +     * 
  +     * This method always returns the English text as specified in the
  +     * relevent RFCs and is not internationalized.
  +     * 
  +     * @param statusCode the numeric status code
        * @return the reason phrase associated with the given status code
  +     * or null if the status code is not recognized.
  +     * 
  +     * TODO: getStatusText should be called getReasonPhrase to match RFC
        */
  -    public static String getStatusText(int nHttpStatusCode) {
  -        LOG.trace("enter HttpStatus.getStatusText(int)");
  +    public static String getStatusText(int statusCode) {
  +		
  +		int classIndex = statusCode/100;
  +		int codeIndex = statusCode-classIndex*100;
  +		if (classIndex < 1 || classIndex > ReasonPhrases.length-1 || 
  +		    codeIndex < 0 || codeIndex > ReasonPhrases[classIndex].length)
  +			return null;
  +		return ReasonPhrases[classIndex][codeIndex];
   
  -        Integer intKey = new Integer(nHttpStatusCode);
  -        if (!MAP_STATUS_CODES.containsKey(intKey)) {
  -            LOG.warn("No status text available for status code " + nHttpStatusCode);
  -            return null;
  -        } else {
  -            return (String) MAP_STATUS_CODES.get(intKey);
  -        }
  +		
       }
   
   
       // -------------------------------------------------------- Private Methods
   
       /**
  -     * Store the given reason phrase (as String), by status code (as Integer).
  -     * @param nKey The status code
  -     * @param strVal The reason phrase
  +     * Store the given reason phrase, by status code.
  +     * @param statusCode The status code to lookup
  +     * @param reasonPhrase The reason phrase for this status code
        */
  -    private static void addStatusCodeMap(int nKey, String strVal) {
  -        MAP_STATUS_CODES.put(new Integer(nKey), strVal);
  +    private static void addStatusCodeMap(int statusCode, String reasonPhrase) {
  +        int classIndex = statusCode/100;
  +        ReasonPhrases[classIndex][statusCode-classIndex*100] = reasonPhrase;
       }
   
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message