Methods Summary |
---|
protected org.apache.http.HeaderElement | createHeaderElement(java.lang.String name, java.lang.String value, org.apache.http.NameValuePair[] params)Creates a header element.
Called from {@link #parseHeaderElement}.
return new BasicHeaderElement(name, value, params);
|
protected org.apache.http.NameValuePair | createNameValuePair(java.lang.String name, java.lang.String value)Creates a name-value pair.
Called from {@link #parseNameValuePair}.
return new BasicNameValuePair(name, value);
|
private static boolean | isOneOf(char ch, char[] chs)
if (chs != null) {
for (int i = 0; i < chs.length; i++) {
if (ch == chs[i]) {
return true;
}
}
}
return false;
|
public static final org.apache.http.HeaderElement[] | parseElements(java.lang.String value, org.apache.http.message.HeaderValueParser parser)Parses elements with the given parser.
// public default constructor
if (value == null) {
throw new IllegalArgumentException
("Value to parse may not be null");
}
if (parser == null)
parser = BasicHeaderValueParser.DEFAULT;
CharArrayBuffer buffer = new CharArrayBuffer(value.length());
buffer.append(value);
ParserCursor cursor = new ParserCursor(0, value.length());
return parser.parseElements(buffer, cursor);
|
public org.apache.http.HeaderElement[] | parseElements(org.apache.http.util.CharArrayBuffer buffer, org.apache.http.message.ParserCursor cursor)
if (buffer == null) {
throw new IllegalArgumentException("Char array buffer may not be null");
}
if (cursor == null) {
throw new IllegalArgumentException("Parser cursor may not be null");
}
List elements = new ArrayList();
while (!cursor.atEnd()) {
HeaderElement element = parseHeaderElement(buffer, cursor);
if (!(element.getName().length() == 0 && element.getValue() == null)) {
elements.add(element);
}
}
return (HeaderElement[])
elements.toArray(new HeaderElement[elements.size()]);
|
public static final org.apache.http.HeaderElement | parseHeaderElement(java.lang.String value, org.apache.http.message.HeaderValueParser parser)Parses an element with the given parser.
if (value == null) {
throw new IllegalArgumentException
("Value to parse may not be null");
}
if (parser == null)
parser = BasicHeaderValueParser.DEFAULT;
CharArrayBuffer buffer = new CharArrayBuffer(value.length());
buffer.append(value);
ParserCursor cursor = new ParserCursor(0, value.length());
return parser.parseHeaderElement(buffer, cursor);
|
public org.apache.http.HeaderElement | parseHeaderElement(org.apache.http.util.CharArrayBuffer buffer, org.apache.http.message.ParserCursor cursor)
if (buffer == null) {
throw new IllegalArgumentException("Char array buffer may not be null");
}
if (cursor == null) {
throw new IllegalArgumentException("Parser cursor may not be null");
}
NameValuePair nvp = parseNameValuePair(buffer, cursor);
NameValuePair[] params = null;
if (!cursor.atEnd()) {
char ch = buffer.charAt(cursor.getPos() - 1);
if (ch != ELEM_DELIMITER) {
params = parseParameters(buffer, cursor);
}
}
return createHeaderElement(nvp.getName(), nvp.getValue(), params);
|
public org.apache.http.NameValuePair | parseNameValuePair(org.apache.http.util.CharArrayBuffer buffer, org.apache.http.message.ParserCursor cursor, char[] delimiters)
if (buffer == null) {
throw new IllegalArgumentException("Char array buffer may not be null");
}
if (cursor == null) {
throw new IllegalArgumentException("Parser cursor may not be null");
}
boolean terminated = false;
int pos = cursor.getPos();
int indexFrom = cursor.getPos();
int indexTo = cursor.getUpperBound();
// Find name
String name = null;
while (pos < indexTo) {
char ch = buffer.charAt(pos);
if (ch == '=") {
break;
}
if (isOneOf(ch, delimiters)) {
terminated = true;
break;
}
pos++;
}
if (pos == indexTo) {
terminated = true;
name = buffer.substringTrimmed(indexFrom, indexTo);
} else {
name = buffer.substringTrimmed(indexFrom, pos);
pos++;
}
if (terminated) {
cursor.updatePos(pos);
return createNameValuePair(name, null);
}
// Find value
String value = null;
int i1 = pos;
boolean qouted = false;
boolean escaped = false;
while (pos < indexTo) {
char ch = buffer.charAt(pos);
if (ch == '"" && !escaped) {
qouted = !qouted;
}
if (!qouted && !escaped && isOneOf(ch, delimiters)) {
terminated = true;
break;
}
if (escaped) {
escaped = false;
} else {
escaped = qouted && ch == '\\";
}
pos++;
}
int i2 = pos;
// Trim leading white spaces
while (i1 < i2 && (HTTP.isWhitespace(buffer.charAt(i1)))) {
i1++;
}
// Trim trailing white spaces
while ((i2 > i1) && (HTTP.isWhitespace(buffer.charAt(i2 - 1)))) {
i2--;
}
// Strip away quotes if necessary
if (((i2 - i1) >= 2)
&& (buffer.charAt(i1) == '"")
&& (buffer.charAt(i2 - 1) == '"")) {
i1++;
i2--;
}
value = buffer.substring(i1, i2);
if (terminated) {
pos++;
}
cursor.updatePos(pos);
return createNameValuePair(name, value);
|
public static final org.apache.http.NameValuePair | parseNameValuePair(java.lang.String value, org.apache.http.message.HeaderValueParser parser)Parses a name-value-pair with the given parser.
if (value == null) {
throw new IllegalArgumentException
("Value to parse may not be null");
}
if (parser == null)
parser = BasicHeaderValueParser.DEFAULT;
CharArrayBuffer buffer = new CharArrayBuffer(value.length());
buffer.append(value);
ParserCursor cursor = new ParserCursor(0, value.length());
return parser.parseNameValuePair(buffer, cursor);
|
public org.apache.http.NameValuePair | parseNameValuePair(org.apache.http.util.CharArrayBuffer buffer, org.apache.http.message.ParserCursor cursor)
return parseNameValuePair(buffer, cursor, ALL_DELIMITERS);
|
public static final org.apache.http.NameValuePair[] | parseParameters(java.lang.String value, org.apache.http.message.HeaderValueParser parser)Parses parameters with the given parser.
if (value == null) {
throw new IllegalArgumentException
("Value to parse may not be null");
}
if (parser == null)
parser = BasicHeaderValueParser.DEFAULT;
CharArrayBuffer buffer = new CharArrayBuffer(value.length());
buffer.append(value);
ParserCursor cursor = new ParserCursor(0, value.length());
return parser.parseParameters(buffer, cursor);
|
public org.apache.http.NameValuePair[] | parseParameters(org.apache.http.util.CharArrayBuffer buffer, org.apache.http.message.ParserCursor cursor)
if (buffer == null) {
throw new IllegalArgumentException("Char array buffer may not be null");
}
if (cursor == null) {
throw new IllegalArgumentException("Parser cursor may not be null");
}
int pos = cursor.getPos();
int indexTo = cursor.getUpperBound();
while (pos < indexTo) {
char ch = buffer.charAt(pos);
if (HTTP.isWhitespace(ch)) {
pos++;
} else {
break;
}
}
cursor.updatePos(pos);
if (cursor.atEnd()) {
return new NameValuePair[] {};
}
List params = new ArrayList();
while (!cursor.atEnd()) {
NameValuePair param = parseNameValuePair(buffer, cursor);
params.add(param);
char ch = buffer.charAt(cursor.getPos() - 1);
if (ch == ELEM_DELIMITER) {
break;
}
}
return (NameValuePair[])
params.toArray(new NameValuePair[params.size()]);
|