org.mortbay.jetty
Class HttpFields

java.lang.Object
  extended by org.mortbay.jetty.HttpFields

public class HttpFields
extends 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.

Author:
Greg Wilkins (gregw)

Nested Class Summary
static class HttpFields.Field
           
 
Field Summary
static String __01Jan1970
           
static Buffer __01Jan1970_BUFFER
           
static BufferDateCache __dateCache
           
static String __separators
           
protected  HashMap _bufferMap
           
protected  SimpleDateFormat[] _dateReceive
           
protected  ArrayList _fields
           
protected  int _revision
           
 
Constructor Summary
HttpFields()
          Constructor.
 
Method Summary
 void add(Buffer name, Buffer value)
          Add to or set a field.
 void add(HttpFields fields)
          Add fields from another HttpFields instance.
 void add(String name, String value)
          Add to or set a field.
 void addDateField(String name, long date)
          Sets the value of a date field.
 void addLongField(Buffer name, long value)
          Sets the value of an long field.
 void addLongField(String name, long value)
          Sets the value of an long field.
 void addSetCookie(Cookie cookie)
          Format a set cookie value
 void clear()
          Clear the header.
 boolean containsKey(Buffer name)
           
 boolean containsKey(String name)
           
 void destroy()
          Destroy the header.
static String formatDate(Calendar calendar, boolean cookie)
          Format HTTP date "EEE, dd MMM yyyy HH:mm:ss 'GMT'" or "EEE, dd-MMM-yy HH:mm:ss 'GMT'"for cookies
static String formatDate(long date, boolean cookie)
          Format HTTP date "EEE, dd MMM yyyy HH:mm:ss 'GMT'" or "EEE, dd-MMM-yy HH:mm:ss 'GMT'"for cookies
static void formatDate(StringBuffer buf, Calendar calendar, boolean cookie)
          Format HTTP date "EEE, dd MMM yyyy HH:mm:ss 'GMT'" or "EEE, dd-MMM-yy HH:mm:ss 'GMT'"for cookies
static String formatDate(StringBuffer buf, long date, boolean cookie)
          Format HTTP date "EEE, dd MMM yyyy HH:mm:ss 'GMT'" or "EEE, dd-MMM-yy HH:mm:ss 'GMT'"for cookies
 Buffer get(Buffer name)
           
 long getDateField(String name)
          Get a header as a date value.
 Enumeration getFieldNames()
          Get enumeration of header _names.
 Iterator getFields()
          Get enumeration of Fields Returns an enumeration of Fields for this request.
 long getLongField(Buffer name)
          Get a header as an long value.
 long getLongField(String name)
          Get a header as an long value.
static Float getQuality(String value)
           
 String getStringField(Buffer name)
           
 String getStringField(String name)
           
 Enumeration getValues(Buffer name)
          Get multi headers
 Enumeration getValues(String name)
          Get multi headers
 Enumeration getValues(String name, String separators)
          Get multi field values with separator.
 void put(Buffer buffer)
           
 void put(Buffer name, Buffer value)
          Set a field.
 void put(Buffer name, Buffer value, long numValue)
          Set a field.
 void put(Buffer name, String value)
          Set a field.
 void put(String name, List list)
          Set a field.
 void put(String name, String value)
          Set a field.
 void putDateField(Buffer name, long date)
          Sets the value of a date field.
 void putDateField(String name, long date)
          Sets the value of a date field.
 void putLongField(Buffer name, long value)
          Sets the value of an long field.
 void putLongField(String name, long value)
          Sets the value of an long field.
static List qualityList(Enumeration e)
          List values in quality order.
 void remove(Buffer name)
          Remove a field.
 void remove(String name)
          Remove a field.
 String toString()
           
static String valueParameters(String value, Map parameters)
          Get field value parameters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

__separators

public static final String __separators
See Also:
Constant Field Values

__dateCache

public static final BufferDateCache __dateCache

__01Jan1970

public static final String __01Jan1970

__01Jan1970_BUFFER

public static final Buffer __01Jan1970_BUFFER

_fields

protected ArrayList _fields

_revision

protected int _revision

_bufferMap

protected HashMap _bufferMap

_dateReceive

protected SimpleDateFormat[] _dateReceive
Constructor Detail

HttpFields

public HttpFields()
Constructor.

Method Detail

formatDate

public static String formatDate(long date,
                                boolean cookie)
Format HTTP date "EEE, dd MMM yyyy HH:mm:ss 'GMT'" or "EEE, dd-MMM-yy HH:mm:ss 'GMT'"for cookies


formatDate

public static String formatDate(Calendar calendar,
                                boolean cookie)
Format HTTP date "EEE, dd MMM yyyy HH:mm:ss 'GMT'" or "EEE, dd-MMM-yy HH:mm:ss 'GMT'"for cookies


formatDate

public static String formatDate(StringBuffer buf,
                                long date,
                                boolean cookie)
Format HTTP date "EEE, dd MMM yyyy HH:mm:ss 'GMT'" or "EEE, dd-MMM-yy HH:mm:ss 'GMT'"for cookies


formatDate

public static void formatDate(StringBuffer buf,
                              Calendar calendar,
                              boolean cookie)
Format HTTP date "EEE, dd MMM yyyy HH:mm:ss 'GMT'" or "EEE, dd-MMM-yy HH:mm:ss 'GMT'"for cookies


getFieldNames

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


getFields

public Iterator getFields()
Get enumeration of Fields Returns an enumeration of Fields for this request.


containsKey

public boolean containsKey(Buffer name)

containsKey

public boolean containsKey(String name)

getStringField

public String getStringField(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.

getStringField

public String getStringField(Buffer 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.

get

public Buffer get(Buffer 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 Enumeration getValues(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 Enumeration getValues(Buffer name)
Get multi headers

Parameters:
name - the case-insensitive field name
Returns:
Enumeration of the value Strings, or null if no such header.

getValues

public Enumeration getValues(String name,
                             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 void put(String name,
                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(Buffer name,
                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(Buffer name,
                Buffer 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(Buffer name,
                Buffer value,
                long numValue)
Set a field.

Parameters:
name - the name of the field
value - the value of the field. If null the field is cleared.
numValue - the numeric value of the field (must match value) or -1

put

public void put(String name,
                List list)
Set a field.

Parameters:
name - the name of the field
list - the List value of the field. If null the field is cleared.

add

public void add(String name,
                String value)
         throws 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:
IllegalArgumentException - If the name is a single valued field and already has a value.

add

public void add(Buffer name,
                Buffer value)
         throws 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:
IllegalArgumentException - If the name is a single valued field and already has a value.

remove

public void remove(String name)
Remove a field.

Parameters:
name -

remove

public void remove(Buffer name)
Remove a field.

Parameters:
name -

getLongField

public long getLongField(String name)
                  throws NumberFormatException
Get a header as an long 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:
NumberFormatException - If bad long found

getLongField

public long getLongField(Buffer name)
                  throws NumberFormatException
Get a header as an long 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:
NumberFormatException - If bad long found

getDateField

public long getDateField(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

putLongField

public void putLongField(Buffer name,
                         long value)
Sets the value of an long field.

Parameters:
name - the field name
value - the field long value

putLongField

public void putLongField(String name,
                         long value)
Sets the value of an long field.

Parameters:
name - the field name
value - the field long value

addLongField

public void addLongField(String name,
                         long value)
Sets the value of an long field.

Parameters:
name - the field name
value - the field long value

addLongField

public void addLongField(Buffer name,
                         long value)
Sets the value of an long field.

Parameters:
name - the field name
value - the field long value

putDateField

public void putDateField(Buffer name,
                         long date)
Sets the value of a date field.

Parameters:
name - the field name
date - the field date value

putDateField

public void putDateField(String name,
                         long date)
Sets the value of a date field.

Parameters:
name - the field name
date - the field date value

addDateField

public void addDateField(String name,
                         long date)
Sets the value of a date field.

Parameters:
name - the field name
date - the field date value

addSetCookie

public void addSetCookie(Cookie cookie)
Format a set cookie value

Parameters:
cookie - The cookie.
cookie2 - If true, use the alternate cookie 2 header

put

public void put(Buffer buffer)
         throws IOException
Throws:
IOException

toString

public String toString()
Overrides:
toString in class Object

clear

public void clear()
Clear the header.


destroy

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


add

public void add(HttpFields fields)
Add fields from another HttpFields instance. Single valued fields are replaced, while all others are added.

Parameters:
fields -

valueParameters

public static String valueParameters(String value,
                                     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 Float getQuality(String value)

qualityList

public static List qualityList(Enumeration e)
List values in quality order.

Parameters:
enum - Enumeration of values with quality parameters
Returns:
values in quality order.


Copyright © 1995-2009 Mort Bay Consulting. All Rights Reserved.