org.mortbay.http
Class HttpFields

java.lang.Object
  |
  +--org.mortbay.http.HttpFields

public class HttpFields
extends java.lang.Object

HTTP Fields. A collection of HTTP header and or Trailer fields. This class is not synchronized and needs to be protected from concurrent access. This class is not synchronized as it is expected that modifications will only be performed by a single thread.

Version:
$Id: HttpFields.java,v 1.5 2001/11/05 02:50:16 gregwilkins Exp $
Author:
Greg Wilkins (gregw)

Field Summary
static java.lang.String __Accept
          Request Fields.
static java.lang.String __AcceptCharset
          Request Fields.
static java.lang.String __AcceptEncoding
          Request Fields.
static java.lang.String __AcceptLanguage
          Request Fields.
static java.lang.String __AcceptRanges
          Response Fields.
static java.lang.String __Age
          Response Fields.
static java.lang.String __Allow
          Entity Fields.
static java.lang.String __Authorization
          Request Fields.
static java.lang.String __CacheControl
          General Fields.
static java.lang.String __Chunked
          Fields Values.
static java.lang.String __Close
           
static char[] __COLON
           
static java.lang.String __Connection
          General Fields.
static java.lang.String __ContentEncoding
          Entity Fields.
static java.lang.String __ContentLanguage
          Entity Fields.
static java.lang.String __ContentLength
          Entity Fields.
static java.lang.String __ContentLocation
          Entity Fields.
static java.lang.String __ContentMD5
          Entity Fields.
static java.lang.String __ContentRange
          Entity Fields.
static java.lang.String __ContentType
          Entity Fields.
static java.lang.String __Cookie
          Other Fields.
static char[] __CRLF
           
static java.lang.String __Date
          General Fields.
static DateCache __dateCache
           
static java.text.SimpleDateFormat[] __dateReceive
           
static java.text.SimpleDateFormat __dateSend
           
static java.lang.String __ETag
          Response Fields.
static java.lang.String __Expect
          Request Fields.
static java.lang.String __ExpectContinue
           
static java.lang.String __Expires
          Entity Fields.
static java.lang.String __Forwarded
          Request Fields.
static java.lang.String __From
          Request Fields.
static java.lang.String __Host
          Request Fields.
static java.lang.String __Identity
           
static java.lang.String __IfMatch
          Request Fields.
static java.lang.String __IfModifiedSince
          Request Fields.
static java.lang.String __IfNoneMatch
          Request Fields.
static java.lang.String __IfRange
          Request Fields.
static java.lang.String __IfUnmodifiedSince
          Request Fields.
static java.lang.String __KeepAlive
          Request Fields.
static java.lang.String __LastModified
          Entity Fields.
static java.lang.String __Location
          Response Fields.
static java.lang.String __MaxForwards
          Request Fields.
static java.lang.String __MessageHttp
           
static java.lang.String __MimeVersion
           
static java.lang.String __Pragma
          General Fields.
static java.lang.String __ProxyAuthenticate
          Response Fields.
static java.lang.String __ProxyAuthorization
          Request Fields.
static java.lang.String __Range
          Request Fields.
static java.lang.String __Referer
          Request Fields.
static java.lang.String __RequestRange
          Request Fields.
static java.lang.String __RetryAfter
          Response Fields.
static java.lang.String __separators
           
static java.lang.String __Server
          Response Fields.
static java.lang.String __ServletEngine
          Response Fields.
static java.lang.String __SetCookie
           
static java.lang.String __SetCookie2
           
static java.lang.String __TE
          Request Fields.
static java.lang.String __TextHtml
           
static java.lang.String __Trailer
          General Fields.
static java.lang.String __TransferEncoding
          General Fields.
static java.lang.String __Upgrade
          General Fields.
static java.lang.String __UserAgent
          Request Fields.
static java.lang.String __Vary
          Response Fields.
static java.lang.String __Via
          General Fields.
static java.lang.String __Warning
          General Fields.
static java.lang.String __WwwAuthenticate
          Response Fields.
static java.lang.String __WwwFormUrlEncode
           
 
Constructor Summary
HttpFields()
          Constructor.
 
Method Summary
 void add(java.lang.String name, java.lang.String value)
          Add to or set a field.
 void addDateField(java.lang.String name, java.util.Date date)
          Adds the value of a date field.
 void addSetCookie(Cookie cookie, boolean cookie2)
          Format a set cookie value
 void clear()
          Clear the header.
 boolean containsKey(java.lang.String name)
           
 void destroy()
          Destroy the header.
 java.lang.String get(java.lang.String name)
           
 long getDateField(java.lang.String name)
          Get a header as a date value.
 java.util.Enumeration getFieldNames()
          Get enumeration of header _names.
 int getIntField(java.lang.String name)
          Get a header as an integer value.
static java.lang.Float getQuality(java.lang.String value)
           
 java.util.Enumeration getValues(java.lang.String name)
          Get multi headers
 java.util.Enumeration getValues(java.lang.String name, java.lang.String separators)
          Get multi field values with separator.
 void put(java.lang.String name, java.util.List value)
          Set a multi value field.
 java.lang.String put(java.lang.String name, java.lang.String value)
          Set a field.
 void putCurrentTime(java.lang.String name)
          Set date field to the current time.
 void putDateField(java.lang.String name, java.util.Date date)
          Sets the value of a date field.
 void putDateField(java.lang.String name, long date)
          Sets the value of a date field.
 void putIntField(java.lang.String name, int value)
          Sets the value of an integer field.
static java.util.List qualityList(java.util.Enumeration enum)
          List values in quality order.
 void read(LineInput in)
          Read HttpHeaders from inputStream.
 java.lang.String remove(java.lang.String name)
          Remove a field.
 int size()
           
 java.lang.String toString()
           
static java.lang.String valueParameters(java.lang.String value, java.util.Map parameters)
          Get field value parameters.
 void write(java.io.Writer writer)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

__CacheControl

public static final java.lang.String __CacheControl
General Fields.

__Connection

public static final java.lang.String __Connection
General Fields.

__Date

public static final java.lang.String __Date
General Fields.

__Pragma

public static final java.lang.String __Pragma
General Fields.

__Trailer

public static final java.lang.String __Trailer
General Fields.

__TransferEncoding

public static final java.lang.String __TransferEncoding
General Fields.

__Upgrade

public static final java.lang.String __Upgrade
General Fields.

__Via

public static final java.lang.String __Via
General Fields.

__Warning

public static final java.lang.String __Warning
General Fields.

__Allow

public static final java.lang.String __Allow
Entity Fields.

__ContentEncoding

public static final java.lang.String __ContentEncoding
Entity Fields.

__ContentLanguage

public static final java.lang.String __ContentLanguage
Entity Fields.

__ContentLength

public static final java.lang.String __ContentLength
Entity Fields.

__ContentLocation

public static final java.lang.String __ContentLocation
Entity Fields.

__ContentMD5

public static final java.lang.String __ContentMD5
Entity Fields.

__ContentRange

public static final java.lang.String __ContentRange
Entity Fields.

__ContentType

public static final java.lang.String __ContentType
Entity Fields.

__Expires

public static final java.lang.String __Expires
Entity Fields.

__LastModified

public static final java.lang.String __LastModified
Entity Fields.

__Accept

public static final java.lang.String __Accept
Request Fields.

__AcceptCharset

public static final java.lang.String __AcceptCharset
Request Fields.

__AcceptEncoding

public static final java.lang.String __AcceptEncoding
Request Fields.

__AcceptLanguage

public static final java.lang.String __AcceptLanguage
Request Fields.

__Authorization

public static final java.lang.String __Authorization
Request Fields.

__Expect

public static final java.lang.String __Expect
Request Fields.

__Forwarded

public static final java.lang.String __Forwarded
Request Fields.

__From

public static final java.lang.String __From
Request Fields.

__Host

public static final java.lang.String __Host
Request Fields.

__IfMatch

public static final java.lang.String __IfMatch
Request Fields.

__IfModifiedSince

public static final java.lang.String __IfModifiedSince
Request Fields.

__IfNoneMatch

public static final java.lang.String __IfNoneMatch
Request Fields.

__IfRange

public static final java.lang.String __IfRange
Request Fields.

__IfUnmodifiedSince

public static final java.lang.String __IfUnmodifiedSince
Request Fields.

__KeepAlive

public static final java.lang.String __KeepAlive
Request Fields.

__MaxForwards

public static final java.lang.String __MaxForwards
Request Fields.

__ProxyAuthorization

public static final java.lang.String __ProxyAuthorization
Request Fields.

__Range

public static final java.lang.String __Range
Request Fields.

__RequestRange

public static final java.lang.String __RequestRange
Request Fields.

__Referer

public static final java.lang.String __Referer
Request Fields.

__TE

public static final java.lang.String __TE
Request Fields.

__UserAgent

public static final java.lang.String __UserAgent
Request Fields.

__AcceptRanges

public static final java.lang.String __AcceptRanges
Response Fields.

__Age

public static final java.lang.String __Age
Response Fields.

__ETag

public static final java.lang.String __ETag
Response Fields.

__Location

public static final java.lang.String __Location
Response Fields.

__ProxyAuthenticate

public static final java.lang.String __ProxyAuthenticate
Response Fields.

__RetryAfter

public static final java.lang.String __RetryAfter
Response Fields.

__Server

public static final java.lang.String __Server
Response Fields.

__ServletEngine

public static final java.lang.String __ServletEngine
Response Fields.

__Vary

public static final java.lang.String __Vary
Response Fields.

__WwwAuthenticate

public static final java.lang.String __WwwAuthenticate
Response Fields.

__Cookie

public static final java.lang.String __Cookie
Other Fields.

__SetCookie

public static final java.lang.String __SetCookie

__SetCookie2

public static final java.lang.String __SetCookie2

__MimeVersion

public static final java.lang.String __MimeVersion

__Identity

public static final java.lang.String __Identity

__Chunked

public static final java.lang.String __Chunked
Fields Values.

__Close

public static final java.lang.String __Close

__TextHtml

public static final java.lang.String __TextHtml

__MessageHttp

public static final java.lang.String __MessageHttp

__WwwFormUrlEncode

public static final java.lang.String __WwwFormUrlEncode

__ExpectContinue

public static final java.lang.String __ExpectContinue

__separators

public static final java.lang.String __separators

__CRLF

public static final char[] __CRLF

__COLON

public static final char[] __COLON

__dateCache

public static final DateCache __dateCache

__dateSend

public static final java.text.SimpleDateFormat __dateSend

__dateReceive

public static java.text.SimpleDateFormat[] __dateReceive
Constructor Detail

HttpFields

public HttpFields()
Constructor.
Method Detail

size

public int size()

getFieldNames

public java.util.Enumeration getFieldNames()
Get enumeration of header _names. Returns an enumeration of strings representing the header _names for this request.

containsKey

public boolean containsKey(java.lang.String name)

get

public java.lang.String get(java.lang.String name)
Parameters:
name - the case-insensitive field name
Returns:
the value of a field, or null if not found. For multiple fields of the same name, only the first is returned.

getValues

public java.util.Enumeration getValues(java.lang.String name)
Get multi headers
Parameters:
name - the case-insensitive field name
Returns:
Enumeration of the values, or null if no such header.

getValues

public java.util.Enumeration getValues(java.lang.String name,
                                       java.lang.String separators)
Get multi field values with separator. The multiple values can be represented as separate headers of the same name, or by a single header using the separator(s), or a combination of both. Separators may be quoted.
Parameters:
name - the case-insensitive field name
separators - String of separators.
Returns:
Enumeration of the values, or null if no such header.

put

public java.lang.String put(java.lang.String name,
                            java.lang.String value)
Set a field.
Parameters:
name - the name of the field
value - the value of the field. If null the field is cleared.

put

public void put(java.lang.String name,
                java.util.List value)
Set a multi value field. If the field is allowed to have multiple values.
Parameters:
name - the name of the field
value - the list of values of the field. If null the field is cleared.

add

public void add(java.lang.String name,
                java.lang.String value)
         throws java.lang.IllegalArgumentException
Add to or set a field. If the field is allowed to have multiple values, add will add multiple headers of the same name.
Parameters:
name - the name of the field
value - the value of the field.
Throws:
java.lang.IllegalArgumentException - If the name is a single valued field

remove

public java.lang.String remove(java.lang.String name)
Remove a field.
Parameters:
name -  

getIntField

public int getIntField(java.lang.String name)
                throws java.lang.NumberFormatException
Get a header as an integer value. Returns the value of an integer field or -1 if not found. The case of the field name is ignored.
Parameters:
name - the case-insensitive field name
Throws:
java.lang.NumberFormatException - If bad integer found

getDateField

public long getDateField(java.lang.String name)
Get a header as a date value. Returns the value of a date field, or -1 if not found. The case of the field name is ignored.
Parameters:
name - the case-insensitive field name

putIntField

public void putIntField(java.lang.String name,
                        int value)
Sets the value of an integer field.
Parameters:
name - the field name
value - the field integer value

putDateField

public void putDateField(java.lang.String name,
                         java.util.Date date)
Sets the value of a date field.
Parameters:
name - the field name
value - the field date value

addDateField

public void addDateField(java.lang.String name,
                         java.util.Date date)
Adds the value of a date field.
Parameters:
name - the field name
value - the field date value

putDateField

public void putDateField(java.lang.String name,
                         long date)
Sets the value of a date field.
Parameters:
name - the field name
value - the field date value

putCurrentTime

public void putCurrentTime(java.lang.String name)
Set date field to the current time. Sets the value of a date field to the current time. Uses efficient DateCache mechanism.
Parameters:
name - the field name

read

public void read(LineInput in)
          throws java.io.IOException
Read HttpHeaders from inputStream.

write

public void write(java.io.Writer writer)
           throws java.io.IOException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

clear

public void clear()
Clear the header. Remove all entries.

destroy

public void destroy()
Destroy the header. Help the garbage collector by null everything that we can.

valueParameters

public static java.lang.String valueParameters(java.lang.String value,
                                               java.util.Map parameters)
Get field value parameters. Some field values can have parameters. This method separates the value from the parameters and optionally populates a map with the paramters. For example:
   FieldName : Value ; param1=val1 ; param2=val2
 
Parameters:
value - The Field value, possibly with parameteres.
parameters - A map to populate with the parameters, or null
Returns:
The value.

getQuality

public static java.lang.Float getQuality(java.lang.String value)

qualityList

public static java.util.List qualityList(java.util.Enumeration enum)
List values in quality order.
Parameters:
enum - Enumeration of values with quality parameters
Returns:
values in quality order.

addSetCookie

public void addSetCookie(Cookie cookie,
                         boolean cookie2)
Format a set cookie value
Parameters:
cookie - The cookie.
cookie2 - If true, use the alternate cookie 2 header


Copyright © 2000 Mortbay Consulting Pty. Ltd. All Rights Reserved.