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