org.apache.commons.httpclient
public class: HeaderElement [javadoc |
source]
java.lang.Object
org.apache.commons.httpclient.NameValuePair
org.apache.commons.httpclient.HeaderElement
All Implemented Interfaces:
Serializable
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 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.
This class also exposes a #parse method for parsing a
Header value into an array of elements.
Also see:
- Header
- author:
< - a href="mailto:bcholmes@interlog.com">B.C. Holmes
- author:
< - a href="mailto:jericho@thinkfree.com">Park, Sung-Gu
- author:
< - a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler
- author:
< - a href="mailto:oleg@ural.com">Oleg Kalnichevski
- since:
1.0 -
- version:
$ - Revision: 480424 $ $Date: 2006-11-29 06:56:49 +0100 (Wed, 29 Nov 2006) $
| Constructor: |
public HeaderElement() {
this(null, null, null);
}
|
public HeaderElement(char[] chars) {
this(chars, 0, chars.length);
}
Constructor with array of characters. Parameters:
chars - the array of characters
- since:
3.0 -
|
public HeaderElement(String name,
String value) {
this(name, value, null);
}
Parameters:
name - my name
value - my (possibly null) value
|
public HeaderElement(String name,
String value,
NameValuePair[] parameters) {
super(name, value);
this.parameters = parameters;
}
Constructor with name, value and parameters. Parameters:
name - my name
value - my (possibly null) value
parameters - my (possibly null) parameters
|
public HeaderElement(char[] chars,
int offset,
int length) {
this();
if (chars == null) {
return;
}
ParameterParser parser = new ParameterParser();
List params = parser.parse(chars, offset, length, ';");
if (params.size() > 0) {
NameValuePair element = (NameValuePair) params.remove(0);
setName(element.getName());
setValue(element.getValue());
if (params.size() > 0) {
this.parameters = (NameValuePair[])
params.toArray(new NameValuePair[params.size()]);
}
}
}
Constructor with array of characters. Parameters:
chars - the array of characters
offset - - the initial offset.
length - - the length.
- since:
3.0 -
|
| Method from org.apache.commons.httpclient.HeaderElement Detail: |
public NameValuePair getParameterByName(String name) {
LOG.trace("enter HeaderElement.getParameterByName(String)");
if (name == null) {
throw new IllegalArgumentException("Name may not be null");
}
NameValuePair found = null;
NameValuePair parameters[] = getParameters();
if (parameters != null) {
for (int i = 0; i < parameters.length; i++) {
NameValuePair current = parameters[ i ];
if (current.getName().equalsIgnoreCase(name)) {
found = current;
break;
}
}
}
return found;
}
Returns parameter with the given name, if found. Otherwise null
is returned |
public NameValuePair[] getParameters() {
// ------------------------------------------------------------- Properties
return this.parameters;
}
|
public static final HeaderElement[] parse(String headerValue) throws HttpException {
LOG.trace("enter HeaderElement.parse(String)");
if (headerValue == null) {
return new HeaderElement[] {};
}
return parseElements(headerValue.toCharArray());
} Deprecated! Use - #parseElements(String).
This parses the value part of a header. The result is an array of
HeaderElement objects. |
public static final HeaderElement[] parseElements(char[] headerValue) {
LOG.trace("enter HeaderElement.parseElements(char[])");
if (headerValue == null) {
return new HeaderElement[] {};
}
List elements = new ArrayList();
int i = 0;
int from = 0;
int len = headerValue.length;
boolean qouted = false;
while (i < len) {
char ch = headerValue[i];
if (ch == '"") {
qouted = !qouted;
}
HeaderElement element = null;
if ((!qouted) && (ch == ',")) {
element = new HeaderElement(headerValue, from, i);
from = i + 1;
} else if (i == len - 1) {
element = new HeaderElement(headerValue, from, len);
}
if ((element != null) && (element.getName() != null)) {
elements.add(element);
}
i++;
}
return (HeaderElement[])
elements.toArray(new HeaderElement[elements.size()]);
}
This parses the value part of a header. The result is an array of
HeaderElement objects. |
public static final HeaderElement[] parseElements(String headerValue) {
LOG.trace("enter HeaderElement.parseElements(String)");
if (headerValue == null) {
return new HeaderElement[] {};
}
return parseElements(headerValue.toCharArray());
}
This parses the value part of a header. The result is an array of
HeaderElement objects. |