FileDocCategorySizeDatePackage
BasicHeaderElement.javaAPI DocAndroid 1.5 API7855Wed May 06 22:41:10 BST 2009org.apache.http.message

BasicHeaderElement

public class BasicHeaderElement extends Object implements HeaderElement, Cloneable
One element of an HTTP header's value.

Some HTTP headers (such as the set-cookie header) have values that can be decomposed into multiple elements. Such headers must be in the following form:

header = [ element ] *( "," [ element ] )
element = name [ "=" [ value ] ] *( ";" [ param ] )
param = name [ "=" [ value ] ]

name = token
value = ( token | quoted-string )

token = 1*<any char except "=", ",", ";", <"> and
white space>
quoted-string = <"> *( text | quoted-char ) <">
text = any char except <">
quoted-char = "\" char

Any amount of white space is allowed between any part of the header, element or param and is ignored. A missing value in any element or param will be stored as the empty {@link String}; if the "=" is also missing null will be stored instead.

This class represents an individual header element, containing both a name/value pair (value may be null) and optionally a set of additional parameters.

author
B.C. Holmes
author
Park, Sung-Gu
author
Mike Bowler
author
Oleg Kalnichevski
version
$Revision: 604625 $ $Date: 2007-12-16 06:11:11 -0800 (Sun, 16 Dec 2007) $
since
4.0

Fields Summary
private final String
name
private final String
value
private final NameValuePair[]
parameters
Constructors Summary
public BasicHeaderElement(String name, String value, NameValuePair[] parameters)
Constructor with name, value and parameters.

param
name header element name
param
value header element value. May be null
param
parameters header element parameters. May be null. Parameters are copied by reference, not by value

        super();
        if (name == null) {
            throw new IllegalArgumentException("Name may not be null");
        }
        this.name = name;
        this.value = value;
        if (parameters != null) {
            this.parameters = parameters;
        } else {
            this.parameters = new NameValuePair[] {};
        }
    
public BasicHeaderElement(String name, String value)
Constructor with name and value.

param
name header element name
param
value header element value. May be null

       this(name, value, null);
    
Methods Summary
public java.lang.Objectclone()

        // parameters array is considered immutable
        // no need to make a copy of it
        return super.clone();
    
public booleanequals(java.lang.Object object)

        if (object == null) return false;
        if (this == object) return true;
        if (object instanceof HeaderElement) {
            BasicHeaderElement that = (BasicHeaderElement) object;
            return this.name.equals(that.name)
                && LangUtils.equals(this.value, that.value)
                && LangUtils.equals(this.parameters, that.parameters);
        } else {
            return false;
        }
    
public java.lang.StringgetName()
Returns the name.

return
String name The name

        return this.name;
    
public org.apache.http.NameValuePairgetParameter(int index)
Obtains the parameter with the given index.

param
index the index of the parameter, 0-based
return
the parameter with the given index

        // ArrayIndexOutOfBoundsException is appropriate
        return this.parameters[index];
    
public org.apache.http.NameValuePairgetParameterByName(java.lang.String name)
Returns parameter with the given name, if found. Otherwise null is returned

param
name The name to search by.
return
NameValuePair parameter with the given name

        if (name == null) {
            throw new IllegalArgumentException("Name may not be null");
        } 
        NameValuePair found = null;
        for (int i = 0; i < this.parameters.length; i++) {
            NameValuePair current = this.parameters[ i ];
            if (current.getName().equalsIgnoreCase(name)) {
                found = current;
                break;
            }
        }
        return found;
    
public intgetParameterCount()
Obtains the number of parameters.

return
the number of parameters

        return this.parameters.length;
    
public org.apache.http.NameValuePair[]getParameters()
Get parameters, if any. The returned array is created for each invocation and can be modified by the caller without affecting this header element.

return
parameters as an array of {@link NameValuePair}s

        return (NameValuePair[])this.parameters.clone();
    
public java.lang.StringgetValue()
Returns the value.

return
String value The current value.

        return this.value;
    
public inthashCode()

        int hash = LangUtils.HASH_SEED;
        hash = LangUtils.hashCode(hash, this.name);
        hash = LangUtils.hashCode(hash, this.value);
        for (int i = 0; i < this.parameters.length; i++) {
            hash = LangUtils.hashCode(hash, this.parameters[i]);
        }
        return hash;
    
public java.lang.StringtoString()

        CharArrayBuffer buffer = new CharArrayBuffer(64);
        buffer.append(this.name);
        if (this.value != null) {
            buffer.append("=");
            buffer.append(this.value);
        }
        for (int i = 0; i < this.parameters.length; i++) {
            buffer.append("; ");
            buffer.append(this.parameters[i]);
        }
        return buffer.toString();