01: // HttpAcceptCharsetList.java
02: // $Id: HttpAcceptCharsetList.java,v 1.6 2000/08/16 21:37:58 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 HttpAcceptCharsetList extends BasicValue {
11: HttpAcceptCharset charsets[] = 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 HttpAcceptCharset(this , raw, ps.start,
20: ps.end));
21: ps.prepare();
22: }
23: charsets = new HttpAcceptCharset[vl.size()];
24: vl.copyInto(charsets);
25: }
26:
27: protected void updateByteValue() {
28: HttpBuffer buf = new HttpBuffer();
29: if (charsets != null) {
30: for (int i = 0; i < charsets.length; i++) {
31: if (i > 0)
32: buf.append(',');
33: charsets[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 charsets;
48: }
49:
50: /**
51: * Add an accpted charset clause to the list.
52: * @param charset The new accepted charset clause.
53: */
54:
55: public void addCharset(HttpAcceptCharset charset) {
56: if (charsets == null) {
57: charsets = new HttpAcceptCharset[1];
58: charsets[0] = charset;
59: } else {
60: int len = charsets.length;
61: HttpAcceptCharset newset[] = new HttpAcceptCharset[len + 1];
62: System.arraycopy(charsets, 0, newset, 0, len);
63: newset[len] = charset;
64: charsets = newset;
65: }
66: }
67:
68: HttpAcceptCharsetList() {
69: this .isValid = false;
70: }
71:
72: HttpAcceptCharsetList(HttpAcceptCharset charsets[]) {
73: this.isValid = isValid;
74: this.charsets = charsets;
75: }
76:
77: }
|