01: // HttpAcceptList.java
02: // $Id: HttpAcceptList.java,v 1.7 2000/08/16 21:37:59 ylafon Exp $
03: // (c) COPYRIGHT MIT and INRIA, 1996.
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 HttpAcceptList extends BasicValue {
11: HttpAccept accept[] = null;
12:
13: protected void parse() {
14: Vector va = 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: HttpAccept a = new HttpAccept(this , raw, ps.start, ps.end);
20: va.addElement(a);
21: ps.prepare();
22: }
23: accept = new HttpAccept[va.size()];
24: va.copyInto(accept);
25: }
26:
27: protected void updateByteValue() {
28: HttpBuffer buf = new HttpBuffer();
29: if (accept != null) {
30: for (int i = 0; i < accept.length; i++) {
31: if (i > 0)
32: buf.append(',');
33: accept[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 accept;
48: }
49:
50: /**
51: * Add an accept clause to that list.
52: * @param a The new accept clause, as an instance of HttpAccept.
53: */
54:
55: public void addAccept(HttpAccept a) {
56: if (accept == null) {
57: accept = new HttpAccept[1];
58: accept[0] = a;
59: } else {
60: HttpAccept newacc[] = new HttpAccept[accept.length + 1];
61: System.arraycopy(accept, 0, newacc, 0, accept.length);
62: newacc[accept.length] = a;
63: accept = newacc;
64: }
65: }
66:
67: HttpAcceptList() {
68: this .isValid = false;
69: }
70:
71: HttpAcceptList(HttpAccept accept[]) {
72: this .isValid = true;
73: this.accept = accept;
74: }
75:
76: }
|