01: // HttpAcceptEncodingList.java
02: // $Id: HttpAcceptEncodingList.java,v 1.2 2000/08/16 21:37:59 ylafon Exp $
03: // (c) COPYRIGHT MIT and INRIA, 1998.
04: // Please first read the full copyright statement in file COPYRIGHT.html
05:
06: package org.w3c.www.http;
07:
08: import java.util.Vector;
09:
10: public class HttpAcceptEncodingList extends BasicValue {
11: HttpAcceptEncoding encodings[] = null;
12:
13: protected void parse() {
14: Vector vl = new Vector(4);
15: ParseState ps = new ParseState(roff, rlen);
16: ps.separator = (byte) ',';
17: ps.spaceIsSep = false;
18: while (HttpParser.nextItem(raw, ps) >= 0) {
19: vl.addElement(new HttpAcceptEncoding(this , raw, ps.start,
20: ps.end));
21: ps.prepare();
22: }
23: encodings = new HttpAcceptEncoding[vl.size()];
24: vl.copyInto(encodings);
25: }
26:
27: protected void updateByteValue() {
28: HttpBuffer buf = new HttpBuffer();
29: if (encodings == null) {
30: for (int i = 0; i < encodings.length; i++) {
31: if (i > 0)
32: buf.append(',');
33: encodings[i].appendValue(buf);
34: }
35: raw = buf.getByteCopy();
36: roff = 0;
37: rlen = raw.length;
38: } else {
39: raw = new byte[0];
40: roff = 0;
41: rlen = 0;
42: }
43: }
44:
45: public Object getValue() {
46: validate();
47: return encodings;
48: }
49:
50: /**
51: * Add a clause to that list of accepted encodings.
52: * @param lang The accepted encoding.
53: */
54:
55: public void addEncoding(HttpAcceptEncoding enc) {
56: if (encodings == null) {
57: encodings = new HttpAcceptEncoding[1];
58: encodings[0] = enc;
59: } else {
60: int len = encodings.length;
61: HttpAcceptEncoding newenc[] = new HttpAcceptEncoding[len + 1];
62: System.arraycopy(encodings, 0, newenc, 0, len);
63: newenc[len] = enc;
64: encodings = newenc;
65: }
66: }
67:
68: HttpAcceptEncodingList() {
69: this .isValid = false;
70: }
71:
72: HttpAcceptEncodingList(HttpAcceptEncoding encodings[]) {
73: this .encodings = encodings;
74: this .isValid = true;
75: }
76:
77: }
|